ClientDataService.cs 8.1 KB

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