Esempio n. 1
0
 public void AddFile(S_FileInfo file, bool withDefaultAttr = false)
 {
     file.NodeID     = this.ID;
     file.FullNodeID = this.FullPathID;
     if (!file.IsNewModel)
     {
         throw new Formula.Exceptions.BusinessException("文件对象不是新建对象,无法调用添加方法");
     }
     file.Save(withDefaultAttr);
     this.FileInfos.Add(file);
 }
Esempio n. 2
0
        public void Download(S_FileInfo fileInfo, string SpaceID, string ArchiveType, bool CheckCar = false)
        {
            var user     = FormulaHelper.GetUserInfo();
            var entities = FormulaHelper.GetEntities <DocConstEntities>();

            if (fileInfo.Space == null)
            {
                throw new Formula.Exceptions.BusinessException("没有获取到申请文件的配置空间信息,无法进行申请下载");
            }
            if (fileInfo.ConfigInfo == null)
            {
                throw new Formula.Exceptions.BusinessException("没有获取到申请文件的文件配置类别信息,无法进行申请下载");
            }
            var carItem = entities.Set <S_CarInfo>().FirstOrDefault(d => d.FileID == fileInfo.ID &&
                                                                    d.State != "Finish" && d.UserID == user.UserID && d.Type == "DownLoad");

            if (carItem == null)
            {
                carItem              = new S_CarInfo();
                carItem.ID           = FormulaHelper.CreateGuid();
                carItem.NodeID       = fileInfo.NodeID;
                carItem.Type         = ItemType.DownLoad.ToString();
                carItem.UserID       = user.UserID;
                carItem.UserName     = user.UserName;
                carItem.CreateDate   = DateTime.Now;
                carItem.FileID       = fileInfo.ID;
                carItem.SpaceID      = SpaceID;
                carItem.ConfigID     = fileInfo.ConfigInfo.ID;
                carItem.Name         = fileInfo.CreateCarName();//fileInfo.Name;
                carItem.Code         = fileInfo.DataEntity.GetValue("Code");
                carItem.State        = ItemState.New.ToString();
                carItem.DataType     = fileInfo.ConfigInfo.Name;
                carItem.CreateUser   = user.UserName;
                carItem.CreateUserID = user.UserID;
                var attchments = new List <string>();
                ArchiveType = "MainFile,Attachments," + ArchiveType;
                foreach (var item in ArchiveType.Split(','))
                {
                    if (!string.IsNullOrEmpty(fileInfo.CurrentAttachment.DataEntity.GetValue(item)))
                    {
                        attchments.Add(fileInfo.CurrentAttachment.DataEntity.GetValue(item));
                    }
                }
                carItem.Attachments = string.Join(",", attchments);
                entities.Set <S_CarInfo>().Add(carItem);
            }
            else if (CheckCar)
            {
                throw new Formula.Exceptions.BusinessException("该文件已在下载车中,请前往下载车申请下载");
            }
        }
Esempio n. 3
0
 public void AddFile(S_FileInfo file, bool withDefaultAttr = false)
 {
     this.SetNodeFileCount();
     file.NodeID       = this.ID;
     file.FullNodeID   = this.FullPathID;
     file.FullNodeName = this.FullPathName;
     file.DataEntity.SetValue("State", DocState.Normal.ToString());
     if (!file.IsNewModel)
     {
         throw new Formula.Exceptions.BusinessException("文件对象不是新建对象,无法调用添加方法");
     }
     file.Save(withDefaultAttr);
     this.FileInfos.Add(file);
 }
Esempio n. 4
0
        void SetFileAttr(S_FileInfo file, string Attr)
        {
            var dic = JsonHelper.ToObject(Attr);

            foreach (string key in dic.Keys)
            {
                if (key == "ID" || key == "NodeID" || key == "SpaceID" || key == "ConfigID" || key == "FullNodeID" || key == "State" || key == "BorrowState" ||
                    key == "BorrowUserID" || key == "BorrowUserName")
                {
                    continue;
                }
                file.DataEntity.SetValue(key, dic.GetValue(key));
            }
        }
