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.

201 line
8.0 KiB

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Data.SqlClient;
  5. namespace Basic.DAL
  6. {
  7. /// <summary>
  8. /// ��������
  9. /// </summary>
  10. public partial class link
  11. {
  12. /// <summary>
  13. /// ����һ������
  14. /// </summary>
  15. public int Add(Basic.Model.link model)
  16. {
  17. StringBuilder strSql = new StringBuilder();
  18. strSql.Append("insert into tb_link(");
  19. strSql.Append("paixu,title,class_id,path,url,target,state,remark,add_time)");
  20. strSql.Append(" values (");
  21. strSql.Append("@paixu,@title,@class_id,@path,@url,@target,@state,@remark,@add_time)");
  22. strSql.Append(";select @@IDENTITY");
  23. SqlParameter[] parameters = {
  24. new SqlParameter("@paixu", SqlDbType.Int,10),
  25. new SqlParameter("@title", SqlDbType.NVarChar,255),
  26. new SqlParameter("@class_id", SqlDbType.Int,10),
  27. new SqlParameter("@path", SqlDbType.NVarChar,255),
  28. new SqlParameter("@url", SqlDbType.NVarChar,255),
  29. new SqlParameter("@target", SqlDbType.Int,10),
  30. new SqlParameter("@state", SqlDbType.Int,10),
  31. new SqlParameter("@remark", SqlDbType.NVarChar,500),
  32. new SqlParameter("@add_time", SqlDbType.DateTime,23)};
  33. parameters[0].Value = model.paixu;
  34. parameters[1].Value = model.title;
  35. parameters[2].Value = model.class_id;
  36. parameters[3].Value = model.path;
  37. parameters[4].Value = model.url;
  38. parameters[5].Value = model.target;
  39. parameters[6].Value = model.state;
  40. parameters[7].Value = model.remark;
  41. parameters[8].Value = model.add_time;
  42. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  43. if (obj == null)
  44. {
  45. return 0;
  46. }
  47. else
  48. {
  49. return Convert.ToInt32(obj);
  50. }
  51. }
  52. /// <summary>
  53. /// ����һ������
  54. /// </summary>
  55. public bool Update(Basic.Model.link model)
  56. {
  57. StringBuilder strSql = new StringBuilder();
  58. strSql.Append("update tb_link set ");
  59. strSql.Append("paixu=@paixu,");
  60. strSql.Append("title=@title,");
  61. strSql.Append("class_id=@class_id,");
  62. strSql.Append("path=@path,");
  63. strSql.Append("url=@url,");
  64. strSql.Append("target=@target,");
  65. strSql.Append("state=@state,");
  66. strSql.Append("remark=@remark,");
  67. strSql.Append("add_time=@add_time");
  68. strSql.Append(" where id=@id");
  69. SqlParameter[] parameters = {
  70. new SqlParameter("@paixu", SqlDbType.Int,10),
  71. new SqlParameter("@title", SqlDbType.NVarChar,255),
  72. new SqlParameter("@class_id", SqlDbType.Int,10),
  73. new SqlParameter("@path", SqlDbType.NVarChar,255),
  74. new SqlParameter("@url", SqlDbType.NVarChar,255),
  75. new SqlParameter("@target", SqlDbType.Int,10),
  76. new SqlParameter("@state", SqlDbType.Int,10),
  77. new SqlParameter("@remark", SqlDbType.NVarChar,500),
  78. new SqlParameter("@add_time", SqlDbType.DateTime,23),
  79. new SqlParameter("@id", SqlDbType.Int,4)};
  80. parameters[0].Value = model.paixu;
  81. parameters[1].Value = model.title;
  82. parameters[2].Value = model.class_id;
  83. parameters[3].Value = model.path;
  84. parameters[4].Value = model.url;
  85. parameters[5].Value = model.target;
  86. parameters[6].Value = model.state;
  87. parameters[7].Value = model.remark;
  88. parameters[8].Value = model.add_time;
  89. parameters[9].Value = model.id;
  90. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  91. if (rows > 0)
  92. {
  93. return true;
  94. }
  95. else
  96. {
  97. return false;
  98. }
  99. }
  100. /// <summary>
  101. /// ɾ��һ������
  102. /// </summary>
  103. public bool Delete(int id)
  104. {
  105. StringBuilder strSql = new StringBuilder();
  106. strSql.Append("delete from tb_link");
  107. strSql.Append(" where id=@id");
  108. SqlParameter[] parameters = {
  109. new SqlParameter("@id", SqlDbType.Int,4)};
  110. parameters[0].Value = id;
  111. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  112. if (rows > 0)
  113. {
  114. return true;
  115. }
  116. else
  117. {
  118. return false;
  119. }
  120. }
  121. /// <summary>
  122. /// �õ�һ������ʵ��
  123. /// </summary>
  124. public Basic.Model.link GetModel(int id)
  125. {
  126. StringBuilder strSql = new StringBuilder();
  127. strSql.Append("select top 1 id,paixu,title,class_id,path,url,target,state,remark,add_time from tb_link");
  128. strSql.Append(" where id=@id");
  129. SqlParameter[] parameters = {
  130. new SqlParameter("@id", SqlDbType.Int,4)};
  131. parameters[0].Value = id;
  132. Basic.Model.link model = new Basic.Model.link();
  133. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  134. if (ds.Tables[0].Rows.Count > 0)
  135. {
  136. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  137. {
  138. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  139. }
  140. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
  141. {
  142. model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
  143. }
  144. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
  145. {
  146. model.title = ds.Tables[0].Rows[0]["title"].ToString();
  147. }
  148. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
  149. {
  150. model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
  151. }
  152. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
  153. {
  154. model.path = ds.Tables[0].Rows[0]["path"].ToString();
  155. }
  156. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
  157. {
  158. model.url = ds.Tables[0].Rows[0]["url"].ToString();
  159. }
  160. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["target"].ToString()))
  161. {
  162. model.target = int.Parse(ds.Tables[0].Rows[0]["target"].ToString());
  163. }
  164. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
  165. {
  166. model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
  167. }
  168. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
  169. {
  170. model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
  171. }
  172. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
  173. {
  174. model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
  175. }
  176. return model;
  177. }
  178. else
  179. {
  180. return null;
  181. }
  182. }
  183. /// <summary>
  184. /// �޸�һ������
  185. /// </summary>
  186. public void UpdateField(int id, string strValue)
  187. {
  188. StringBuilder strSql = new StringBuilder();
  189. strSql.Append("update tb_link set " + strValue);
  190. strSql.Append(" where id=" + id);
  191. DbHelperSQL.ExecuteSql(strSql.ToString());
  192. }
  193. }
  194. }