PartInfoDal.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 PartInfoDal
  10. {
  11. private IDatabase CurrDb = null;
  12. public PartInfoDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public IEnumerable<Partinfo> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  17. {
  18. var pros = CurrDb.FindListForCondition<Partinfo>($" { 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<Partinfo>( filter, ref errorinfo);
  26. if (entities != null)
  27. {
  28. return entities.Count();
  29. }
  30. return 0;
  31. }
  32. /// <summary>
  33. /// 添加机台并返回机台Id
  34. /// </summary>
  35. /// <param name="role"></param>
  36. /// <param name="userCode"></param>
  37. /// <returns></returns>
  38. public int Add(Partinfo pro, string userCode, ref string errorinfo)
  39. {
  40. var entities = CurrDb.FindListForCondition<Partinfo>($" and a.partCode='{pro.partCode}' ", ref errorinfo);
  41. if (entities != null && entities.Count() > 0)
  42. {
  43. errorinfo = "partCode已存在,请确认";
  44. return -1;
  45. } pro.RecCode = userCode;
  46. pro.ModCode = userCode;
  47. pro.RecTime = DateTime.Now;
  48. pro.ModTime = DateTime.Now;
  49. string sql = $"insert into Partinfo(partCode,RecCode,RecTime," +
  50. $"ModCode,ModTime) values('{pro.partCode}','{pro.RecCode}'," +
  51. $"'{pro.RecTime.ToString("yyyy-MM-dd")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd")}');";
  52. sql += "select @@identity;";
  53. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  54. return id;
  55. }
  56. /// <summary>
  57. /// 待优化 存在删除后不能
  58. /// </summary>
  59. /// <param name="role"></param>
  60. /// <param name="userCode"></param>
  61. /// <param name="errorinfo"></param>
  62. /// <returns></returns>
  63. public int Update(Partinfo role, string userCode, ref string errorinfo)
  64. {
  65. var entities = CurrDb.FindListForCondition<Partinfo>($" and a.partCode='{role.partCode}' " +
  66. $"and a.ID<>{role.ID}", ref errorinfo);
  67. if (entities != null && entities.Count() > 0)
  68. {
  69. errorinfo = "已存在相同的机台,请确认";
  70. return -1;
  71. }
  72. if (CurrDb.UpdateFor(role, userCode) < 0)
  73. {
  74. return -1;
  75. }
  76. return role.ID;
  77. }
  78. public int Delete(int id, ref string msg)
  79. {
  80. var sql = $"delete from PartMachine where partID={id} ";
  81. if (CurrDb.ExecuteBySql(sql) < 0)
  82. return -1;
  83. if (CurrDb.DeleteFor<Partinfo>(id) < 0)
  84. {
  85. msg = "删除失败";
  86. return -1;
  87. }
  88. msg = string.Empty;
  89. return 1;
  90. }
  91. public Partinfo Get(int id)
  92. {
  93. var pro = CurrDb.FindEntityFor<Partinfo>(id);
  94. return pro;
  95. }
  96. }
  97. }