EquipmentnumberDal.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using DllEapEntity.Dtos;
  4. using DllEapEntity.OFILM;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. namespace DllEapDal.OFILM
  10. {
  11. public class EquipmentnumberDal
  12. {
  13. private IDatabase CurrDb = null;
  14. public EquipmentnumberDal(IDatabase db)
  15. {
  16. CurrDb = db;
  17. }
  18. public IEnumerable<Equipmentnumber> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  19. {
  20. var pros = CurrDb.FindListForCondition<Equipmentnumber>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  21. return pros;
  22. }
  23. public int GetCount(string filter)
  24. {
  25. string errorinfo = string.Empty;
  26. var entities = CurrDb.FindListForCondition<Equipmentnumber>(filter, ref errorinfo);
  27. if (entities != null)
  28. {
  29. return entities.Count();
  30. }
  31. return 0;
  32. }
  33. public Equipmentnumber Get(int id)
  34. {
  35. var pro = CurrDb.FindEntityFor<Equipmentnumber>(id);
  36. return pro;
  37. }
  38. /// <summary>
  39. /// 添加WorkingProcedure并返回Id
  40. /// </summary>
  41. /// <param name="role"></param>
  42. /// <param name="userCode"></param>
  43. /// <returns></returns>
  44. public int Add(Equipmentnumber pro, string userCode, ref string errorinfo)
  45. {
  46. //var entities = CurrDb.FindListForCondition<Equipmentnumber>($" and a.equipmentmodel='{pro.Equipmentmodel}' and a.threeFloor='{pro.ThreeFloor}' ", ref errorinfo);
  47. //if (entities != null && entities.Count() > 0)
  48. //{
  49. // errorinfo = "已存在相同园区,机种,工段,作业内容,请确认";
  50. // return -1;
  51. //}
  52. CurrDb.InsertFor(pro, userCode);
  53. var sql = "select @@identity;";
  54. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  55. return id;
  56. }
  57. /// <summary>
  58. /// 批量新增
  59. /// </summary>
  60. /// <param name="pros"></param>
  61. /// <param name="userCode"></param>
  62. /// <param name="errorinfo"></param>
  63. /// <returns></returns>
  64. public int Adds(IEnumerable<Equipmentnumber> pros, string userCode, ref string errorinfo)
  65. {
  66. try
  67. {
  68. string sqldel = $"delete from Equipmentnumber ";
  69. CurrDb.ExecuteBySql(sqldel);
  70. CurrDb.InsertFor<Equipmentnumber>(pros, userCode);
  71. var sql = "select @@identity;";
  72. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  73. return id;
  74. }
  75. catch (Exception e)
  76. {
  77. errorinfo = e.ToString();
  78. return -1;
  79. }
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. /// <param name="role"></param>
  85. /// <param name="userCode"></param>
  86. /// <param name="errorinfo"></param>
  87. /// <returns></returns>
  88. public int Update(Equipmentnumber role, string userCode, ref string errorinfo)
  89. {
  90. //var entities = CurrDb.FindListForCondition<WorkingProcedure>($" and a.park='{role.Park}' and a.MachineType='{role.MachineType}' and a.workshopSection='{role.WorkshopSection}' and a.assignmentContent='{role.AssignmentContent}' " +
  91. // $"and a.ID<>{role.ID}", ref errorinfo);
  92. //if (entities != null && entities.Count() > 0)
  93. //{
  94. // errorinfo = "已存在相同园区,机种,工段,作业内容,请确认";
  95. // return -1;
  96. //}
  97. if (CurrDb.UpdateFor(role, userCode) < 0)
  98. {
  99. return -1;
  100. }
  101. return role.ID;
  102. }
  103. public IEnumerable<Equipmentnumber> getWorkingProcedure(int id)
  104. {
  105. var sql = $"select * from Equipmentnumber where ID={id}";
  106. return CurrDb.FindList<Equipmentnumber>(sql);
  107. }
  108. public int Delete(int id, ref string msg)
  109. {
  110. if (CurrDb.DeleteFor<Equipmentnumber>(id) < 0)
  111. {
  112. msg = "删除失败";
  113. return -1;
  114. }
  115. msg = string.Empty;
  116. return 1;
  117. }
  118. public IEnumerable<Equipmentnumber> GetEquipmentnumberExprort(string filter, string sortField, string sortOrder, int take)
  119. {
  120. var sql = $"select * from Equipmentnumber limit {take}";
  121. IEnumerable<Equipmentnumber> dtos = CurrDb.FindList<Equipmentnumber>(sql).Take(take);
  122. if (dtos == null || dtos.Count() <= 0)
  123. return null;
  124. return dtos;
  125. }
  126. /// <summary>
  127. /// 分页获取设备型号,园区,楼层
  128. /// </summary>
  129. /// <param name="start"></param>
  130. /// <param name="length"></param>
  131. /// <param name="order"></param>
  132. /// <param name="sort"></param>
  133. /// <param name="filter"></param>
  134. /// <returns></returns>
  135. public IEnumerable<ForecastDto> getEquipmentmodel(int start, int length, string order, string sort, string filter)
  136. {
  137. string sql = $@"select * from ( (select id,equipmentmodel,accounting,'三号园区' as park,'2#1F' as floor,IFNULL(threeSecFir,0) as score from equipmentnumber)
  138. UNION
  139. (select id,equipmentmodel,accounting,'未来城' as park,'A1#1F' as floor,IFNULL(futureCity,0) as score from equipmentnumber)
  140. UNION
  141. (select id,equipmentmodel,accounting,'未来城' as park,'A1#3F' as floor,IFNULL(futureCityThird,0) as score from equipmentnumber)
  142. UNION
  143. (select id,equipmentmodel,accounting,'二号园区' as park,'A1#1F' as floor,IFNULL(secfirstFir,0) as score from equipmentnumber)
  144. UNION
  145. (select id,equipmentmodel,accounting,'二号园区' as park,'A1#2F' as floor,IFNULL(secFirstSec,0) as score from equipmentnumber)
  146. UNION
  147. (select id,equipmentmodel,accounting,'二号园区' as park,'A1#3F' as floor,IFNULL(secFirstThird,0) as score from equipmentnumber)
  148. UNION
  149. (select id,equipmentmodel,accounting,'二号园区' as park,'A2#1F' as floor,IFNULL(secSecFirst,0) as score from equipmentnumber)
  150. UNION
  151. (select id,equipmentmodel,accounting,'二号园区' as park,'A2#2F' as floor,IFNULL(secSecSec,0) as score from equipmentnumber) )tt
  152. where 1=1 {filter}
  153. order by equipmentmodel,park limit {start - 1},{length}";
  154. IEnumerable<ForecastDto> dtos = CurrDb.FindList<ForecastDto>(sql);
  155. if (dtos == null || dtos.Count() <= 0)
  156. return null;
  157. return dtos;
  158. }
  159. public IEnumerable<SelectDto<int>> GetMultipleSelects(string filter)
  160. {
  161. var sql = "select ID value,equipmentmodel label from equipmentnumber";
  162. var entities = CurrDb.FindList<SelectDto<int>>(sql);
  163. return entities;
  164. }
  165. }
  166. }