GroupsCustomersService.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 团组客户保险数据访问类
  12. /// </summary>
  13. public class GroupsCustomersService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<GroupsCustomers> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<GroupsCustomers>.excuteSql(new GroupsCustomers(), "GroupsCustomers", 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. GroupsCustomers excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<GroupsCustomers> gcList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (gcList == null || gcList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return gcList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public GroupsCustomers GetGroupsCustomersByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from GroupsCustomers where Id = @id and isdel=0", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 获取全部 - 分页
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<GroupsCustomers> GetGroupsCustomers(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string clientName)
  57. {
  58. string sqlwhere = "IsDel = 0 and DIId = '" + tourCode + "' and ClientName like '%" + clientName + "%'";
  59. return PageBase<GroupsCustomers>.excutePageSql(new GroupsCustomers(), "GroupsCustomers", "GroupsCustomers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  60. }
  61. /// <summary>
  62. /// 增加
  63. /// </summary>
  64. /// <returns></returns>
  65. public bool AddGroupsCustomers(GroupsCustomers v, out int id)
  66. {
  67. string sql = "insert into GroupsCustomers values(@DIId,@ClientName,@InsuranceCosts,@Currency,@Attachment,@Remark,@Operator,@OperatorDate,@IsDel,@Iid);SELECT @@IDENTITY";
  68. SqlParameter[] parameter = new SqlParameter[]{
  69. new SqlParameter("@DIId",v.DIId),
  70. new SqlParameter("@ClientName",v.ClientName),
  71. new SqlParameter("@InsuranceCosts",v.InsuranceCosts),
  72. new SqlParameter("@Currency",v.Currency),
  73. new SqlParameter("@Attachment",v.Attachment),
  74. new SqlParameter("@Remark",v.Remark),
  75. new SqlParameter("@Operator",v.Operators),
  76. new SqlParameter("@OperatorDate",v.OperatorsDate),
  77. new SqlParameter("@IsDel",v.IsDel),
  78. new SqlParameter("@Iid",v.Iid)
  79. };
  80. int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
  81. if (obj > 0)
  82. {
  83. id = obj;
  84. return true;
  85. }
  86. id = 0;
  87. return false;
  88. }
  89. /// <summary>
  90. /// 编辑
  91. /// </summary>
  92. /// <returns></returns>
  93. public bool EditGroupsCustomers(GroupsCustomers v)
  94. {
  95. string sql = "update GroupsCustomers set DIId = @DIId,ClientName = @ClientName,InsuranceCosts = @InsuranceCosts,Currency = @Currency,Attachment = @Attachment,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate,Iid =@Iid where Id = @Id";
  96. SqlParameter[] parameter = new SqlParameter[]{
  97. new SqlParameter("@DIId",v.DIId),
  98. new SqlParameter("@ClientName",v.ClientName),
  99. new SqlParameter("@InsuranceCosts",v.InsuranceCosts),
  100. new SqlParameter("@Currency",v.Currency),
  101. new SqlParameter("@Attachment",v.Attachment),
  102. new SqlParameter("@Remark",v.Remark),
  103. new SqlParameter("@Operator",v.Operators),
  104. new SqlParameter("@OperatorDate",v.OperatorsDate),
  105. new SqlParameter("@Iid",v.Iid),
  106. new SqlParameter("@Id",v.Id)
  107. };
  108. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  109. return true;
  110. return false;
  111. }
  112. /// <summary>
  113. /// 删除
  114. /// </summary>
  115. /// <param name="id"></param>
  116. /// <returns></returns>
  117. public bool DelGroupsCustomers(int id)
  118. {
  119. if (SqlHelper.ExecuteNonQuery("update GroupsCustomers set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  120. return true;
  121. return false;
  122. }
  123. public double GetByIid(int Iid)
  124. {
  125. string sql = "select sum(InsuranceCosts) from GroupsCustomers where Iid = " + Iid + "";
  126. object obj = SqlHelper.ExecuteScalar(sql, CommandType.Text);
  127. if (obj != null)
  128. {
  129. if (!string.IsNullOrEmpty(obj.ToString()))
  130. {
  131. double value = (double)obj;
  132. return value;
  133. }
  134. else
  135. return 0;
  136. }
  137. else
  138. return 0;
  139. }
  140. /// <summary>
  141. /// 保险费用 - 分页
  142. /// </summary>
  143. /// <returns></returns>
  144. public List<GroupsCustomers> GetGroupsCustomersByDid(int pageIndex, out int sumPage, out int totalRecord, string tourCode)
  145. {
  146. string sqlwhere = "IsDel = 0 and Iid = '" + tourCode + "'";
  147. return PageBase<GroupsCustomers>.excutePageSql(new GroupsCustomers(), "GroupsCustomers", "GroupsCustomers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  148. }
  149. }
  150. }