ProgramFileParamDal.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Cksoft.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using DllEapEntity.Rms;
  6. using System.Linq;
  7. namespace DllEapDal
  8. {
  9. public class ProgramFileParamDal
  10. {
  11. private IDatabase CurrDb;
  12. public ProgramFileParamDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public IEnumerable<ProgramFileParams> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  17. {
  18. var pros = CurrDb.FindListForCondition<ProgramFileParams>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  19. return pros;
  20. }
  21. public int GetCount(string filter)
  22. {
  23. string sql = $"select count(1) from programfileparams a where 1=1 {filter}";
  24. return Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
  25. }
  26. public ProgramFileParams Get(int id)
  27. {
  28. var pro = CurrDb.FindEntityFor<ProgramFileParams>(id);
  29. return pro;
  30. }
  31. /// <summary>
  32. /// 添加角色并返回角色Id
  33. /// </summary>
  34. /// <param name="role"></param>
  35. /// <param name="userCode"></param>
  36. /// <returns></returns>
  37. public int Add(int programId,IEnumerable<ProgramFileParams>pros, string userCode)
  38. {
  39. var sql = $"delete from ProgramFileParams where PreiD={programId}";
  40. CurrDb.ExecuteBySql(sql);
  41. if (pros != null && pros.Count() > 0)
  42. {
  43. foreach(var item in pros)
  44. {
  45. if (CurrDb.Insert(item) < 0)
  46. {
  47. return -1;
  48. }
  49. }
  50. }
  51. return 1;
  52. }
  53. public int Update(ProgramParamsDetail role, string userCode)
  54. {
  55. if (CurrDb.UpdateFor(role, userCode) < 0)
  56. {
  57. return -1;
  58. }
  59. return role.ID;
  60. }
  61. public int Delete(int id, ref string msg)
  62. {
  63. // 判断是否有产品正在使用该程序
  64. if (CurrDb.DeleteFor<ProgramParamsDetail>(id) < 0)
  65. {
  66. msg = "删除失败";
  67. return -1;
  68. }
  69. msg = string.Empty;
  70. return 1;
  71. }
  72. }
  73. }