InsuranceCostService.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace DAL
  9. {
  10. public class InsuranceCostService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<InsuranceCost> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<InsuranceCost>.excuteSql(new InsuranceCost(), "InsuranceCost", sql, CommandType.Text, param);
  21. }
  22. /// <summary>
  23. /// 增加
  24. /// </summary>
  25. /// <returns></returns>
  26. public bool AddInsuranceCost(InsuranceCost c, out int id)
  27. {
  28. string sql = "insert into InsuranceCost values(@GName,@RechargeCost,@Remarks,@Operators,@OperatorDate,@IsDel);SELECT @@IDENTITY";
  29. SqlParameter[] parameter = new SqlParameter[]{
  30. new SqlParameter("@GName",c.GName),
  31. new SqlParameter("@RechargeCost",c.RechargeCost),
  32. new SqlParameter("@Remarks",c.Remarks),
  33. new SqlParameter("@Operators",c.Operators),
  34. new SqlParameter("@OperatorDate",c.OperatorDate),
  35. new SqlParameter("@IsDel",c.IsDel)
  36. };
  37. int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
  38. if (obj > 0)
  39. {
  40. id = obj;
  41. return true;
  42. }
  43. id = 0;
  44. return false;
  45. }
  46. /// <summary>
  47. /// 获取单个对象
  48. /// </summary>
  49. /// <param name="sql">sql语句</param>
  50. /// <param name="param">可变参数数组</param>
  51. /// <returns>返回空或者单个对象</returns>
  52. InsuranceCost excuteType(string sql, params SqlParameter[] param)
  53. {
  54. //查询结果放入对象集合
  55. List<InsuranceCost> diList = excuteSql(sql, param);
  56. //判断集合是否为空
  57. if (diList == null || diList.Count == 0)
  58. //返回null
  59. return null;
  60. //返回单个对象
  61. return diList[0];
  62. }
  63. public InsuranceCost GetInsuranceCostInfoByID(int id)
  64. {
  65. return excuteType("select * from InsuranceCost where Id = @id and isdel=0", new SqlParameter("@id", id));
  66. // return excuteType("select SUM(InsuranceBalance) as InsuranceBalance,GName from InsuranceCost where DId = @id and isdel=0 group by InsuranceBalance,GName", new SqlParameter("@id", id));
  67. }
  68. /// <summary>
  69. /// 获取全部 - 分页
  70. /// </summary>
  71. /// <returns></returns>
  72. public List<InsuranceCost> GetInsuranceCost(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string clientName)
  73. {
  74. string sqlwhere;
  75. if ((tourCode == "" || tourCode == null) && (clientName == "" || clientName == null))
  76. {
  77. sqlwhere = "IsDel = 0 ";
  78. }
  79. else
  80. {
  81. sqlwhere = "IsDel = 0 and DID = '" + tourCode + "' and GName like '%" + clientName + "%'";
  82. }
  83. return PageBase<InsuranceCost>.excutePageSql(new InsuranceCost(), "InsuranceCost", "InsuranceCost", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  84. }
  85. /// <summary>
  86. /// 根据id查询信息
  87. /// </summary>
  88. /// <param name="id"></param>
  89. /// <returns></returns>
  90. public InsuranceCost GetInsuranceCostByID(int id)
  91. {
  92. return excuteType("select * from InsuranceCost where Id = @id and isdel=0 order by id asc", new SqlParameter("@id", id));
  93. // return excuteType("select SUM(InsuranceBalance) as InsuranceBalance,GName from InsuranceCost where DId = @id and isdel=0 group by InsuranceBalance,GName", new SqlParameter("@id", id));
  94. }
  95. public bool EditInsuranceCostByID(InsuranceCost c, int id)
  96. {
  97. string sql = "update InsuranceCost set GName = @ClientName,RechargeCost = @RechargeCost,Remarks = @Remarks,OperatorDate = @OperatorDate where Id = @Id";
  98. SqlParameter[] parameter = new SqlParameter[]{
  99. new SqlParameter("@ClientName",c.GName),
  100. new SqlParameter("@RechargeCost",c.RechargeCost),
  101. new SqlParameter("@Remarks",c.Remarks),
  102. new SqlParameter("@OperatorDate",c.OperatorDate),
  103. new SqlParameter("@Id",id)
  104. };
  105. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  106. return true;
  107. return false;
  108. }
  109. /// <summary>
  110. /// 名称 Id
  111. /// </summary>
  112. /// <param name="id"></param>
  113. /// <returns></returns>
  114. public List<InsuranceCost> GetInsuranceCostInfo()
  115. {
  116. return excuteSql("select * from InsuranceCost where isdel=0 order by id asc");
  117. }
  118. /// <summary>
  119. /// 删除
  120. /// </summary>
  121. /// <param name="id"></param>
  122. /// <returns></returns>
  123. public bool DelInsuranceCost(int id)
  124. {
  125. if (SqlHelper.ExecuteNonQuery("update InsuranceCost set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  126. return true;
  127. return false;
  128. }
  129. ///// <summary>
  130. ///// 根据ID获取 - 分页
  131. ///// </summary>
  132. //public DataTable GetAll(int pageIndex, int pageSize, out int sumPage, out int totalRecord, int id)
  133. //{
  134. // string sql = "select g.ClientName,g.InsuranceCosts,d.TeamName from InsuranceCost as i join GroupsCustomers as g on g.Iid = i.Id join DelegationInfo as d on g.DIId = d.Id where g.IsDel = 0 and i.Id = @id ";
  135. // SqlParameter[] parameter = new SqlParameter[]{
  136. // new SqlParameter("@Id",id),
  137. // };
  138. // object result = SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter);
  139. // if (result != null)
  140. // {
  141. // totalRecord = Convert.ToInt32(result.ToString());
  142. // //计算出总页数
  143. // sumPage = totalRecord % 10 == 0 ? totalRecord / 10 : totalRecord / 10 + 1;
  144. // }
  145. // else
  146. // {
  147. // totalRecord = 0;
  148. // //计算出总页数
  149. // sumPage = 1;
  150. // }
  151. // return SqlHelper.TransferProcedure("exec_page", CommandType.StoredProcedure, parameter);
  152. // // return SqlHelper.TransferProcedure("exec_creditCardPayment", CommandType.StoredProcedure, parameter);
  153. //}
  154. }
  155. }