ProjectandprogramDal.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 ProjectandprogramDal
  10. {
  11. private IDatabase CurrDb = null;
  12. private string commonFilter = null;
  13. public ProjectandprogramDal(IDatabase db)
  14. {
  15. CurrDb = db;
  16. }
  17. public ProjectandprogramDal(IDatabase db, string userCode)
  18. {
  19. CurrDb = db;
  20. var smDal = new StaffMachineDal(CurrDb);
  21. string errorinfo = string.Empty;
  22. var idFilter = smDal.GetFilter(userCode, ref errorinfo);
  23. commonFilter = idFilter;
  24. }
  25. public int GetCount(string filter)
  26. {
  27. string errorinfo = string.Empty;
  28. //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
  29. var entities = CurrDb.FindListForCondition<Projectandprogram>(commonFilter + filter, ref errorinfo);
  30. if (entities != null)
  31. {
  32. return entities.Count();
  33. }
  34. return 0;
  35. }
  36. public IEnumerable<Projectandprogram> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  37. {
  38. var pros = CurrDb.FindListForCondition<Projectandprogram>($" {commonFilter + filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  39. return pros;
  40. }
  41. public Projectandprogram Get(int id)
  42. {
  43. var pro = CurrDb.FindEntityFor<Projectandprogram>(id);
  44. return pro;
  45. }
  46. public int Add(Projectandprogram pro, string userCode, ref string errorinfo)
  47. {
  48. var entities = CurrDb.FindListForCondition<Projectandprogram>($" and a.Recipe='{pro.Recipe}' ", ref errorinfo);
  49. if (entities != null && entities.Count() > 0)
  50. {
  51. errorinfo = "程序已存在,请确认";
  52. return -1;
  53. }
  54. pro.RecCode = userCode;
  55. pro.ModCode = userCode;
  56. pro.RecTime = DateTime.Now;
  57. pro.ModTime = DateTime.Now;
  58. string sql = $"insert into Projectandprogram(Recipe,Project,RecCode,RecTime," +
  59. $"ModCode,ModTime) values('{pro.Recipe}','{pro.Project}','{pro.RecCode}'," +
  60. $"'{pro.RecTime.ToString("yyyy-MM-dd")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd")}');";
  61. sql += "select @@identity;";
  62. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  63. return id;
  64. }
  65. public int Update(Projectandprogram role, string userCode, ref string errorinfo)
  66. {
  67. var entities = CurrDb.FindListForCondition<Projectandprogram>($" and a.Recipe='{role.Recipe}' " +
  68. $"and a.ID<>{role.Id}", ref errorinfo);
  69. if (entities != null && entities.Count() > 0)
  70. {
  71. errorinfo = "已存在相同的程序,请确认";
  72. return -1;
  73. }
  74. if (CurrDb.UpdateFor(role, userCode) < 0)
  75. {
  76. return -1;
  77. }
  78. return role.Id;
  79. }
  80. public int Delete(int id, ref string msg)
  81. {
  82. if (CurrDb.DeleteFor<Projectandprogram>(id) < 0)
  83. {
  84. msg = "删除失败";
  85. return -1;
  86. }
  87. msg = string.Empty;
  88. return 1;
  89. }
  90. }
  91. }