Esempio n. 5
0
        public void SyncInstanceDataState()
        {
            var details   = this.T_Borrow_FileInfo.ToList();
            var spaceList = new List <S_DOC_Space>();

            foreach (var item in details)
            {
                var space = spaceList.FirstOrDefault(a => a.ID == item.SpaceID);
                if (space == null)
                {
                    space = DocConfigHelper.CreateConfigSpaceByID(item.SpaceID);
                    if (space == null)
                    {
                        continue;
                    }
                    spaceList.Add(space);
                }
                if (!String.IsNullOrEmpty(item.FileID))
                {
                    var file = new S_FileInfo(item.FileID, space);
                    if (file == null)
                    {
                        continue;
                    }
                    file.DataEntity.SetValue("BorrowState", BorrowReturnState.Borrow.ToString());
                    file.DataEntity.SetValue("BorrowUserID", this.CreateUserID);
                    file.DataEntity.SetValue("BorrowUserName", this.CreateUserName);
                    file.Save(false);
                }
                else
                {
                    var node = new S_NodeInfo(item.NodeID, space);
                    if (node == null)
                    {
                        continue;
                    }
                    node.DataEntity.SetValue("BorrowState", BorrowReturnState.Borrow.ToString());
                    node.DataEntity.SetValue("BorrowUserID", this.CreateUserID);
                    node.DataEntity.SetValue("BorrowUserName", this.CreateUserName);
                    node.Save(false);
                }
            }
        }
Esempio n. 6
0
        private S_FileInfo archFile(Dictionary <string, object> reorganizeDetail, S_NodeInfo node, string targetConfigID = "")
        {
            var fileConfig = node.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault(a => a.FileID == targetConfigID);

            if (fileConfig == null)
            {
                throw new Formula.Exceptions.BusinessException("节点【" + node.Name + "】下无法绑定该文件类型【" + targetConfigID + "】!");
            }
            if (fileConfig != null && fileConfig.S_DOC_File != null)
            {
                var file             = new DocSystem.Logic.Domain.S_FileInfo(node.Space.ID, fileConfig.S_DOC_File.ID);
                var fileFields       = fileConfig.S_DOC_File.S_DOC_FileAttr.Select(a => a.FileAttrField).ToList();
                var buttonEditFields = fileConfig.S_DOC_File.S_DOC_FileAttr.Where(a => a.InputType.IndexOf(ControlType.ButtonEdit.ToString()) > -1).ToList();
                foreach (var item in buttonEditFields)
                {
                    fileFields.Add(item.FileAttrField + "Name");
                }

                foreach (var fileds in fileFields)
                {
                    if (fileds.ToLower() == "id" || fileds.ToLower() == "attr" || fileds.ToLower() == "storagenum" || fileds.ToLower() == "storagetype" || fileds.ToLower() == "mainfile")
                    {
                        continue;
                    }
                    var _value = reorganizeDetail.GetValue(fileds);
                    if (fileds.ToLower().Equals("quantity"))
                    {
                        file.DataEntity.SetValue("StorageNum", _value);
                    }
                    if (!string.IsNullOrEmpty(_value))
                    {
                        file.DataEntity.SetValue(fileds, _value);
                    }
                }



                //var file = new DocSystem.Logic.Domain.S_FileInfo(node.Space.ID, fileConfig.S_DOC_File.ID);
                if (!String.IsNullOrEmpty(reorganizeDetail.GetValue("Attr")))
                {
                    SetFileAttr(file, reorganizeDetail.GetValue("Attr"));
                }
                //file.DataEntity.SetValue("Name", reorganizeDetail.GetValue("Name"));
                file.DataEntity.SetValue("StorageType", "Electronic");
                file.DataEntity.SetValue("NodeID", node.ID);
                //file.DataEntity.SetValue("Code", reorganizeDetail.GetValue("Code"));
                //file.DataEntity.SetValue("RelateID", reorganizeDetail.GetValue("RelateID"));
                //file.DataEntity.SetValue("State", DocState.Normal);
                //归档人、部门、时间存储
                if (!string.IsNullOrEmpty(GetQueryString("SendUser")))
                {
                    Dictionary <string, string> depate = GetDepartment(GetQueryString("SendUser"));
                    file.DataEntity.SetValue("ArchivePeople", GetQueryString("SendUser"));
                    file.DataEntity.SetValue("ArchivePeopleName", depate.GetValue("SendUserName"));
                    file.DataEntity.SetValue("ArchiveDate", GetQueryString("SendDate"));
                    file.DataEntity.SetValue("ArchiveDepartment", depate.GetValue("DeptID"));
                    file.DataEntity.SetValue("ArchiveDepartmentName", depate.GetValue("DeptName"));
                }
                if (!String.IsNullOrEmpty(reorganizeDetail.GetValue("MainFile")))
                {
                    var attachment = new S_Attachment(node.Space.ID);
                    attachment.DataEntity.SetValue("MainFile", reorganizeDetail.GetValue("MainFile"));
                    attachment.DataEntity.SetValue("PDFFile", reorganizeDetail.GetValue("PDFFile"));
                    attachment.DataEntity.SetValue("PlotFile", reorganizeDetail.GetValue("PlotFile"));
                    attachment.DataEntity.SetValue("XrefFile", reorganizeDetail.GetValue("XrefFile"));
                    attachment.DataEntity.SetValue("DwfFile", reorganizeDetail.GetValue("DwfFile"));
                    attachment.DataEntity.SetValue("TiffFile", reorganizeDetail.GetValue("TiffFile"));
                    attachment.DataEntity.SetValue("SignPdfFile", reorganizeDetail.GetValue("SignPdfFile"));
                    file.AddAttachment(attachment);
                }
                file.IsValidateDataAttr = false;
                DocSystem.FileController.FileValidateDataAttr(file);
                //node.AddFile(file, true);
                file.Save(true);
                return(file);
            }
            return(null);
        }
