PartMachineDal.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 PartMachineDal
  10. {
  11. private IDatabase CurrDb = null;
  12. private string commonFilter = null;
  13. public PartMachineDal(IDatabase db)
  14. {
  15. CurrDb = db;
  16. }
  17. public PartMachineDal(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 IEnumerable<PartMachine> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  26. {
  27. var pros = CurrDb.FindListForCondition<PartMachine>($" {commonFilter + filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  28. return pros;
  29. }
  30. public int GetCount(string filter)
  31. {
  32. string errorinfo = string.Empty;
  33. //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
  34. var entities = CurrDb.FindListForCondition<PartMachine>(commonFilter + filter, ref errorinfo);
  35. if (entities != null)
  36. {
  37. return entities.Count();
  38. }
  39. return 0;
  40. }
  41. public PartMachine Get(int id)
  42. {
  43. var pro = CurrDb.FindEntityFor<PartMachine>(id);
  44. return pro;
  45. }
  46. public int DeleteMac(IEnumerable<int> funcIds, int roleId)
  47. {
  48. var sql = $"delete from PartMachine where partID={roleId} ";
  49. if (CurrDb.ExecuteBySql(sql) < 0)
  50. return -1;
  51. return 1;
  52. }
  53. public int Add(IEnumerable<int> funcIds, int macID, string[] pros, string[] employs, string[] qtypes, string usercode)
  54. {
  55. if (funcIds == null || funcIds.Count() <= 0)
  56. {
  57. return 1;
  58. }
  59. int count = 0;
  60. foreach (var item in funcIds)
  61. {
  62. var res = CurrDb.InsertFor<PartMachine>(new PartMachine()
  63. {
  64. machineID = item,
  65. partID = macID,
  66. programName = pros[count],
  67. employNum = employs[count],
  68. qtype = qtypes[count],
  69. RecTime = DateTime.Now,
  70. ModTime = DateTime.Now,
  71. ModCode = usercode,
  72. RecCode = usercode,
  73. }, usercode);
  74. if (res < 0)
  75. return -1;
  76. count++;
  77. }
  78. return 1;
  79. }
  80. }
  81. }