/mojoPortal.Data.MySql/DBCategoryItem.cs
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
- // Author: Joe Audette
- // Created: 2011-10-30
- // Last Modified: 2012-07-20
- //
- // The use and distribution terms for this software are covered by the
- // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
- // which can be found in the file CPL.TXT at the root of this distribution.
- // By using this software in any fashion, you are agreeing to be bound by
- // the terms of this license.
- //
- // You must not remove this notice, or any other, from this software.
-
- using System;
- using System.Text;
- using System.Data;
- using System.Data.Common;
- using System.Configuration;
- using System.Globalization;
- using System.IO;
- using MySql.Data.MySqlClient;
-
- namespace mojoPortal.Data
- {
-
- public static class DBCategoryItem
- {
- /// <summary>
- /// Inserts a row in the mp_CategoryItem table. Returns rows affected count.
- /// </summary>
- /// <param name="guid"> guid </param>
- /// <param name="siteGuid"> siteGuid </param>
- /// <param name="featureGuid"> featureGuid </param>
- /// <param name="moduleGuid"> moduleGuid </param>
- /// <param name="itemGuid"> itemGuid </param>
- /// <param name="categoryGuid"> categoryGuid </param>
- /// <param name="extraGuid"> extraGuid </param>
- /// <returns>int</returns>
- public static int Create(
- Guid guid,
- Guid siteGuid,
- Guid featureGuid,
- Guid moduleGuid,
- Guid itemGuid,
- Guid categoryGuid,
- Guid extraGuid)
- {
-
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("INSERT INTO mp_CategoryItem (");
- sqlCommand.Append("Guid, ");
- sqlCommand.Append("SiteGuid, ");
- sqlCommand.Append("FeatureGuid, ");
- sqlCommand.Append("ModuleGuid, ");
- sqlCommand.Append("ItemGuid, ");
- sqlCommand.Append("CategoryGuid, ");
- sqlCommand.Append("ExtraGuid )");
-
- sqlCommand.Append(" VALUES (");
- sqlCommand.Append("?Guid, ");
- sqlCommand.Append("?SiteGuid, ");
- sqlCommand.Append("?FeatureGuid, ");
- sqlCommand.Append("?ModuleGuid, ");
- sqlCommand.Append("?ItemGuid, ");
- sqlCommand.Append("?CategoryGuid, ");
- sqlCommand.Append("?ExtraGuid )");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[7];
-
- arParams[0] = new MySqlParameter("?Guid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = guid.ToString();
-
- arParams[1] = new MySqlParameter("?SiteGuid", MySqlDbType.VarChar, 36);
- arParams[1].Direction = ParameterDirection.Input;
- arParams[1].Value = siteGuid.ToString();
-
- arParams[2] = new MySqlParameter("?FeatureGuid", MySqlDbType.VarChar, 36);
- arParams[2].Direction = ParameterDirection.Input;
- arParams[2].Value = featureGuid.ToString();
-
- arParams[3] = new MySqlParameter("?ModuleGuid", MySqlDbType.VarChar, 36);
- arParams[3].Direction = ParameterDirection.Input;
- arParams[3].Value = moduleGuid.ToString();
-
- arParams[4] = new MySqlParameter("?ItemGuid", MySqlDbType.VarChar, 36);
- arParams[4].Direction = ParameterDirection.Input;
- arParams[4].Value = itemGuid.ToString();
-
- arParams[5] = new MySqlParameter("?CategoryGuid", MySqlDbType.VarChar, 36);
- arParams[5].Direction = ParameterDirection.Input;
- arParams[5].Value = categoryGuid.ToString();
-
- arParams[6] = new MySqlParameter("?ExtraGuid", MySqlDbType.VarChar, 36);
- arParams[6].Direction = ParameterDirection.Input;
- arParams[6].Value = extraGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return rowsAffected;
-
- }
-
-
-
-
- /// <summary>
- /// Deletes a row from the mp_CategoryItem table. Returns true if row deleted.
- /// </summary>
- /// <param name="guid"> guid </param>
- /// <returns>bool</returns>
- public static bool Delete(Guid guid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("Guid = ?Guid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?Guid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = guid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
-
- }
-
- public static bool DeleteByItem(Guid itemGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("ItemGuid = ?ItemGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?ItemGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = itemGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
-
- public static bool DeleteByExtraGuid(Guid extraGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("ExtraGuid = ?ExtraGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?ExtraGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = extraGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
-
- public static bool DeleteByCategory(Guid categoryGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("CategoryGuid = ?CategoryGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?CategoryGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = categoryGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
-
- public static bool DeleteByModule(Guid moduleGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("ModuleGuid = ?ModuleGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?ModuleGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = moduleGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
-
- public static bool DeleteByFeature(Guid featureGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("FeatureGuid = ?FeatureGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?FeatureGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = featureGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
-
- public static bool DeleteBySite(Guid siteGuid)
- {
- StringBuilder sqlCommand = new StringBuilder();
- sqlCommand.Append("DELETE FROM mp_CategoryItem ");
- sqlCommand.Append("WHERE ");
- sqlCommand.Append("SiteGuid = ?SiteGuid ");
- sqlCommand.Append(";");
-
- MySqlParameter[] arParams = new MySqlParameter[1];
-
- arParams[0] = new MySqlParameter("?SiteGuid", MySqlDbType.VarChar, 36);
- arParams[0].Direction = ParameterDirection.Input;
- arParams[0].Value = siteGuid.ToString();
-
- int rowsAffected = MySqlHelper.ExecuteNonQuery(
- ConnectionString.GetWriteConnectionString(),
- sqlCommand.ToString(),
- arParams);
-
- return (rowsAffected > 0);
- }
- }
- }