示例#1
0
        ///// <summary>
        ///// 加载分页数据
        ///// </summary>
        ///// <param name="intPageIndex"></param>
        ///// <param name="intPageSize"></param>
        ///// <param name="whereLambda"></param>
        ///// <param name="dicOrderBy"></param>
        ///// <returns></returns>
        //public Page<Folder> GetByPage(int intPageIndex,int intPageSize,Expression<Func<Folder,bool>> whereLambda = null,Dictionary<string,string> dicOrderBy = null)
        //{
        //	if(whereLambda == null)
        //	{
        //		whereLambda = u => 1 == 1;
        //	}
        //	var q = db.Folder.Where(whereLambda).OrderBy(dicOrderBy);
        //	var list = q.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList();
        //	return new Page<Folder>(intPageIndex,intPageSize,q.Count(),list);
        //}
        /// <summary>
        /// 新增文件关联
        /// </summary>
        /// <param name="folderModel"></param>
        /// <returns></returns>
        public CommonResult Add(DocumentFolder documentfolderModel)
        {
            if (IsRepeatFolderUIDwithDocumentUID(documentfolderModel.UID, documentfolderModel.FolderUID))
            {
                return(CommonResult.Instance("已存在此项目名,请换一个再试"));
            }
            documentfolderModel.DocumentFolderNo = db.Database.SqlQuery <string>("select ([dbo].[GetNextTN]('DocumentFolder'))").FirstOrDefault();

            db.DocumentFolder.Add(documentfolderModel);
            if (db.SaveChanges() < 0)
            {
                return(CommonResult.Instance("新建失败"));
            }
            //AllServices.ActionLogService.AddLog("新增文件",folderModel.ToJson(),Enums.ActionCategory.Add);
            Log4NetHelper.Info("新增关联文件记录", documentfolderModel.ToJson());
            return(CommonResult.Instance(documentfolderModel.UID));
        }
示例#2
0
 /// <summary>
 /// 更新文件夹
 /// </summary>
 /// <param name="folderModel"></param>
 /// <returns></returns>
 public CommonResult Update(Folder folderModel)
 {
     if (IsRepeatFolderName(folderModel.UID, folderModel.FolderName))
     {
         return(CommonResult.Instance("已存在此项目名,请换一个再试"));
     }
     db.Folder.Where(folder => folder.UID == folderModel.UID).Update(u => new Folder()
     {
         FolderName = folderModel.FolderName,
         FatherID   = folderModel.FatherID,
         Editor     = folderModel.Editor,
         EditTime   = DateTime.Now
     });
     Log4NetHelper.Info("更新文件夹信息", folderModel.ToJson());
     //AllServices.ActionLogService.AddLog("更新项目信息",model.ToJson(),Enums.ActionCategory.Update);
     return(CommonResult.Instance());
 }
示例#3
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="strUserName"></param>
        /// <param name="strPassword"></param>
        /// <returns></returns>
        public CommonResult Login(string strUserName, string strPassword)
        {
            //if(strUserName.ToLower() == AllConfigServices.SettingsConfig.SuperAdminAccount && strPassword == AllConfigServices.SettingsConfig.SuperAdminPassword)
            //{
            SysFormsAuthenticationHelper <Models.User> .SetAuthSession(strUserName, new User()
            {
                //UserID = strUserName
                UserName = strUserName,
                Password = strPassword
            });

            //return CommonResult.Instance();
            //}

            strPassword = strPassword.ToMD5();
            var userInfo = db.User.Where(u => u.UserName == strUserName && u.Password == strPassword).FirstOrDefault();

            if (userInfo != null)
            {
                int intState = (int)ItemState.Disable;
                if (userInfo.State == intState)
                {
                    return(CommonResult.Instance("账号被禁用,请联系管理员"));
                }
                else
                {
                    var q = from permission in db.Permission
                            join userPermission in db.UserPermission on permission.PermissionNo equals userPermission.PermissionID
                            join user in db.User on userPermission.UserNo equals user.UserNo
                            where user.UserNo == userInfo.UserNo
                            select permission;
                    var listRole = q.ToList();
                    if (listRole.Where(lisRole => lisRole.State == intState).Count() > 0)
                    {
                        return(CommonResult.Instance("账号所属角色被禁用,请联系管理员"));
                    }
                }
            }
            else
            {
                return(CommonResult.Instance("账号或密码错误"));
            }
            //return CommonResult.Instance();
            return(CommonResult.Instance(1, "登陆成功", userInfo));
        }
