PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mojoPortal.Data.MySql/DBCategoryItem.cs

http://mojoportal.codeplex.com
C# | 270 lines | 188 code | 55 blank | 27 comment | 0 complexity | a4d16e9d6a540d3f1f0b22acb148401f MD5 | raw file
Possible License(s): CPL-1.0, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause, Apache-2.0
  1. // Author: Joe Audette
  2. // Created: 2011-10-30
  3. // Last Modified: 2012-07-20
  4. //
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. using System;
  13. using System.Text;
  14. using System.Data;
  15. using System.Data.Common;
  16. using System.Configuration;
  17. using System.Globalization;
  18. using System.IO;
  19. using MySql.Data.MySqlClient;
  20. namespace mojoPortal.Data
  21. {
  22. public static class DBCategoryItem
  23. {
  24. /// <summary>
  25. /// Inserts a row in the mp_CategoryItem table. Returns rows affected count.
  26. /// </summary>
  27. /// <param name="guid"> guid </param>
  28. /// <param name="siteGuid"> siteGuid </param>
  29. /// <param name="featureGuid"> featureGuid </param>
  30. /// <param name="moduleGuid"> moduleGuid </param>
  31. /// <param name="itemGuid"> itemGuid </param>
  32. /// <param name="categoryGuid"> categoryGuid </param>
  33. /// <param name="extraGuid"> extraGuid </param>
  34. /// <returns>int</returns>
  35. public static int Create(
  36. Guid guid,
  37. Guid siteGuid,
  38. Guid featureGuid,
  39. Guid moduleGuid,
  40. Guid itemGuid,
  41. Guid categoryGuid,
  42. Guid extraGuid)
  43. {
  44. StringBuilder sqlCommand = new StringBuilder();
  45. sqlCommand.Append("INSERT INTO mp_CategoryItem (");
  46. sqlCommand.Append("Guid, ");
  47. sqlCommand.Append("SiteGuid, ");
  48. sqlCommand.Append("FeatureGuid, ");
  49. sqlCommand.Append("ModuleGuid, ");
  50. sqlCommand.Append("ItemGuid, ");
  51. sqlCommand.Append("CategoryGuid, ");
  52. sqlCommand.Append("ExtraGuid )");
  53. sqlCommand.Append(" VALUES (");
  54. sqlCommand.Append("?Guid, ");
  55. sqlCommand.Append("?SiteGuid, ");
  56. sqlCommand.Append("?FeatureGuid, ");
  57. sqlCommand.Append("?ModuleGuid, ");
  58. sqlCommand.Append("?ItemGuid, ");
  59. sqlCommand.Append("?CategoryGuid, ");
  60. sqlCommand.Append("?ExtraGuid )");
  61. sqlCommand.Append(";");
  62. MySqlParameter[] arParams = new MySqlParameter[7];
  63. arParams[0] = new MySqlParameter("?Guid", MySqlDbType.VarChar, 36);
  64. arParams[0].Direction = ParameterDirection.Input;
  65. arParams[0].Value = guid.ToString();
  66. arParams[1] = new MySqlParameter("?SiteGuid", MySqlDbType.VarChar, 36);
  67. arParams[1].Direction = ParameterDirection.Input;
  68. arParams[1].Value = siteGuid.ToString();
  69. arParams[2] = new MySqlParameter("?FeatureGuid", MySqlDbType.VarChar, 36);
  70. arParams[2].Direction = ParameterDirection.Input;
  71. arParams[2].Value = featureGuid.ToString();
  72. arParams[3] = new MySqlParameter("?ModuleGuid", MySqlDbType.VarChar, 36);
  73. arParams[3].Direction = ParameterDirection.Input;
  74. arParams[3].Value = moduleGuid.ToString();
  75. arParams[4] = new MySqlParameter("?ItemGuid", MySqlDbType.VarChar, 36);
  76. arParams[4].Direction = ParameterDirection.Input;
  77. arParams[4].Value = itemGuid.ToString();
  78. arParams[5] = new MySqlParameter("?CategoryGuid", MySqlDbType.VarChar, 36);
  79. arParams[5].Direction = ParameterDirection.Input;
  80. arParams[5].Value = categoryGuid.ToString();
  81. arParams[6] = new MySqlParameter("?ExtraGuid", MySqlDbType.VarChar, 36);
  82. arParams[6].Direction = ParameterDirection.Input;
  83. arParams[6].Value = extraGuid.ToString();
  84. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  85. ConnectionString.GetWriteConnectionString(),
  86. sqlCommand.ToString(),
  87. arParams);
  88. return rowsAffected;
  89. }
  90. /// <summary>
  91. /// Deletes a row from the mp_CategoryItem table. Returns true if row deleted.
  92. /// </summary>
  93. /// <param name="guid"> guid </param>
  94. /// <returns>bool</returns>
  95. public static bool Delete(Guid guid)
  96. {
  97. StringBuilder sqlCommand = new StringBuilder();
  98. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  99. sqlCommand.Append("WHERE ");
  100. sqlCommand.Append("Guid = ?Guid ");
  101. sqlCommand.Append(";");
  102. MySqlParameter[] arParams = new MySqlParameter[1];
  103. arParams[0] = new MySqlParameter("?Guid", MySqlDbType.VarChar, 36);
  104. arParams[0].Direction = ParameterDirection.Input;
  105. arParams[0].Value = guid.ToString();
  106. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  107. ConnectionString.GetWriteConnectionString(),
  108. sqlCommand.ToString(),
  109. arParams);
  110. return (rowsAffected > 0);
  111. }
  112. public static bool DeleteByItem(Guid itemGuid)
  113. {
  114. StringBuilder sqlCommand = new StringBuilder();
  115. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  116. sqlCommand.Append("WHERE ");
  117. sqlCommand.Append("ItemGuid = ?ItemGuid ");
  118. sqlCommand.Append(";");
  119. MySqlParameter[] arParams = new MySqlParameter[1];
  120. arParams[0] = new MySqlParameter("?ItemGuid", MySqlDbType.VarChar, 36);
  121. arParams[0].Direction = ParameterDirection.Input;
  122. arParams[0].Value = itemGuid.ToString();
  123. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  124. ConnectionString.GetWriteConnectionString(),
  125. sqlCommand.ToString(),
  126. arParams);
  127. return (rowsAffected > 0);
  128. }
  129. public static bool DeleteByExtraGuid(Guid extraGuid)
  130. {
  131. StringBuilder sqlCommand = new StringBuilder();
  132. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  133. sqlCommand.Append("WHERE ");
  134. sqlCommand.Append("ExtraGuid = ?ExtraGuid ");
  135. sqlCommand.Append(";");
  136. MySqlParameter[] arParams = new MySqlParameter[1];
  137. arParams[0] = new MySqlParameter("?ExtraGuid", MySqlDbType.VarChar, 36);
  138. arParams[0].Direction = ParameterDirection.Input;
  139. arParams[0].Value = extraGuid.ToString();
  140. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  141. ConnectionString.GetWriteConnectionString(),
  142. sqlCommand.ToString(),
  143. arParams);
  144. return (rowsAffected > 0);
  145. }
  146. public static bool DeleteByCategory(Guid categoryGuid)
  147. {
  148. StringBuilder sqlCommand = new StringBuilder();
  149. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  150. sqlCommand.Append("WHERE ");
  151. sqlCommand.Append("CategoryGuid = ?CategoryGuid ");
  152. sqlCommand.Append(";");
  153. MySqlParameter[] arParams = new MySqlParameter[1];
  154. arParams[0] = new MySqlParameter("?CategoryGuid", MySqlDbType.VarChar, 36);
  155. arParams[0].Direction = ParameterDirection.Input;
  156. arParams[0].Value = categoryGuid.ToString();
  157. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  158. ConnectionString.GetWriteConnectionString(),
  159. sqlCommand.ToString(),
  160. arParams);
  161. return (rowsAffected > 0);
  162. }
  163. public static bool DeleteByModule(Guid moduleGuid)
  164. {
  165. StringBuilder sqlCommand = new StringBuilder();
  166. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  167. sqlCommand.Append("WHERE ");
  168. sqlCommand.Append("ModuleGuid = ?ModuleGuid ");
  169. sqlCommand.Append(";");
  170. MySqlParameter[] arParams = new MySqlParameter[1];
  171. arParams[0] = new MySqlParameter("?ModuleGuid", MySqlDbType.VarChar, 36);
  172. arParams[0].Direction = ParameterDirection.Input;
  173. arParams[0].Value = moduleGuid.ToString();
  174. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  175. ConnectionString.GetWriteConnectionString(),
  176. sqlCommand.ToString(),
  177. arParams);
  178. return (rowsAffected > 0);
  179. }
  180. public static bool DeleteByFeature(Guid featureGuid)
  181. {
  182. StringBuilder sqlCommand = new StringBuilder();
  183. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  184. sqlCommand.Append("WHERE ");
  185. sqlCommand.Append("FeatureGuid = ?FeatureGuid ");
  186. sqlCommand.Append(";");
  187. MySqlParameter[] arParams = new MySqlParameter[1];
  188. arParams[0] = new MySqlParameter("?FeatureGuid", MySqlDbType.VarChar, 36);
  189. arParams[0].Direction = ParameterDirection.Input;
  190. arParams[0].Value = featureGuid.ToString();
  191. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  192. ConnectionString.GetWriteConnectionString(),
  193. sqlCommand.ToString(),
  194. arParams);
  195. return (rowsAffected > 0);
  196. }
  197. public static bool DeleteBySite(Guid siteGuid)
  198. {
  199. StringBuilder sqlCommand = new StringBuilder();
  200. sqlCommand.Append("DELETE FROM mp_CategoryItem ");
  201. sqlCommand.Append("WHERE ");
  202. sqlCommand.Append("SiteGuid = ?SiteGuid ");
  203. sqlCommand.Append(";");
  204. MySqlParameter[] arParams = new MySqlParameter[1];
  205. arParams[0] = new MySqlParameter("?SiteGuid", MySqlDbType.VarChar, 36);
  206. arParams[0].Direction = ParameterDirection.Input;
  207. arParams[0].Value = siteGuid.ToString();
  208. int rowsAffected = MySqlHelper.ExecuteNonQuery(
  209. ConnectionString.GetWriteConnectionString(),
  210. sqlCommand.ToString(),
  211. arParams);
  212. return (rowsAffected > 0);
  213. }
  214. }
  215. }