MMSecSubDetailDal.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace DllEapDal
  8. {
  9. public class MMSecSubDetailDal
  10. {
  11. private IDatabase CurrDb;
  12. public MMSecSubDetailDal(IDatabase db)
  13. {
  14. this.CurrDb = db;
  15. }
  16. public IEnumerable<ModelSubDetail> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  17. {
  18. var pros = CurrDb.FindListForCondition<ModelSubDetail>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo).ToList();
  19. return pros;
  20. }
  21. public int GetCount(string filter)
  22. {
  23. string errorinfo = string.Empty;
  24. var entities = CurrDb.FindListForCondition<ModelSubDetail>(filter, ref errorinfo);
  25. if (entities != null)
  26. {
  27. return entities.Count();
  28. }
  29. return 0;
  30. }
  31. public ModelSubDetail Get(int id)
  32. {
  33. string errorinfo = string.Empty;
  34. var pro = CurrDb.FindEntityFor<ModelSubDetail>(id);
  35. return pro;
  36. }
  37. /// <summary>
  38. /// 添加角色并返回角色Id
  39. /// </summary>
  40. /// <param name="role"></param>
  41. /// <param name="userCode"></param>
  42. /// <returns></returns>
  43. public int Add(ModelSubDetail pro, string userCode, ref string errorinfo)
  44. {
  45. pro.RecCode = pro.ModCode = userCode;
  46. pro.RecTime = pro.ModTime = DateTime.Now;
  47. var entity = CurrDb.FindListForCondition<ModelSubDetail>($" and a.FName ='{pro.FName}'", ref errorinfo).FirstOrDefault();
  48. if (entity != null)
  49. {
  50. errorinfo = "名称相同的二级参数已存在,请修改后重新添加";
  51. return -1;
  52. }
  53. string sql = $"insert into ModelSubDetail(PreID,FNum,UCL,CL,LCL,Remark,RecCode,RecTime,ModCode,ModTime,FName) values('{pro.PreID}'," +
  54. $"'{pro.FNum}','{pro.UCL}','{pro.CL}','{pro.LCL}','{pro.Remark}','{pro.RecCode}'," +
  55. $"'{pro.RecTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd HH:mm:ss")}'," +
  56. $"'{pro.FName}');";
  57. sql += "select @@identity;";
  58. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  59. errorinfo = "";
  60. return 1;
  61. }
  62. public int Update(ModelSubDetail role, string userCode, ref string error)
  63. {
  64. var entity = CurrDb.FindListForCondition<ModelSubDetail>($" and a.FName ='{role.FName}' and a.id <> '{role.ID}'", ref error).FirstOrDefault();
  65. if (entity != null)
  66. {
  67. error = "参数已存在,请确认";
  68. return -1;
  69. }
  70. if (CurrDb.UpdateFor(role, userCode) > 0)
  71. {
  72. return role.ID;
  73. }
  74. return -1;
  75. }
  76. public int Delete(int id, ref string msg)
  77. {
  78. // 判断是否有产品正在使用该程序
  79. string sql = $"select * from ppsubdetail where MPSubDetailID='{id}'";
  80. var ppSubDetails = CurrDb.FindList<PPSubDetail>(sql);
  81. if (ppSubDetails != null && ppSubDetails.Count() > 0)
  82. {
  83. msg = "该参数有正在使用的程序,不能删除,请确认";
  84. return -1;
  85. }
  86. //var rule = CurrDb.FindList<ProgramRule>(sql).FirstOrDefault();
  87. //if (rule != null)
  88. //{
  89. // msg = "该程序已经设置规则,如需删除,请先删除对应的规则";
  90. // return -1;
  91. //}
  92. if (CurrDb.DeleteFor<ModelSubDetail>(id) < 0)
  93. {
  94. msg = "删除时出错,请联系管理员";
  95. return -1;
  96. }
  97. msg = string.Empty;
  98. return 1;
  99. }
  100. public ModelSubDetail getModelSubDetail(int id)
  101. {
  102. return CurrDb.FindEntity<ModelSubDetail>(id);
  103. }
  104. }
  105. }