コード例 #1
0
        /// <summary>
        /// 直接创建目录
        /// </summary>
        /// <param name="dirId"></param>
        /// <param name="dirName"></param>
        /// <returns></returns>
        protected bool AddDirDirectly(ref string dirId, string dirName, DirTypeEnum dirType, string parentDirId)
        {
            if (string.IsNullOrEmpty(dirName))
            {
                return(false);
            }
            if (parentDirId == null)
            {
                parentDirId = string.Empty;
            }

            Dictionary <string, LibChangeRecord> dicChanges       = new Dictionary <string, LibChangeRecord>();
            Dictionary <string, object>          dicChangeColumns = new Dictionary <string, object>();

            LibEntryParam entryParam = new LibEntryParam();

            entryParam.ParamStore.Add("ParentDirId", parentDirId);
            entryParam.ParamStore.Add("ParentDirType", (int)dirType);

            this.DataSet.Clear();

            this.AddNew(entryParam);
            if (this.ManagerMessage.IsThrow)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(dirId))
            {
                dirId = LibSysUtils.ToString(this.DataSet.Tables[0].Rows[0]["DIRID"]);
            }

            object[] pks = new object[] { dirId };
            //因对于Add的对象Save方法中会检查Add的第一条记录数据并做相关处理,因此需要模拟生成前端传递来的change数据
            LibChangeRecord record = new LibChangeRecord();

            foreach (DataColumn col in this.DataSet.Tables[0].Columns)
            {
                dicChangeColumns.Add(col.ColumnName, this.DataSet.Tables[0].Rows[0][col.ColumnName]);//将文档主表的第一行数据变成change数据
            }
            dicChangeColumns["DIRID"]       = dirId;
            dicChangeColumns["DIRNAME"]     = dirName;
            dicChangeColumns["DIRTYPE"]     = (dirType == DirTypeEnum.Public) ? 0 : 1;
            dicChangeColumns["PARENTDIRID"] = parentDirId;

            record.Add.Add(dicChangeColumns);
            dicChanges.Add("DMDIRECTORY", record);

            this.DataSet.Clear();//将通过addNew添加的数据全清空,以免和通过change数据添加的重复了。

            this.Save(BillAction.AddNew, pks, dicChanges, null);
            if (this.ManagerMessage.IsThrow)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
ファイル: DMCommonMethod.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 获得文档库的根目录
        /// </summary>
        /// <param name="dirType">目录类型</param>
        /// <returns></returns>
        public static string GetDMRootPath(DirTypeEnum dirType)
        {
            if (Directory.Exists(EnvProvider.Default.DocumentsPath) == false)
            {
                Directory.CreateDirectory(EnvProvider.Default.DocumentsPath);
            }
            string path = Path.Combine(EnvProvider.Default.DocumentsPath, (dirType == DirTypeEnum.Public ? "" : "my"));//根据是否为私有类型在路径下增加my

            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            return(path);
        }
コード例 #3
0
ファイル: DirLinkAddress.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 为文档编号列表,获取各个文档对应的所属目录列表(从顶级目录到最终目录)
        /// </summary>
        /// <param name="docIds">文档编号列表</param>
        /// <returns></returns>
        public static Dictionary <string, List <DocInfo> > GetParentDirIdsForDocs(List <string> docIds)
        {
            if (docIds == null || docIds.Count == 0)
            {
                return(null);
            }

            List <string> newList = (from item in docIds
                                     select string.Format("'{0}'", item)).ToList();
            string docIdsQueryStr = string.Join(",", newList);

            Dictionary <string, List <DocInfo> > dicDocId_DirIds = new Dictionary <string, List <DocInfo> >();
            //构造递归查询语句。
            //从本级目录开始到顶级目录。第一行为本级目录(DirID标识的目录),最后一行为顶级目录(父目录为空)
            string        sqlFindParent = "";
            string        tempTableName = string.Format("{0}_{1}", "temp", DateTime.Now.Ticks);
            LibDataAccess dataAccess    = new LibDataAccess();

            if (dataAccess.DatabaseType == LibDatabaseType.SqlServer)
            {
                sqlFindParent = " with " + tempTableName + " as  " +
                                "   ( " +
                                "   select b.DOCID,a.DIRID,a.DIRNAME,a.PARENTDIRID,a.DIRPATH, a.DIRTYPE, b.CREATORID  from DMDIRECTORY a  " +
                                "   left join DMDOCUMENT b on a.DIRID = b.DIRID where b.DOCID in  (" + docIdsQueryStr + ") " +
                                "   union all " +
                                "   select t.DOCID,k.DIRID,k.DIRNAME,k.PARENTDIRID,k.DIRPATH, k.DIRTYPE, t.CREATORID from DMDIRECTORY k inner " +
                                "                               join " + tempTableName + " t on t.PARENTDIRID = k.DIRID " +
                                "   ) select * from " + tempTableName +
                                "   order by DOCID";
            }
            else
            {
                //Oracle的递归查询待测试
                //To DO
                sqlFindParent = "select b.DOCID,a.DIRID,a.DIRNAME,a.PARENTDIRID,a.DIRPATH, a.DIRTYPE, b.CREATORID from (select CONNECT_BY_ROOT(DIRID) as ROOTDIRID,DIRID,DIRNAME,PARENTDIRID,DIRPATH,DIRTYPE " +
                                " from DMDIRECTORY START WITH DIRID in (select distinct DIRID from DMDOCUMENT where DOCID in (" + docIdsQueryStr + ")) " +
                                " CONNECT BY PRIOR PARENTDIRID = DIRID) a left join DMDOCUMENT b on a.ROOTDIRID = b.DIRID order by b.DOCID";
            }
            if (string.IsNullOrEmpty(sqlFindParent))
            {
                return(null);
            }
            DataSet   ds = dataAccess.ExecuteDataSet(sqlFindParent);
            DataTable dt = new DataTable();

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
            }
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow row = null;
                //倒序,从根目录开始
                string      docId     = string.Empty;
                string      dirId     = string.Empty;
                DirTypeEnum dirType   = DirTypeEnum.Public;
                string      creatorId = string.Empty;
                for (int i = dt.Rows.Count - 1; i >= 0; i--)
                {
                    row       = dt.Rows[i];
                    docId     = LibSysUtils.ToString(row["DOCID"]);
                    dirId     = LibSysUtils.ToString(row["DIRID"]);
                    dirType   = (DirTypeEnum)LibSysUtils.ToInt32(row["DIRTYPE"]);
                    creatorId = LibSysUtils.ToString(row["CREATORID"]);
                    DocInfo temp = new DocInfo()
                    {
                        DocId     = docId,
                        DirType   = dirType,
                        CreatorId = creatorId,
                        DirId     = dirId
                    };
                    if (dicDocId_DirIds.ContainsKey(docId) == false)
                    {
                        dicDocId_DirIds.Add(docId, new List <DocInfo>()
                        {
                            temp
                        });
                    }
                    else
                    {
                        dicDocId_DirIds[docId].Add(temp);
                    }
                }
            }
            return(dicDocId_DirIds);
        }
