Exemple #1
0
 protected override void AfterDelete()
 {
     base.AfterDelete();
     if (this.isDeleteSubs)
     {
         //删除文件夹目录。sql中的表单记录操作可以回滚,磁盘上的文件目录和文档操作统一处理,失败了也不用回滚。
         DataRow masterRow = this.DataSet.Tables[0].Rows[0];
         if (masterRow == null)
         {
             return;
         }
         string dirId = LibSysUtils.ToString(masterRow["DIRID"]);
         //DirLinkAddress dirLink = new DirLinkAddress(dirId, this.DataAccess);
         if (dirLink.DirSavePath == string.Empty)
         {
             return;
         }
         //先定位到文档库根路径
         //string path = Path.Combine(EnvProvider.Default.DocumentsPath, (LibSysUtils.ToInt32(masterRow["DIRTYPE"]) == 0 ? "" : "my"));//根据是否为私有类型在路径下增加my
         string path = DMCommonMethod.GetDMRootPath((DirTypeEnum)LibSysUtils.ToInt32(masterRow["DIRTYPE"]));
         path = Path.Combine(path, dirLink.DirSavePath);
         try
         {
             if (Directory.Exists(path))
             {
                 Directory.Delete(path, true);//删除目录文件夹及其子目录文件夹、文件等。
             }
         }
         catch (Exception exp)
         {
             //对于删除文档目录在磁盘上的文件夹的动作,因为文件系统的删除无法回滚,不再向上抛出异常(以免触发本级事务回滚),仅记录异常信息,以便后续手动清理
             DMCommonMethod.WriteLog("DeleteDirectory", string.Format("DirID:{0}\r\nPath:{1}\r\nError:{2}", dirId, path, exp.ToString()));
         }
     }
 }
Exemple #2
0
        protected override void AfterUpdate()
        {
            base.AfterUpdate();
            if (this.ManagerMessage.IsThrow)
            {
                return;//如果已经有错误发生则直接返回
            }
            try
            {
                DataRow masterRow = this.DataSet.Tables[0].Rows[0];
                //先定位到文档库根路径
                string path = DMCommonMethod.GetDMRootPath((DirTypeEnum)LibSysUtils.ToInt32(masterRow["DIRTYPE"]));
                //string path = Path.Combine(EnvProvider.Default.DocumentsPath, (LibSysUtils.ToInt32(masterRow["DIRTYPE"]) == 0 ? "" : "my"));//根据是否为私有类型在路径下增加my

                string relativePath = string.Empty;
                if (masterRow.RowState == DataRowState.Added)
                {
                    //添加时创建目录文件夹
                    DirLinkAddress dirLink = new DirLinkAddress(LibSysUtils.ToString(masterRow["DIRID"]), this.DataAccess);
                    relativePath = dirLink.DirSavePath;
                    path         = Path.Combine(path, relativePath);
                    Directory.CreateDirectory(path);
                }
                else
                {
                    //update时检查父目录是否变化,如有变化根据将目录对应的文件夹移动到父目录文件夹下
                    string oldParentID     = LibSysUtils.ToString(masterRow["PARENTDIRID", DataRowVersion.Original]);
                    string currentParentID = LibSysUtils.ToString(masterRow["PARENTDIRID"]);
                    if (oldParentID.Equals(currentParentID) == false)
                    {
                        DirLinkAddress dirLink = new DirLinkAddress(LibSysUtils.ToString(masterRow["DIRID"]), this.DataAccess);
                        relativePath = dirLink.DirSavePath;
                        string newDirPath = Path.Combine(path, relativePath);
                        Directory.Move(_OldDirPath, newDirPath);//移动文件夹
                    }
                }
            }
            catch (Exception exp)
            {
                this.ManagerMessage.AddMessage(LibMessageKind.Error, "保存目录失败,原因:" + exp.Message);
                throw exp;
            }
        }
