ReportlogicDal.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ReportlogicDal
  13. {
  14. private IDatabase CurrDb = null;
  15. public ReportlogicDal(IDatabase db)
  16. {
  17. CurrDb = db;
  18. }
  19. public IEnumerable<Reportlogic> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  20. {
  21. try
  22. {
  23. var pros = CurrDb.FindListForCondition<Reportlogic>($" {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<Reportlogic>(filter, ref errorinfo);
  36. if (entities != null)
  37. {
  38. return entities.Count();
  39. }
  40. return 0;
  41. }
  42. public Reportlogic GetSingle(string pageName, string errorinfo)
  43. {
  44. string filter = $" and a.pageName='{pageName}'";
  45. var pro = CurrDb.FindListForCondition<Reportlogic>(filter,ref errorinfo).FirstOrDefault();
  46. return pro;
  47. }
  48. /// <summary>
  49. /// 添加WorkingProcedure并返回Id
  50. /// </summary>
  51. /// <param name="role"></param>
  52. /// <param name="userCode"></param>
  53. /// <returns></returns>
  54. public int Add(Reportlogic pro, string userCode, ref string errorinfo)
  55. {
  56. var entities = CurrDb.FindListForCondition<Reportlogic>($" and a.pageName='{pro.pageName}' ", ref errorinfo);
  57. if (entities != null && entities.Count() > 0)
  58. {
  59. errorinfo = "已存在相同界面名称,请确认!";
  60. return -1;
  61. }
  62. CurrDb.InsertFor(pro, userCode);
  63. var sql = "select @@identity;";
  64. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  65. return id;
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <param name="role"></param>
  71. /// <param name="userCode"></param>
  72. /// <param name="errorinfo"></param>
  73. /// <returns></returns>
  74. public int Update(Reportlogic role, string userCode, ref string errorinfo)
  75. {
  76. var entities = CurrDb.FindListForCondition<Reportlogic>($" and a.pageName='{role.pageName}' and a.ID<>{role.ID}", ref errorinfo);
  77. if (entities != null && entities.Count() > 0)
  78. {
  79. errorinfo = "已存在相同界面名称,请确认";
  80. return -1;
  81. }
  82. if (CurrDb.UpdateFor(role, userCode) < 0)
  83. {
  84. return -1;
  85. }
  86. return role.ID;
  87. }
  88. }
  89. }