示例#4
0
        /// <summary>
        /// 加载分页数据(高级查询)
        /// </summary>
        /// <param name="intPageIndex"></param>
        /// <param name="intPageSize"></param>
        /// <param name="whereLambda"></param>
        /// <param name="dicOrderBy"></param>
        /// <returns></returns>
        //public Page<Models.Document> GetSearchByPage(int intPageIndex,int intPageSize,int intFolderUID,string strTag,DateTime dateBeginTime,DateTime dateEndTime,Dictionary<string,string> dicOrderBy = null)
        //{
        //	if(whereLambda == null)
        //	{
        //		whereLambda = u => 1 == 1;
        //	}
        //	int intFolderUID = 71;//所属系统ID
        //	string strTag = "2";//标签
        //	DateTime dateBeginTime = Convert.ToDateTime("2018-01-12");
        //	DateTime dateEndTime = Convert.ToDateTime("2018-01-13");

        //	var q = db.Document.Where(
        //		d => db.DocumentFolder.Where(df => df.FolderUID == intFolderUID).Select(s => s.DocumentUID).Contains(d.UID) &&
        //		db.DocumentTag.Where(dt => dt.Tag.Contains(strTag)).Select(s => s.DocumentUID).Contains(d.UID) &&
        //		d.CreateTime <= dateEndTime && d.CreateTime >= dateBeginTime
        //		);

        //	var q = db.Document.Where(whereLambda).OrderBy(dicOrderBy);
        //	var list = q.Skip((intPageIndex - 1) * intPageSize).Take(intPageSize).ToList();
        //	return new Page<Models.Document>(intPageIndex,intPageSize,q.Count(),list);
        //}

        /// <summary>
        /// 更新项目
        /// </summary>
        /// <param name="documentModel"></param>
        /// <returns></returns>
        public CommonResult Update(Models.Document documentModel)
        {
            if (IsRepeatDocumentName(documentModel.DocumentName, documentModel.DocumentPath))
            {
                return(CommonResult.Instance("已存在此文件名,请换一个再试"));
            }
            db.Document.Where(document => document.UID == documentModel.UID).Update(u => new Models.Document()
            {
                DocumentName = documentModel.DocumentName,
                DocumentPath = documentModel.DocumentPath,
                Editor       = documentModel.Editor,
                EditTime     = documentModel.EditTime,
                State        = documentModel.State
            });
            //AllServices.ActionLogService.AddLog("更新项目信息",model.ToJson(),Enums.ActionCategory.Update);
            Log4NetHelper.Info("更新上传记录", documentModel.ToJson());
            return(CommonResult.Instance());
        }
示例#5
0
 /// <summary>
 /// 更新任务
 /// </summary>
 /// <param name="tasklistModel"></param>
 /// <returns></returns>
 public CommonResult Update(Models.TaskList tasklistModel)
 {
     if (IsRepeatTaskListName(tasklistModel.TaskListNo, tasklistModel.TaskListName))
     {
         return(CommonResult.Instance("已存在此任务名,请换一个再试"));
     }
     db.TaskList.Where(taskList => taskList.UID == tasklistModel.UID).Update(u => new Models.TaskList()
     {
         TaskListName = tasklistModel.TaskListName,
         Editor       = tasklistModel.Editor,
         EditTime     = tasklistModel.EditTime,
         Remark       = tasklistModel.Remark,
         State        = tasklistModel.State
     });
     Log4NetHelper.Info("更新任务", tasklistModel.ToJson());
     //AllServices.ActionLogService.AddLog("更新项目信息",model.ToJson(),Enums.ActionCategory.Update);
     return(CommonResult.Instance());
 }
