Brak opisu

Rotation.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using CallCenterApi.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace CallCenterApi.DAL
  11. {
  12. public class Rotation
  13. {
  14. /// <summary>
  15. /// 增加一条图片
  16. /// </summary>
  17. /// <param name="model"></param>
  18. /// <returns></returns>
  19. public int Add(Model.Rotation model)
  20. {
  21. StringBuilder strSql = new StringBuilder();
  22. strSql.Append("insert into Rotation(");
  23. strSql.Append("roname,romath,uploadpeo,uploaddate,isEnable)");
  24. strSql.Append(" values (");
  25. strSql.Append("@roname,@romath,@uploadpeo,@uploaddate,@isEnable)");
  26. strSql.Append(";select @@IDENTITY");
  27. SqlParameter[] parameters = {
  28. new SqlParameter("@roname", SqlDbType.NVarChar,100),
  29. new SqlParameter("@romath", SqlDbType.NVarChar,300),
  30. new SqlParameter("@uploadpeo", SqlDbType.NVarChar,100),
  31. new SqlParameter("@uploaddate", SqlDbType.DateTime),
  32. new SqlParameter ("@isEnable",SqlDbType.Int,4)};
  33. parameters[0].Value = model.roname;
  34. parameters[1].Value = model.romath;
  35. parameters[2].Value = model.uploadpeo;
  36. parameters[3].Value = model.uploaddate;
  37. parameters[4].Value = model.isEnable;
  38. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  39. if (obj == null)
  40. {
  41. return 0;
  42. }
  43. else
  44. {
  45. return Convert.ToInt32(obj);
  46. }
  47. }
  48. /// <summary>
  49. /// 查询图片信息
  50. /// </summary>
  51. /// <returns></returns>
  52. public DataSet GetList(string name)
  53. {
  54. StringBuilder strSql = new StringBuilder();
  55. strSql.Append("select ");
  56. strSql.Append(" * ");
  57. strSql.Append(" FROM Rotation ");
  58. if (name != "")
  59. {
  60. strSql.Append(" where roname like '%" + name + "%' ");
  61. }
  62. var ds = DbHelperSQL.Query(strSql.ToString());
  63. return ds;
  64. }
  65. /// <summary>
  66. /// 禁用图片信息
  67. /// </summary>
  68. /// <param name="id"></param>
  69. /// <returns></returns>
  70. public bool delrotation(string id)
  71. {
  72. StringBuilder strSql = new StringBuilder();
  73. strSql.Append("update Rotation set isEnable=1 ");
  74. strSql.Append(" where id in (" + id + ") ");
  75. int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
  76. if (rows > 0)
  77. {
  78. return true;
  79. }
  80. else
  81. {
  82. return false;
  83. }
  84. }
  85. /// <summary>
  86. /// 启用图片信息
  87. /// </summary>
  88. /// <param name="id"></param>
  89. /// <returns></returns>
  90. public bool poenRotion(string id)
  91. {
  92. StringBuilder strSql = new StringBuilder();
  93. strSql.Append("update Rotation set isEnable=0 ");
  94. strSql.Append(" where id in (" + id + ") ");
  95. int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
  96. if (rows > 0)
  97. {
  98. return true;
  99. }
  100. else
  101. {
  102. return false;
  103. }
  104. }
  105. /// <summary>
  106. /// 删除图片
  107. /// </summary>
  108. /// <param name="id"></param>
  109. /// <returns></returns>
  110. public bool SCRotion(string id)
  111. {
  112. StringBuilder strSql = new StringBuilder();
  113. strSql.Append("delete from Rotation");
  114. strSql.Append(" where id in (" + id + ") ");
  115. int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
  116. if (rows > 0)
  117. {
  118. return true;
  119. }
  120. else
  121. {
  122. return false;
  123. }
  124. }
  125. /// <summary>
  126. /// 得到一个对象实体
  127. /// </summary>
  128. public CallCenterApi.Model.Rotation DataRowToModel(DataRow row)
  129. {
  130. #region 之前的
  131. #endregion
  132. Model.Rotation model = new Model.Rotation();//主表字段
  133. if (row != null)
  134. {
  135. #region 主表信息======================
  136. //利用反射获得属性的所有公共属性
  137. Type modelType = model.GetType();
  138. for (int i = 0; i < row.Table.Columns.Count; i++)
  139. {
  140. PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
  141. if (proInfo != null && row[i] != DBNull.Value)
  142. {
  143. //用索引值设置属性值
  144. proInfo.SetValue(model, row[i], null);
  145. }
  146. }
  147. #endregion
  148. }
  149. return model;
  150. }
  151. }
  152. }