Esempio n. 7
0
        void _archiveDBS(S_D_DBS parentDBS, List <S_D_DBS> archiveDbsList, S_NodeInfo parentNode, S_DOC_Space docSpace, bool archiveFiles = true, bool isAll = true)
        {
            var folders = archiveDbsList.Where(d => d.ParentID == parentDBS.ID).ToList();

            foreach (var folder in folders)
            {
                if (String.IsNullOrEmpty(folder.ArchiveFolder))
                {
                    continue;
                }
                S_NodeInfo node = S_NodeInfo.GetNode(docSpace.ID, folder.ArchiveFolder, " where Name='" + folder.Name + "' and ParentID='" + parentNode.ID + "' ");
                if (node == null)
                {
                    node = new DocSystem.Logic.Domain.S_NodeInfo(docSpace.ID, folder.ArchiveFolder);
                    this.SetAttr <S_D_DBS>(node, folder);
                    node.Name = folder.Name;
                    node.DataEntity.SetValue("State", DocState.Normal.ToString());
                    node.DataEntity.SetValue("RelateID", folder.ID);
                    parentNode.AddChild(node, true);
                }
                else
                {
                    this.SetAttr <S_D_DBS>(node, folder);
                    node.Name = folder.Name;
                    node.DataEntity.SetValue("State", DocState.Normal.ToString());
                    node.DataEntity.SetValue("RelateID", folder.ID);
                    node.Save();
                }
                if (archiveFiles && node.ConfigInfo.S_DOC_FileNodeRelation.Count > 0 && node.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault().S_DOC_File != null)
                {
                    #region 归档文件
                    var fileConfig = node.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault().S_DOC_File;
                    var docList    = folder.S_D_Document.ToList();
                    var _group     = docList.GroupBy(a => a.RelateID).Select(a =>
                                                                             new { a.Key, MaxVersion = a.Max(b => (string.IsNullOrEmpty(b.Version) ? 0d : Convert.ToDouble(b.Version))) }
                                                                             ).ToList();
                    if (!isAll)
                    {
                        docList = docList.Where(a => _group.Any(g => g.Key == a.RelateID && g.MaxVersion == (string.IsNullOrEmpty(a.Version) ? 0d : Convert.ToDouble(a.Version)))).ToList();
                    }
                    foreach (var doc in docList)
                    {
                        var file = S_FileInfo.GetFile(docSpace.ID, fileConfig.ID, " NodeID='" + node.ID + "' and RelateID='" + doc.ID + "' ");
                        if (file == null)
                        {
                            file = new DocSystem.Logic.Domain.S_FileInfo(docSpace.ID, fileConfig.ID);
                            if (!String.IsNullOrEmpty(doc.Attr))
                            {
                                this.SetFileAttr(file, doc.Attr);
                            }
                            file.DataEntity.SetValue("Name", doc.Name);
                            file.DataEntity.SetValue("Code", doc.Code);
                            file.DataEntity.SetValue("RelateID", doc.ID);
                            file.DataEntity.SetValue("State", DocState.Normal);
                            if (!String.IsNullOrEmpty(doc.MainFiles) || !String.IsNullOrEmpty(doc.PDFFile) ||
                                !String.IsNullOrEmpty(doc.PlotFile) || !String.IsNullOrEmpty(doc.XrefFile) ||
                                !String.IsNullOrEmpty(doc.DwfFile) || !String.IsNullOrEmpty(doc.TiffFile) ||
                                !String.IsNullOrEmpty(doc.SignPdfFile))
                            {
                                var attachment = new S_Attachment(docSpace.ID);
                                attachment.DataEntity.SetValue("MainFile", doc.MainFiles);
                                attachment.DataEntity.SetValue("PDFFile", doc.PDFFile);
                                attachment.DataEntity.SetValue("PlotFile", doc.PlotFile);
                                attachment.DataEntity.SetValue("XrefFile", doc.XrefFile);
                                attachment.DataEntity.SetValue("DwfFile", doc.DwfFile);
                                attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                                attachment.DataEntity.SetValue("SignPdfFile", doc.SignPdfFile);
                                attachment.DataEntity.SetValue("CreateUser", this.CurrentUserInfo.UserID);
                                attachment.DataEntity.SetValue("CreateUserName", this.CurrentUserInfo.UserName);
                                file.AddAttachment(attachment);
                            }
                            node.AddFile(file, true);
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(doc.Attr))
                            {
                                this.SetFileAttr(file, doc.Attr);
                            }
                            file.Save();
                            var attachment = new S_Attachment(docSpace.ID);
                            attachment.DataEntity.SetValue("MainFile", doc.MainFiles);
                            attachment.DataEntity.SetValue("PDFFile", doc.PDFFile);
                            attachment.DataEntity.SetValue("PlotFile", doc.PlotFile);
                            attachment.DataEntity.SetValue("XrefFile", doc.XrefFile);
                            attachment.DataEntity.SetValue("DwfFile", doc.DwfFile);
                            attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                            attachment.DataEntity.SetValue("SignPdfFile", doc.SignPdfFile);
                            attachment.DataEntity.SetValue("CreateUser", this.CurrentUserInfo.UserID);
                            attachment.DataEntity.SetValue("CreateUserName", this.CurrentUserInfo.UserName);
                            file.AddAttachment(attachment);
                        }
                        doc.State       = "Archive";
                        doc.ArchiveDate = DateTime.Now;
                        if (doc.RelateTable == "S_E_Product")
                        {
                            //string update = "Update S_E_Product Set ArchiveState='True', ArchiveDate='" + DateTime.Now.ToString() + "' where ID='" + doc.RelateID + "'";
                            string update = string.Format(@"update S_E_Product set ArchiveState='True', ArchiveDate='{2}' where ID='{0}'
update S_E_ProductVersion set ArchiveState='True', ArchiveDate='{2}' where ProductID='{0}' and Version='{1}'", doc.RelateID, doc.Version, DateTime.Now.ToString());
                            this.entities.Database.ExecuteSqlCommand(update);
                        }
                    }
                    #endregion
                }
                _archiveDBS(folder, archiveDbsList, node, docSpace, archiveFiles, isAll);
            }
        }
