ProgramMstDetailDal.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Cksoft.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using DllEapEntity.Rms;
  6. using System.Linq;
  7. using DllEapEntity;
  8. namespace DllEapDal
  9. {
  10. public class ProgramMstDetailDal
  11. {
  12. private IDatabase CurrDb;
  13. public ProgramMstDetailDal(IDatabase db)
  14. {
  15. this.CurrDb = db;
  16. }
  17. public IEnumerable<ProgramParamsDetail> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  18. {
  19. var pros = CurrDb.FindListForCondition<ProgramParamsDetail>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  20. return pros;
  21. }
  22. public int GetCount(string filter)
  23. {
  24. string sql = $"select count(1) from ProgramParamsDetail a where 1=1 {filter}";
  25. return Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
  26. }
  27. public ProgramParamsDetail Get(int id)
  28. {
  29. var pro = CurrDb.FindEntityFor<ProgramParamsDetail>(id);
  30. return pro;
  31. }
  32. /// <summary>
  33. /// 添加角色并返回角色Id
  34. /// </summary>
  35. /// <param name="role"></param>
  36. /// <param name="userCode"></param>
  37. /// <returns></returns>
  38. public int Add(ProgramParamsDetail pro, string userCode)
  39. {
  40. pro.RecCode = pro.ModCode = userCode;
  41. pro.RecTime = pro.ModTime = DateTime.Now;
  42. string sql = $"insert into ProgramParamsDetail(PreID,MMSecDetailID,UCL,CL,LCL,SVTYPE,CTLTYPE,MODULE,Remark,RecCode,RecTime," +
  43. $"ModCode,ModTime,IsCompare,FNum) values('{pro.PreID}','{pro.MMSecDetailID}','{pro.UCL}','{pro.CL}','{pro.LCL}','{pro.SVType}','{pro.CTLType}'," +
  44. $"'{pro.Module}','{pro.Remark}','{pro.RecCode}','{pro.RecTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd HH:mm:ss")}',{pro.IsCompare},{pro.FNum});";
  45. sql += "select @@identity;";
  46. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  47. string errorinfo = string.Empty;
  48. var modelDetails = CurrDb.FindListForCondition<ModelSubDetail>($" and PreID='{pro.MMSecDetailID}'", ref errorinfo);
  49. if (modelDetails != null && modelDetails.Count() > 0)
  50. {
  51. foreach (var item in modelDetails)
  52. {
  53. var ppsubDetail = new PPSubDetail
  54. {
  55. CL = item.CL,
  56. FNum = item.FNum,
  57. IsCompare = 1,
  58. LCL = item.LCL,
  59. ModCode = userCode,
  60. ModTime = DateTime.Now,
  61. MPSubDetailID = item.ID,
  62. ParameFName = item.FName,
  63. PreID = id,
  64. RecCode = userCode,
  65. RecTime = DateTime.Now,
  66. UCL = item.UCL
  67. };
  68. if (CurrDb.InsertFor<PPSubDetail>(ppsubDetail, userCode) <= 0)
  69. {
  70. return -1;
  71. }
  72. }
  73. }
  74. return id;
  75. }
  76. public int Update(ProgramParamsDetail role, string userCode)
  77. {
  78. if(CurrDb.UpdateFor(role, userCode)<0)
  79. {
  80. return -1;
  81. }
  82. return role.ID;
  83. }
  84. public int Delete(int id, ref string msg)
  85. {
  86. // 判断是否有产品正在使用该程序
  87. if (CurrDb.DeleteFor<ProgramParamsDetail>(id) < 0)
  88. {
  89. msg = "删除失败";
  90. return -1;
  91. }
  92. msg = string.Empty;
  93. return 1;
  94. }
  95. }
  96. }