SetDataTypeService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 SetDataTypeService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. public List<SetDataType> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<SetDataType>.excuteSql(new SetDataType(), "SetDataType", 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. SetDataType excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<SetDataType> setDataTypeList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (setDataTypeList == null || setDataTypeList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return setDataTypeList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public SetDataType GetSetDataTypeByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from SetDataType where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 根据名称查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public SetDataType GetSetDataTypeByName(string Name)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from SetDataType where Name = @Name", new SqlParameter("@Name", Name));
  61. }
  62. /// <summary>
  63. /// 获取全部
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<SetDataType> GetAll()
  67. {
  68. return excuteSql("select * from SetDataType");
  69. }
  70. /// <summary>
  71. /// 根据多个id查询多条数据
  72. /// </summary>
  73. /// <returns></returns>
  74. public List<SetDataType> GetAllByIds(string[] Ids)
  75. {
  76. string strId = "";
  77. if (Ids.Length > 0)
  78. for (int i = 0; i < Ids.Length; i++)
  79. if (i == Ids.Length-1) strId += Ids[i].ToString();
  80. else strId += Ids[i].ToString() + ",";
  81. return excuteSql("select * from SetDataType where id IN (" + strId + ");");
  82. }
  83. /// <summary>
  84. /// 获取已启用的数据
  85. /// </summary>
  86. /// <returns></returns>
  87. public List<SetDataType> GetAllByIsEnable()
  88. {
  89. return excuteSql("select * from SetDataType where IsEnable = 1");
  90. }
  91. /// <summary>
  92. /// 新增
  93. /// </summary>
  94. /// <param name="sdt">对象</param>
  95. public bool AddSetDataType(SetDataType sdt)
  96. {
  97. if (SqlHelper.ExecuteNonQuery("insert into SetDataType values(@Name,@IsEnable)", CommandType.Text, new SqlParameter("@Name",sdt.Name),new SqlParameter("@IsEnable",sdt.IsEnable)) > 0)
  98. return true;
  99. return false;
  100. }
  101. /// <summary>
  102. /// 更新状态
  103. /// </summary>
  104. /// <param name="isEnable"></param>
  105. /// <returns></returns>
  106. public bool UpdateState(int isEnable, int id)
  107. {
  108. if (SqlHelper.ExecuteNonQuery("update SetDataType set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
  109. return true;
  110. return false;
  111. }
  112. /// <summary>
  113. /// 编辑
  114. /// </summary>
  115. /// <param name="sdt"></param>
  116. /// <returns></returns>
  117. public bool EditSetDataType(SetDataType sdt)
  118. {
  119. if (SqlHelper.ExecuteNonQuery("update SetDataType set Name = @Name ,IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@Name", sdt.Name), new SqlParameter("@IsEnable", sdt.IsEnable), new SqlParameter("@Id",sdt.Id)) > 0)
  120. return true;
  121. return false;
  122. }
  123. }
  124. }