示例#6
0
 /// <summary>
 /// 新增文件夹
 /// </summary>
 /// <param name="folderModel"></param>
 /// <returns></returns>
 public CommonResult Add(Folder folderModel)
 {
     if (IsRepeatFolderName(folderModel.UID, folderModel.FolderName))
     {
         return(CommonResult.Instance("已存在此文件名,请换一个再试"));
     }
     folderModel.FolderNo   = db.Database.SqlQuery <string>("select ([dbo].[GetNextTN]('Folder')) ").FirstOrDefault();
     folderModel.CreateTime = DateTime.Now;
     folderModel.EditTime   = DateTime.Now;
     db.Folder.Add(folderModel);
     if (db.SaveChanges() < 0)
     {
         return(CommonResult.Instance(0, "新建失败", folderModel.FolderName));
     }
     //AllServices.ActionLogService.AddLog("新增文件夹",folderModel.ToJson(),Enums.ActionCategory.Add);
     Log4NetHelper.Info("新增文件夹", folderModel.ToJson());
     return(CommonResult.Instance());
 }
示例#7
0
        /// <summary>
        /// 更新项目
        /// </summary>
        /// <param name="projectModel"></param>
        /// <returns></returns>
        public CommonResult Update(Models.Project projectModel)
        {
            if (IsRepeatProjectName(projectModel.ProjectNo, projectModel.ProjectName))
            {
                return(CommonResult.Instance("已存在此项目名,请换一个再试"));
            }
            db.Project.Where(project => project.ProjectNo == projectModel.ProjectNo).Update(u => new Models.Project()
            {
                ProjectName = projectModel.ProjectName,
                Creater     = projectModel.Creater,
                CreateTime  = projectModel.CreateTime,
                Editor      = projectModel.Editor,
                EditTime    = DateTime.Now,
                Remark      = projectModel.Remark,
                State       = projectModel.State
            });

            //AllServices.ActionLogService.AddLog("更新项目信息",model.ToJson(),Enums.ActionCategory.Update);
            return(CommonResult.Instance());
        }
示例#8
0
        /// <summary>
        /// 新增图片处理
        /// </summary>
        /// <param name="intUID"></param>
        /// <param name="strFileNameWithoutExtension"></param>
        /// <param name="strFileSaveVirtualPath"></param>
        /// <param name="strFileExtension"></param>
        /// <param name="strSize"></param>
        /// <param name="intDpiID"></param>
        /// <param name="actionType"></param>
        /// <param name="strUserName"></param>
        /// <returns></returns>
        public CommonResult AddImageHandler(int intUID, string strFileNameWithoutExtension, string strFileSaveVirtualPath, string strFileExtension, string strSize, int intDpiID, ActionType actionType, string strUserName)
        {
            CommonResult commonResult = new CommonResult();

            if (actionType == ActionType.Add)
            {
                //添加上传文件记录(原图)
                commonResult = AllServices.DocumentService.Add(new Models.Document()
                {
                    DocumentName      = strFileNameWithoutExtension,
                    DocumentType      = strFileExtension.ToLower(),
                    DocumentPath      = strFileSaveVirtualPath,
                    PictureSize       = strSize,
                    PictureResolution = intDpiID.ToInt() == 0 ? "96dpi" : "72dpi",
                    Creater           = strUserName,
                    Editor            = strUserName,
                    CreateTime        = DateTime.Now,
                    EditTime          = DateTime.Now,
                    State             = Convert.ToInt32(ItemState.Enable)
                                        //IsSystemCreate = false
                });
            }
            else if (actionType == ActionType.Modify)
            {
                //更新图片记录
                Document documentModel = new Document();
                documentModel.UID               = intUID;
                documentModel.DocumentName      = strFileNameWithoutExtension;
                documentModel.DocumentPath      = strFileSaveVirtualPath;
                documentModel.PictureSize       = strSize;
                documentModel.PictureResolution = intDpiID.ToInt() == 0 ? "96dpi" : "72dpi";
                documentModel.Editor            = strUserName;
                documentModel.EditTime          = DateTime.Now;
                documentModel.State             = Convert.ToInt32(ItemState.Disable);
                commonResult = AllServices.DocumentService.Update(documentModel);
            }
            return(commonResult);
        }