Esempio n. 8
0
        public JsonResult Archive(string ProjectInfoID, bool IsAll)
        {
            Action action = () =>
            {
                var projectInfo = this.GetEntityByID <S_I_ProjectInfo>(ProjectInfoID);
                if (projectInfo == null)
                {
                    throw new Formula.Exceptions.BusinessException("未能找到项目信息,无法归档");
                }

                var rootFolder = projectInfo.ProjectMode.S_T_DBSDefine.FirstOrDefault(d => d.DBSType == DBSType.Root.ToString());
                if (String.IsNullOrEmpty(rootFolder.ArchiveFolder))
                {
                    throw new Formula.Exceptions.BusinessException("没有为根节点定义归档目录,项目无法归档");
                }

                var archiveFolders = projectInfo.S_D_DBS.Where(d => !String.IsNullOrEmpty(d.ArchiveFolder)).ToList();

                var sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.InfrasBaseConfig);
                var dt        = sqlHelper.ExecuteDataTable("select * from S_DOC_Node  where ID='" + rootFolder.ArchiveFolder + "'");
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessException("根节点定义的归档目录不存在,归档失败");
                }
                var folderDef = FormulaHelper.DataRowToDic(dt.Rows[0]);
                var docSpace  = DocSystem.Logic.DocConfigHelper.CreateConfigSpaceByID(folderDef.GetValue("SpaceID"));
                if (docSpace == null)
                {
                    throw new Formula.Exceptions.BusinessException("所选择的档案空间定义不存在,请联系管理员确认档案空间配置是否正确");
                }

                S_NodeInfo rootNode = S_NodeInfo.GetNode(docSpace.ID, rootFolder.ArchiveFolder, " where RelateID='" + projectInfo.DBSRoot.ID + "'");
                if (rootNode == null)
                {
                    rootNode      = new DocSystem.Logic.Domain.S_NodeInfo(docSpace.ID, rootFolder.ArchiveFolder);
                    rootNode.Name = projectInfo.Name;
                    rootNode.DataEntity.SetValue("Code", projectInfo.Code);
                    rootNode.DataEntity.SetValue("State", DocState.Normal.ToString());
                    rootNode.DataEntity.SetValue("RelateID", projectInfo.DBSRoot.ID);
                }
                this.SetAttr <S_I_ProjectInfo>(rootNode, projectInfo);
                rootNode.Save(true);

                var fileConfig = rootNode.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault();
                if (fileConfig != null && fileConfig.S_DOC_File != null)
                {
                    Convert.ToDouble("");
                    var docList = projectInfo.DBSRoot.S_D_Document.Where(d => d.State != "Archive").ToList();
                    var _group  = docList.GroupBy(a => a.RelateID).Select(a =>
                                                                          new { a.Key, MaxVersion = a.Max(b => (string.IsNullOrEmpty(b.Version) ? 0d : Convert.ToDouble(b.Version))) }
                                                                          ).ToList();
                    if (!IsAll)
                    {
                        docList = docList.Where(a => _group.Any(g => g.Key == a.RelateID && g.MaxVersion == (string.IsNullOrEmpty(a.Version) ? 0d : Convert.ToDouble(a.Version)))).ToList();
                    }
                    foreach (var doc in docList)
                    {
                        var file = new DocSystem.Logic.Domain.S_FileInfo(docSpace.ID, fileConfig.S_DOC_File.ID);
                        if (!String.IsNullOrEmpty(doc.Attr))
                        {
                            this.SetFileAttr(file, doc.Attr);
                        }
                        file.DataEntity.SetValue("Name", doc.Name);
                        file.DataEntity.SetValue("Code", doc.Code);
                        rootNode.AddFile(file, true);
                        if (!String.IsNullOrEmpty(doc.MainFiles) || !String.IsNullOrEmpty(doc.PDFFile) ||
                            !String.IsNullOrEmpty(doc.PlotFile) || !String.IsNullOrEmpty(doc.XrefFile) ||
                            !String.IsNullOrEmpty(doc.DwfFile) || !String.IsNullOrEmpty(doc.TiffFile) ||
                            !String.IsNullOrEmpty(doc.SignPdfFile))
                        {
                            var attachment = new S_Attachment(docSpace.ID);
                            attachment.DataEntity.SetValue("MainFile", doc.MainFiles);
                            attachment.DataEntity.SetValue("PDFFile", doc.PDFFile);
                            attachment.DataEntity.SetValue("PlotFile", doc.PlotFile);
                            attachment.DataEntity.SetValue("XrefFile", doc.XrefFile);
                            attachment.DataEntity.SetValue("DwfFile", doc.DwfFile);
                            attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                            attachment.DataEntity.SetValue("SignPdfFile", doc.SignPdfFile);
                            attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                            attachment.DataEntity.SetValue("CreateUser", this.CurrentUserInfo.UserID);
                            attachment.DataEntity.SetValue("CreateUserName", this.CurrentUserInfo.UserName);
                            file.AddAttachment(attachment);
                        }
                        doc.State       = "Archive";
                        doc.ArchiveDate = DateTime.Now;
                        if (doc.RelateTable == "S_E_Product")
                        {
                            //string update = "Update S_E_Product Set ArchiveState='True', ArchiveDate='" + DateTime.Now.ToString() + "' where ID='" + doc.RelateID + "'";
                            string update = string.Format(@"update S_E_Product set ArchiveState='True', ArchiveDate='{2}' where ID='{0}'
update S_E_ProductVersion set ArchiveState='True', ArchiveDate='{2}' where ProductID='{0}' and Version='{1}'", doc.RelateID, doc.Version, DateTime.Now.ToString());
                            this.entities.Database.ExecuteSqlCommand(update);
                        }
                    }
                }
                this._archiveDBS(projectInfo.DBSRoot, archiveFolders, rootNode, docSpace, true, IsAll);
                this.entities.SaveChanges();
            };

            if (System.Configuration.ConfigurationManager.AppSettings["UseMsdtc"].ToLower() == "true")
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    action();
                    ts.Complete();
                }
            }
            else
            {
                action();
            }
            return(Json(""));
        }
