ProgramRuleDal.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Cksoft.Data;
  2. using DllEapEntity.Rms;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace DllEapDal
  8. {
  9. public class ProgramRuleDal
  10. {
  11. private IDatabase CurrDb;
  12. public ProgramRuleDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public IEnumerable<ProgramRule> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  17. {
  18. var pros = CurrDb.FindListForCondition<ProgramRule>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  19. return pros;
  20. }
  21. public int GetCount(string filter)
  22. {
  23. string errorinfo = string.Empty;
  24. //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
  25. var entities = CurrDb.FindListForCondition<ProgramRule>(filter, ref errorinfo);
  26. if (entities != null)
  27. {
  28. return entities.Count();
  29. }
  30. return 0;
  31. }
  32. public ProgramRule Get(int id)
  33. {
  34. var pro = CurrDb.FindEntityFor<ProgramRule>(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(ProgramRule pro, string userCode, ref string errorinfo)
  44. {
  45. var entities = CurrDb.FindListForCondition<ProgramRule>($" and a.PartCode='{pro.PartCode}' and a.ProgramMstID='{pro.ProgramMstID}'", ref errorinfo);
  46. if (entities != null && entities.Count() > 0)
  47. {
  48. errorinfo = "已存在编号与程序都相同的规则,请确认";
  49. return -1;
  50. }
  51. pro.RecCode = pro.ModCode = userCode;
  52. pro.RecTime = pro.ModTime = DateTime.Now;
  53. string sql = $"insert into ProgramRule(ProgramMstID,PartCode,Remark,RecCode,RecTime," +
  54. $"ModCode,ModTime,IsUse) values('{pro.ProgramMstID}','{pro.PartCode}','{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.IsUse});";
  55. sql += "select @@identity;";
  56. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  57. return id;
  58. }
  59. public int Update(ProgramRule role, string userCode, ref string errorinfo)
  60. {
  61. var entities = CurrDb.FindListForCondition<ProgramRule>($" and a.PartCode='{role.PartCode}' and a.ProgramMstID='{role.ProgramMstID}' " +
  62. $"and a.ID<>{role.ID}", ref errorinfo);
  63. if (entities != null && entities.Count() > 0)
  64. {
  65. errorinfo = "已存在编号与程序都相同的规则,请确认";
  66. return -1;
  67. }
  68. if(CurrDb.UpdateFor(role, userCode) < 0)
  69. {
  70. return -1;
  71. }
  72. return role.ID;
  73. }
  74. public int Delete(int id, ref string msg)
  75. {
  76. if (CurrDb.DeleteFor<ProgramRule>(id) < 0)
  77. {
  78. msg = "删除失败";
  79. return -1;
  80. }
  81. msg = string.Empty;
  82. return 1;
  83. }
  84. public int ChangeIsUse(int id, int isUse)
  85. {
  86. string sql = string.Format($"update programrule set isuse={isUse} where id={id}");
  87. return CurrDb.ExecuteBySql(sql);
  88. }
  89. }
  90. }