示例#9
0
        /// <summary>
        /// 处理旧图片
        /// </summary>
        /// <param name="strFileSavePath">图片虚拟路径</param>
        /// <returns></returns>
        public CommonResult OldImageHandler(string strFileSaveVirtualPath, ImageUploadBaseConfig imageUploadConfig, string strUserName)
        {
            try
            {
                string strFileSavePath = PathHelper.GetMapPath(strFileSaveVirtualPath);
                //是否存在图片文件
                if (FileHelper.Exists(strFileSavePath))
                {
                    #region 处理同路径旧图片
                    //File.Delete(strFileSavePath);
                    string strNewFileName = FileHelper.ResetFileMinName(strFileSavePath);
                    if (!FileHelper.RenameFile(strFileSavePath, strNewFileName))                  //重命名旧文件
                    {
                        return(CommonResult.Instance("旧文件重命名失败"));
                    }
                    //更新旧文件的信息
                    Document oldDocumentModel = new Document();
                    oldDocumentModel.UID          = AllServices.DocumentService.GetUID(strFileSaveVirtualPath);
                    oldDocumentModel.DocumentName = strNewFileName;
                    oldDocumentModel.DocumentPath = string.Format("{0}/{1}", imageUploadConfig.SavePath, strNewFileName);
                    oldDocumentModel.Editor       = strUserName;
                    oldDocumentModel.EditTime     = DateTime.Now;
                    oldDocumentModel.State        = Convert.ToInt32(ItemState.Disable);

                    #endregion
                    return(AllServices.DocumentService.Update(oldDocumentModel));
                }
                else
                {
                    return(CommonResult.Instance("处理旧图片失败"));
                }
            }
            catch (Exception ex)
            {
                return(CommonResult.Instance(ex.ToString()));
            }
        }
示例#10
0
        /// <summary>
        /// 新增项目
        /// </summary>
        /// <param name="projectModel"></param>
        /// <returns></returns>
        public CommonResult Add(Models.Project projectModel)
        {
            if (IsRepeatProjectName(projectModel.ProjectNo, projectModel.ProjectName))
            {
                return(CommonResult.Instance("已存在此任务名,请换一个再试"));
            }

            projectModel.ProjectNo   = db.Database.SqlQuery <string>("select ([dbo].[GetNextTN]('Project')) ").FirstOrDefault();
            projectModel.ProjectName = projectModel.ProjectName;
            projectModel.Creater     = projectModel.Creater;
            projectModel.Editor      = projectModel.Editor;
            projectModel.CreateTime  = projectModel.CreateTime;
            projectModel.EditTime    = projectModel.EditTime;
            projectModel.Remark      = projectModel.Remark;
            projectModel.State       = Convert.ToInt32(ItemState.Enable);

            db.Project.Add(projectModel);
            if (db.SaveChanges() < 0)
            {
                return(CommonResult.Instance(0, "新建失败", projectModel.ProjectName));
            }
            return(CommonResult.Instance());
            //AllServices.ActionLogService.AddLog("新增文件",folderModel.ToJson(),Enums.ActionCategory.Add);
        }
示例#11
0
        /// <summary>
        /// 操作结果(返回json字符串)
        /// </summary>
        /// <returns></returns>
        public static string ToJsonStr(int code, string errMsg, string data)
        {
            var instance = new CommonResult(code, errMsg, data);

            return(Utility.ObjExtension.ToJson(instance));
        }
示例#12
0
        /// <summary>
        /// 操作失败(返回json字符串)
        /// </summary>
        /// <returns></returns>
        public static string ToJsonStr(string errMsg)
        {
            var instance = new CommonResult(errMsg);

            return(Utility.ObjExtension.ToJson(instance));
        }
