PageRenderTime 37ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/v1.0/YxShop/YXShop.SQLServerDAL/Product/ProductBrand.cs

http://acexpo.codeplex.com
C# | 300 lines | 229 code | 15 blank | 56 comment | 18 complexity | e3fdb70c42d1e27ba03da112b951bb5d MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using YXShop.IDAL.Product;
  7. using System.Data;
  8. namespace YXShop.SQLServerDAL.Product
  9. {
  10. public class ProductBrand:IProductBrand
  11. {
  12. #region "DataBase Operation"
  13. /// <summary>
  14. /// ????
  15. /// </summary>
  16. /// <remarks></remarks>
  17. public int Add(YXShop.Model.Product.ProductBrand model)
  18. {
  19. SqlParameter[] paras = (SqlParameter[])this.ValueParas(model);
  20. string sequel = "Insert into [yxs_productbrand](";
  21. sequel = sequel + "[commontypes], [name], [image], [attirbute], [description], [sort], [isrecommend])";
  22. sequel = sequel + "Values(";
  23. sequel = sequel + "@commontypes, @name,@images,@attirbute,@description,@sort,@isrecommend) ;select @@IDENTITY ";
  24. object obj = ChangeHope.DataBase.SQLServerHelper.GetSingle(sequel, paras);
  25. if (obj == null)
  26. {
  27. return 0;
  28. }
  29. else
  30. {
  31. return Convert.ToInt32(obj);
  32. }
  33. }
  34. /// <summary>
  35. /// ????
  36. /// </summary>
  37. /// <remarks></remarks>
  38. public void Delete(int id)
  39. {
  40. string sequel = "Delete From [yxs_productbrand]" + this.UpdateWhereSequel;
  41. SqlParameter[] parameters = (SqlParameter[])this.ValueIDPara(id);
  42. ChangeHope.DataBase.SQLServerHelper.ExecuteSql(sequel, parameters);
  43. }
  44. /// <summary>
  45. /// ?????????????????, ???????
  46. /// </summary>
  47. /// <remarks></remarks>
  48. public int Amend(YXShop.Model.Product.ProductBrand model)
  49. {
  50. string sequel = "Update [yxs_productbrand] set ";
  51. sequel = sequel + "[commontypes] =@commontypes ,[name] =@name ,[image]=@images ,[attirbute] =@attirbute ,[description] =@description ,[sort] =@sort ,[isrecommend] =@isrecommend";
  52. sequel = sequel + UpdateWhereSequel;
  53. object obj = ChangeHope.DataBase.SQLServerHelper.ExecuteSql(sequel, (SqlParameter[])this.ValueParas(model));
  54. if (obj == null)
  55. {
  56. return 0;
  57. }
  58. else
  59. {
  60. return Convert.ToInt32(obj);
  61. }
  62. }
  63. /// <summary>
  64. /// ?????????
  65. /// </summary>
  66. /// <param name="uID"></param>
  67. /// <param name="columnName"></param>
  68. /// <param name="value"></param>
  69. /// <returns></returns>
  70. public int Amend(int id, string columnName, Object value)
  71. {
  72. string sequel = "Update [yxs_productbrand] set ";
  73. sequel = sequel + "[" + columnName + "] =@Value ";
  74. sequel = sequel + UpdateWhereSequel;
  75. SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@Value", value), new SqlParameter("@bid", id) };
  76. object obj = ChangeHope.DataBase.SQLServerHelper.GetSingle(sequel, paras);
  77. if (obj == null)
  78. {
  79. return 0;
  80. }
  81. else
  82. {
  83. return Convert.ToInt32(obj);
  84. }
  85. }
  86. #endregion
  87. #region "Data Load"
  88. /// <summary>
  89. /// ????
  90. /// </summary>
  91. /// <param name="row"></param>
  92. /// <returns></returns>
  93. public YXShop.Model.Product.ProductBrand GetModel(System.Data.DataRow row)
  94. {
  95. YXShop.Model.Product.ProductBrand model = new YXShop.Model.Product.ProductBrand();
  96. if (row != null)
  97. {
  98. model.ID = int.Parse(row["bid"].ToString());
  99. model.Name = row["name"].ToString();
  100. model.CommonTypes =int.Parse(row["commontypes"].ToString());
  101. model.Sort = int.Parse(row["sort"].ToString());
  102. model.Description = row["description"].ToString();
  103. model.Attirbute = row["attirbute"].ToString();
  104. model.Images = row["image"].ToString();
  105. model.Isrecommend = int.Parse(row["isrecommend"].ToString());
  106. return model;
  107. }
  108. else
  109. {
  110. return null;
  111. }
  112. }
  113. /// <summary>
  114. /// ID??
  115. /// </summary>
  116. /// <remarks></remarks>
  117. public YXShop.Model.Product.ProductBrand GetModelID(int id)
  118. {
  119. string sequel = SelectSequel + UpdateWhereSequel;
  120. SqlParameter[] paras = (SqlParameter[])this.ValueIDPara(id);
  121. DataSet ds = ChangeHope.DataBase.SQLServerHelper.Query(sequel, paras);
  122. if (ds.Tables[0].Rows.Count > 0)
  123. {
  124. return GetModel(ds.Tables[0].Rows[0]);
  125. }
  126. else
  127. {
  128. return null;
  129. }
  130. }
  131. /// <summary>
  132. /// BrandName??
  133. /// </summary>
  134. /// <remarks></remarks>
  135. public YXShop.Model.Product.ProductBrand GetModelName(string BrandName)
  136. {
  137. string sequel = SelectSequel + " where name=@name";
  138. SqlParameter[] paras = new SqlParameter[1];
  139. paras[0] = new SqlParameter("@name", SqlDbType.VarChar, 100);
  140. paras[0].Value = BrandName;
  141. DataSet ds = ChangeHope.DataBase.SQLServerHelper.Query(sequel, paras);
  142. if (ds.Tables[0].Rows.Count > 0)
  143. {
  144. return GetModel(ds.Tables[0].Rows[0]);
  145. }
  146. else
  147. {
  148. return null;
  149. }
  150. }
  151. /// <summary>
  152. /// ??CID????
  153. /// </summary>
  154. /// <param name="CID"></param>
  155. /// <returns></returns>
  156. public System.Data.DataTable GetBrandList(string CID)
  157. {
  158. string strSql = this.SelectSequel + "Where ','+[cid]+',' like '%," + CID + ",%'";
  159. return ChangeHope.DataBase.SQLServerHelper.Query(strSql).Tables[0];
  160. }
  161. /// <summary>
  162. /// ????
  163. /// </summary>
  164. /// <remarks></remarks>
  165. public ChangeHope.DataBase.DataByPage GetList()
  166. {
  167. ChangeHope.DataBase.DataByPage dataPage = new ChangeHope.DataBase.DataByPage();
  168. dataPage.Sql = "[select] * [from] yxs_productbrand [where] 1=1 [order by] sort asc";
  169. dataPage.GetRecordSetByPage();
  170. return dataPage;
  171. }
  172. /// <summary>
  173. /// ??????List
  174. /// </summary>
  175. /// <remarks></remarks>
  176. public List<YXShop.Model.Product.ProductBrand> GetDTList(string strBrandId)
  177. {
  178. List<YXShop.Model.Product.ProductBrand> list = new List<YXShop.Model.Product.ProductBrand>();
  179. string strSql = this.SelectSequel;
  180. if (strBrandId != "" && strBrandId != string.Empty)
  181. {
  182. strSql += " where bid in(" + strBrandId + ")";
  183. }
  184. using (SqlDataReader reader = ChangeHope.DataBase.SQLServerHelper.ExecuteReader(strSql.ToString()))
  185. {
  186. while (reader.Read())
  187. {
  188. YXShop.Model.Product.ProductBrand model = new YXShop.Model.Product.ProductBrand();
  189. model.ID = Convert.ToInt32(reader["bid"]);
  190. model.Name = reader["name"].ToString();
  191. model.Sort =Convert.ToInt32(reader["sort"].ToString());
  192. list.Add(model);
  193. }
  194. }
  195. return list;
  196. }
  197. public List<YXShop.Model.Product.ProductBrand> GetCommonTypes()
  198. {
  199. List<YXShop.Model.Product.ProductBrand> list = new List<YXShop.Model.Product.ProductBrand>();
  200. string strSql = this.SelectSequel + " where commontypes=0";
  201. using (SqlDataReader reader = ChangeHope.DataBase.SQLServerHelper.ExecuteReader(strSql.ToString()))
  202. {
  203. while (reader.Read())
  204. {
  205. YXShop.Model.Product.ProductBrand model = new YXShop.Model.Product.ProductBrand();
  206. model.ID = Convert.ToInt32(reader["bid"]);
  207. model.Name = reader["name"].ToString();
  208. list.Add(model);
  209. }
  210. }
  211. return list;
  212. }
  213. /// <summary>
  214. /// ????????
  215. /// </summary>
  216. /// <remarks></remarks>
  217. public ChangeHope.DataBase.DataByPage GetList(string orderfield, int pagesize, string Conditions)
  218. {
  219. ChangeHope.DataBase.DataByPage dataPage = new ChangeHope.DataBase.DataByPage();
  220. dataPage.Sql = "[select] * [from] yxs_productbrand [where] 1=1 " + Conditions + " " + orderfield;
  221. dataPage.PageSize = pagesize;
  222. dataPage.GetRecordSetByPage();
  223. return dataPage;
  224. }
  225. #endregion
  226. #region "Other function"
  227. string selectSequel = string.Empty;
  228. protected string SelectSequel
  229. {
  230. get
  231. {
  232. if (selectSequel == string.Empty)
  233. selectSequel = "Select *,1 PersistStatus From [yxs_productbrand] ";
  234. return selectSequel;
  235. }
  236. set
  237. {
  238. this.selectSequel = value;
  239. }
  240. }
  241. /// <summary>
  242. ///
  243. /// </summary>
  244. protected string UpdateWhereSequel
  245. {
  246. get
  247. {
  248. return " Where [bid] = @bid";
  249. }
  250. }
  251. /// <summary>
  252. /// ???????????????????????
  253. /// </summary>
  254. /// <remarks></remarks>
  255. public IDbDataParameter[] ValueParas(YXShop.Model.Product.ProductBrand model)
  256. {
  257. SqlParameter[] paras = new SqlParameter[8];
  258. paras[0] = new SqlParameter("@bid", SqlDbType.Int, 4);
  259. paras[0].Value = model.ID;
  260. paras[1] = new SqlParameter("@commontypes", SqlDbType.Int, 4);
  261. paras[1].Value = model.CommonTypes;
  262. paras[2] = new SqlParameter("@name", SqlDbType.VarChar, 100);
  263. paras[2].Value = model.Name;
  264. paras[3] = new SqlParameter("@attirbute", SqlDbType.VarChar,100);
  265. paras[3].Value = model.Attirbute;
  266. paras[4] = new SqlParameter("@description", SqlDbType.VarChar,1000);
  267. paras[4].Value = model.Description;
  268. paras[5] = new SqlParameter("@images", SqlDbType.VarChar,100);
  269. paras[5].Value = model.Images;
  270. paras[6] = new SqlParameter("@sort", SqlDbType.Int, 4);
  271. paras[6].Value = model.Sort;
  272. paras[7] = new SqlParameter("@isrecommend",SqlDbType.Int,4);
  273. paras[7].Value = model.Isrecommend;
  274. return paras;
  275. }
  276. public IDbDataParameter[] ValueIDPara(int id)
  277. {
  278. SqlParameter[] paras = new SqlParameter[1];
  279. paras[0] = new SqlParameter("@bid", id);
  280. paras[0].DbType = DbType.Int32;
  281. return paras;
  282. }
  283. #endregion
  284. }
  285. }