You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 line
10 KiB

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Data.SqlClient;
  5. using System.Collections.Generic;
  6. namespace Basic.DAL
  7. {
  8. /// <summary>
  9. /// ����
  10. /// </summary>
  11. public partial class albums
  12. {
  13. /// <summary>
  14. /// ����һ������
  15. /// </summary>
  16. public int Add(Basic.Model.albums model)
  17. {
  18. StringBuilder strSql = new StringBuilder();
  19. strSql.Append("insert into tb_albums(");
  20. strSql.Append("paixu,guid,big_img,small_img,remark)");
  21. strSql.Append(" values (");
  22. strSql.Append("@paixu,@guid,@big_img,@small_img,@remark)");
  23. strSql.Append(";select @@IDENTITY");
  24. SqlParameter[] parameters = {
  25. new SqlParameter("@paixu", SqlDbType.Int,10),
  26. new SqlParameter("@guid", SqlDbType.NVarChar,50),
  27. new SqlParameter("@big_img", SqlDbType.NVarChar,255),
  28. new SqlParameter("@small_img", SqlDbType.NVarChar,255),
  29. new SqlParameter("@remark", SqlDbType.NVarChar,500)};
  30. parameters[0].Value = model.paixu;
  31. parameters[1].Value = model.guid;
  32. parameters[2].Value = model.big_img;
  33. parameters[3].Value = model.small_img;
  34. parameters[4].Value = model.remark;
  35. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  36. if (obj == null)
  37. {
  38. return 0;
  39. }
  40. else
  41. {
  42. return Convert.ToInt32(obj);
  43. }
  44. }
  45. /// <summary>
  46. /// ����һ������
  47. /// </summary>
  48. public bool Update(Basic.Model.albums model)
  49. {
  50. StringBuilder strSql = new StringBuilder();
  51. strSql.Append("update tb_albums set ");
  52. strSql.Append("paixu=@paixu,");
  53. strSql.Append("guid=@guid,");
  54. strSql.Append("big_img=@big_img,");
  55. strSql.Append("small_img=@small_img,");
  56. strSql.Append("remark=@remark");
  57. strSql.Append(" where id=@id");
  58. SqlParameter[] parameters = {
  59. new SqlParameter("@paixu", SqlDbType.Int,10),
  60. new SqlParameter("@guid", SqlDbType.NVarChar,50),
  61. new SqlParameter("@big_img", SqlDbType.NVarChar,255),
  62. new SqlParameter("@small_img", SqlDbType.NVarChar,255),
  63. new SqlParameter("@remark", SqlDbType.NVarChar,500),
  64. new SqlParameter("@id", SqlDbType.Int,4)};
  65. parameters[0].Value = model.paixu;
  66. parameters[1].Value = model.guid;
  67. parameters[2].Value = model.big_img;
  68. parameters[3].Value = model.small_img;
  69. parameters[4].Value = model.remark;
  70. parameters[5].Value = model.id;
  71. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  72. if (rows > 0)
  73. {
  74. return true;
  75. }
  76. else
  77. {
  78. return false;
  79. }
  80. }
  81. /// <summary>
  82. /// ɾ��һ������
  83. /// </summary>
  84. public bool Delete(int id)
  85. {
  86. StringBuilder strSql = new StringBuilder();
  87. strSql.Append("delete from tb_albums");
  88. strSql.Append(" where id=@id");
  89. SqlParameter[] parameters = {
  90. new SqlParameter("@id", SqlDbType.Int,4)};
  91. parameters[0].Value = id;
  92. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  93. if (rows > 0)
  94. {
  95. return true;
  96. }
  97. else
  98. {
  99. return false;
  100. }
  101. }
  102. /// <summary>
  103. /// �õ�һ������ʵ��
  104. /// </summary>
  105. public Basic.Model.albums GetModel(int id)
  106. {
  107. StringBuilder strSql = new StringBuilder();
  108. strSql.Append("select top 1 id,paixu,guid,big_img,small_img,remark from tb_albums");
  109. strSql.Append(" where id=@id");
  110. SqlParameter[] parameters = {
  111. new SqlParameter("@id", SqlDbType.Int,4)};
  112. parameters[0].Value = id;
  113. Basic.Model.albums model = new Basic.Model.albums();
  114. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  115. if (ds.Tables[0].Rows.Count > 0)
  116. {
  117. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  118. {
  119. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  120. }
  121. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
  122. {
  123. model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
  124. }
  125. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
  126. {
  127. model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
  128. }
  129. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["big_img"].ToString()))
  130. {
  131. model.big_img = ds.Tables[0].Rows[0]["big_img"].ToString();
  132. }
  133. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["small_img"].ToString()))
  134. {
  135. model.small_img = ds.Tables[0].Rows[0]["small_img"].ToString();
  136. }
  137. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
  138. {
  139. model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
  140. }
  141. return model;
  142. }
  143. else
  144. {
  145. return null;
  146. }
  147. }
  148. /// <summary>
  149. /// ���������б�
  150. /// </summary>
  151. public List<Basic.Model.albums> GetList(string _guid)
  152. {
  153. List<Basic.Model.albums> modelList = new List<Basic.Model.albums>();
  154. StringBuilder strSql = new StringBuilder();
  155. strSql.Append("select * ");
  156. strSql.Append(" from tb_albums ");
  157. strSql.Append(" where guid='" + _guid + "'");
  158. DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0];
  159. int rowsCount = dt.Rows.Count;
  160. if (rowsCount > 0)
  161. {
  162. Basic.Model.albums model;
  163. for (int n = 0; n < rowsCount; n++)
  164. {
  165. model = new Basic.Model.albums();
  166. if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
  167. {
  168. model.id = int.Parse(dt.Rows[n]["id"].ToString());
  169. }
  170. if (dt.Rows[n]["paixu"] != null && dt.Rows[n]["paixu"].ToString() != "")
  171. {
  172. model.paixu = int.Parse(dt.Rows[n]["paixu"].ToString());
  173. }
  174. if (dt.Rows[n]["guid"] != null && dt.Rows[n]["guid"].ToString() != "")
  175. {
  176. model.guid = dt.Rows[n]["guid"].ToString();
  177. }
  178. if (dt.Rows[n]["big_img"] != null && dt.Rows[n]["big_img"].ToString() != "")
  179. {
  180. model.big_img = dt.Rows[n]["big_img"].ToString();
  181. }
  182. if (dt.Rows[n]["small_img"] != null && dt.Rows[n]["small_img"].ToString() != "")
  183. {
  184. model.small_img = dt.Rows[n]["small_img"].ToString();
  185. }
  186. if (dt.Rows[n]["remark"] != null && dt.Rows[n]["remark"].ToString() != "")
  187. {
  188. model.remark = dt.Rows[n]["remark"].ToString();
  189. }
  190. modelList.Add(model);
  191. }
  192. }
  193. return modelList;
  194. }
  195. /// <summary>
  196. /// ���Ҳ����ڵ�ͼƬ��ɾ����ɾ����ͼƬ������
  197. /// </summary>
  198. public void DeleteList(List<Basic.Model.albums> models, string _guid)
  199. {
  200. StringBuilder idList = new StringBuilder();
  201. if (models != null)
  202. {
  203. foreach (Basic.Model.albums modelt in models)
  204. {
  205. if (modelt.id > 0)
  206. {
  207. idList.Append(modelt.id + ",");
  208. }
  209. }
  210. }
  211. string id_list = Basic.Tools.Utils.DelLastChar(idList.ToString(), ",");
  212. StringBuilder strSql = new StringBuilder();
  213. strSql.Append("select id,big_img,small_img from tb_albums where guid='" + _guid + "'");
  214. if (!string.IsNullOrEmpty(id_list))
  215. {
  216. strSql.Append(" and id not in(" + id_list + ")");
  217. }
  218. Basic.BasicPage bp = new BasicPage();
  219. DataSet ds = bp.SelectDataBase("tb_albums", strSql.ToString());
  220. foreach (DataRow dr in ds.Tables[0].Rows)
  221. {
  222. bool result = Delete(int.Parse(dr["id"].ToString()));//ɾ������
  223. if (result)
  224. {
  225. Basic.Tools.Utils.DeleteFile("../.." + dr["big_img"].ToString()); //ɾ��ԭͼ
  226. Basic.Tools.Utils.DeleteFile("../.." + dr["small_img"].ToString()); //ɾ������ͼ
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// ɾ�����ݺ�ͼƬ
  232. /// </summary>
  233. public void Delete(string _guid)
  234. {
  235. StringBuilder strSql = new StringBuilder();
  236. strSql.Append("select id,big_img,small_img from tb_albums where guid='" + _guid + "'");
  237. Basic.BasicPage bp = new BasicPage();
  238. DataSet ds = bp.SelectDataBase("tb_albums", strSql.ToString());
  239. foreach (DataRow dr in ds.Tables[0].Rows)
  240. {
  241. bool result = Delete(int.Parse(dr["id"].ToString()));//ɾ������
  242. if (result)
  243. {
  244. Basic.Tools.Utils.DeleteFile("../../" + dr["big_img"].ToString()); //ɾ��ԭͼ
  245. Basic.Tools.Utils.DeleteFile("../../" + dr["small_img"].ToString()); //ɾ������ͼ
  246. }
  247. }
  248. }
  249. }
  250. }