SetDataService.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 SetDataService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. public List<SetData> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<SetData>.excuteSql(new SetData(), "SetData", 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. SetData excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<SetData> setDataList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (setDataList == null || setDataList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return setDataList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public SetData GetSetDataByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from SetData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// c按字查询 电码
  54. /// </summary>
  55. /// <param name="id"></param>
  56. /// <returns></returns>
  57. public SetData GetSetDataByNameCode(string NameCode)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from SetData where Name = @NameCode and STid = 47 and IsDel = 0", new SqlParameter("@NameCode", NameCode));
  61. }
  62. /// <summary>
  63. /// 获取信用卡账单类型费用
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<SetData> GetAllTocreditCard()
  67. {
  68. return excuteSql("select * from setData where sTid=16 and isdel = 0");
  69. }
  70. /// <summary>
  71. /// 获取全部
  72. /// </summary>
  73. /// <returns></returns>
  74. public List<SetData> GetAll()
  75. {
  76. return excuteSql("select * from SetData where IsDel = 0");
  77. }
  78. /// <summary>
  79. /// 根据name范围获取数据
  80. /// </summary>
  81. /// <returns></returns>
  82. public List<SetData> GetByLvl(string lvl)
  83. {
  84. return excuteSql("select * from SetData where IsDel = 0 and STid=42 and Name in (" + lvl + ")");
  85. }
  86. /// <summary>
  87. /// 根据对应外键获取数据
  88. /// </summary>
  89. /// <returns></returns>
  90. public List<SetData> GetAll(int STid)
  91. {
  92. return excuteSql("select * from SetData where IsDel = 0 And STid = @STid and Name <> '其他款项' order by Name asc", new SqlParameter("@STid", STid));
  93. }
  94. /// <summary>
  95. /// 根据对应外键获取数据
  96. /// </summary>
  97. /// <returns></returns>
  98. public List<SetData> GetAllOrderByRemark(int STid)
  99. {
  100. return excuteSql("select * from SetData where IsDel = 0 And STid = @STid and Name <> '其他款项' order by Remark", new SqlParameter("@STid", STid));
  101. }
  102. /// <summary>
  103. /// 根据条件查询条件获取 - 分页
  104. /// </summary>
  105. /// <param name="pageIndex"></param>
  106. /// <param name="sumPage"></param>
  107. /// <param name="totalRecord"></param>
  108. /// <param name="dataType"></param>
  109. /// <returns></returns>
  110. public List<SetData> GetAll(int pageIndex, out int sumPage, out int totalRecord, string dataType, string name)
  111. {
  112. string sqlwhere = "STid = " + dataType + " and IsDel = 0";
  113. if (!string.IsNullOrEmpty(name))
  114. sqlwhere += " and Name like '%" + name + "%'";
  115. return PageBase<SetData>.excutePageSql(new SetData(), "SetData", "SetData", "*", "id desc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  116. }
  117. /// <summary>
  118. /// 新增
  119. /// </summary>
  120. /// <param name="sdt">对象</param>
  121. public bool AddSetData(SetData sd)
  122. {
  123. if (SqlHelper.ExecuteNonQuery("insert into SetData values(@Name,@Remark,@STid,@IsDel)", CommandType.Text, new SqlParameter("@Name", sd.Name), new SqlParameter("@Remark", sd.Remark), new SqlParameter("@STid", sd.STid), new SqlParameter("@IsDel", sd.IsDel)) > 0)
  124. return true;
  125. return false;
  126. }
  127. /// <summary>
  128. /// 更新状态
  129. /// </summary>
  130. /// <param name="isEnable"></param>
  131. /// <returns></returns>
  132. public bool UpdateState(int isEnable, int id)
  133. {
  134. if (SqlHelper.ExecuteNonQuery("update SetData set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
  135. return true;
  136. return false;
  137. }
  138. /// <summary>
  139. /// 编辑
  140. /// </summary>
  141. /// <param name="sdt"></param>
  142. /// <returns></returns>
  143. public bool EditSetData(SetData sd)
  144. {
  145. if (SqlHelper.ExecuteNonQuery("update SetData set Name = @Name ,Remark = @Remark ,STid = @STid where Id = @Id", CommandType.Text, new SqlParameter("@Name", sd.Name), new SqlParameter("@Remark", sd.Remark), new SqlParameter("STid", sd.STid), new SqlParameter("@Id", sd.Id)) > 0)
  146. return true;
  147. return false;
  148. }
  149. /// <summary>
  150. /// 删除
  151. /// </summary>
  152. /// <param name="id"></param>
  153. /// <returns></returns>
  154. public bool DelSetData(int id)
  155. {
  156. if (SqlHelper.ExecuteNonQuery("update SetData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  157. return true;
  158. return false;
  159. }
  160. /// <summary>
  161. /// 根据名称查询
  162. /// </summary>
  163. /// <param name="p"></param>
  164. /// <returns></returns>
  165. public SetData GetAll(string Name)
  166. {
  167. //调用获取单个对象的方法
  168. return excuteType("select * from SetData where Name = @Name and IsDel = 0", new SqlParameter("@Name", Name));
  169. }
  170. /// <summary>
  171. /// 根据多个STid查询多条数据
  172. /// </summary>
  173. /// <returns></returns>
  174. public List<SetData> GetAllBySTids(string[] STids)
  175. {
  176. string strId = "";
  177. if (STids.Length > 0)
  178. for (int i = 0; i < STids.Length; i++)
  179. if (i == STids.Length - 1) strId += STids[i].ToString();
  180. else strId += STids[i].ToString() + ",";
  181. return excuteSql("select * from SetData where IsDel = 0 and STid IN (" + strId + ");");
  182. }
  183. }
  184. }