Пример #1
0
        // GET: User
        public ActionResult Add()
        {
            int           id     = CommonHelper.GetPostValue("id").ToInt(-1);
            UserAddEntity entity = new UserAddEntity();

            entity.RoleList = _bgRoleService.List();
            long positionId   = LoginHelper.PositionId;
            long departmentId = LoginHelper.DepartmentId;

            entity.PositionList         = _bgPositionService.GetlistByLvlAndDepartmentId(positionId, departmentId);
            entity.ShortStaticFieldList = _bgShortStaticFieldService.GetListByType(0);
            entity.CardFieldList        = _bgShortStaticFieldService.GetListByType(1);
            if (id > 0)
            {
                entity.BgUser = _bgUserService.GetUserById(id);
                if (entity.BgUser == null)
                {
                    string msg = HttpUtility.HtmlEncode("未获得该用户信息");
                    string url = DomainUrlHelper.EmployeeBgPath + "/menu/error?ErrorCode=E000&ErrorMsg=" + msg;
                    return(Redirect(url));
                }
            }
            ViewBag.add = id < 0;
            return(View(entity));
        }
Пример #2
0
        public JsonApproveEmployPassEntity ApproveEmployPass()
        {
            JsonApproveEmployPassEntity result = new JsonApproveEmployPassEntity();
            long id     = CommonHelper.GetPostValue("id").ToLong(-1);
            int  status = CommonHelper.GetPostValue("status").ToInt(-1);

            if (id < 0 || status < 0)
            {
                result.ErrorCode    = "E001";
                result.ErrorMessage = "获得信息不全!";
                return(result);
            }

            T_BG_User user = _bgUserService.GetUserById(id);

            if (user == null)
            {
                result.ErrorCode    = "E002";
                result.ErrorMessage = "该角色已经被删除!";
                return(result);
            }
            if (user.Status != 0)
            {
                result.ErrorCode    = "E004";
                result.ErrorMessage = "该角色已经修改,请刷新页面!";
                return(result);
            }

            user.Status      = status;
            user.ApproveTime = DateTime.Now;
            user.ApproveName = LoginHelper.UserName;
            bool success = _bgUserService.Update(user);

            if (success)
            {
                result.ErrorCode    = "E000";
                result.ErrorMessage = "成功";
            }
            else
            {
                result.ErrorCode    = "E003";
                result.ErrorMessage = "更新失败!";
            }
            return(result);
        }
Пример #3
0
        public JsonResult Pass()
        {
            JsonUserPassEntity json = new JsonUserPassEntity();
            long id    = CommonHelper.GetPostValue("id").ToLong(-1L);
            int  state = CommonHelper.GetPostValue("state").ToInt(0);

            if (id < 0)
            {
                json.ErrorCode    = "E001";
                json.ErrorMessage = "参数不全!";
                return(Json(json));
            }

            T_BG_User user = _bgUserService.GetUserById(id);

            if (user == null)
            {
                json.ErrorCode    = "E002";
                json.ErrorMessage = "未获得该对象,请刷新页面!";
                return(Json(json));
            }
            user.Status      = state;
            user.ApproveName = LoginHelper.UserName;
            user.ApproveTime = DateTime.Now;
            bool result = _bgUserService.Update(user);

            if (result)
            {
                json.ErrorCode    = "E000";
                json.ErrorMessage = "成功!";
            }
            else
            {
                json.ErrorCode    = "E002";
                json.ErrorMessage = "失败,请刷新页面!";
            }
            return(Json(json));
        }