Exemple #3
0
        protected override void BeforeUpdate()
        {
            base.BeforeUpdate();
            DataRow masterRow = this.DataSet.Tables[0].Rows[0];

            #region 操作权限标识设置
            HashSet <string> hasSet = new HashSet <string>();
            foreach (DataRow curRow in this.DataSet.Tables[1].Rows)
            {
                if (curRow.RowState == DataRowState.Deleted)
                {
                    continue;
                }
                DataRow[] subRows = curRow.GetChildRows(DmDirectoryBcfTemplate.PermissionDetailSubRelationName, DataRowVersion.Current);
                int       mark    = 0;
                foreach (DataRow subRow in subRows)
                {
                    if (LibSysUtils.ToBoolean(subRow["CANUSE"]))
                    {
                        mark += LibSysUtils.ToInt32(subRow["OPERATEPOWERID"]);
                    }
                }
                curRow["OPERATEMARK"] = mark;
                string type_BelongID = string.Format("{0}_{1}", LibSysUtils.ToInt32(curRow["BELONGTYPE"]), LibSysUtils.ToString(curRow["BELONGID"]));
                if (hasSet.Contains(type_BelongID))
                {
                    this.ManagerMessage.AddMessage(LibMessageKind.Error, string.Format("权限行{0}的拥有者重复。", curRow["ROWNO"]));
                }
                else
                {
                    hasSet.Add(type_BelongID);
                }
            }
            #endregion



            try
            {
                if (masterRow.RowState == DataRowState.Added)
                {
                    //添加前设置目录文件夹对应的文件夹名称
                    string dirName = Guid.NewGuid().ToString().ToUpper(); //新的文件夹名称,用于对应新创建的文件夹
                    masterRow["DIRPATH"] = dirName;                       //保存对应的文件夹路径

                    #region 检查管理权限
                    //根据权限设置,确定是否采用前台传递的目录数据。虽然根据权限设置前端控制不显示相关页面,但需要防止前端伪造数据。
                    DirTypeEnum dirType     = (DirTypeEnum)LibSysUtils.ToInt32(masterRow["DIRTYPE"]);
                    string      parentDirId = LibSysUtils.ToString(masterRow["PARENTDIRID"]);
                    if (dirType == DirTypeEnum.Public && string.IsNullOrEmpty(parentDirId) == false)
                    {
                        //公共目录才进行检查。如果父目录为空,则应为超级管理员创建也不用检查。
                        if (DMPermissionControl.Default.HasPermission(this.Handle, parentDirId, string.Empty, DMFuncPermissionEnum.Manage) == false)
                        {
                            //新增时如果对父目录没有管理权限,则设置了目录权限也没用。
                            this.DataSet.Tables[2].RejectChanges();
                            this.DataSet.Tables[1].RejectChanges();
                        }
                    }
                    #endregion
                }
                else
                {
                    string dirId = LibSysUtils.ToString(masterRow["DIRID"]);
                    #region 检查管理权限
                    //根据权限设置,确定是否采用前台传递的目录数据。虽然根据权限设置前端控制不显示相关页面,但需要防止前端伪造数据。
                    DirTypeEnum dirType = (DirTypeEnum)LibSysUtils.ToInt32(masterRow["DIRTYPE"]);
                    if (dirType == DirTypeEnum.Public)
                    {
                        //公共目录才进行检查。
                        if (DMPermissionControl.Default.HasPermission(this.Handle, dirId, string.Empty, DMFuncPermissionEnum.Manage) == false)
                        {
                            //修改时如果对目录没有管理权限,则设置了目录权限也没用。
                            this.DataSet.Tables[2].RejectChanges();
                            this.DataSet.Tables[1].RejectChanges();
                        }
                    }
                    #endregion

                    string oldParentID     = LibSysUtils.ToString(masterRow["PARENTDIRID", DataRowVersion.Original]);
                    string currentParentID = LibSysUtils.ToString(masterRow["PARENTDIRID"]);
                    if (oldParentID.Equals(currentParentID) == false)
                    {
                        DirLinkAddress dirLink = new DirLinkAddress(LibSysUtils.ToString(masterRow["DIRID", DataRowVersion.Original]), this.DataAccess);
                        if (dirLink.SubDirIdList.Contains(currentParentID))
                        {
                            this.ManagerMessage.AddMessage(LibMessageKind.Error, "不能将子目录设置为父目录!");
                            return;
                        }
                        _OldDirPath = string.Empty;
                        //如果是修改的,则记录修改前的SavePath
                        string path = DMCommonMethod.GetDMRootPath((DirTypeEnum)LibSysUtils.ToInt32(masterRow["DIRTYPE"]));
                        //string path = Path.Combine(EnvProvider.Default.DocumentsPath, (LibSysUtils.ToInt32(masterRow["DIRTYPE"]) == 0 ? "" : "my"));//根据是否为私有类型在路径下增加my
                        string relativePath = dirLink.DirSavePath;
                        _OldDirPath = Path.Combine(path, relativePath);
                    }
                }
            }
            catch (Exception exp)
            {
                this.ManagerMessage.AddMessage(LibMessageKind.Error, "保存目录失败,原因:" + exp.Message);
                throw exp;
            }
        }