/// <summary> /// 批量复制分项资料库图文档,作为任务书附件(没有历史版本) /// </summary> /// <param name="userId"></param> /// <param name="pageId"></param> /// <param name="arrId"></param> /// <returns></returns> public InvokeResult <List <int> > BatchCopyProjectDoc(int userId, int pageId, int[] arrId, List <string> thumbsImages) { InvokeResult <List <int> > res = new InvokeResult <List <int> >(); List <int> retIds = new List <int>(); try { using (TransactionScope trans = new TransactionScope()) { StringBuilder thumbStr = new StringBuilder(); //thumbStr.Append("<root>"); foreach (int fileId in arrId) { var oldFile = this._ctx.FileLibraries.FirstOrDefault(r => r.fileId == fileId); if (oldFile != null) { #region 制文件信息 FileLibrary fileLib = new FileLibrary { createData = DateTime.Now, createUserId = userId, name = oldFile.name, ext = oldFile.ext, sysObjId = 3,//已定义好的系统对象 localPath = oldFile.localPath, tags = string.Empty, lastVersion = 1, size = oldFile.size, hash = oldFile.hash }; _ctx.FileLibraries.InsertOnSubmit(fileLib); _ctx.SubmitChanges(); #endregion #region 制版本信息 FileLibVersion version = new FileLibVersion() { fileId = fileLib.fileId, fileName = fileLib.name, localPath = fileLib.localPath, createData = DateTime.Now, createUserId = fileLib.createUserId, fileVersion = 1, ext = fileLib.ext, hash = fileLib.hash }; this._ctx.FileLibVersions.InsertOnSubmit(version); this._ctx.SubmitChanges(); #endregion #region 添加关联信息 PageFile pageFile = new PageFile() { pageId = pageId, fileId = fileLib.fileId, fileType = 1, bizFileLibId = oldFile.fileId }; this._ctx.PageFiles.InsertOnSubmit(pageFile); this._ctx.SubmitChanges(); #endregion #region 拷贝文件 string appPath = AppDomain.CurrentDomain.BaseDirectory; string filePath = CommonBll.GetSysObjDir(oldFile.sysObjId.Value.ToString(), oldFile.sysObjId.Value, oldFile.createData); string oldFileName = CommonBll.GetSysObjDocImg(oldFile.fileId, oldFile.hash, oldFile.lastVersion, "m"); string descPath = CommonBll.GetSysObjDir(fileLib.sysObjId.Value.ToString(), fileLib.sysObjId.Value, fileLib.createData); string descPhyPath = FileExtension.CreateFolder(string.Format("{0}{1}", appPath, descPath)); string descFileName = CommonBll.GetSysObjDocImg(fileLib.fileId, fileLib.hash, fileLib.lastVersion, "m"); foreach (var s in thumbsImages) { string sourcePhyFileName = string.Format("{0}{1}{2}", appPath, filePath, oldFileName.Replace("_m.", "_" + s + ".")); string descPhyFileName = string.Format("{0}{1}", descPhyPath, descFileName.Replace("_m.", "_" + s + ".")); if (File.Exists(sourcePhyFileName) == true) { File.Copy(sourcePhyFileName, descPhyFileName); } } #endregion retIds.Add(fileLib.fileId); //thumbStr.AppendFormat("<file hash=\"{0}\" size=\"{1}\" param=\"sysObject@{2}-{3}\" />", fileLib.hash, fileLib.size, fileLib.fileId, version.verId); } } //thumbStr.Append("</root>"); trans.Complete(); res.Status = Status.Successful; res.Message = thumbStr.ToString(); res.Value = retIds; } } catch (Exception ex) { res.Message = ex.Message; res.Status = Status.Failed; } return(res); }