TProcessDal.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using Cksoft.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using DllEapEntity;
  6. using DllEapEntity.Mes;
  7. using System.Linq;
  8. using DllEapEntity.Rms;
  9. namespace DllEapDal
  10. {
  11. public class TProcessDal
  12. {
  13. private IDatabase CurrDb;
  14. public TProcessDal(IDatabase db)
  15. {
  16. CurrDb = db;
  17. }
  18. public IEnumerable<Process> Get()
  19. {
  20. var models = CurrDb.FindList<Process>();
  21. return models;
  22. }
  23. public IEnumerable<TProcess> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  24. {
  25. var pros = CurrDb.FindListForCondition<TProcess>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  26. return pros;
  27. }
  28. public int GetCount(string filter)
  29. {
  30. string errorinfo = string.Empty;
  31. //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
  32. var entities = CurrDb.FindListForCondition<TProcess>(filter, ref errorinfo);
  33. if (entities != null)
  34. {
  35. return entities.Count();
  36. }
  37. return 0;
  38. }
  39. public TProcess Get(int id)
  40. {
  41. var pro = CurrDb.FindEntityFor<TProcess>(id);
  42. return pro;
  43. }
  44. /// <summary>
  45. /// 添加角色并返回角色Id
  46. /// </summary>
  47. /// <param name="role"></param>
  48. /// <param name="userCode"></param>
  49. /// <returns></returns>
  50. public int Add(TProcess pro, string userCode, ref string errorinfo)
  51. {
  52. var entities = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{pro.FCode}' ", ref errorinfo);
  53. if (entities != null && entities.Count() > 0)
  54. {
  55. errorinfo = "制程已存在,请确认";
  56. return -1;
  57. }
  58. string error = string.Empty;
  59. pro.reccode = pro.modcode = userCode;
  60. pro.rectime = pro.rectime = DateTime.Now;
  61. /* string sql = $"insert into tprocess(FCode,FName,Remark,RecCode,RecTime," +
  62. $"ModCode,ModTime,IsChange,UseImage) values('{pro.FCode}','{pro.FName}','{pro.Remark}','{pro.reccode}','{pro.rectime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.modcode}'," +
  63. $"'{pro.modtime.ToString("yyyy-MM-dd HH:mm:ss")}',{pro.IsChange},'{pro.UseImage}');";*/
  64. if (CurrDb.InsertFor<TProcess>(pro, error) >0)
  65. {
  66. string sql = "select @@identity;";
  67. var id = Convert.ToInt32((CurrDb.FindObject(sql)) ?? "-1");
  68. return id;
  69. }
  70. else
  71. {
  72. return -1;
  73. }
  74. }
  75. public int Update(TProcess role, string userCode, ref string errorinfo)
  76. {
  77. var entities = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{role.FCode}' " +
  78. $"and a.ID<>{role.ID}", ref errorinfo);
  79. if (entities != null && entities.Count() > 0)
  80. {
  81. errorinfo = "已存在相同的制程,请确认";
  82. return -1;
  83. }
  84. var old = CurrDb.FindEntityFor<TProcess>(role.ID);
  85. if (CurrDb.UpdateFor(role, userCode) < 0)
  86. {
  87. return -1;
  88. }
  89. var sql = $"UPDATE mactprocess set PCode='{role.FCode}' where PCode='{old.FCode}' and id>0";
  90. if (CurrDb.ExecuteBySql(sql) < 0)
  91. {
  92. errorinfo = "更新机台制程信息表失败";
  93. return -1;
  94. }
  95. return role.ID;
  96. }
  97. public IEnumerable<MacTProcess> getmactprocess(TProcess process)
  98. {
  99. var sql = $"select * from mactprocess where pCode='{process.FCode}'";
  100. return CurrDb.FindList<MacTProcess>(sql);
  101. }
  102. public TProcess getTProcess(int id)
  103. {
  104. return CurrDb.FindEntity<TProcess>(id);
  105. }
  106. public int Delete(int id, ref string msg)
  107. {
  108. var process = CurrDb.FindEntityFor<TProcess>(id);
  109. var sql = $"delete from mactprocess where pCode='{process.FCode}'";
  110. if (CurrDb.ExecuteBySql(sql) < 0)
  111. {
  112. msg = "删除机台制程关系表失败";
  113. return -1;
  114. }
  115. if (CurrDb.DeleteFor<TProcess>(id) < 0)
  116. {
  117. msg = "删除失败";
  118. return -1;
  119. }
  120. msg = string.Empty;
  121. return 1;
  122. }
  123. public int ChangeField(string field, int id, object value)
  124. {
  125. var sql = $"update TProcess set {field}='{value}' where id='{id}'";
  126. if (CurrDb.ExecuteBySql(sql) < 0)
  127. {
  128. return -1;
  129. }
  130. return 1;
  131. }
  132. public TProcess AddOrGet(TProcess process,string userCode,ref string errorinfo)
  133. {
  134. var exist = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{process.FCode.Trim()}'",
  135. ref errorinfo).FirstOrDefault();
  136. if (exist != null)
  137. return exist;
  138. if (CurrDb.InsertFor(process, userCode) < 0)
  139. return null;
  140. exist = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{process.FCode.Trim()}'",
  141. ref errorinfo).FirstOrDefault();
  142. return exist;
  143. }
  144. }
  145. }