Пример #4
0
        //[HttpPost]
        public JsonResult Post(string id)
        {
            string userid   = CommonHelper.GetPostValue("key");
            string filename = CommonHelper.GetPostValue("fn");
            string type     = CommonHelper.GetPostValue("type").ToString("PublicFile");

            OrignalTypeEnum saveType = type.Equals("GuideFile") || type.Equals("3")
                ? OrignalTypeEnum.GuideFile
                : type.Equals("ActiveFile") || type.Equals("1")
                    ? OrignalTypeEnum.ActiveFile
                    : OrignalTypeEnum.PublicFile;

            //
            //这个方法暂时这样,需要优化
            //
            userid = LoginHelper.UserId.ToString();
            long lUserId = userid.ToLong(-1);

            //string.IsNullOrEmpty(sign) ||
            if (string.IsNullOrEmpty(userid) || lUserId <= 0)
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10000", ErrorMessage = "非法请求"
                }));
            }
            T_BG_User bgUser = _bgUserService.GetUserById(userid.ToLong(-1));

            if (bgUser == null)
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10000", ErrorMessage = "请重新登录"
                }));
            }
            if (HttpContext.Request.Files.Count > 0)
            {
                try
                {
                    HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0];
                    if (file.ContentLength <= 0)
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10000", ErrorMessage = "上传的文档为空!"
                        }));
                    }

                    FileExtension[] fileExs = new FileExtension[] { FileExtension.DOC, FileExtension.DOCX, FileExtension.PDF };
                    string          fileExt = FileValidation.FileExtension(file, fileExs);
                    if (string.IsNullOrEmpty(fileExt))
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10000", ErrorMessage = "请上传WORD、PDF格式的文档!"
                        }));
                    }

                    string originFileName = Regex.Replace(file.FileName, "." + fileExt, "." + fileExt, RegexOptions.IgnoreCase);
                    string savename       = Guid.NewGuid().ToString("N");
                    if (!string.IsNullOrEmpty(filename))
                    {
                        savename = filename.Replace(string.Format("{0}_", LoginHelper.UserId), "");
                    }
                    string ofile       = originFileName;
                    string newFileName = OriginalSaveHelper.CreateNewSaveFileName(userid, savename, fileExt);
                    string savePath    = OriginalSaveHelper.GetSavePath(newFileName, fileExt, type);
                    string fn          = newFileName.Replace(string.Format(".{0}", fileExt), "");
                    if (!Directory.Exists(savePath))
                    {
                        Directory.CreateDirectory(savePath);
                    }
                    string strMs = string.Empty;
                    //string exception = "服务端异常";
                    string newFilePath = string.Format(@"{0}\{1}", savePath, newFileName);
                    file.SaveAs(newFilePath);
                    int iPageNum = 0;
                    fileExt = fileExt.ToLower();
                    if (fileExt == "pdf" || fileExt.EndsWith("pdf"))
                    {
                        iPageNum = PdfSaveHelper.GetPdfFilePages(newFilePath, out strMs);
                    }
                    //如果iPageNum 不更新或不上传
                    if (iPageNum < 0)
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10000", ErrorMessage = "服务器不能解析上传的pdf,请选择其他文件重新上传!"
                        }));
                    }

                    T_BG_UpFiles bgUpFiles = new T_BG_UpFiles {
                        filename = fn, filehash = FileHelper.GetFileHash(newFilePath), userid = lUserId, fileoriginname = originFileName, filepath = newFilePath, ext = fileExt, addtime = DateTime.Now, type = saveType.ToInt(0)
                    };

                    string fileorigin = originFileName.ReplaceSqlTag();
                    long   cnt        = _bgUpFilesService.GetListByUserIdAndFileNameAndExt(originFileName, lUserId, fileExt, saveType.ToInt(0));
                    long   reslt      = _bgUpFilesService.Add(bgUpFiles);
                    if (reslt > 0)
                    {
                        string oname  = fileorigin.ToLower().Replace("." + bgUpFiles.ext.ToLower(), "");
                        string attach = cnt <= 0
                            ? string.Format("{0}.{1}", oname, bgUpFiles.ext)
                            : string.Format("{0}({1}).{2}", oname, cnt, bgUpFiles.ext);

                        return(Json(new FileUploadEntity {
                            ErrorCode = "00000", ErrorMessage = fn, Attach = attach, FilePath = bgUpFiles.filepath, FileType = fileExt
                        }));
                    }
                    else
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10003", ErrorMessage = "服务端保存文件失败"
                        }));
                    }
                }
                catch (Exception)
                {
                    return(Json(new FileUploadEntity {
                        ErrorCode = "10000", ErrorMessage = "服务端异常"
                    }));
                }
            }
            else
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10002", ErrorMessage = "请选择文件"
                }));
            }
        }
        // GET: EmailUppload
        public JsonResult SendFile()
        {
            string userid = CommonHelper.GetPostValue("key");
            string type   = "EmailFile"; //CommonHelper.GetPostValue("type").ToString("PublicFile");

            OrignalTypeEnum saveType = OrignalTypeEnum.EmailFile;

            userid = LoginHelper.UserId.ToString();
            long lUserId = userid.ToLong(-1);

            if (string.IsNullOrEmpty(userid) || lUserId <= 0)
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10000", ErrorMessage = "非法请求!"
                }));
            }
            T_BG_User bgUser = _bgUserService.GetUserById(userid.ToLong(-1));

            if (bgUser == null)
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10000", ErrorMessage = "请重新登录!"
                }));
            }

            if (HttpContext.Request.Files.Count > 0)
            {
                try
                {
                    HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0];
                    if (file.ContentLength <= 0)
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10000", ErrorMessage = "上传的附件为空!"
                        }));
                    }
                    //FileExtension[] fileExs = new FileExtension[] { FileExtension.DOC, FileExtension.DOCX, FileExtension.PDF };
                    //string fileExt = FileValidation.FileExtension(file, fileExs);
                    //if (string.IsNullOrEmpty(fileExt))
                    //{
                    //    return Json(new FileUploadEntity { ErrorCode = "10000", ErrorMessage = "请上传WORD、PDF格式的文档!" });
                    //}

                    string fileExt        = Path.GetExtension(file.FileName);
                    string originFileName = Regex.Replace(file.FileName, "." + fileExt, "." + fileExt, RegexOptions.IgnoreCase);
                    string savePath       = OriginalSaveHelper.GetEmailSavePath(fileExt.Replace(".", ""), type);
                    if (string.IsNullOrEmpty(savePath))
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10000", ErrorMessage = "上传的路径获取失败!"
                        }));
                    }
                    if (!Directory.Exists(savePath))
                    {
                        Directory.CreateDirectory(savePath);
                    }
                    string newFilePath = string.Format(@"{0}\{1}", savePath, file.FileName);
                    file.SaveAs(newFilePath);

                    T_BG_UpFiles bgUpFiles = new T_BG_UpFiles {
                        filename = file.FileName, filehash = FileHelper.GetFileHash(newFilePath), userid = lUserId, fileoriginname = originFileName, filepath = newFilePath, ext = fileExt, addtime = DateTime.Now, type = saveType.ToInt(0)
                    };
                    //long cnt = _bgUpFilesService.GetListByUserIdAndFileNameAndExt(originFileName, lUserId, fileExt, saveType.ToInt(0));
                    long reslt = _bgUpFilesService.Add(bgUpFiles);
                    if (reslt > 0)
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "00000", ErrorMessage = "上传成功", Attach = file.FileName, FilePath = bgUpFiles.filepath, FileType = fileExt
                        }));
                    }
                    else
                    {
                        return(Json(new FileUploadEntity {
                            ErrorCode = "10003", ErrorMessage = "服务端保存文件失败"
                        }));
                    }
                }
                catch (Exception)
                {
                    return(Json(new FileUploadEntity {
                        ErrorCode = "10000", ErrorMessage = "服务端异常"
                    }));
                }
            }
            else
            {
                return(Json(new FileUploadEntity {
                    ErrorCode = "10002", ErrorMessage = "请选择附件!"
                }));
            }
        }