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
        /// <summary>
        /// 下载文件
        /// 检查用户对指定文档的下载权限,如果有则将文件复制到临时目录然后通过文件流返回
        /// </summary>
        /// <returns></returns>
        public FileStreamResult Download()
        {
            string docId       = string.Empty;
            int    modifyVerId = -1;

            try
            {
                docId = Request.QueryString["DocId"];
                string userHandle     = Request.QueryString["UserHandle"];
                string modifyVerIdStr = Request.QueryString["modifyVerId"];
                if (string.IsNullOrEmpty(docId) || string.IsNullOrEmpty(userHandle) || string.IsNullOrEmpty(modifyVerIdStr))
                {
                    return(null);
                }

                if (int.TryParse(modifyVerIdStr, out modifyVerId) == false)
                {
                    return(null);
                }

                string downloadName = string.Empty;
                string tempFilePath = DMCommonMethod.CheckAndGetDownloadTempFile(userHandle, docId, modifyVerId, out downloadName);
                var    contentType  = MimeMapping.GetMimeMapping(downloadName);
                return(File(new FileStream(tempFilePath, FileMode.Open), contentType, downloadName));
            }
            catch (Exception exp)
            {
                DMCommonMethod.WriteLog("DocumentController.Download", string.Format("DocId:{0}\r\nModifyVerId:{1}\r\nError:{2}", docId, modifyVerId, exp.ToString()));
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 将word文档转成txt
        /// </summary>
        /// <param name="fileName">文档全路径</param>
        public void Convert(string fileName)
        {
            if (!File.Exists(fileName))
            {
                //打印日志
                Console.WriteLine("文件不存在");
                return;
            }
            FileInfo info = new FileInfo(fileName);

            if (info.Extension != ".doc" && info.Extension != ".docx")
            {
                //打印日志
                Console.WriteLine("文件格式错误");
                return;
            }
            destFileName = Path.Combine(DMCommonMethod.GetDMRootTempPath(), string.Format("_{0}.txt", CreateOnlyFileNameUtil.CreateOnlyFileName()));

            Application app = new Application();

            app.Visible = false;
            object obj       = System.Reflection.Missing.Value;
            object inputFile = fileName;

            Document doc = app.Documents.Open(ref inputFile, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj);

            object outfile = destFileName;
            object fmt     = WdSaveFormat.wdFormatEncodedText;

            doc.SaveAs(ref outfile, ref fmt, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj);
            doc.Close(ref obj, ref obj, ref obj);
            app.Quit();
            app = null;
        }
Exemple #4
0
        public string SaveNew()
        {
            //string userName = string.Empty;
            string fileFullPath = string.Empty;
            string userHandle   = Request.QueryString["userHandle"];
            string fileName     = Request.QueryString["fileName"];
            bool   isAllow      = false;

            if (string.IsNullOrEmpty(userHandle) || string.IsNullOrEmpty(fileName))
            {
                return("参数错误");

                throw new Exception("参数错误");
            }

            #region 新增权限判断
            isAllow = true;
            #endregion

            //获取文件保存路径
            fileFullPath = Path.Combine(DMCommonMethod.GetDMRootTempPath(), fileName);

            if (isAllow)
            {
                FileSaver fs = new FileSaver();
                fs.SaveToFile(fileFullPath);
                //fs.CustomSaveResult = "ok";
                fs.Close();
                return("ok");
            }
            else
            {
                throw new Exception("无编辑权限,无法保存");
            }
        }
Exemple #5
0
        /// <summary>
        /// 将PPT转成txt
        /// </summary>
        /// <param name="fileName"></param>
        public void Convert(string fileName)
        {
            if (!File.Exists(fileName))
            {
                //打印日志
                //Console.WriteLine("文件不存在");
                DMCommonMethod.WriteLog("文档管理", fileName + "文件不存在");
                return;
            }
            FileInfo info = new FileInfo(fileName);

            if (info.Extension != ".ppt" && info.Extension != ".pptx")
            {
                //打印日志
                //Console.WriteLine("文件格式错误");
                DMCommonMethod.WriteLog("文档管理", fileName + "文件格式错误");
                return;
            }
            destFileName = Path.Combine(DMCommonMethod.GetDMRootTempPath(), string.Format("_{0}.txt", CreateOnlyFileNameUtil.CreateOnlyFileName()));

            try
            {
                FileStream   fs = new FileStream(destFileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                Application  pa = new Application();
                Presentation pp = pa.Presentations.Open(fileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                //开始读取每一页
                foreach (Slide slide in pp.Slides)
                {
                    //开始读取每一个数据块
                    foreach (Shape shape in slide.Shapes)
                    {
                        try
                        {
                            if (shape.TextFrame.TextRange != null)//如果是文字,文字处理
                            {
                                string text = shape.TextFrame.TextRange.Text.Trim();
                                sw.Write(text);
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message == "指定的值超出了范围")
                            {
                                continue;
                            }
                        }
                    }
                    sw.WriteLine();
                }
                sw.Close();
            }
            catch (Exception ex)
            {
                DMCommonMethod.WriteLog("文档管理", fileName + "文件转换错误\n" + ex.Message);
            }
        }
Exemple #6
0
        public string SaveNewTxt()
        {
            string fileFullPath = string.Empty;
            string userHandle   = Request.Form["userHandle"];
            string fileName     = Request.Form["fileName"];
            string contents     = Request.Form["contents"];
            bool   isAllow      = false;

            if (string.IsNullOrEmpty(userHandle) || string.IsNullOrEmpty(fileName))
            {
                return("参数错误");

                throw new Exception("参数错误");
            }

            #region 新增权限判断
            isAllow = true;
            #endregion

            //获取文件保存路径
            fileFullPath = Path.Combine(DMCommonMethod.GetDMRootTempPath(), fileName);

            if (isAllow)
            {
                StreamWriter sw = new StreamWriter(fileFullPath);
                try
                {
                    foreach (char c in contents)
                    {
                        if (c == '\n')
                        {
                            sw.Write('\r');
                        }
                        sw.Write(c);
                    }
                    sw.Flush();
                }
                catch (Exception)
                {
                    return("保存失败");

                    throw;
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }
                return("ok");
            }
            else
            {
                throw new Exception("无编辑权限,无法保存");
            }
        }
Exemple #7
0
        /// <summary>
        /// 更新目录下的文档数量
        /// </summary>
        /// <param name="dirId"></param>
        public static void UpdateDocCountOfDir(string dirId, LibDataAccess dataAccess)
        {
            if (string.IsNullOrEmpty(dirId) || dataAccess == null)
            {
                return;
            }
            string sql = "Update DMDIRECTORY set DOCCOUNT = (select count(*) from DMDOCUMENT B where B.DIRID = '" + dirId + "') where DIRID= '" + dirId + "' ";

            try
            {
                dataAccess.ExecuteNonQuery(sql);
            }
            catch (Exception exp)
            {
                DMCommonMethod.WriteLog("DmDirectoryBcf.UpdateDocCountOfDir", string.Format("DirId:{0},\r\nError:{1}", dirId, exp.ToString()));
            }
        }
Exemple #8
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 #9
0
        public string Save()
        {
            //string userName = string.Empty;
            string fileFullPath = string.Empty;
            string fileId       = Request.QueryString["fileId"];
            string userHandle   = Request.QueryString["userHandle"];
            string fileName     = Request.QueryString["fileName"];
            bool   isAllow      = false;

            if (string.IsNullOrEmpty(userHandle) || string.IsNullOrEmpty(fileId) || string.IsNullOrEmpty(fileName))
            {
                return("参数错误");

                throw new Exception("参数错误");
            }

            #region 权限判断
            List <DMFuncPermissionEnum> permissionList = DMPermissionControl.Default.GetPermissionOf(userHandle, fileId);
            if (permissionList.Contains(DMFuncPermissionEnum.Edit))
            {
                isAllow = true;
            }
            #endregion

            //获取文件保存路径
            fileFullPath = Path.Combine(DMCommonMethod.GetDMRootTempPath(), fileName);

            if (isAllow)
            {
                FileSaver fs = new FileSaver();
                fs.SaveToFile(fileFullPath);
                //fs.CustomSaveResult = "ok";
                fs.Close();
                return("ok");
            }
            else
            {
                //return View("PermissionError");
                throw new Exception("无编辑权限,无法保存");
            }
        }
Exemple #10
0
        /// <summary>
        /// 将Excel转成txt
        /// </summary>
        /// <param name="fileName"></param>
        public void Convert(string fileName)
        {
            if (!File.Exists(fileName))
            {
                //打印日志
                //Console.WriteLine("文件不存在");
                DMCommonMethod.WriteLog("文档管理", fileName + "文件不存在");
                return;
            }
            FileInfo info = new FileInfo(fileName);

            if (info.Extension != ".xls" && info.Extension != ".xlsx")
            {
                //打印日志
                //Console.WriteLine("文件格式错误");
                DMCommonMethod.WriteLog("文档管理", fileName + "文件格式错误");
                return;
            }
            destFileName = Path.Combine(DMCommonMethod.GetDMRootTempPath(), string.Format("_{0}.txt", CreateOnlyFileNameUtil.CreateOnlyFileName()));

            try
            {
                FileStream   fs = new FileStream(destFileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                var conn = new OleDbConnection();
                conn.ConnectionString = String.Format(@"provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0 Macro;hdr=yes';data source={0}", fileName);
                conn.Open();
                DataTable sheetTb = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                foreach (DataRow sheet in sheetTb.Rows)
                {
                    string tableName = sheet["TABLE_NAME"].ToString();

                    string           sql = String.Format("select * from [{0}]", tableName);
                    OleDbDataAdapter da  = new OleDbDataAdapter(sql, conn);

                    var ds = new DataSet();
                    da.Fill(ds);

                    var tb1 = ds.Tables[0];

                    if (tb1.Rows.Count == 0)
                    {
                        continue; // 空表
                    }
                    if (tb1.Rows.Count == 1 && tb1.Columns.Count == 1)
                    {
                        if (tb1.Rows[0][0] == DBNull.Value)
                        {
                            continue; // 空表
                        }
                    }

                    int[] colMaxLen = new int[tb1.Columns.Count];

                    foreach (DataRow row in tb1.Rows)
                    {
                        for (int j = 0; j < tb1.Columns.Count; ++j)
                        {
                            DataColumn col     = tb1.Columns[j];
                            string     content = row[j].ToString();

                            bool hasYinhao = false;
                            if (-1 != content.IndexOf("\r") || -1 != content.IndexOf("\n"))
                            {
                                hasYinhao = true;
                            }
                            string fmt;
                            fmt = String.Format("{0}{1}0{2}{3}{4}", hasYinhao ? "\"" : "",
                                                "{", "}", hasYinhao ? "\"" : "", j + 1 == tb1.Columns.Count ? "" : "\t");
                            sw.Write(fmt, row[j]);
                        }
                        sw.WriteLine();
                    }
                }
                sw.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
                DMCommonMethod.WriteLog("文档管理", fileName + "文件转换失败\n," + ex.Message);
            }
        }
Exemple #11
0
        /// <summary>
        /// 检查表单附件目录,如果需要的目录不存在则创建。返回检查得到的目录编号
        /// 目录编号为表单的功能代码progid,名称为表单的功能显示名称
        /// 添加到公共目录下的“表单附件”目录下,如该父目录不存在则创建
        /// 子目录按照日期构建
        /// </summary>
        /// <param name="progId"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        public bool CheckAndAddBillAttachmentDir(string progId, out string retDirId)
        {
            retDirId = string.Empty;
            if (string.IsNullOrEmpty(progId))
            {
                return(false);
            }
            string displayName = string.Empty;
            string sql         = string.Empty;
            object obj         = DBNull.Value;

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

            try
            {
                LibHandle systemHandle = LibHandleCache.Default.GetSystemHandle();
                this.Handle = systemHandle;//设置为系统用户

                LibDataAccess dataAccess = this.DataAccess;
                //检查“表单附件”一级公共目录
                if (string.IsNullOrEmpty(ProgDirInfo.BillAttachmentTopDirId))
                {
                    sql = string.Format("select DIRID from DMDIRECTORY where DIRNAME = '{0}' and DIRTYPE = 0 and PARENTDIRID = '' order by CREATETIME asc", ProgDirInfo.BillAttachmentTopDirName);
                    obj = dataAccess.ExecuteScalar(sql);
                    if (string.IsNullOrEmpty(LibSysUtils.ToString(obj)))
                    {
                        //表单附件一级目录还不存在
                        string topDirId = string.Empty;
                        if (AddDirDirectly(ref topDirId, ProgDirInfo.BillAttachmentTopDirName, DirTypeEnum.Public, "") == false)
                        {
                            return(false);
                        }
                        else
                        {
                            ProgDirInfo.BillAttachmentTopDirId = topDirId;
                        }
                    }
                    else
                    {
                        ProgDirInfo.BillAttachmentTopDirId = (string)obj;
                    }
                }

                ProgDirInfo progDirInfo = ProgDirInfo.GetDirInfo(progId);
                if (progDirInfo == null || string.IsNullOrEmpty(progDirInfo.DirId) ||
                    string.IsNullOrEmpty(progDirInfo.ProgDisplayName))
                {
                    progDirInfo = new ProgDirInfo(progId);
                    //查找ProgId对应的功能名称
                    sql         = string.Format("select PROGNAME from AXPFUNCLIST where PROGID = '{0}'", progId);
                    displayName = LibSysUtils.ToString(dataAccess.ExecuteScalar(sql));
                    if (string.IsNullOrEmpty(displayName))
                    {
                        return(false);
                    }
                    progDirInfo.ProgDisplayName = displayName;
                }
                if (string.IsNullOrEmpty(progDirInfo.DirId))
                {
                    //检查功能模块二级目录
                    sql = string.Format("select DIRID from DMDIRECTORY where DIRID = '{0}'", progId);
                    obj = dataAccess.ExecuteScalar(sql);
                    if (string.IsNullOrEmpty(LibSysUtils.ToString(obj)))
                    {
                        //表单附件二级目录(功能模块)还不存在
                        if (AddDirDirectly(ref progId, displayName, DirTypeEnum.Public, ProgDirInfo.BillAttachmentTopDirId) == false)
                        {
                            return(false);
                        }
                        progDirInfo.DirId = progId;
                    }
                    progDirInfo.DirId = progId;
                }
                //检查三级目录,日期名
                string threeDirName = DateTime.Now.ToString("yyyyMMdd");
                retDirId = progDirInfo.GetDayDirId(threeDirName);
                if (string.IsNullOrEmpty(retDirId))
                {
                    sql = string.Format("select DIRID from DMDIRECTORY where DIRNAME = '{0}' and DIRTYPE = 0 and PARENTDIRID = '{1}' order by CREATETIME asc", threeDirName, progId);
                    obj = dataAccess.ExecuteScalar(sql);
                    if (string.IsNullOrEmpty(LibSysUtils.ToString(obj)))
                    {
                        //表单附件三级目录还不存在
                        bool ret = AddDirDirectly(ref retDirId, threeDirName, DirTypeEnum.Public, progDirInfo.DirId);
                        if (ret)
                        {
                            progDirInfo.AddDayDirId(threeDirName, retDirId);
                            ProgDirInfo.AddDirInfo(progDirInfo);
                        }
                        return(ret);
                    }
                    else
                    {
                        retDirId = (string)obj;
                        if (string.IsNullOrEmpty(retDirId))
                        {
                            return(false);
                        }
                        else
                        {
                            progDirInfo.AddDayDirId(threeDirName, retDirId);
                            ProgDirInfo.AddDirInfo(progDirInfo);
                        }
                    }
                }
                return(true);
            }
            catch (Exception exp)
            {
                DMCommonMethod.WriteLog("DmDirectoryBcf.AddBillAttachmentDir", string.Format("ProgId:{0}\r\nDisplayName:{1}\r\nError:{2}", progId, displayName, exp.ToString()));
                return(false);
            }
        }
Exemple #12
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;
            }
        }
Exemple #13
0
        /// <summary>
        /// 使用用户名密码  下载文件
        /// 检查用户对指定文档的下载权限,如果有则将文件复制到临时目录然后通过文件流返回
        /// </summary>
        /// <returns></returns>
        public FileStreamResult DownloadForPassword()
        {
            string docId       = string.Empty;
            int    modifyVerId = -1;

            try
            {
                docId = Request.Form["docId"];
                string userId         = Request.Form["userId"];
                string password       = Request.Form["password"];
                string modifyVerIdStr = Request.Form["modifyVerId"];
                if (string.IsNullOrEmpty(docId) || string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(modifyVerIdStr) || string.IsNullOrEmpty(password))
                {
                    return(null);
                }

                if (int.TryParse(modifyVerIdStr, out modifyVerId) == false)
                {
                    return(null);
                }

                string downloadName = string.Empty;

                SqlBuilder    builder    = new SqlBuilder("axp.User");
                string        sql        = builder.GetQuerySql(0, "A.PERSONID", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password)));
                LibDataAccess dataAccess = new LibDataAccess();
                string        personId   = LibSysUtils.ToString(dataAccess.ExecuteScalar(sql));
                if (personId == null)
                {
                    throw new Exception("用户账户或密码错误");
                }

                //权限判断
                if (userId.ToLower() != "admin")
                {
                    //DMUserPermission userPermission = DMUserPermissionCache.Default.GetCacheItem(personId);
                    //if (!userPermission.CheckCan(string.Empty, docId, DMFuncPermissionEnum.Download))
                    //{
                    //    throw new Exception("没有权限下载该文件");
                    //}
                }


                DirLinkAddress dirlink = new DirLinkAddress(docId);
                downloadName = dirlink.DocName;
                //复制一份到临时目录
                string tempPath    = Path.Combine(DMCommonMethod.GetDMRootTempPath(), string.Format("{0}_{1}", DateTime.Now.Ticks.ToString(), downloadName));
                string docFullPath = dirlink.GetDocFullPath(modifyVerId);
                if (System.IO.File.Exists(docFullPath))
                {
                    System.IO.File.Copy(docFullPath, tempPath);
                    var contentType = MimeMapping.GetMimeMapping(downloadName);
                    return(File(new FileStream(tempPath, FileMode.Open), contentType, downloadName));
                }
                throw new Exception("文件不存在");
            }
            catch (Exception exp)
            {
                DMCommonMethod.WriteLog("DocumentController.Download", string.Format("DocId:{0}\r\nModifyVerId:{1}\r\nError:{2}", docId, modifyVerId, exp.ToString()));
                return(null);
            }
        }
Exemple #14
0
        public string SaveTxt()
        {
            string fileFullPath = string.Empty;
            string fileId       = Request.Form["fileId"];
            string userHandle   = Request.Form["userHandle"];
            string fileName     = Request.Form["fileName"];
            string contents     = Request.Form["contents"];
            bool   isAllow      = false;

            if (string.IsNullOrEmpty(contents) || string.IsNullOrEmpty(fileId) || string.IsNullOrEmpty(userHandle))
            {
                return("参数错误");

                throw new Exception("参数错误");
            }

            #region 权限判断
            List <DMFuncPermissionEnum> permissionList = DMPermissionControl.Default.GetPermissionOf(userHandle, fileId);
            if (permissionList.Contains(DMFuncPermissionEnum.Edit))
            {
                isAllow = true;
            }
            #endregion

            //获取文件保存路径
            fileFullPath = Path.Combine(DMCommonMethod.GetDMRootTempPath(), fileName);

            if (isAllow)
            {
                StreamWriter sw = null;

                try
                {
                    sw = new StreamWriter(fileFullPath);
                    foreach (char c in contents)
                    {
                        if (c == '\n')
                        {
                            sw.Write('\r');
                        }
                        sw.Write(c);
                    }
                    sw.Flush();
                }
                catch (Exception)
                {
                    return("保存失败");

                    throw;
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }

                return("ok");
            }
            else
            {
                throw new Exception("无编辑权限,无法保存");
            }
        }