示例#13
0
        /// <summary>
        /// 上传图片处理
        /// </summary>
        /// <param name="file"></param>
        /// <param name="imageUploadConfig">图片上传配置基类或其派生类</param>
        /// <returns></returns>
        public CommonResult ImageHandler(HttpPostedFileBase postFile, ImageUploadBaseConfig imageUploadConfig, string strUserName, DataModel dataModel, ActionType actionType)
        {
            try
            {
                #region 验证并保存原图
                //验证目标目录是否存在
                if (!Directory.Exists(PathHelper.GetMapPath(imageUploadConfig.SavePath)))
                {
                    return(CommonResult.Instance("找不到指定的上传文件目录"));
                }
                //获取文件扩展名
                string fileExtension = Path.GetExtension(postFile.FileName);
                //检查文件是否为可上传的文件格式
                bool isAllowExtension = imageUploadConfig.AllowExtension.ToStr().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Contains(fileExtension);
                if (!isAllowExtension)
                {
                    return(CommonResult.Instance("不允许上传的图片类型"));
                }
                //上传文件大小限制
                if (postFile.ContentLength > imageUploadConfig.MaxSize * 1024)
                {
                    return(CommonResult.Instance(string.Format("上传的图片不能大于{0}K", imageUploadConfig.MaxSize)));
                }
                //设置图片名称
                var fileName = dataModel["DefinedName"].ToStr();                //postFile.FileName;
                //取得扩展名
                string strExt = dataModel["Ext"].ToStr();
                //取得图片名称(去扩展名)
                string strFileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                //设置图片存放目录(虚拟路径)
                string strFileSaveVirtualPath = string.Format("{0}/{1}{2}", imageUploadConfig.SavePath, fileName, strExt);
                //设置图片存放目录(物理路径)
                string strFileSavePath = PathHelper.GetMapPath(strFileSaveVirtualPath);

                //是否处理相同路径图片
                this.OldImageHandler(strFileSaveVirtualPath, imageUploadConfig, strUserName);
                //if(FileHelper.Exists(strFileSavePath))
                //{
                //	#region 处理同路径旧图片
                //	//File.Delete(strFileSavePath);
                //	string strNewFileName = FileHelper.ResetFileMinName(strFileSavePath);
                //	if(!FileHelper.RenameFile(strFileSavePath,strNewFileName))//重命名旧文件
                //	{
                //		return CommonResult.Instance("旧文件重命名失败");
                //	}
                //	//更新旧文件的信息
                //	Document oldDocumentModel = new Document();
                //	oldDocumentModel.UID = AllServices.DocumentService.GetUID(strFileSaveVirtualPath);
                //	oldDocumentModel.DocumentName = strNewFileName;
                //	oldDocumentModel.DocumentPath = string.Format("{0}/{1}",imageUploadConfig.SavePath,strNewFileName);
                //	oldDocumentModel.Editor = stringUserName;
                //	oldDocumentModel.EditTime = DateTime.Now;
                //	oldDocumentModel.State = Convert.ToInt32(ItemState.Disable);
                //	AllServices.DocumentService.Update(oldDocumentModel);
                //	#endregion

                //}
                //保存图片
                postFile.SaveAs(strFileSavePath);
                #endregion

                #region 处理图片
                string mode    = imageUploadConfig.Mode;
                string strJson = string.Empty;

                if (!mode.Contains("None"))
                {
                    //处理后的图片保存目录
                    string imgHandlerDir = imageUploadConfig.SavePath + "/" + "m";
                    if (!Directory.Exists(PathHelper.GetMapPath(imgHandlerDir)))
                    {
                        Directory.CreateDirectory(PathHelper.GetMapPath(imgHandlerDir));
                    }
                    //目标图片名称
                    string fileNameByTarget = Path.GetFileName(strFileSavePath);
                    //目标图片的虚拟路径
                    string fileSaveVirtualPathByTarget = string.Format("{0}/{1}", imgHandlerDir, fileNameByTarget);
                    //目标图片的物理路径
                    string fileSavePathByTarget = PathHelper.GetMapPath(fileSaveVirtualPathByTarget);
                    //处理图片
                    ImageHelper.CompressType cType = ImageHelper.CompressType.Zoom;
                    switch (mode.ToLower())
                    {
                    case "cut":
                        cType = ImageHelper.CompressType.WidthAndHeightCut;
                        break;

                    case "zoom":
                        cType = ImageHelper.CompressType.Zoom;
                        break;

                    case "stretch":
                        cType = ImageHelper.CompressType.WidthAndHeight;
                        break;
                    }
                    ImageHelper.Thumb(strFileSavePath, fileSavePathByTarget, imageUploadConfig.Width, imageUploadConfig.Height, cType, imageUploadConfig.Quality);
                    //添加上传文件记录(处理后的图片)
                    AllServices.DocumentService.Add(new Models.Document()
                    {
                        //DocumentName = fileNameByTarget,
                        ////File_Extension = fileExtension.ToLower(),
                        //DocumentPath = fileSaveVirtualPathByTarget,
                        //PictureSize = new System.IO.FileInfo(fileSavePathByTarget).Length.ToStr(),
                        ////IsSystemCreate = true
                    });
                    //删除原图
                    if (imageUploadConfig.DelOriginalPhoto)
                    {
                        File.Delete(strFileSavePath);
                    }
                    else
                    {
                        //添加上传文件记录(原图)
                        AllServices.DocumentService.Add(new Models.Document()
                        {
                            //DocumentName = fileName,
                            //File_Extension = fileExtension.ToLower(),
                            //DocumentPath = strFileSaveVirtualPath,
                            //PictureSize = postFile.ContentLength.ToStr(),
                            //IsSystemCreate = false
                        });
                    }
                    strFileSaveVirtualPath = fileSaveVirtualPathByTarget;
                }
                #endregion

                //释放图片资源
                postFile.InputStream.Close();
                postFile.InputStream.Dispose();

                CommonResult commonResult = this.AddImageHandler(0, fileName, strFileSaveVirtualPath, dataModel["Ext"].ToStr(), dataModel["Size"].ToStr(), dataModel["DpiID"].ToInt32(), actionType, strUserName);
                return(commonResult);
            }
            catch (Exception ex)
            {
                return(CommonResult.Instance(ex.ToString()));
            }
        }
