OfdisconDal.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using DllEapEntity.Dtos;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. namespace DllEapDal.OFILM
  11. {
  12. public class OfdisconDal
  13. {
  14. private IDatabase CurrDb = null;
  15. public OfdisconDal(IDatabase db)
  16. {
  17. CurrDb = db;
  18. }
  19. public IEnumerable<Ofdiscon> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  20. {
  21. try
  22. {
  23. var pros = CurrDb.FindListForCondition<Ofdiscon>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  24. return pros;
  25. }
  26. catch (Exception ex)
  27. {
  28. Console.WriteLine(ex.ToString() + ex.StackTrace);
  29. return null;
  30. }
  31. }
  32. public int GetCount(string filter)
  33. {
  34. string errorinfo = string.Empty;
  35. var entities = CurrDb.FindListForCondition<Ofdiscon>(filter, ref errorinfo);
  36. if (entities != null)
  37. {
  38. return entities.Count();
  39. }
  40. return 0;
  41. }
  42. public Ofdiscon Get(int id)
  43. {
  44. var pro = CurrDb.FindEntityFor<Ofdiscon>(id);
  45. return pro;
  46. }
  47. /// <summary>
  48. /// 添加WorkingProcedure并返回Id
  49. /// </summary>
  50. /// <param name="role"></param>
  51. /// <param name="userCode"></param>
  52. /// <returns></returns>
  53. public int Add(Ofdiscon pro, string userCode, ref string errorinfo)
  54. {
  55. var entities = CurrDb.FindListForCondition<Ofdiscon>($" and a.plantid='{pro.plantid}' and a.pcode='{pro.pcode}' ", ref errorinfo);
  56. if (entities != null && entities.Count() > 0)
  57. {
  58. errorinfo = "已存在相同厂房ID、工序,请确认!";
  59. return -1;
  60. }
  61. CurrDb.InsertFor(pro, userCode);
  62. var sql = "select @@identity;";
  63. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  64. return id;
  65. }
  66. /// <summary>
  67. ///
  68. /// </summary>
  69. /// <param name="role"></param>
  70. /// <param name="userCode"></param>
  71. /// <param name="errorinfo"></param>
  72. /// <returns></returns>
  73. public int Update(Ofdiscon role, string userCode, ref string errorinfo)
  74. {
  75. var entities = CurrDb.FindListForCondition<Ofdiscon>($" and a.plantid='{role.plantid}' and a.pcode='{role.pcode}' " +
  76. $"and a.ID<>{role.id}", ref errorinfo);
  77. if (entities != null && entities.Count() > 0)
  78. {
  79. errorinfo = "已存在相同厂房ID、工序,请确认";
  80. return -1;
  81. }
  82. if (CurrDb.UpdateFor(role, userCode) < 0)
  83. {
  84. return -1;
  85. }
  86. return role.id;
  87. }
  88. public IEnumerable<Ofdiscon> getWorkingProcedure(int id)
  89. {
  90. var sql = $"select * from Ofdiscon where ID={id}";
  91. return CurrDb.FindList<Ofdiscon>(sql);
  92. }
  93. public int Delete(int id, ref string msg)
  94. {
  95. if (CurrDb.DeleteFor<Ofdiscon>(id) < 0)
  96. {
  97. msg = "删除失败";
  98. return -1;
  99. }
  100. msg = string.Empty;
  101. return 1;
  102. }
  103. public IEnumerable<Ofdiscon> GetOfdisconExprort(int take)
  104. {
  105. var sql = $"select * from Ofdiscon limit {take}";
  106. IEnumerable<Ofdiscon> dtos = CurrDb.FindList<Ofdiscon>(sql).Take(take);
  107. if (dtos == null || dtos.Count() <= 0)
  108. return null;
  109. return dtos;
  110. }
  111. }
  112. }