Beispiel #1
0
        public virtual void forbidden()
        {
            string listIDs = Request["ID"];

            foreach (var ID in listIDs.Split(','))
            {
                if (Tool.IsNullOrEmpty(ID))
                {
                    continue;
                }
                var file = S_FileInfo.GetFile(ID, this.SpaceID);
                file.Recover();
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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(""));
        }