BusinessFileRelationDal.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using DllEapEntity.Dtos;
  8. namespace DllEapDal
  9. {
  10. public class BusinessFileRelationDal
  11. {
  12. private IDatabase CurrDb = null;
  13. private string commonFilter = null;
  14. public BusinessFileRelationDal(IDatabase db)
  15. {
  16. CurrDb = db;
  17. }
  18. public BusinessFileRelationDal(IDatabase db, string userCode)
  19. {
  20. CurrDb = db;
  21. var smDal = new StaffMachineDal(CurrDb);
  22. string errorinfo = string.Empty;
  23. var idFilter = smDal.GetFilter(userCode, ref errorinfo);
  24. commonFilter = idFilter;
  25. }
  26. public BusinessFileRelation IUBusinessFileRelation(BusinessFileRelation mst, string usercode, ref string errorinfo)
  27. {
  28. try
  29. {
  30. int result = 0;
  31. int id = mst.ID;
  32. if (mst.EntityStatusID == 1)
  33. {
  34. mst.RecCode = usercode;
  35. mst.RecTime = DateTime.Now;
  36. mst.ModCode = usercode;
  37. mst.ModTime = DateTime.Now;
  38. result = CurrDb.InsertFor(mst, usercode);
  39. if (result < 0)
  40. {
  41. return null;
  42. }
  43. object objid = CurrDb.FindObject("select @@IDENTITY");
  44. if (objid.ToString() == "")
  45. {
  46. return null;
  47. }
  48. id = int.Parse(objid.ToString());
  49. }
  50. else
  51. {
  52. mst.ModCode = usercode;
  53. mst.ModTime = DateTime.Now;
  54. result = CurrDb.UpdateFor(mst, usercode);
  55. if (result < 0)
  56. {
  57. return null;
  58. }
  59. }
  60. mst = CurrDb.FindEntityFor<BusinessFileRelation>(id);
  61. return mst;
  62. }
  63. catch (Exception e)
  64. {
  65. errorinfo = e.Message;
  66. return null;
  67. }
  68. }
  69. public BusinessFileRelation IUBusinessFileRelation(int busifileid,int fileid, string usercode, ref string errorinfo)
  70. {
  71. try
  72. {
  73. string condition = $" and a.BusinessFileID={busifileid} and a.FileInfoID={fileid}";
  74. List<BusinessFileRelation> list = CurrDb.FindListForCondition<BusinessFileRelation>(condition, ref errorinfo).ToList();
  75. if (list.Count > 0)
  76. return list[0];
  77. BusinessFileRelation rela = new BusinessFileRelation();
  78. rela.BusinessFileID = busifileid;
  79. rela.FileInfoID = fileid;
  80. condition = $" and a.BusinessFileID={busifileid}";
  81. list = CurrDb.FindListForCondition<BusinessFileRelation>(condition, ref errorinfo).ToList();
  82. if (list.Count <= 0)
  83. {
  84. rela.Version = 1;
  85. }
  86. else
  87. {
  88. rela.Version = list.Max(t => t.Version) + 1;
  89. }
  90. rela = IUBusinessFileRelation(rela, usercode, ref errorinfo);
  91. return rela;
  92. }
  93. catch (Exception e)
  94. {
  95. errorinfo = e.Message;
  96. return null;
  97. }
  98. }
  99. private string ComputerPath(TFileInfo entity)
  100. {
  101. int dir = entity.ID / 1000;
  102. return $"{dir}";
  103. }
  104. }
  105. }