NewClientDataService.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 NewClientDataService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<NewClientData> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<NewClientData>.excuteSql(new NewClientData(), "NewClientData", 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. NewClientData excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<NewClientData> 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="cd"></param>
  43. /// <returns></returns>
  44. public bool AddClientData(NewClientData cd)
  45. {
  46. string sql = "insert into NewClientData values(@Number,@Lvl,@Client,@Weight,@ClientShort,@Contact,@Gender,@Passport,@PassportDate,@Job,@TelePhone,@Phone,@Email,@Location,@Address,@Birthday,@OtherInfo,@Ascription,@Remarks,@FZR,@WeChat,@Category,@PreDele,@FinlishedDele,@OPer,@OPdate,@IsDel)";
  47. SqlParameter[] parameter = new SqlParameter[]{
  48. new SqlParameter("@Number",cd.Number),
  49. new SqlParameter("@Lvl",cd.Lvl),
  50. new SqlParameter("@Client",cd.Client),
  51. new SqlParameter("@Weight",cd.Weight),
  52. new SqlParameter("@ClientShort",cd.ClientShort),
  53. new SqlParameter("@Contact",cd.Contact),
  54. new SqlParameter("@Gender",cd.Gender),
  55. new SqlParameter("@Passport",cd.Passport),
  56. new SqlParameter("@PassportDate",cd.PassportDate),
  57. new SqlParameter("@Job",cd.Job),
  58. new SqlParameter("@TelePhone",cd.TelePhone),
  59. new SqlParameter("@Phone",cd.Phone),
  60. new SqlParameter("@Email",cd.Email),
  61. new SqlParameter("@Location",cd.Location),
  62. new SqlParameter("@Address",cd.Address),
  63. new SqlParameter("@Birthday",cd.Birthday),
  64. new SqlParameter("@OtherInfo",cd.OtherInfo),
  65. new SqlParameter("@Ascription",cd.Ascription),
  66. new SqlParameter("@Remarks",cd.Remarks),
  67. new SqlParameter("@FZR",cd.FZR),
  68. new SqlParameter("@WeChat",cd.WeChat),
  69. new SqlParameter("@Category",cd.Category),
  70. new SqlParameter("@PreDele",cd.PreDele),
  71. new SqlParameter("@FinlishedDele",cd.FinlishedDele),
  72. new SqlParameter("@OPer",cd.OPer),
  73. new SqlParameter("@OPdate",cd.OPdate),
  74. new SqlParameter("@IsDel",cd.IsDel)
  75. };
  76. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  77. return true;
  78. return false;
  79. }
  80. /// <summary>
  81. /// 编辑
  82. /// </summary>
  83. /// <param name="sdt"></param>
  84. /// <returns></returns>
  85. public bool EditClientData(NewClientData cd)
  86. {
  87. string sql = "update NewClientData set Number=@Number,Lvl=@Lvl,Client=@Client,Weight=@Weight,ClientShort=@ClientShort,Contact=@Contact,Gender=@Gender,Passport=@Passport,PassportDate=@PassportDate,Job=@Job,TelePhone=@TelePhone,Phone=@Phone,Email=@Email,Location=@Location,Address=@Address,Birthday=@Birthday,OtherInfo=@OtherInfo,Ascription=@Ascription,Remarks=@Remarks,FZR=@FZR,WeChat=@WeChat,Category=@Category,PreDele=@PreDele,FinlishedDele=@FinlishedDele,OPer=@OPer,OPdate=@OPdate,IsDel=@IsDel where Id = @Id";
  88. SqlParameter[] parameter = new SqlParameter[] {
  89. new SqlParameter("@Number",cd.Number),
  90. new SqlParameter("@Lvl",cd.Lvl),
  91. new SqlParameter("@Client",cd.Client),
  92. new SqlParameter("@Weight",cd.Weight),
  93. new SqlParameter("@ClientShort",cd.ClientShort),
  94. new SqlParameter("@Contact",cd.Contact),
  95. new SqlParameter("@Gender",cd.Gender),
  96. new SqlParameter("@Passport",cd.Passport),
  97. new SqlParameter("@PassportDate",cd.PassportDate),
  98. new SqlParameter("@Job",cd.Job),
  99. new SqlParameter("@TelePhone",cd.TelePhone),
  100. new SqlParameter("@Phone",cd.Phone),
  101. new SqlParameter("@Email",cd.Email),
  102. new SqlParameter("@Location",cd.Location),
  103. new SqlParameter("@Address",cd.Address),
  104. new SqlParameter("@Birthday",cd.Birthday),
  105. new SqlParameter("@OtherInfo",cd.OtherInfo),
  106. new SqlParameter("@Ascription",cd.Ascription),
  107. new SqlParameter("@Remarks",cd.Remarks),
  108. new SqlParameter("@FZR",cd.FZR),
  109. new SqlParameter("@WeChat",cd.WeChat),
  110. new SqlParameter("@Category",cd.Category),
  111. new SqlParameter("@PreDele",cd.PreDele),
  112. new SqlParameter("@FinlishedDele",cd.FinlishedDele),
  113. new SqlParameter("@OPer",cd.OPer),
  114. new SqlParameter("@OPdate",cd.OPdate),
  115. new SqlParameter("@IsDel",cd.IsDel),
  116. new SqlParameter("@Id",cd.ID)
  117. };
  118. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  119. return true;
  120. return false;
  121. }
  122. /// <summary>
  123. /// 删除
  124. /// </summary>
  125. /// <param name="id"></param>
  126. /// <returns></returns>
  127. public bool DelClientData(int id)
  128. {
  129. string opdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  130. if (SqlHelper.ExecuteNonQuery("update NewClientData set IsDel = 1 , opdate='" + opdate + "' where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  131. return true;
  132. return false;
  133. }
  134. /// <summary>
  135. /// 根据Lvl,Contact,Client查询对象信息
  136. /// </summary>
  137. /// <param name="Contact">客户名称</param>
  138. /// <param name="Client">单位名称</param>
  139. /// <returns>返回空或者单个对象信息</returns>
  140. public NewClientData GetClientData(string lvl, string Contact, string Client)
  141. {
  142. //调用获取单个对象的方法
  143. return excuteType("select * from NewClientData where Lvl= @Lvl and Contact = @Contact and Client = @Client and IsDel = 0", new SqlParameter("@Lvl", lvl), new SqlParameter("@Contact", Contact), new SqlParameter("@Client", Client));
  144. }
  145. /// <summary>
  146. /// 根据id查询对象信息
  147. /// </summary>
  148. /// <param name="id">id</param>
  149. /// <returns>返回空或者单个对象信息</returns>
  150. public NewClientData GetClientDatabyid(int id)
  151. {
  152. //调用获取单个对象的方法
  153. return excuteType("select * from NewClientData where id = @id and IsDel = 0", new SqlParameter("@id", id));
  154. }
  155. /// <summary>
  156. /// 查询所有
  157. /// </summary>
  158. /// <param name="id">id</param>
  159. /// <returns>返回空或者单个对象信息</returns>
  160. public List<NewClientData> GetALL()
  161. {
  162. //调用获取单个对象的方法
  163. return excuteSql("select * from NewClientData where IsDel = 0 order by Id"); //
  164. }
  165. public List<NewClientData> GetALL(string fzrName,bool cbodz)
  166. {
  167. string sql = $"select * from NewClientData where IsDel = 0 ";
  168. string sqlWhere = string.Empty;
  169. if (cbodz)
  170. {
  171. sqlWhere += $" and (FZR = '|{fzrName}|' or fzr = '|{fzrName}' or fzr = '||{fzrName}' or fzr = '|{fzrName}||' or fzr = '|||{fzrName}' or fzr = '|{fzrName}|||') ";
  172. }
  173. else
  174. {
  175. sqlWhere = $" and FZR like '%{fzrName}%' order by Id";
  176. }
  177. return excuteSql(sql + sqlWhere); //
  178. }
  179. /// <summary>
  180. /// 根据Contact,Client查询对象信息
  181. /// </summary>
  182. /// <param name="Contact">客户名称</param>
  183. /// <param name="Client">单位名称</param>
  184. /// <returns>返回空或者单个对象信息</returns>
  185. public List<NewClientData> GetClientDatabyCC(string Contact, string Client)
  186. {
  187. string sql = "select * from NewClientData where IsDel = 0";
  188. if (Contact != null && Contact != "")
  189. sql = sql + " like %@Contact%";
  190. if (Contact != null && Contact != "")
  191. sql = sql + " like %@Client%";
  192. //调用获取单个对象的方法
  193. return excuteSql(sql, new SqlParameter("@Contact", Contact), new SqlParameter("@Client", Client));
  194. }
  195. public List<NewClientData> GetClientDatabyUid(int pageIndex, out int sumPage, out int totalRecord, string lvl, string Contact, string Client, string area, int uid, string category, string range, string ascription)
  196. {
  197. string sqlwhere = "IsDel = 0 and (Contact like '%" + Contact + "%'or Remarks like '%" + Contact + "%') ";
  198. if (!string.IsNullOrEmpty(Client) || Client != "")
  199. {
  200. string temp = "";
  201. foreach (char s in Client)
  202. {
  203. temp = temp + "%" + s;
  204. }
  205. sqlwhere = sqlwhere + " and Client like '" + temp + "%'";
  206. }
  207. if (!string.IsNullOrEmpty(area) || area != "")
  208. {
  209. string temparea = "";
  210. foreach (char s in area)
  211. {
  212. temparea = temparea + "%" + s;
  213. }
  214. sqlwhere = sqlwhere + " and Location like '" + temparea + "%'";
  215. }
  216. if (!string.IsNullOrEmpty(uid.ToString()) || uid.ToString() != "")
  217. {
  218. string name = new UsersService().GetUsersByID(uid).CnName;
  219. sqlwhere = sqlwhere + " and (OPer='" + uid + "'" + " or FZR like '%" + name + "%')";
  220. }
  221. if (category != "全部")
  222. sqlwhere += " and Category = '" + category + "'";
  223. if (lvl != "全部")
  224. sqlwhere += " and Lvl = '" + lvl + "'";
  225. // case "青海":
  226. // ddlCategory.DataSource = new SetDataService().GetAllOrderByRemark(37).FindAll(c => c.Name.Contains("青海"));
  227. //break;
  228. // case "陕西":
  229. // ddlCategory.DataSource = new SetDataService().GetAllOrderByRemark(37).FindAll(c => c.Name.Contains("陕西") || c.Name.Contains("西安"));
  230. //break;
  231. // case "宁夏":
  232. // ddlCategory.DataSource = new SetDataService().GetAllOrderByRemark(37).FindAll(c => c.Name.Contains("宁夏") || c.Name.Contains("银川"));
  233. //break;
  234. // case "甘肃":
  235. // ddlCategory.DataSource = new SetDataService().GetAllOrderByRemark(37).FindAll(c => c.Name.Contains("甘肃") || c.Name.Contains("兰州"));
  236. //break;
  237. switch (range)
  238. {
  239. case "四川":
  240. sqlwhere += " and (Lvl like '%四%川%' or Lvl like '%成%都%')";
  241. break;
  242. case "贵州":
  243. sqlwhere += " and (Lvl like '%贵%州%' or Lvl like '%贵%阳%')";
  244. break;
  245. case "云南":
  246. sqlwhere += " and (Lvl like '%云%南%' or Lvl like '%昆%明%')";
  247. break;
  248. case "重庆":
  249. sqlwhere += " and (Lvl like '%重庆%')";
  250. break;
  251. case "西藏":
  252. sqlwhere += " and (Lvl like '%西%藏%' or Lvl like '%拉%萨%')";
  253. break;
  254. case "青海":
  255. sqlwhere += " and (Lvl like '%青%海%' or Lvl like '%西%宁%')";
  256. break;
  257. case "陕西":
  258. sqlwhere += " and (Lvl like '%陕%西%' or Lvl like '%西%安%')";
  259. break;
  260. case "宁夏":
  261. sqlwhere += " and (Lvl like '%宁%夏%' or Lvl like '%银%川%')";
  262. break;
  263. case "甘肃":
  264. sqlwhere += " and (Lvl like '%甘%肃%' or Lvl like '%兰%州%')";
  265. break;
  266. case "新疆":
  267. sqlwhere += " and (Lvl like '%新%疆%' or Lvl like '%乌%鲁%木%齐%')";
  268. break;
  269. case "全部":
  270. break;
  271. }
  272. if (ascription != "全部")
  273. {
  274. sqlwhere += "and Ascription like '%" + ascription + "%'";
  275. }
  276. return PageBase<NewClientData>.excutePageSql(new NewClientData(), "NewClientData", "NewClientData", "*", "weight desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  277. }
  278. public List<NewClientData> GetClientData(int pageIndex, out int sumPage, out int totalRecord, string lvl, string FZR, string Contact, string Client, string area, string category, string range, string ascription)
  279. {
  280. string sqlwhere = "IsDel = 0 and (Contact like '%" + Contact + "%'or Remarks like '%" + Contact + "%')";
  281. if (!string.IsNullOrEmpty(Client) || Client != "")
  282. {
  283. string temp = "";
  284. foreach (char s in Client)
  285. {
  286. temp = temp + "%" + s;
  287. }
  288. sqlwhere = sqlwhere + " and Client like '" + temp + "%'";
  289. }
  290. if (!string.IsNullOrEmpty(area) || area != "")
  291. {
  292. string temparea = "";
  293. foreach (char s in area)
  294. {
  295. temparea = temparea + "%" + s;
  296. }
  297. sqlwhere = sqlwhere + " and Location like '" + temparea + "%'";
  298. }
  299. if (category != "全部")
  300. sqlwhere += " and Category = '" + category + "'";
  301. if (lvl != "全部")
  302. sqlwhere += " and Lvl = '" + lvl + "'";
  303. if (FZR != "全部")
  304. sqlwhere += " and FZR like '%" + FZR + "%'";
  305. switch (range)
  306. {
  307. case "四川":
  308. sqlwhere += " and (Lvl like '%四%川%' or Lvl like '%成%都%')";
  309. break;
  310. case "贵州":
  311. sqlwhere += " and (Lvl like '%贵%州%' or Lvl like '%贵%阳%')";
  312. break;
  313. case "云南":
  314. sqlwhere += " and (Lvl like '%云%南%' or Lvl like '%昆%明%')";
  315. break;
  316. case "重庆":
  317. sqlwhere += " and (Lvl like '%重庆%')";
  318. break;
  319. case "西藏":
  320. sqlwhere += " and (Lvl like '%西%藏%' or Lvl like '%拉%萨%')";
  321. break;
  322. case "青海":
  323. sqlwhere += " and (Lvl like '%青%海%' or Lvl like '%西%宁%')";
  324. break;
  325. case "陕西":
  326. sqlwhere += " and (Lvl like '%陕%西%' or Lvl like '%西%安%')";
  327. break;
  328. case "宁夏":
  329. sqlwhere += " and (Lvl like '%宁%夏%' or Lvl like '%银%川%')";
  330. break;
  331. case "甘肃":
  332. sqlwhere += " and (Lvl like '%甘%肃%' or Lvl like '%兰%州%')";
  333. break;
  334. case "新疆":
  335. sqlwhere += " and (Lvl like '%新%疆%' or Lvl like '%乌%鲁%木%齐%')";
  336. break;
  337. case "全部":
  338. break;
  339. }
  340. if (ascription != "全部")
  341. {
  342. sqlwhere += "and Ascription like '%" + ascription + "%'";
  343. }
  344. return PageBase<NewClientData>.excutePageSql(new NewClientData(), "NewClientData", "NewClientData", "*", "weight desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  345. }
  346. public List<NewClientData> GetClientDataByCboxDz(int pageIndex, out int sumPage, out int totalRecord, string lvl, string FZR, string Contact, string Client, string area, string category, string range, string ascription)
  347. {
  348. string sqlwhere = "IsDel = 0 and (Contact like '%" + Contact + "%'or Remarks like '%" + Contact + "%')";
  349. if (!string.IsNullOrEmpty(Client) || Client != "")
  350. {
  351. string temp = "";
  352. foreach (char s in Client)
  353. {
  354. temp = temp + "%" + s;
  355. }
  356. sqlwhere = sqlwhere + " and Client like '" + temp + "%'";
  357. }
  358. if (!string.IsNullOrEmpty(area) || area != "")
  359. {
  360. string temparea = "";
  361. foreach (char s in area)
  362. {
  363. temparea = temparea + "%" + s;
  364. }
  365. sqlwhere = sqlwhere + " and Location like '" + temparea + "%'";
  366. }
  367. if (category != "全部")
  368. sqlwhere += " and Category = '" + category + "'";
  369. if (lvl != "全部")
  370. sqlwhere += " and Lvl = '" + lvl + "'";
  371. if (FZR != "全部") {
  372. sqlwhere += $" and (FZR = '|{FZR}|' or fzr = '|{FZR}' or fzr = '||{FZR}' or fzr = '|{FZR}||' or fzr = '|||{FZR}' or fzr = '|{FZR}|||') ";
  373. }
  374. else
  375. {
  376. sqlwhere += $" and (FZR = '|张海麟|' or fzr = '|张海麟' or fzr = '||张海麟' or fzr = '|张海麟||' or fzr = '|||张海麟' or fzr = '|张海麟|||') ";
  377. }
  378. switch (range)
  379. {
  380. case "四川":
  381. sqlwhere += " and (Lvl like '%四%川%' or Lvl like '%成%都%')";
  382. break;
  383. case "贵州":
  384. sqlwhere += " and (Lvl like '%贵%州%' or Lvl like '%贵%阳%')";
  385. break;
  386. case "云南":
  387. sqlwhere += " and (Lvl like '%云%南%' or Lvl like '%昆%明%')";
  388. break;
  389. case "重庆":
  390. sqlwhere += " and (Lvl like '%重庆%')";
  391. break;
  392. case "西藏":
  393. sqlwhere += " and (Lvl like '%西%藏%' or Lvl like '%拉%萨%')";
  394. break;
  395. case "青海":
  396. sqlwhere += " and (Lvl like '%青%海%' or Lvl like '%西%宁%')";
  397. break;
  398. case "陕西":
  399. sqlwhere += " and (Lvl like '%陕%西%' or Lvl like '%西%安%')";
  400. break;
  401. case "宁夏":
  402. sqlwhere += " and (Lvl like '%宁%夏%' or Lvl like '%银%川%')";
  403. break;
  404. case "甘肃":
  405. sqlwhere += " and (Lvl like '%甘%肃%' or Lvl like '%兰%州%')";
  406. break;
  407. case "新疆":
  408. sqlwhere += " and (Lvl like '%新%疆%' or Lvl like '%乌%鲁%木%齐%')";
  409. break;
  410. case "全部":
  411. break;
  412. }
  413. if (ascription != "全部")
  414. {
  415. sqlwhere += "and Ascription like '%" + ascription + "%'";
  416. }
  417. return PageBase<NewClientData>.excutePageSql(new NewClientData(), "NewClientData", "NewClientData", "*", "weight desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  418. }
  419. public string GetLvl(string FZR)
  420. {
  421. string Lvl = "";
  422. using (DataTable dt = SqlHelper.TransferProcedure("GetLvlByFZR", CommandType.StoredProcedure, new SqlParameter("@FZR", FZR)))
  423. {
  424. if (dt != null && dt.Rows.Count != 0)
  425. {
  426. for (int i = 0; i < dt.Rows.Count; i++)
  427. {
  428. Lvl += dt.Rows[i][0].ToString() + ",";
  429. }
  430. }
  431. }
  432. return Lvl;
  433. }
  434. /// <summary>
  435. /// 雷怡 2021-08-3 14:49
  436. /// 获取市场客户总数量
  437. /// </summary>
  438. public int GetCustomerNumber()
  439. {
  440. string sql = "select * from NewClientData where IsDel = 0";
  441. return excuteSql(sql).Count;
  442. }
  443. }
  444. }