123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using DllEapEntity.Dtos;
- using DllHsms;
- namespace DllEapDal
- {
- public class ShareFileDal
- {
- private IDatabase CurrDb = null;
- public ShareFileDal(IDatabase db)
- {
- CurrDb = db;
- }
- public ShareFile IShareFile(byte[] filedatas,ref string errorinfo)
- {
- try
- {
- if(filedatas==null)
- {
- filedatas = new byte[10];
- }
- int result = 0;
- ShareFile entity = new ShareFile();
- entity.FileLen = filedatas.Length;
- result = CurrDb.InsertFor<ShareFile>(entity, "");
- if(result<0)
- {
- errorinfo = "插入记录发生未知错误。";
- return null;
- }
- object objid = CurrDb.FindObject("select @@IDENTITY");
- if (objid.ToString() == "")
- {
- return null;
- }
- int id = int.Parse(objid.ToString());
- string filedir = AppConfigurtaionServices.Configuration["ShareFileDir"];
- entity = CurrDb.FindEntityFor<ShareFile>(id);
- entity.FilePath = $"{filedir}\\{id}";
- CurrDb.UpdateFor<ShareFile>(entity, "");
- //写入文件
- result = UnityHelper.WriteFile(filedir, id.ToString(), filedatas, ref errorinfo);
- if (result <= 0)
- return null;
- return entity;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- public ShareFile IShareFile(OrderBlock sendentity, ref string errorinfo)
- {
- try
- {
- List<OrderData> datas = sendentity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
- int parentid = datas[0].ID;//获取L的ID值
- datas = sendentity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
- string programname = datas[0].FContent;
- byte[] filedatas = datas[1].OrgDatas;
- datas[1].OrgDatas = null;//清空原始数据
- ShareFile entity = IShareFile(filedatas, ref errorinfo);
- if (entity == null)
- return null;
- datas[1].FContent = entity.FilePath;
- return entity;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- /// <summary>
- /// 根据文件路径,将文件复制到共享目录
- /// </summary>
- /// <param name="filepath"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public ShareFile MadeShareFile(string filepath, ref string errorinfo)
- {
- try
- {
- byte[] filedatas = UnityHelper.ReadFile(filepath, ref errorinfo);
- if (filedatas == null)
- return null;
- ShareFile entity = IShareFile(filedatas, ref errorinfo);
- if (entity == null)
- return null;
- return entity;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- public ShareFile MadeShareFileForDad3350(string filepath,string orgprogram, ref string errorinfo)
- {
- try
- {
- byte[] filedatas = UnityHelper.ReadFile(filepath, ref errorinfo);
- if (filedatas == null)
- return null;
- //转换程序名称
- filedatas = DiodesProgramFileHelper.ReplaceProgramName(filedatas, orgprogram, ref errorinfo);
- if (filedatas == null)
- return null;
- ShareFile entity = IShareFile(filedatas, ref errorinfo);
- if (entity == null)
- return null;
- return entity;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- }
- }
|