123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using DllEapEntity.Dtos;
- namespace DllEapDal
- {
- public class BusinessFileRelationDal
- {
- private IDatabase CurrDb = null;
- private string commonFilter = null;
- public BusinessFileRelationDal(IDatabase db)
- {
- CurrDb = db;
- }
- public BusinessFileRelationDal(IDatabase db, string userCode)
- {
- CurrDb = db;
- var smDal = new StaffMachineDal(CurrDb);
- string errorinfo = string.Empty;
- var idFilter = smDal.GetFilter(userCode, ref errorinfo);
- commonFilter = idFilter;
- }
- public BusinessFileRelation IUBusinessFileRelation(BusinessFileRelation mst, string usercode, ref string errorinfo)
- {
- try
- {
- int result = 0;
- int id = mst.ID;
- if (mst.EntityStatusID == 1)
- {
- mst.RecCode = usercode;
- mst.RecTime = DateTime.Now;
- mst.ModCode = usercode;
- mst.ModTime = DateTime.Now;
- result = CurrDb.InsertFor(mst, usercode);
- if (result < 0)
- {
- return null;
- }
- object objid = CurrDb.FindObject("select @@IDENTITY");
- if (objid.ToString() == "")
- {
- return null;
- }
- id = int.Parse(objid.ToString());
- }
- else
- {
- mst.ModCode = usercode;
- mst.ModTime = DateTime.Now;
- result = CurrDb.UpdateFor(mst, usercode);
- if (result < 0)
- {
- return null;
- }
- }
- mst = CurrDb.FindEntityFor<BusinessFileRelation>(id);
- return mst;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- public BusinessFileRelation IUBusinessFileRelation(int busifileid,int fileid, string usercode, ref string errorinfo)
- {
- try
- {
- string condition = $" and a.BusinessFileID={busifileid} and a.FileInfoID={fileid}";
- List<BusinessFileRelation> list = CurrDb.FindListForCondition<BusinessFileRelation>(condition, ref errorinfo).ToList();
- if (list.Count > 0)
- return list[0];
- BusinessFileRelation rela = new BusinessFileRelation();
- rela.BusinessFileID = busifileid;
- rela.FileInfoID = fileid;
- condition = $" and a.BusinessFileID={busifileid}";
- list = CurrDb.FindListForCondition<BusinessFileRelation>(condition, ref errorinfo).ToList();
- if (list.Count <= 0)
- {
- rela.Version = 1;
- }
- else
- {
- rela.Version = list.Max(t => t.Version) + 1;
- }
- rela = IUBusinessFileRelation(rela, usercode, ref errorinfo);
- return rela;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- private string ComputerPath(TFileInfo entity)
- {
- int dir = entity.ID / 1000;
- return $"{dir}";
- }
- }
- }
|