Esempio n. 9
0
        public JsonResult ArchiveFile(string ProjectInfoID, string Files)
        {
            Action action = () =>
            {
                var projectInfo = this.GetEntityByID <S_I_ProjectInfo>(ProjectInfoID);
                if (projectInfo == null)
                {
                    throw new Formula.Exceptions.BusinessException("未能找到项目信息,无法归档");
                }
                var rootFolder = projectInfo.ProjectMode.S_T_DBSDefine.FirstOrDefault(d => d.DBSType == DBSType.Root.ToString());
                if (String.IsNullOrEmpty(rootFolder.ArchiveFolder))
                {
                    throw new Formula.Exceptions.BusinessException("没有为根节点定义归档目录,项目无法归档");
                }


                var sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.InfrasBaseConfig);
                var dt        = sqlHelper.ExecuteDataTable("select * from S_DOC_Node  where ID='" + rootFolder.ArchiveFolder + "'");
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessException("根节点定义的归档目录不存在,归档失败");
                }
                var folderDef = FormulaHelper.DataRowToDic(dt.Rows[0]);
                var docSpace  = DocSystem.Logic.DocConfigHelper.CreateConfigSpaceByID(folderDef.GetValue("SpaceID"));
                if (docSpace == null)
                {
                    throw new Formula.Exceptions.BusinessException("所选择的档案空间定义不存在,请联系管理员确认档案空间配置是否正确");
                }

                #region 创建项目根节点
                S_NodeInfo rootNode = S_NodeInfo.GetNode(docSpace.ID, rootFolder.ArchiveFolder, " where RelateID='" + projectInfo.DBSRoot.ID + "'");
                if (rootNode == null)
                {
                    rootNode      = new DocSystem.Logic.Domain.S_NodeInfo(docSpace.ID, rootFolder.ArchiveFolder);
                    rootNode.Name = projectInfo.Name;
                    rootNode.DataEntity.SetValue("Code", projectInfo.Code);
                    rootNode.DataEntity.SetValue("State", DocState.Normal.ToString());
                }
                #endregion
                this.SetAttr <S_I_ProjectInfo>(rootNode, projectInfo);
                rootNode.DataEntity.SetValue("RelateID", projectInfo.DBSRoot.ID);
                rootNode.Save(true);

                var fileList = JsonHelper.ToList(Files);
                foreach (var item in fileList)
                {
                    if (item.Keys.Contains("NewAdd") && item.GetValue("NewAdd") == "T")
                    {
                        continue;
                    }
                    var doc = this.GetEntityByID <S_D_Document>(item.GetValue("DocumentID"));
                    if (doc == null)
                    {
                        continue;
                    }
                    var folder = doc.S_D_DBS;
                    if (String.IsNullOrEmpty(folder.ArchiveFolder))
                    {
                        throw new Formula.Exceptions.BusinessException("没有为【" + folder.Name + "】配置指定归档信息,无法归档");
                    }
                    var node = rootNode.AllChildren.FirstOrDefault(d => d.RelateID == folder.ID);
                    if (node == null)
                    {
                        this._archiveDBS(projectInfo.DBSRoot, folder.Ansestors, rootNode, docSpace, false);
                        node = rootNode.AllChildren.FirstOrDefault(d => d.RelateID == folder.ID);
                    }
                    if (node == null)
                    {
                        throw new Formula.Exceptions.BusinessException("目录创建失败,文件【" + doc.Name + "】归档失败");
                    }

                    #region 归档文件
                    var fileConfig = node.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault();
                    if (fileConfig != null && fileConfig.S_DOC_File != null)
                    {
                        var file = S_FileInfo.GetFile(docSpace.ID, fileConfig.S_DOC_File.ID, " NodeID='" + node.ID + "' and RelateID='" + doc.ID + "' ");
                        if (file == null)
                        {
                            file = new DocSystem.Logic.Domain.S_FileInfo(docSpace.ID, fileConfig.S_DOC_File.ID);
                            if (!String.IsNullOrEmpty(doc.Attr))
                            {
                                this.SetFileAttr(file, doc.Attr);
                            }
                            file.DataEntity.SetValue("Name", doc.Name);
                            file.DataEntity.SetValue("Code", doc.Code);
                            file.DataEntity.SetValue("RelateID", doc.ID);
                            file.DataEntity.SetValue("State", DocState.Normal);
                            if (!String.IsNullOrEmpty(doc.MainFiles) || !String.IsNullOrEmpty(doc.PDFFile) ||
                                !String.IsNullOrEmpty(doc.PlotFile) || !String.IsNullOrEmpty(doc.XrefFile) ||
                                !String.IsNullOrEmpty(doc.DwfFile) || !String.IsNullOrEmpty(doc.TiffFile) ||
                                !String.IsNullOrEmpty(doc.SignPdfFile))
                            {
                                var attachment = new S_Attachment(docSpace.ID);
                                attachment.DataEntity.SetValue("MainFile", doc.MainFiles);
                                attachment.DataEntity.SetValue("PDFFile", doc.PDFFile);
                                attachment.DataEntity.SetValue("PlotFile", doc.PlotFile);
                                attachment.DataEntity.SetValue("XrefFile", doc.XrefFile);
                                attachment.DataEntity.SetValue("DwfFile", doc.DwfFile);
                                attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                                attachment.DataEntity.SetValue("SignPdfFile", doc.SignPdfFile);
                                file.AddAttachment(attachment);
                            }
                            node.AddFile(file, true);
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(doc.Attr))
                            {
                                this.SetFileAttr(file, doc.Attr);
                            }
                            file.DataEntity.SetValue("RelateID", doc.ID);
                            file.Save();
                            var attachment = new S_Attachment(docSpace.ID);
                            attachment.DataEntity.SetValue("MainFile", doc.MainFiles);
                            attachment.DataEntity.SetValue("PDFFile", doc.PDFFile);
                            attachment.DataEntity.SetValue("PlotFile", doc.PlotFile);
                            attachment.DataEntity.SetValue("XrefFile", doc.XrefFile);
                            attachment.DataEntity.SetValue("DwfFile", doc.DwfFile);
                            attachment.DataEntity.SetValue("TiffFile", doc.TiffFile);
                            attachment.DataEntity.SetValue("SignPdfFile", doc.SignPdfFile);
                            file.AddAttachment(attachment);
                        }
                        doc.State       = "Archive";
                        doc.ArchiveDate = DateTime.Now;
                        if (doc.RelateTable == "S_E_Product")
                        {
                            //string update = "Update S_E_Product Set ArchiveState='True', ArchiveDate='" + DateTime.Now.ToString() + "' where ID='" + doc.RelateID + "'";
                            string update = string.Format(@"update S_E_Product set ArchiveState='True', ArchiveDate='{2}' where ID='{0}'
update S_E_ProductVersion set ArchiveState='True', ArchiveDate='{2}' where ProductID='{0}' and Version='{1}'", doc.RelateID, doc.Version, DateTime.Now.ToString());
                            this.entities.Database.ExecuteSqlCommand(update);
                        }
                    }
                    #endregion
                }
                this.entities.SaveChanges();
            };

            if (System.Configuration.ConfigurationManager.AppSettings["UseMsdtc"].ToLower() == "true")
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    action();
                    ts.Complete();
                }
            }
            else
            {
                action();
            }
            return(Json(""));
        }
