SendMachineSuppliesDataServices.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Models;
  9. namespace DAL
  10. {
  11. /// <summary>
  12. /// 雷怡 2021-08-18-14:34
  13. /// 送机物资资料数据访问层
  14. /// </summary>
  15. public class SendMachineSuppliesDataServices
  16. {
  17. List<SendMachineSuppliesData> excuteSql(string sql, params SqlParameter[] param)
  18. {
  19. return ServiceBase<SendMachineSuppliesData>.excuteSql(new SendMachineSuppliesData(), "SendMachineSuppliesData", sql, CommandType.Text, param);
  20. }
  21. SendMachineSuppliesData excuteType(string sql, params SqlParameter[] param)
  22. {
  23. //查询结果放入对象集合
  24. List<SendMachineSuppliesData> List = excuteSql(sql, param);
  25. SendMachineSuppliesData smsd = new SendMachineSuppliesData();
  26. //判断集合是否为空
  27. if (List == null || List.Count == 0)
  28. {
  29. return smsd;
  30. }
  31. //返回单个对象
  32. return List[0];
  33. }
  34. /// <summary>
  35. /// //增Add
  36. /// </summary>
  37. /// <param name="smsd">送机物资数据类</param>
  38. /// <returns></returns>
  39. public bool Add(SendMachineSuppliesData smsd)
  40. {
  41. string sql = "insert into SendMachineSuppliesData values(@Country,@MaterialName,@MaterialPrice,@MaterialRemark,@Operator,@OperatingTime,@Isdel);SELECT @@IDENTITY";
  42. SqlParameter[] parameter = new SqlParameter[]{
  43. new SqlParameter("@Country",smsd.Country),
  44. new SqlParameter("@MaterialName",smsd.MaterialName),
  45. new SqlParameter("@MaterialPrice",smsd.MaterialPrice),
  46. new SqlParameter("@MaterialRemark",smsd.MaterialRemark),
  47. new SqlParameter("@Operator",smsd.Operator),
  48. new SqlParameter("@OperatingTime",smsd.OperatingTime),
  49. new SqlParameter("@Isdel",smsd.Isdel)
  50. };
  51. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  52. return true;
  53. return false;
  54. }
  55. /// <summary>
  56. /// //改Update
  57. /// </summary>
  58. /// <param name="smsd">送机物资数据</param>
  59. /// <returns></returns>
  60. public bool Update(SendMachineSuppliesData smsd)
  61. {
  62. string sql = "update SendMachineSuppliesData set Country=@Country,MaterialName=@MaterialName,MaterialPrice=@MaterialPrice,MaterialRemark=@MaterialRemark,"
  63. + "Operator=@Operator,OperatingTime=@OperatingTime,Isdel=@Isdel where Id = @Id";
  64. SqlParameter[] parameter = new SqlParameter[]{
  65. new SqlParameter("@Country",smsd.Country),
  66. new SqlParameter("@MaterialName",smsd.MaterialName),
  67. new SqlParameter("@MaterialPrice",smsd.MaterialPrice),
  68. new SqlParameter("@MaterialRemark",smsd.MaterialRemark),
  69. new SqlParameter("@Operator",smsd.Operator),
  70. new SqlParameter("@OperatingTime",smsd.OperatingTime),
  71. new SqlParameter("@Isdel",smsd.Isdel),
  72. new SqlParameter("@Id",smsd.Id)
  73. };
  74. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  75. return true;
  76. return false;
  77. }
  78. /// <summary>
  79. /// //删
  80. /// </summary>
  81. /// <param name="id"></param>
  82. /// <returns></returns>
  83. public bool Delete(int id)
  84. {
  85. if (SqlHelper.ExecuteNonQuery("update SendMachineSuppliesData set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  86. return true;
  87. return false;
  88. }
  89. /// <summary>
  90. /// 根据条件查询条件获取 - 分页
  91. /// </summary>
  92. /// <param name="pageIndex"></param>
  93. /// <param name="sumPage"></param>
  94. /// <param name="totalRecord"></param>
  95. /// <param name="MaterialName"></param>
  96. /// <returns></returns>
  97. public List<SendMachineSuppliesData> GetPagingQuery(int pageIndex, out int sumPage, out int totalRecord, string MaterialName)
  98. {
  99. string sqlwhere = "IsDel = 0 ";
  100. if (!string.IsNullOrEmpty(MaterialName) && !string.IsNullOrEmpty(MaterialName))
  101. sqlwhere += " and (MaterialName like '%" + MaterialName + "%')";
  102. return PageBase<SendMachineSuppliesData>.excutePageSql(new SendMachineSuppliesData(), "SendMachineSuppliesData", "SendMachineSuppliesData", "*", "OperatingTime desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  103. }
  104. /// <summary>
  105. /// 查询数据
  106. /// </summary>
  107. /// <returns></returns>
  108. public List<SendMachineSuppliesData> GetAll()
  109. {
  110. return excuteSql("select * from SendMachineSuppliesData Where IsDel = 0 order by OperatingTime desc");
  111. }
  112. /// <summary>
  113. /// 根据id 查询数据
  114. /// </summary>
  115. /// <returns></returns>
  116. public SendMachineSuppliesData GetAllById(int id)
  117. {
  118. return excuteType("select * from SendMachineSuppliesData Where IsDel = 0 and id ='" + id + "'");
  119. }
  120. /// <summary>
  121. /// 根据 物资名称 查询数据
  122. /// </summary>
  123. /// <returns></returns>
  124. public SendMachineSuppliesData GetAllByMaterialName(string MaterialName)
  125. {
  126. return excuteType("select * from SendMachineSuppliesData Where IsDel = 0 and MaterialName like '%" + MaterialName + "'%");
  127. }
  128. }
  129. }