MMsecDetailDal.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using DllEapEntity.Rms;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DllEapDal
  9. {
  10. public class MMSecDetailDal
  11. {
  12. private IDatabase CurrDb;
  13. public MMSecDetailDal(IDatabase db)
  14. {
  15. this.CurrDb = db;
  16. }
  17. public IEnumerable<MMSecDetail> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  18. {
  19. var pros = CurrDb.FindListForCondition<MMSecDetail>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo).ToList();
  20. return pros;
  21. }
  22. public int GetCount(string filter)
  23. {
  24. string errorinfo = string.Empty;
  25. var entities = CurrDb.FindListForCondition<MMSecDetail>(filter, ref errorinfo);
  26. if (entities != null)
  27. {
  28. return entities.Count();
  29. }
  30. return 0;
  31. }
  32. public MMSecDetail Get(int id)
  33. {
  34. string errorinfo = string.Empty;
  35. var pro = CurrDb.FindEntityFor<MMSecDetail>(id);
  36. return pro;
  37. }
  38. /// <summary>
  39. /// 添加角色并返回角色Id
  40. /// </summary>
  41. /// <param name="role"></param>
  42. /// <param name="userCode"></param>
  43. /// <returns></returns>
  44. public int Add(MMSecDetail pro, string userCode, ref string errorinfo)
  45. {
  46. pro.RecCode = pro.ModCode = userCode;
  47. pro.RecTime = pro.ModTime = DateTime.Now;
  48. //var entity = CurrDb.FindListForCondition<ProgramMst>($" and a.FName ='{pro.FName}'", ref errorinfo).FirstOrDefault();
  49. //if (entity != null)
  50. //{
  51. // errorinfo = "程序名已存在,请修改后重新添加";
  52. // return -1;
  53. //}
  54. //string sql = $"insert into ProgramMst(FName,ModelID,ProcessCode,Remark,RecCode,RecTime,ModCode,ModTime) values('{pro.FName}','{pro.ModelID}'," +
  55. // $"'{pro.ProcessCode}','{pro.Remark}','{pro.RecCode}','{pro.RecTime}','{pro.ModCode}','{pro.ModTime}');";
  56. //sql += "select @@identity;";
  57. //var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  58. //if (pro.ParamsDetail != null && pro.ParamsDetail.Count() > 0)
  59. //{
  60. // foreach (var item in pro.ParamsDetail)
  61. // {
  62. // item.PreID = id;
  63. // if (CurrDb.InsertFor<ProgramParamsDetail>(item, userCode) < 0)
  64. // {
  65. // errorinfo = "新增程序参数失败,请联系管理员";
  66. // return -1;
  67. // }
  68. // }
  69. //}
  70. errorinfo = "";
  71. return 1;
  72. }
  73. public int Update(ProgramMst role, string userCode, ref string error)
  74. {
  75. var entity = CurrDb.FindListForCondition<ProgramMst>($" and a.FName ='{role.FName}' and a.id <> '{role.ID}'", ref error).FirstOrDefault();
  76. if (entity != null)
  77. {
  78. error = "程序名已存在,请确认";
  79. return -1;
  80. }
  81. var sql = $"delete from programparamsdetail where PreID='{role.ID}'";
  82. if (CurrDb.ExecuteBySql(sql) < 0)
  83. {
  84. error = "删除原参数失败,请联系管理员";
  85. return -1;
  86. }
  87. var detail = role.ParamsDetail;
  88. if (detail != null && detail.Count() > 0)
  89. {
  90. foreach (var item in detail)
  91. {
  92. item.PreID = role.ID;
  93. if (CurrDb.InsertFor<ProgramParamsDetail>(item, userCode) < 0)
  94. {
  95. error = "新增程序参数失败,请联系管理员";
  96. return -1;
  97. }
  98. }
  99. }
  100. if (CurrDb.UpdateFor(role, userCode) > 0)
  101. {
  102. return role.ID;
  103. }
  104. return -1;
  105. }
  106. public IEnumerable< ModelSubDetail> getmodelsubdetail( int id)
  107. {
  108. string sql = $"select * from modelsubdetail where PreId='{id}'";
  109. return CurrDb.FindList<ModelSubDetail>(sql);
  110. }
  111. public int Delete(int id, ref string msg)
  112. {
  113. var items = CurrDb.FindListForCondition<OrderEvent>($" and a.MMSecDetailID={id}", ref msg).ToList();
  114. if (items != null && items.Count() > 0)
  115. {
  116. msg = "当前事件参数正在被使用,不能删除";
  117. return -1;
  118. }
  119. var prams = CurrDb.FindListForCondition<ProgramParamsDetail>($" and a.MMSecDetailID={id}", ref msg);
  120. if (prams != null && prams.Count() > 0)
  121. {
  122. msg = "当前事件参数正在被使用,不能删除";
  123. return -1;
  124. }
  125. var reportsPrams = CurrDb.FindListForCondition<ReportDetail>($" and a.SecId=(select secid from MMSecDetail where id={id} limit 1,1)", ref msg);
  126. if (reportsPrams != null && reportsPrams.Count() > 0)
  127. {
  128. msg = "当前事件参数正在被使用,不能删除";
  129. return -1;
  130. }
  131. string sql = $"delete from modelsubdetail where PreId='{id}'";
  132. if (CurrDb.ExecuteBySql(sql) < 0)
  133. {
  134. msg = "删除二级参数时出错,请联系管理员";
  135. return -1;
  136. }
  137. if (CurrDb.DeleteFor<MMSecDetail>(id) < 0)
  138. {
  139. msg = "删除程序主表时出错,请联系管理员";
  140. return -1;
  141. }
  142. msg = string.Empty;
  143. return 1;
  144. }
  145. }
  146. }