示例#14
0
        /// <summary>
        /// 上传图片合并处理
        /// </summary>
        /// <param name="file"></param>
        /// <param name="imageUploadConfig">图片上传配置基类或其派生类</param>
        /// <returns></returns>
        public CommonResult ChunkImageHandler(ImageUploadBaseConfig imageUploadConfig, string strUserName, DataModel dataModel, ActionType actionType)
        {
            try
            {
                //验证目标目录是否存在
                if (!Directory.Exists(PathHelper.GetMapPath(imageUploadConfig.SavePath)))
                {
                    return(CommonResult.Instance("找不到指定的上传文件目录"));
                }
                string strFileName = dataModel["DefinedName"].ToStr();
                string strExt      = dataModel["Ext"].ToStr();
                //设置图片存放目录(虚拟路径)
                string strFileSaveVirtualPath = string.Format("{0}/{1}{2}", imageUploadConfig.SavePath, strFileName, strExt);
                //设置图片存放目录(物理路径)
                string strFileSavePath = PathHelper.GetMapPath(strFileSaveVirtualPath);

                //处理相同路径图片
                this.OldImageHandler(strFileSaveVirtualPath, imageUploadConfig, strUserName);

                #region 合并文件
                string strGuid = dataModel["Guid"].ToStr();
                //设置图片存放分片目录(虚拟路径)
                string strFileSaveChunkPath = string.Format("{0}/{1}", imageUploadConfig.SavePath, "chunk\\" + strGuid + "\\");
                string strSourcePath        = PathHelper.GetMapPath(strFileSaveChunkPath); //临时文件夹
                string strTargetPath        = strFileSavePath;                             //合并后的文件

                DirectoryInfo dicInfo = new DirectoryInfo(strSourcePath);
                if (Directory.Exists(Path.GetDirectoryName(strSourcePath)))
                {
                    FileInfo[] files = dicInfo.GetFiles();
                    foreach (FileInfo file in files.OrderBy(f => int.Parse(f.Name)))
                    {
                        FileStream   addFile   = new FileStream(strTargetPath, FileMode.Append, FileAccess.Write);
                        BinaryWriter AddWriter = new BinaryWriter(addFile);

                        //获得上传的分片数据流
                        Stream       stream     = file.Open(FileMode.Open);
                        BinaryReader TempReader = new BinaryReader(stream);
                        //将上传的分片追加到临时文件末尾
                        AddWriter.Write(TempReader.ReadBytes((int)stream.Length));
                        //关闭BinaryReader文件阅读器
                        TempReader.Close();
                        stream.Close();
                        AddWriter.Close();
                        addFile.Close();

                        TempReader.Dispose();
                        stream.Dispose();
                        AddWriter.Dispose();
                        addFile.Dispose();
                    }
                    FileHelper.DelectDir(strSourcePath);
                    CommonResult commonResult = this.AddImageHandler(0, strFileName, strFileSaveVirtualPath, dataModel["Ext"].ToStr(), dataModel["Size"].ToStr(), dataModel["DpiID"].ToInt32(), actionType, strUserName);
                    return(CommonResult.Instance());
                }
                return(CommonResult.Instance());
            }
            catch (Exception ex)
            {
                return(CommonResult.Instance(ex.ToString()));
            }
            #endregion
        }