コード例 #4
0
ファイル: DirLinkAddress.cs プロジェクト: liusj666/AxNew
        /// <summary>
        /// 根据目录标识,构造目录链接
        /// </summary>
        public void CreateDirLink()
        {
            //构造递归查询语句。
            //从本级目录开始到顶级目录。第一行为本级目录(DirID标识的目录),最后一行为顶级目录(父目录为空)
            string sqlFindParent = "";
            string tempTableName = string.Format("{0}_{1}", "temp", DateTime.Now.Ticks);

            if (this.DataAccess.DatabaseType == LibDatabaseType.SqlServer)
            {
                sqlFindParent = " with " + tempTableName + " as  " +
                                "   ( " +
                                "   select a.DIRID,a.DIRNAME,a.PARENTDIRID,a.DIRPATH,A.DIRTYPE  from DMDIRECTORY a where DIRID = '" + DirID + "' " +
                                "   union all " +
                                "   select k.DIRID,k.DIRNAME,k.PARENTDIRID,k.DIRPATH,k.DIRTYPE from DMDIRECTORY k inner " +
                                "                               join " + tempTableName + " t on t.PARENTDIRID = k.DIRID " +
                                "   ) select * from " + tempTableName;
            }
            else
            {
                //Oracle的递归查询待测试
                sqlFindParent = "select DIRID,DIRNAME,PARENTDIRID,DIRPATH,DIRTYPE " +
                                " from DMDIRECTORY " +
                                " START WITH DIRID='" + DirID + "' " +
                                " CONNECT BY DIRID = PRIOR PARENTDIRID ";
            }

            _DirSavePath  = string.Empty;
            _DirNameLink  = string.Empty;
            _DirIdLink    = string.Empty;
            _DirLinkTable = new DataTable();
            _ParentDirIdList.Clear();

            DataSet ds = this.DataAccess.ExecuteDataSet(sqlFindParent);

            if (ds != null && ds.Tables.Count > 0)
            {
                _DirLinkTable = ds.Tables[0];
            }
            if (_DirLinkTable != null && _DirLinkTable.Rows.Count > 0)
            {
                DataRow row = null;
                //倒序,从根目录开始
                for (int i = _DirLinkTable.Rows.Count - 1; i >= 0; i--)
                {
                    row          = _DirLinkTable.Rows[i];
                    _DirSavePath = Path.Combine(_DirSavePath, LibSysUtils.ToString(row["DIRPATH"]));
                    _DirNameLink = string.Format("{0}/{1}", _DirNameLink, LibSysUtils.ToString(row["DIRNAME"]));
                    _DirIdLink   = string.Format("{0}/{1}", _DirIdLink, LibSysUtils.ToString(row["DIRID"]));
                    if (isForDir == false || i != 0)
                    {
                        //对于目录来说 只添加父目录(i==0),对于文档来说目录都要添加
                        _ParentDirIdList.Add(LibSysUtils.ToString(row["DIRID"]));
                    }
                    if (i == 0)
                    {
                        //最底层的目录,设置目录类型
                        _DirType     = (DirTypeEnum)LibSysUtils.ToInt32(row["DIRTYPE"]);
                        _DirNameLink = string.Format("/{0}{1}", (_DirType == DirTypeEnum.Public) ? "公共文档" : "个人文档", _DirNameLink);
                    }
                }
            }

            GetSubDirIds();
        }
コード例 #5
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;
            }
        }