Esempio n. 10
0
        public void Publish()
        {
            var user = FormulaHelper.GetUserInfo();

            if (this.ReorganizeState == DocSystem.Logic.ReorganizeState.Execute.ToString())
            {
                if (this.ReorganizeUser != user.UserID)
                {
                    throw new Formula.Exceptions.BusinessException("【" + this.TaskName + "】已经由【" + this.ReorganizeUserName + "】整编,请等【" + this.ReorganizeUserName + "】整编完成以后再操作");
                }
            }
            else if (this.ReorganizeState != DocSystem.Logic.ReorganizeState.Finish.ToString())
            {
                throw new Formula.Exceptions.BusinessException("【" + this.TaskName + "】未完成整编,无法归档");
            }

            var docList = this.GetDocConfigSqlHelper().ExecuteList <S_R_Reorganize_DocumentList>
                              ("select * from S_R_Reorganize_DocumentList where S_R_ReorganizeID='" + this.ID + "'");

            if (docList.Any(a => string.IsNullOrEmpty(a.ReorganizeFullID)))
            {
                throw new Formula.Exceptions.BusinessException("所有文件资料都指定整编目录后才能归档");
            }

            //归档
            var    docSpace = DocConfigHelper.CreateConfigSpaceByID(this.SpaceID);
            var    nodeIds  = docList.Select(a => a.ReorganizeFullID.Split('.').LastOrDefault()).Distinct();
            var    db       = SQLHelper.CreateSqlHelper(docSpace.SpaceKey, docSpace.ConnectString);
            string sql      = "select * from S_NodeInfo where ID in ('" + string.Join("','", nodeIds) + "') ";
            var    dt       = db.ExecuteDataTable(sql);
            var    nodeList = new List <S_NodeInfo>();

            foreach (DataRow row in dt.Rows)
            {
                nodeList.Add(new S_NodeInfo(row));
            }

            foreach (var item in docList)
            {
                var nodeID = item.ReorganizeFullID.Split('.').LastOrDefault();
                var node   = nodeList.FirstOrDefault(a => a.ID == nodeID);
                if (node == null)
                {
                    throw new Formula.Exceptions.BusinessException("【" + this.TaskName + "】未找到【" + item.Name + "】的整编目录【" + item.ReorganizePath + "】,无法归档");
                }
                var fileConfig = node.ConfigInfo.S_DOC_FileNodeRelation.FirstOrDefault();
                if (fileConfig != null && fileConfig.S_DOC_File != null)
                {
                    var file = S_FileInfo.GetFile(docSpace.ID, fileConfig.S_DOC_File.ID, " NodeID='" + node.ID + "' and RelateID='" + item.RelateID + "' ");
                    if (file == null)
                    {
                        file = new DocSystem.Logic.Domain.S_FileInfo(docSpace.ID, fileConfig.S_DOC_File.ID);
                        if (!String.IsNullOrEmpty(item.Attr))
                        {
                            this.SetFileAttr(file, item.Attr);
                        }
                        file.DataEntity.SetValue("Name", item.Name);
                        file.DataEntity.SetValue("Code", item.Code);
                        file.DataEntity.SetValue("RelateID", item.RelateID);
                        file.DataEntity.SetValue("State", DocState.Normal);
                        if (!String.IsNullOrEmpty(item.MainFile))
                        {
                            var attachment = new S_Attachment(docSpace.ID);
                            attachment.DataEntity.SetValue("MainFile", item.MainFile);
                            attachment.DataEntity.SetValue("PDFFile", item.PDFFile);
                            attachment.DataEntity.SetValue("PlotFile", item.PlotFile);
                            attachment.DataEntity.SetValue("XrefFile", item.XrefFile);
                            attachment.DataEntity.SetValue("DwfFile", item.DwfFile);
                            attachment.DataEntity.SetValue("TiffFile", item.TiffFile);
                            attachment.DataEntity.SetValue("SignPdfFile", item.SignPdfFile);
                            file.AddAttachment(attachment);
                        }
                        node.AddFile(file, true);
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(item.Attr))
                        {
                            this.SetFileAttr(file, item.Attr);
                        }
                        file.DataEntity.SetValue("RelateID", item.RelateID);
                        file.Save();
                        var attachment = new S_Attachment(docSpace.ID);
                        attachment.DataEntity.SetValue("MainFile", item.MainFile);
                        attachment.DataEntity.SetValue("PDFFile", item.PDFFile);
                        attachment.DataEntity.SetValue("PlotFile", item.PlotFile);
                        attachment.DataEntity.SetValue("XrefFile", item.XrefFile);
                        attachment.DataEntity.SetValue("DwfFile", item.DwfFile);
                        attachment.DataEntity.SetValue("TiffFile", item.TiffFile);
                        attachment.DataEntity.SetValue("SignPdfFile", item.SignPdfFile);
                        file.AddAttachment(attachment);
                    }
                }
            }
        }