示例#15
0
        /// <summary>
        /// 图片下载处理(单个图片直接返回,多个图片打包成zip,成功返回压缩包地址)
        /// </summary>
        /// <param name="postFile"></param>
        /// <param name="imageUploadConfig"></param>
        /// <param name="stringUserName"></param>
        /// <param name="dataModel"></param>
        /// <param name="actionType"></param>
        /// <returns></returns>
        public CommonResult ImageHandler(ImageUploadBaseConfig imageUploadConfig, List <DataModel> listDataModel)
        {
            //验证目标目录是否存在
            if (!Directory.Exists(PathHelper.GetMapPath(imageUploadConfig.SavePath)))
            {
                return(CommonResult.Instance("找不到指定的上传文件目录"));
            }
            if (!Directory.Exists(PathHelper.GetMapPath(imageUploadConfig.SaveCompressPath)))
            {
                return(CommonResult.Instance("找不到指定的存放压缩文件目录"));
            }
            if (!Directory.Exists(PathHelper.GetMapPath(imageUploadConfig.SaveTempPath)))
            {
                return(CommonResult.Instance("找不到指定的存放打包文件临时目录"));
            }


            if (listDataModel.Count() == 1)           //单个文件下载,不需要打包
            {
                DataModel dataModel = listDataModel[0];
                string    strUrl    = dataModel["url"].ToStr();
                if (string.IsNullOrEmpty(strUrl))               //设置图片存放目录(物理路径)
                {
                    return(CommonResult.Instance("下载链接为空,请检查"));
                }
                string strSourceFileName = PathHelper.GetMapPath(strUrl);
                return(CommonResult.Instance(2, null, strSourceFileName));
            }
            //要压缩的文件夹,把需要打包的文件存放在此文件夹
            string strPath = PathHelper.GetMapPath(imageUploadConfig.SaveTempPath);

            FileHelper.DelectDir(strPath);
            try
            {
                //压缩后的文件存放路径
                string strDestFile     = PathHelper.GetMapPath(imageUploadConfig.SaveCompressPath);
                string strName         = "icon.zip";
                string strLastDestFile = string.Format("{0}/{1}", strDestFile, FileHelper.ResetFileName(strName));

                foreach (DataModel dataModel in listDataModel)
                {
                    string strUrl            = dataModel["url"].ToStr();
                    string strSourceFileName = PathHelper.GetMapPath(strUrl);
                    string strFileName       = Path.GetFileName(strSourceFileName);
                    string strNewPath        = string.Format("{0}/{1}", strPath, strFileName);
                    System.IO.File.Copy(strSourceFileName, strNewPath, true);                  //拷贝文件到压缩文件夹  //true为覆盖同名文件
                }
                ZipUtil.CreateZipFile(strPath, strLastDestFile);
                //单个文件下载,不需要打包
                //foreach(string fileName in list)
                //{
                //	string sourceFileName = System.IO.Path.Combine(filePath,fileName) + ".xls";
                //	string destFileName = System.IO.Path.Combine(dPath,fileName) + ".xls";
                //	System.IO.File.Copy(sourceFileName,destFileName,true);
                //}
                //参数为文件存放路径,下载的文件格式,文件名字
                //return File(destFile,"application/image",System.IO.Path.GetFileName(destFile));

                return(CommonResult.Instance(1, null, strLastDestFile));
            }
            catch (Exception ex)
            {
                FileHelper.DelectDir(strPath);
                return(CommonResult.Instance(ex.ToString()));
            }
        }