PMHistoryDal.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using DllEapEntity.PM;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DllEapDal
  9. {
  10. public class PMHistoryDal
  11. {
  12. private IDatabase CurrDb;
  13. public PMHistoryDal(IDatabase db)
  14. {
  15. CurrDb = db;
  16. }
  17. public IEnumerable<PMHistory> Get()
  18. {
  19. var models = CurrDb.FindList<PMHistory>();
  20. return models;
  21. }
  22. public IEnumerable<PMHistory> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  23. {
  24. var pros = CurrDb.FindListForCondition<PMHistory>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  25. if (pros != null && pros.Count() > 0)
  26. {
  27. foreach(var item in pros)
  28. {
  29. var attaches = CurrDb.FindListForCondition<Attachment>($" and a.PreId={item.ID}",ref errorinfo);
  30. item.Attachments = attaches;
  31. }
  32. }
  33. return pros;
  34. }
  35. public int GetCount(string filter)
  36. {
  37. string errorinfo = string.Empty;
  38. //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
  39. var entities = CurrDb.FindListForCondition<PMHistory>(filter, ref errorinfo);
  40. if (entities != null)
  41. {
  42. return entities.Count();
  43. }
  44. return 0;
  45. }
  46. public PMHistory Get(int id)
  47. {
  48. string errorinfo = string.Empty;
  49. var pro = CurrDb.FindEntityFor<PMHistory>(id);
  50. if (pro != null)
  51. {
  52. var attaches = CurrDb.FindListForCondition<Attachment>($" and a.PreId={id}", ref errorinfo);
  53. pro.Attachments = attaches;
  54. }
  55. return pro;
  56. }
  57. /// <summary>
  58. /// 添加角色并返回角色Id
  59. /// </summary>
  60. /// <param name="role"></param>
  61. /// <param name="userCode"></param>
  62. /// <returns></returns>
  63. public int Add(PMHistory pro, string userCode, ref string errorinfo)
  64. {
  65. pro.RecCode = pro.ModCode = userCode;
  66. pro.RecTime = pro.ModTime = DateTime.Now;
  67. var sql = $@"insert into PMHistory (macid,pmid,pmtime,maintenance,remark,reccode,rectime,modcode,modtime,pmer)
  68. values('{pro.MacID}','{pro.PMID}','{pro.PMTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.Maintenance}','{pro.Remark}','{pro.RecCode}','{pro.RecTime.ToString("yyyy-MM-dd HH:mm:ss")}',
  69. '{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.Pmer}');select @@identity;";
  70. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
  71. if (pro.Attachments != null && pro.Attachments.Count() > 0)
  72. {
  73. foreach(var item in pro.Attachments)
  74. {
  75. item.PreId = id;
  76. if (CurrDb.InsertFor<Attachment>(item, userCode) < 0)
  77. {
  78. errorinfo = "插入附件失败,请联系管理员";
  79. return -1;
  80. }
  81. }
  82. }
  83. return id;
  84. }
  85. public int Update(PMHistory role, string userCode, ref string errorinfo)
  86. {
  87. return CurrDb.UpdateFor<PMHistory>(role, userCode);
  88. }
  89. public int Delete(int id, ref string msg)
  90. {
  91. if (CurrDb.DeleteFor<PMSchema>(id) < 0)
  92. {
  93. msg = "删除失败";
  94. return -1;
  95. }
  96. msg = string.Empty;
  97. return 1;
  98. }
  99. }
  100. }