MediaSuppliersService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. public class MediaSuppliersService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<MediaSuppliers> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<MediaSuppliers>.excuteSql(new MediaSuppliers(), "MediaSuppliers", sql, CommandType.Text, param);
  21. }
  22. /// <summary>
  23. /// 获取单个对象
  24. /// </summary>
  25. /// <param name="sql">sql语句</param>
  26. /// <param name="param">可变参数数组</param>
  27. /// <returns>返回空或者单个对象</returns>
  28. MediaSuppliers excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<MediaSuppliers> cdList = excuteSql(sql, param);
  32. //判断集合是否为空
  33. if (cdList == null || cdList.Count == 0)
  34. //返回null
  35. return null;
  36. //返回单个对象
  37. return cdList[0];
  38. }
  39. /// <summary>
  40. /// 根据编号查询对象信息
  41. /// </summary>
  42. /// <param name="id">对象编号</param>
  43. /// <returns>返回空或者单个对象信息</returns>
  44. public MediaSuppliers GetMediaSuppliersByID(int id)
  45. {
  46. //调用获取单个对象的方法
  47. return excuteType("select * from MediaSuppliers where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  48. }
  49. /// <summary>
  50. /// 查询信息
  51. /// </summary>
  52. /// <returns>返回空或者单个对象信息</returns>
  53. public List<MediaSuppliers> GetMediaSuppliersName(string name)
  54. {
  55. //调用获取单个对象的方法
  56. return excuteSql("select * from MediaSuppliers where Name like '%" + name + "%'");
  57. }
  58. /// <summary>
  59. /// 查询信息
  60. /// </summary>
  61. /// <returns>返回空或者单个对象信息</returns>
  62. public List<MediaSuppliers> GetMediaSuppliersByUnitName(string unitName)
  63. {
  64. //调用获取单个对象的方法
  65. return excuteSql("select * from MediaSuppliers where UnitName = '" + unitName + "'");
  66. }
  67. /// <summary>
  68. /// 查询信息
  69. /// </summary>
  70. /// <returns>返回空或者单个对象信息</returns>
  71. public MediaSuppliers GetMediaSuppliersNameByEntity(string name)
  72. {
  73. //调用获取单个对象的方法
  74. return excuteType("select * from MediaSuppliers where Name = '" + name + "'");
  75. }
  76. /// <summary>
  77. /// 根据条件查询对象信息
  78. /// </summary>
  79. /// <param name="name">客户名称</param>
  80. /// <param name="unitName">单位名称</param>
  81. /// <returns>返回空或者单个对象信息</returns>
  82. public MediaSuppliers GetMediaSuppliers(string name, string unitName)
  83. {
  84. //调用获取单个对象的方法
  85. return excuteType("select * from MediaSuppliers where Name = @Name and UnitName = @UnitName and IsDel = 0", new SqlParameter("@Name", name), new SqlParameter("@UnitName", unitName));
  86. }
  87. /// <summary>
  88. /// 根据条件查询对象信息
  89. /// </summary>
  90. /// <param name="name">客户名称</param>
  91. /// <param name="unitName">单位名称</param>
  92. /// <returns>返回空或者单个对象信息</returns>
  93. public MediaSuppliers GetMediaSuppliers(string unitName)
  94. {
  95. //调用获取单个对象的方法
  96. return excuteType("select * from MediaSuppliers where UnitName = @UnitName", new SqlParameter("@UnitName", unitName));
  97. }
  98. /// <summary>
  99. /// 获取全部 - 分页
  100. /// </summary>
  101. /// <returns></returns>
  102. public List<MediaSuppliers> GetMediaSuppliers(int pageIndex, out int sumPage, out int totalRecord, string departmentType, string name, string unitName, string tel)
  103. {
  104. //string sql = "join Users as u on m.Operator = u.Id";
  105. string sqlwhere = "IsDel = 0 and Name like '%" + name + "%' and UnitName like '%" + unitName + "%' and Tel like '%" + tel + "%'";
  106. if (departmentType != "全部")
  107. sqlwhere += " and Did = " + departmentType + "";
  108. //string sqly = sql + sqlwhere;
  109. return PageBase<MediaSuppliers>.excutePageSql(new MediaSuppliers(), "MediaSuppliers", "MediaSuppliers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  110. }
  111. /// <summary>
  112. /// 增加
  113. /// </summary>
  114. /// <param name="cd"></param>
  115. /// <returns></returns>
  116. public bool AddMediaSuppliers(MediaSuppliers cd)
  117. {
  118. string sql = "insert into MediaSuppliers values(@DId,@Privince,@City,@Name,@Sex,@UnitName,@UnitAbbreviation,@Post,@Tel,@QQ,@Email,@Fax,@Address,@OtherInformation,@Operator,@OperatorDate,@IsDel)";
  119. SqlParameter[] parameter = new SqlParameter[]{
  120. new SqlParameter("@DId",cd.Did),
  121. new SqlParameter("@Privince",cd.Privince),
  122. new SqlParameter("@City",cd.City),
  123. new SqlParameter("@Name",cd.Name),
  124. new SqlParameter("@Sex",cd.Sex),
  125. new SqlParameter("@UnitName",cd.UnitName),
  126. new SqlParameter("@UnitAbbreviation",cd.UnitAbbreviation),
  127. new SqlParameter("@Post",cd.Post),
  128. new SqlParameter("@Tel",cd.Tel),
  129. new SqlParameter("@QQ",cd.QQ),
  130. new SqlParameter("@Email",cd.Email),
  131. new SqlParameter("@Fax",cd.Fax),
  132. new SqlParameter("@Address",cd.Address),
  133. new SqlParameter("@OtherInformation",cd.OtherInformation),
  134. new SqlParameter("@Operator",cd.Operators),
  135. new SqlParameter("@OperatorDate",cd.OperatorsDate),
  136. new SqlParameter("@IsDel",cd.IsDel)
  137. };
  138. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  139. return true;
  140. return false;
  141. }
  142. /// <summary>
  143. /// 编辑
  144. /// </summary>
  145. /// <param name="sdt"></param>
  146. /// <returns></returns>
  147. public bool EditMediaSuppliers(MediaSuppliers cd)
  148. {
  149. string sql = "update MediaSuppliers set DId = @DId,Privince=@Privince,City=@City,Name = @Name,Sex = @Sex,UnitName = @UnitName,UnitAbbreviation = @UnitAbbreviation,Post = @Post,Tel = @Tel,QQ=@QQ,Email = @Email,Fax = @Fax,Address=@Address,OtherInformation = @OtherInformation,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
  150. SqlParameter[] parameter = new SqlParameter[] {
  151. new SqlParameter("@DId",cd.Did),
  152. new SqlParameter("@Privince",cd.Privince),
  153. new SqlParameter("@City",cd.City),
  154. new SqlParameter("@Name",cd.Name),
  155. new SqlParameter("@Sex",cd.Sex),
  156. new SqlParameter("@UnitName",cd.UnitName),
  157. new SqlParameter("@UnitAbbreviation",cd.UnitAbbreviation),
  158. new SqlParameter("@Post",cd.Post),
  159. new SqlParameter("@Tel",cd.Tel),
  160. new SqlParameter("@QQ",cd.QQ),
  161. new SqlParameter("@Email",cd.Email),
  162. new SqlParameter("@Fax",cd.Fax),
  163. new SqlParameter("@Address",cd.Address),
  164. new SqlParameter("@OtherInformation",cd.OtherInformation),
  165. new SqlParameter("@Operator",cd.Operators),
  166. new SqlParameter("@OperatorDate",cd.OperatorsDate),
  167. new SqlParameter("@IsDel",cd.IsDel),
  168. new SqlParameter("@Id",cd.Id)
  169. };
  170. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  171. return true;
  172. return false;
  173. }
  174. /// <summary>
  175. /// 删除
  176. /// </summary>
  177. /// <param name="id"></param>
  178. /// <returns></returns>
  179. public bool DelMediaSuppliers(int id)
  180. {
  181. if (SqlHelper.ExecuteNonQuery("update MediaSuppliers set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  182. return true;
  183. return false;
  184. }
  185. }
  186. }