Exemple #1
0
        public static void WriteLog(int user_id, string info, string ip, string target, int type, string device, LythenContext db)
        {
            Sys_Log log = new Sys_Log
            {
                log_content = info,
                log_device  = device,
                log_ip      = ip,
                log_target  = target,
                log_time    = DateTime.Now,
                log_type    = type,
                log_user_id = user_id
            };

            db.Sys_Log.Add(log);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection <DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                ErrorUnit.WriteErrorLog(errors.ToString(), "WriteLog");
            }
            catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), "WriteLog"); }
        }
Exemple #2
0
        public JsonResult DeleteContent(int id)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            Reimbursement_Content content = db.Reimbursement_Content.Find(id);

            if (content == null)
            {
                json.msg_code = "nodate";
                json.msg_text = "报销内容不存在或被删除。";
                goto next;
            }
            Reimbursement bill = db.Reimbursement.Find(content.c_reimbursement_code);

            if (bill != null)
            {
                int user = Common.PageValidate.FilterParam(User.Identity.Name);
                if (user != bill.r_add_user_id)
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "没有权限操作他人申请的报销单。";
                    goto next;
                }
                if (bill.r_bill_state == 1)
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "已批复同意的报销单不允许删除。";
                    goto next;
                }
            }
            var details = db.Reimbursement_Detail.Where(x => x.detail_content_id == content.content_id);

            foreach (var detail in details)
            {
                db.Reimbursement_Detail.Remove(detail);
            }
            db.Reimbursement_Content.Remove(content);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().Name);
                json.msg_code = "error";
                json.msg_text = "报销单删除失败。";
                goto next;
            }
            json.state    = 1;
            json.msg_code = "success";
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            if (ex != null)
            {
                Trace.TraceError(ex.ToString());
                ErrorUnit.WriteErrorLog(ex.ToString(), e.GetType().ToString());
            }
        }
Exemple #4
0
        public JsonResult DeleteAttachment(int id)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            Reimbursement_Attachment atta = db.Reimbursement_Attachment.Find(id);

            if (atta == null)
            {
                json.msg_code = "nodate";
                json.msg_text = "附件不存在或被删除。";
                goto next;
            }
            Reimbursement bill = db.Reimbursement.Find(atta.atta_reimbursement_code);

            if (bill != null)
            {
                int user = Common.PageValidate.FilterParam(User.Identity.Name);
                if (user != bill.r_add_user_id && !RoleCheck.CheckHasAuthority(user, db, "系统管理"))
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "没有权限操作他人申请的报销单。";
                    goto next;
                }
                if (bill.r_bill_state == 1)
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "已批复同意的报销单不允许删除任何信息。";
                    goto next;
                }
            }
            db.Reimbursement_Attachment.Remove(atta);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().Name);
                json.msg_code = "error";
                json.msg_text = "附件删除失败。";
                goto next;
            }
            json.state    = 1;
            json.msg_code = "success";
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
 public override void OnException(ExceptionContext filterContext)
 {
     if (!filterContext.ExceptionHandled)
     {
         if (filterContext.Exception != null)
         {
             Trace.TraceError(filterContext.Exception.ToString());
             StringBuilder sb = new StringBuilder();
             foreach (var item in filterContext.RouteData.Values)
             {
                 sb.Append(item.Key).Append(": ").Append(item.Value).Append("\r\n");
             }
             ErrorUnit.WriteErrorLog(filterContext.Exception.ToString(), sb.ToString());
         }
         filterContext.ExceptionHandled = true;
     }
 }
Exemple #6
0
        public ActionResult Edit([Bind(Include = "id,code,name,expireDate,source,amount,balance,info,state")] FundsModel funds)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "添加经费", "经费管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }
            SetSelect();
            if (ModelState.IsValid)
            {
                Funds model = db.Funds.Find(funds.id);
                if (funds == null)
                {
                    ViewBag.msg = "没有找到该经费。";
                    return(View(funds));
                }
                if (user != model.f_manager && !RoleCheck.CheckHasAuthority(user, db, "经费管理"))
                {
                    ViewBag.msg = "您不是该经费的管理员,没有更改权限。";
                    return(View(funds));
                }
                if (model.f_name != funds.name)
                {
                    if (db.Funds.Where(x => x.f_name == funds.name && x.f_id != funds.id).Count() > 0)
                    {
                        ViewBag.msg = "该名称已被使用";
                        return(View(funds));
                    }
                }
                if (model.f_code != funds.code)
                {
                    if (db.Funds.Where(x => x.f_code == funds.code && x.f_id != funds.id).Count() > 0)
                    {
                        ViewBag.msg = "该代码已被使用";
                        return(View(funds));
                    }
                }
                if (funds.amount == 0)
                {
                    ViewBag.msg = "请输入经费总额。";
                    return(View(funds));
                }
                if (funds.balance == null || funds.balance == 0)
                {
                    //自动设置余额
                    decimal usedfunds = (from fs in db.Funds
                                         join bill in db.Reimbursement
                                         on fs.f_id equals bill.r_funds_id
                                         join u in db.User_Info
                                         on fs.f_manager equals u.user_id into T1
                                         from t1 in T1.DefaultIfEmpty()
                                         where fs.f_id == funds.id && bill.r_add_user_id == user && bill.r_bill_state == 1
                                         select bill.r_fact_amount).DefaultIfEmpty(0).Sum();
                    if (usedfunds > 0)
                    {
                        funds.balance = funds.amount - usedfunds;
                    }
                    if (funds.balance < 0)
                    {
                        ViewBag.msg = "出错:当前设置的经费总额小于已使用的经费总额。";
                        return(View(funds));
                    }
                }
                funds.toDBModel(model);
                db.Entry(model).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                    SysLog.WriteLog(user, string.Format("经费修改[{0}]", model.f_code), IpHelper.GetIP(), model.f_id.ToString(), 6, "", db);
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder errors = new StringBuilder();
                    IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                    foreach (DbEntityValidationResult result in validationResult)
                    {
                        ICollection <DbValidationError> validationError = result.ValidationErrors;
                        foreach (DbValidationError err in validationError)
                        {
                            errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                        }
                    }
                    ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name);
                    ViewBag.msg = " 经费信息更新失败。";
                    return(View(funds));
                }
                ViewBag.msg = "经费信息修改成功。";
            }
            return(View(funds));
        }
        public JsonResult Delete(int?id)
        {
            BaseJsonData json = new BaseJsonData();
            int          uid  = PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(uid, db, "用户管理"))
            {
                json.state    = 0;
                json.msg_text = "没有权限。";
                goto next;
            }
            if (id == 1)
            {
                goto next;
            }
            if (!User.Identity.IsAuthenticated)
            {
                goto next;
            }
            if (id == null)
            {
                goto next;
            }
            if (id == 1)
            {
                json.state    = 1;
                json.msg_text = "该帐号不允许删除。";
                goto next;
            }
            User_Info user_Info = db.User_Info.Find(id);

            if (user_Info == null)
            {
                json.state    = 1;
                json.msg_text = "所选用户不存在或已被删除。";
                goto next;
            }
            User_Extend extend = db.User_Extend.Find(id);

            db.User_Info.Remove(user_Info);
            if (extend != null)
            {
                db.User_Extend.Remove(extend);
            }
            try
            {
                db.SaveChanges();
                json.state    = 1;
                json.msg_code = "success";
                json.msg_text = "删除成功。";
                SysLog.WriteLog(uid, string.Format("删除用户[{0}]信息", Common.DEncrypt.AESEncrypt.Decrypt(user_Info.real_name)), IpHelper.GetIP(), id.ToString(), 2, "", db);
            }
            catch (Exception ex)
            {
                ErrorUnit.WriteErrorLog(ex.ToString(), this.GetType().Name);
                json.state    = 1;
                json.msg_text = "删除可能没有成功,请刷新页面查看。";
            }
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit([Bind(Include = "id,name,realName,certificateType,certificateNo,mobile,email,password,password2,state,gender,postId,officePhone,picture,deptId,deptChild,roleId")] UserEditModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            int user = PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "用户管理") && user != model.id)
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限!" }));
            }
            setSelect();
            if (ModelState.IsValid)
            {
                if (model.deptChild != null && model.deptId != null)
                {
                    List <SelectOption> options = DropDownList.getDepartment((int)model.deptId);
                    ViewBag.DeptChild = DropDownList.SetDropDownList(options);
                }
                User_Info info = db.User_Info.Find(model.id);
                info.ToDecrypt();
                if (info == null)
                {
                    ViewBag.msg = "该用户可能已被删除,无法更改。";
                    goto next;
                }
                model.toUserInfoDB(info);
                if (db.User_Info.Where(x => x.user_name == info.user_name && x.user_id != info.user_id).Count() > 0)
                {
                    ViewBag.msg = "该用户名已注册。";
                    goto next;
                }
                if (!string.IsNullOrEmpty(model.password))
                {
                    if (model.password != model.password2)
                    {
                        ViewBag.msg = "两次输入密码不一致,请重新输入。";
                        goto next;
                    }
                    var salt = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper();
                    info.user_password = PasswordUnit.getPassword(model.password.ToUpper(), salt);
                    info.user_salt     = salt;
                }
                info.ToEncrypt();
                if (db.User_Info.Where(x => (x.user_certificate_type == info.user_certificate_type && x.user_certificate_no == info.user_certificate_no) && x.user_id != info.user_id).Count() > 0)
                {
                    ViewBag.msg = "该证件号已注册。";
                    goto next;
                }
                if (db.User_Info.Where(x => x.user_email == info.user_email && x.user_id != info.user_id).Count() > 0)
                {
                    ViewBag.msg = "该邮箱已注册。";
                    goto next;
                }
                if (db.User_Info.Where(x => x.user_mobile == info.user_mobile && x.user_id != info.user_id).Count() > 0)
                {
                    ViewBag.msg = "该手机号已注册。";
                    goto next;
                }
                db.Entry <User_Info>(info).State = EntityState.Modified;
                bool        edit   = true;
                User_Extend extend = db.User_Extend.Find(info.user_id);
                if (extend == null)
                {
                    edit           = false;
                    extend         = new User_Extend();
                    extend.user_id = info.user_id;
                }
                if (!string.IsNullOrEmpty(model.picture) && model.picture != extend.user_picture)
                {
                    string photoDir = ConfigurationManager.AppSettings["photoPath"];
                    if (!Directory.Exists(photoDir))
                    {
                        Directory.CreateDirectory(photoDir);
                    }
                    string photoTempDir   = ConfigurationManager.AppSettings["tempPhotoPath"];
                    string file_name      = string.Format("{0}{1}", photoDir, model.picture).Replace("_temp", "");
                    string temp_file_name = string.Format("{0}{1}", photoTempDir, model.picture);
                    if (System.IO.File.Exists(temp_file_name))
                    {
                        FileInfo fi = new FileInfo(temp_file_name);
                        fi.CopyTo(file_name, true);
                        model.picture = Path.GetFileName(file_name);
                    }
                    else
                    {
                        ViewBag.msg = "图片保存失败。";
                    }
                }
                model.toUserExtendDB(extend);
                extend.user_edit_time = DateTime.Now;
                extend.user_edit_user = PageValidate.FilterParam(User.Identity.Name);
                if (edit)
                {
                    db.Entry <User_Extend>(extend).State = EntityState.Modified;
                }
                else
                {
                    db.User_Extend.Add(extend);
                }
                edit = true;
                if (model.roleId != null)
                {
                    User_vs_Role uvr = db.User_vs_Role.Find(info.user_id);
                    if (uvr == null)
                    {
                        edit = false;
                        uvr  = new User_vs_Role();
                    }
                    uvr.uvr_user_id = info.user_id;
                    uvr.uvr_role_id = (int)model.roleId;
                    if (edit)
                    {
                        db.Entry <User_vs_Role>(uvr).State = EntityState.Modified;
                    }
                    else
                    {
                        db.User_vs_Role.Add(uvr);
                    }
                }
                try
                {
                    db.SaveChanges();
                    ViewBag.msg = " 更新成功。";
                    SysLog.WriteLog(user, string.Format("修改用户[{0}]信息", model.realName), IpHelper.GetIP(), info.user_id.ToString(), 2, "", db);
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder errors = new StringBuilder();
                    IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                    foreach (DbEntityValidationResult result in validationResult)
                    {
                        ICollection <DbValidationError> validationError = result.ValidationErrors;
                        foreach (DbValidationError err in validationError)
                        {
                            errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                        }
                    }
                    ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name);
                    ViewBag.msg = " 更新失败。";
                }
            }
next:
            return(View(model));
        }
        public ActionResult Create([Bind(Include = "name,realName,certificateType,certificateNo,mobile,email,password,password2,state,gender,postId,officePhone,picture,deptId,deptChild,roleId")] UserEditModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            int user = PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "用户管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }
            setSelect();
            if (ModelState.IsValid)
            {
                User_Info info = new User_Info();
                model.toUserInfoDB(info);
                if (db.User_Info.Where(x => x.user_name == info.user_name).Count() > 0)
                {
                    ViewBag.msg = "该用户名已注册。";
                    goto next;
                }
                var salt = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper();
                info.user_password = PasswordUnit.getPassword(model.password.ToUpper(), salt);
                info.user_salt     = salt;
                info.ToEncrypt();
                if (db.User_Info.Where(x => x.user_certificate_type == info.user_certificate_type && x.user_certificate_no == info.user_certificate_no).Count() > 0)
                {
                    ViewBag.msg = "该证件号已注册。";
                    goto next;
                }
                if (db.User_Info.Where(x => x.user_email == info.user_email).Count() > 0)
                {
                    ViewBag.msg = "该邮箱已注册。";
                    goto next;
                }
                if (db.User_Info.Where(x => x.user_mobile == info.user_mobile).Count() > 0)
                {
                    ViewBag.msg = "该手机号已注册。";
                    goto next;
                }
                if (model.password != model.password2)
                {
                    ViewBag.msg = "两次输入密码不一致,请重新输入。";
                    goto next;
                }

                db.User_Info.Add(info);
                try
                {
                    db.SaveChanges();
                }catch (Exception ex)
                {
                    ViewBag.msg = "信息录入失败,请重新录入。";
                    ErrorUnit.WriteErrorLog(ex.ToString(), this.GetType().Name);
                    goto next;
                }

                User_Extend extend = new User_Extend();
                model.toUserExtendDB(extend);
                extend.user_id       = info.user_id;
                extend.user_add_user = PageValidate.FilterParam(User.Identity.Name);
                extend.user_add_time = DateTime.Now;
                db.User_Extend.Add(extend);
                string photoDir = ConfigurationManager.AppSettings["photoPath"];
                if (!Directory.Exists(photoDir))
                {
                    Directory.CreateDirectory(photoDir);
                }
                string photoTempDir   = ConfigurationManager.AppSettings["tempPhotoPath"];
                string file_name      = string.Format("{0}{1}", photoDir, extend.user_picture).Replace("_temp", "");
                string temp_file_name = string.Format("{0}{1}", photoTempDir, extend.user_picture);
                if (System.IO.File.Exists(temp_file_name))
                {
                    FileInfo fi = new FileInfo(temp_file_name);
                    fi.CopyTo(file_name, true);
                }
                else
                {
                    ViewBag.msg = "图片保存失败。";
                }
                if (model.roleId != null)
                {
                    User_vs_Role uvr = new User_vs_Role();
                    uvr.uvr_user_id = info.user_id;
                    uvr.uvr_role_id = (int)model.roleId;
                    db.User_vs_Role.Add(uvr);
                }
                db.SaveChanges();
                SysLog.WriteLog(user, string.Format("添加用户[{0}]", model.realName), IpHelper.GetIP(), info.user_id.ToString(), 2, "", db);
                ViewBag.msg = " 用户创建成功。";
            }
            else
            {
                StringBuilder sbmsg = new StringBuilder();
                foreach (var value in ModelState.Values)
                {
                    if (value.Errors.Count() > 0)
                    {
                        foreach (var err in value.Errors)
                        {
                            sbmsg.Append(err.ErrorMessage);
                        }
                        ViewBag.msg = sbmsg.ToString();;
                    }
                }
            }
next:

            return(View(model));
        }
Exemple #10
0
        public JsonResult Create(ApplyListModel _sbill)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            SetSelect(0);
            if (ModelState.IsValid)
            {
                Reimbursement bill = new Reimbursement();
                bill.r_bill_amount      = _sbill.amount;
                bill.r_bill_state       = 0;
                bill.r_add_date         = DateTime.Now;
                bill.r_add_user_id      = user;
                bill.reimbursement_info = _sbill.info;
                var maxfa = db.Reimbursement.OrderByDescending(x => x.reimbursement_code).FirstOrDefault();
                //apply_number:年份+10001自增
                if (maxfa == null)
                {
                    bill.reimbursement_code = DateTime.Now.Year.ToString() + "10001";
                }
                else
                {
                    bill.reimbursement_code = DateTime.Now.Year.ToString() + (int.Parse(maxfa.reimbursement_code.Substring(4)) + 1);
                }
                db.Reimbursement.Add(bill);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                    json.msg_code = "error";
                    json.msg_text = "报销单提交失败。";
                    goto next;
                }

                StringBuilder sbErr = new StringBuilder();
                //添加报销内容
                foreach (ViewContentModel citem in _sbill.contents)
                {
                    Reimbursement_Content content = new Reimbursement_Content();
                    content.c_reimbursement_code = bill.reimbursement_code;
                    content.c_amount             = citem.amount;
                    content.c_dic_id             = citem.selectId;
                    db.Reimbursement_Content.Add(content);
                    try
                    {
                        //必需先提交更改,因为下面添加明细需要用到自动生成的ID。
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                    //添加明细
                    if (citem.details != null && citem.details.Count() > 0)
                    {
                        foreach (ViewDetailContent viewDetail in citem.details)
                        {
                            Reimbursement_Detail detail = new Reimbursement_Detail()
                            {
                                detail_amount     = viewDetail.amount,
                                detail_content_id = content.content_id,
                                detail_date       = DateTime.Parse(viewDetail.strDate + " 00:00"),
                                detail_info       = viewDetail.detailInfo
                            };
                            db.Reimbursement_Detail.Add(detail);
                        }
                    }
                    //添加附件
                    if (citem.attachments != null && citem.attachments.Count() > 0)
                    {
                        string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                        string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                        if (!Directory.Exists(attachment_path))
                        {
                            Directory.CreateDirectory(attachment_path);
                        }
                        string filePath, tempFile, saveFileName = "", storeFileName;
                        foreach (ViewAttachment item in citem.attachments)
                        {
                            try
                            {
                                saveFileName  = Path.GetFileName(item.fileName);
                                storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                tempFile      = attachment_temp_path + item.fileName;
                                filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                if (System.IO.File.Exists(filePath))
                                {
                                    System.IO.File.Delete(filePath);
                                }
                                System.IO.File.Move(tempFile, filePath);
                            }
                            catch (Exception e)
                            {
                                ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString());
                                sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n");
                                continue;
                            }
                            Reimbursement_Attachment attachment = new Reimbursement_Attachment
                            {
                                attachment_path         = storeFileName,
                                atta_detail_id          = content.content_id,
                                atta_reimbursement_code = bill.reimbursement_code
                            };
                            db.Reimbursement_Attachment.Add(attachment);
                        }
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }

                //添加其他附件
                if (_sbill.attachments != null && _sbill.attachments.Count() > 0)
                {
                    string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                    string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                    if (!Directory.Exists(attachment_path))
                    {
                        Directory.CreateDirectory(attachment_path);
                    }
                    string filePath, tempFile, saveFileName = "", storeFileName;
                    foreach (ViewAttachment item in _sbill.attachments)
                    {
                        try
                        {
                            saveFileName  = Path.GetFileName(item.fileName);
                            storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                            tempFile      = attachment_temp_path + item.fileName;
                            filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                            if (System.IO.File.Exists(filePath))
                            {
                                System.IO.File.Delete(filePath);
                            }
                            System.IO.File.Move(tempFile, filePath);
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString());
                            sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n");
                            continue;
                        }
                        Reimbursement_Attachment attachment = new Reimbursement_Attachment
                        {
                            attachment_path         = storeFileName,
                            atta_detail_id          = 0,
                            atta_reimbursement_code = bill.reimbursement_code
                        };
                        db.Reimbursement_Attachment.Add(attachment);
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }
                //添加批复人
                Process_Respond pr = new Process_Respond();
                pr.pr_reimbursement_code = bill.reimbursement_code;
                pr.pr_user_id            = _sbill.next;
                pr.pr_number             = 1;
                db.Process_Respond.Add(pr);
                try
                {
                    db.SaveChanges();
                    SysLog.WriteLog(user, string.Format("添加报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
                }
                catch (Exception e)
                {
                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                    Delete(bill.reimbursement_code);
                    json.msg_code = "error";
                    json.msg_text = "报销单提交失败。";
                    goto next;
                }
                json.state    = 1;
                json.msg_code = bill.reimbursement_code;
                json.msg_text = sbErr.ToString();
            }
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #11
0
        // GET: ApplyManager/Delete/5
        public JsonResult Delete(string number)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            if (number == null)
            {
                json.msg_code = "errorNumber";
                json.msg_text = "报销单号获取失败。";
                goto next;
            }
            //查询订单状态,如果已批复,不能撤销。如果没有,删除流程。
            Reimbursement bill = db.Reimbursement.Find(number);

            if (bill == null)
            {
                json.msg_code = "nodate";
                json.msg_text = "报销单不存在或被删除。";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            if (user != bill.r_add_user_id)
            {
                json.msg_code = "forbidden";
                json.msg_text = "没有权限操作他人申请的报销单。";
                goto next;
            }
            if (bill.r_bill_state == 1)
            {
                json.msg_code = "forbidden";
                json.msg_text = "已批复同意的报销单不允许删除。";
                goto next;
            }
            var cs = db.Reimbursement_Content.Where(x => x.c_reimbursement_code == bill.reimbursement_code);

            //删除报销内容
            if (cs.Count() > 0)
            {
                foreach (Reimbursement_Content citem in cs)
                {
                    //删除报销细节
                    db.Reimbursement_Detail.RemoveRange(db.Reimbursement_Detail.Where(x => x.detail_content_id == citem.content_id));
                    db.Reimbursement_Content.Remove(citem);
                }
            }
            //删除附件
            db.Reimbursement_Attachment.RemoveRange(db.Reimbursement_Attachment.Where(x => x.atta_reimbursement_code == bill.reimbursement_code));
            //删除批复
            db.Process_Respond.RemoveRange(db.Process_Respond.Where(x => x.pr_reimbursement_code == bill.reimbursement_code));
            //删除总单
            db.Reimbursement.Remove(bill);
            try
            {
                db.SaveChanges();
                SysLog.WriteLog(user, string.Format("删除报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
            }
            catch (DbEntityValidationException ex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection <DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name);
                json.msg_code = "error";
                json.msg_text = "报销单删除失败。";
                goto next;
            }
            json.state    = 1;
            json.msg_code = "success";
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #12
0
        public JsonResult Edit(ApplyListModel viewBill)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            SetSelect(0);
            if (ModelState.IsValid)
            {
                Reimbursement bill = db.Reimbursement.Find(viewBill.reimbursementCode);
                if (bill == null)
                {
                    json.msg_code = "error";
                    json.msg_text = "没有主申请单,更新失败。";
                    goto next;
                }
                if (viewBill.next == 0)
                {
                    json.msg_code = "error";
                    json.msg_text = "必需选择审核用户。";
                    goto next;
                }
                StringBuilder sbmsg = new StringBuilder();
                if (bill.r_bill_state == 1)
                {
                    json.msg_code = "error";
                    json.msg_text = "该报销单已经批复完成,不允许修改。";
                    goto next;
                }
                else
                {
                    bill.r_bill_amount      = viewBill.amount;
                    bill.r_fact_amount      = viewBill.amount;
                    bill.r_bill_state       = 0;
                    bill.r_add_date         = DateTime.Now;
                    bill.reimbursement_info = viewBill.info;
                    db.Entry(bill).State    = EntityState.Modified;
                    //录入报销事由
                    Reimbursement_Content content = null;

                    foreach (ViewContentModel citem in viewBill.contents)
                    {
                        if (citem.contentId != null && citem.contentId != 0)
                        {
                            content = db.Reimbursement_Content.Find(citem.contentId);
                            if (content != null)
                            {
                                content.c_amount        = citem.amount;
                                db.Entry(content).State = EntityState.Modified;
                            }
                        }
                        else
                        {
                            content = new Reimbursement_Content();
                            content.c_reimbursement_code = bill.reimbursement_code;
                            content.c_dic_id             = citem.selectId;
                            content.c_amount             = citem.amount;
                            db.Reimbursement_Content.Add(content);
                        }

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            sbmsg.Append("报销内容录入失败<br />");
                            continue;
                        }

                        //录入明细
                        if (citem.details != null && citem.details.Count() > 0)
                        {
                            Reimbursement_Detail detail = null;
                            foreach (ViewDetailContent item in citem.details)
                            {
                                if (item.detailId != null && item.detailId != 0)
                                {
                                    detail = db.Reimbursement_Detail.Find(item.detailId);
                                }
                                else
                                {
                                    detail = new Reimbursement_Detail();
                                    detail.detail_content_id = content.content_id;
                                }
                                detail.detail_amount     = item.amount;
                                detail.detail_date       = DateTime.Parse(item.strDate + " 00:00");
                                detail.detail_info       = item.detailInfo;
                                detail.detail_content_id = content.content_id;
                                if (item.detailId != null && item.detailId != 0)
                                {
                                    db.Entry(detail).State = EntityState.Modified;
                                }
                                else
                                {
                                    db.Reimbursement_Detail.Add(detail);
                                }
                            }
                        }
                        //录入附件
                        if (citem.attachments != null && citem.attachments.Count() > 0)
                        {
                            string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                            string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                            if (!Directory.Exists(attachment_path))
                            {
                                Directory.CreateDirectory(attachment_path);
                            }
                            string filePath, tempFile, saveFileName = "", storeFileName;
                            foreach (ViewAttachment item in citem.attachments)
                            {
                                if (item.id > 0)
                                {
                                    continue;
                                }
                                try
                                {
                                    saveFileName  = Path.GetFileName(item.fileName);
                                    storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                    tempFile      = attachment_temp_path + item.fileName;
                                    filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                    if (System.IO.File.Exists(filePath))
                                    {
                                        System.IO.File.Delete(filePath);
                                    }
                                    System.IO.File.Move(tempFile, filePath);
                                }
                                catch (Exception e)
                                {
                                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                                    sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传");
                                    continue;
                                }
                                Reimbursement_Attachment attachment = new Reimbursement_Attachment
                                {
                                    attachment_path         = storeFileName,
                                    atta_detail_id          = (int)citem.contentId,
                                    atta_reimbursement_code = bill.reimbursement_code
                                };
                                db.Reimbursement_Attachment.Add(attachment);
                            }
                        }

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            sbmsg.Append("报销明细录入失败<br />");
                            continue;
                        }
                    }
                    //录入附件
                    if (viewBill.attachments != null && viewBill.attachments.Count() > 0)
                    {
                        string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                        string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                        if (!Directory.Exists(attachment_path))
                        {
                            Directory.CreateDirectory(attachment_path);
                        }
                        string filePath, tempFile, saveFileName = "", storeFileName;
                        foreach (ViewAttachment item in viewBill.attachments)
                        {
                            if (item.id > 0)
                            {
                                continue;
                            }
                            try
                            {
                                saveFileName  = Path.GetFileName(item.fileName);
                                storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                tempFile      = attachment_temp_path + item.fileName;
                                filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                if (System.IO.File.Exists(filePath))
                                {
                                    System.IO.File.Delete(filePath);
                                }
                                System.IO.File.Move(tempFile, filePath);
                            }
                            catch (Exception e)
                            {
                                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                                sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传");
                                continue;
                            }
                            Reimbursement_Attachment attachment = new Reimbursement_Attachment
                            {
                                attachment_path         = storeFileName,
                                atta_detail_id          = 0,
                                atta_reimbursement_code = bill.reimbursement_code
                            };
                            db.Reimbursement_Attachment.Add(attachment);
                        }
                        try
                        {
                            //干脆都先提交得了
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            Delete(bill.reimbursement_code);
                            json.msg_code = "error";
                            json.msg_text = "报销单附件提交失败。";
                            goto next;
                        }
                    }
                    //录入批复流程
                    db.Process_Respond.RemoveRange(db.Process_Respond.Where(x => x.pr_reimbursement_code == bill.reimbursement_code));
                    //添加批复人
                    Process_Respond pr = new Process_Respond();
                    pr.pr_reimbursement_code = bill.reimbursement_code;
                    pr.pr_user_id            = viewBill.next;
                    pr.pr_number             = 1;
                    db.Process_Respond.Add(pr);
                    try
                    {
                        db.SaveChanges();
                        SysLog.WriteLog(user, string.Format("修改报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }
                json.state    = 1;
                json.msg_code = bill.reimbursement_code;
                json.msg_text = sbmsg.ToString();
            }
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SetAgree(Respond respond)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。";
                json.msg_code = "notLogin";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            int user = PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "批复管理", "批复"))
            {
                json.msg_text = "没有权限。";
                json.msg_code = "paramErr";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            if (respond.id == null || respond.id == 0)
            {
                json.msg_text = "参数传递失败,请重试。";
                json.msg_code = "paramErr";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            Process_Respond model = db.Process_Respond.Find(respond.id);

            if (model == null)
            {
                json.msg_text = "没找到该流程,可能已经撤销,请重试。";
                json.msg_code = "None";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            if (user != model.pr_user_id)
            {
                json.msg_text = "非该流程的当前批复人。";
                json.msg_code = "paramErr";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            var exists = db.Process_Respond.Where(x => x.pr_reimbursement_code == model.pr_reimbursement_code && x.pr_user_id == respond.next);

            if (exists.Count() > 0)
            {
                json.msg_text = "该审核人已存在审批列表中。";
                json.msg_code = "Exists";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            //批复当前流程
            int state = respond.state;

            model.pr_state        = state;
            model.pr_time         = DateTime.Now;
            model.pr_content      = PageValidate.InputText(Server.UrlDecode(respond.reason), 2000);
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;

            //是否为批复不通过
            Reimbursement bill = db.Reimbursement.Find(model.pr_reimbursement_code);

            if (bill == null)
            {
                json.msg_text = "操作失败,该报销单已被删除。";
                json.msg_code = "Error";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            if (state == 1)
            {
                Funds fmodel = db.Funds.Find(bill.r_funds_id);
                if (fmodel == null)
                {
                    json.msg_text = "所申请的经费已不存在,无法继续。";
                    json.msg_code = "applyError";
                    json.state    = 0;
                    return(Json(json, JsonRequestBehavior.AllowGet));
                }
                //是否有next
                if (respond.next != null && respond.next != 0)
                {
                    Process_Respond pr = new Process_Respond();
                    pr.pr_reimbursement_code = model.pr_reimbursement_code;
                    pr.pr_user_id            = (int)respond.next;
                    pr.pr_number             = model.pr_number + 1;
                    db.Process_Respond.Add(pr);
                    model.next            = pr.pr_id;
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    if (fmodel.f_balance < bill.r_bill_amount)
                    {
                        //经费不足,回退批复
                        json.msg_text = "当前经费余额不足,无法继续。";
                        json.msg_code = "applyError";
                        json.state    = 0;
                        return(Json(json, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        fmodel.f_balance       = fmodel.f_balance - bill.r_bill_amount;
                        db.Entry(fmodel).State = System.Data.Entity.EntityState.Modified;
                        bill.r_bill_state      = state;
                        bill.r_fact_amount     = bill.r_bill_amount;
                        db.Entry(bill).State   = System.Data.Entity.EntityState.Modified;
                    }
                }
            }
            else
            {
                bill.r_bill_state    = state;
                db.Entry(bill).State = System.Data.Entity.EntityState.Modified;
            }
            try
            {
                db.SaveChanges();
                SysLog.WriteLog(user, string.Format("批复报帐单[{0}],结果为[{1}]", bill.reimbursement_code, state), IpHelper.GetIP(), bill.reimbursement_code, 3, "", db);
            }
            catch (DbEntityValidationException et)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable <DbEntityValidationResult> validationResult = et.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection <DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name);
                json.msg_text = "审核失败。";
                json.msg_code = "respondError";
                json.state    = 0;
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            json.msg_text = "操作成功。";
            json.msg_code = "success";
            json.state    = 1;
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        public JsonResult LogReceive(string id, decimal amount)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);
            var bill = db.Reimbursement.Find(id);

            if (bill == null)
            {
                json.msg_text = "没有找到该报销单。";
                json.msg_code = "noData";
                goto next;
            }
            if (bill.r_bill_state != 1)
            {
                json.msg_text = "不能操作未批复报销单。";
                json.msg_code = "noData";
                goto next;
            }
            bool isManager = RoleCheck.CheckHasAuthority(user, db, "系统管理");

            if (!isManager && bill.c_has_log)
            {
                json.msg_text = "已操作录入实际信用金额。";
                json.msg_code = "noData";
                goto next;
            }
            if (user != bill.r_add_user_id && !isManager)
            {
                json.msg_text = "不能操作他人报销单。";
                json.msg_code = "noData";
                goto next;
            }
            bill.r_fact_amount   = amount;
            bill.c_has_log       = true;
            db.Entry(bill).State = EntityState.Modified;
            Funds funds = db.Funds.Find(bill.r_funds_id);

            if (funds != null)
            {
                decimal m = bill.r_bill_amount - bill.r_fact_amount;
                funds.f_balance       = funds.f_balance + m;
                db.Entry(funds).State = EntityState.Modified;
            }
            try
            {
                db.SaveChanges();
                SysLog.WriteLog(user, string.Format("录入报销单[{0}]实领金额{1}元", bill.reimbursement_code, amount), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
            }
            catch (Exception e)
            {
                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().Name);
                json.msg_code = "error";
                json.msg_text = "录入失败。";
                goto next;
            }
            json.state    = 1;
            json.msg_code = "success";
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit([Bind(Include = "user_id,user_name,real_name,gender,user_phone,user_info,user_email,user_password,user_password2,user_home_address,user_photo_path,role_id,state")] TeacherEditModel model)
        {
            setSelect();
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            if (ModelState.IsValid)
            {
                //if (Session["token"] == null || Session["token"].ToString() != model.token)
                //{
                //    ViewBag.msg = "异常操作,请退出当前页面后重新进入操作。";
                //    return View(model);
                //}
                int userid = PageValidate.FilterParam(User.Identity.Name);
                if (!RoleCheck.CheckHasAuthority(userid, db, "用户管理") && model.user_id != userid)
                {
                    return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
                }
                User_Info user_Info = db.User_Infos.Find(model.user_id);
                if (user_Info == null)
                {
                    ViewBag.msg = "没有找到相关信息,资料可能被删除。";
                    return(View(model));
                }

                if (db.User_Infos.Where(x => x.user_id != model.user_id && x.user_phone == model.user_phone).Count() > 0)
                {
                    ViewBag.msg = "该手机号码已存在。";
                    return(View(model));
                }
                if (!string.IsNullOrEmpty(model.user_password))
                {
                    if (model.user_password != model.user_password2)
                    {
                        ViewBag.msg = "两次输入的密码不匹配。";
                        return(View(model));
                    }
                    var salt = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper();
                    user_Info.user_password = AESEncrypt.Encrypt(PasswordUnit.getPassword(model.user_password.ToUpper(), salt));
                    user_Info.user_salt     = salt;
                }
                string err = "";
                if (!string.IsNullOrEmpty(model.user_photo_path) && model.user_photo_path != user_Info.user_photo_path)
                {
                    string photoDir = MyConfiguration.GetPhotoPath();
                    if (!Directory.Exists(photoDir))
                    {
                        Directory.CreateDirectory(photoDir);
                    }
                    string photoTempDir   = MyConfiguration.GetTempPhotoPath();
                    string file_name      = string.Format("{0}{1}", photoDir, model.user_photo_path).Replace("_temp", "");
                    string temp_file_name = string.Format("{0}{1}", photoTempDir, model.user_photo_path);
                    if (System.IO.File.Exists(temp_file_name))
                    {
                        FileInfo fi = new FileInfo(temp_file_name);
                        fi.CopyTo(file_name, true);
                        model.user_photo_path     = Path.GetFileName(file_name);
                        user_Info.user_photo_path = model.user_photo_path;
                    }
                    else
                    {
                        err = "图片保存失败。";
                    }
                }
                user_Info.user_name         = model.user_name;
                user_Info.user_phone        = model.user_phone;
                user_Info.user_info         = model.user_info;
                user_Info.user_email        = model.user_email;
                user_Info.user_home_address = model.user_home_address;
                user_Info.user_update_time  = DateTime.Now;
                user_Info.user_update_user  = userid;
                user_Info.user_gender       = model.gender;
                user_Info.real_name         = model.real_name;
                user_Info.user_is_teacher   = true;
                if (string.IsNullOrEmpty(user_Info.user_bindCode))
                {
                    user_Info.user_bindCode = Guid.NewGuid().ToString("N").Substring(0, 8);
                }
                db.Entry(user_Info).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }catch (Exception e)
                {
                    err = "资料保存失败。";
                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                }
                //权限设置
                if (RoleCheck.CheckIsSuperAdmin(model.user_id, db))
                {
                    if (model.role_id != 1)
                    {
                        err = "系统管理员权限不允许更改。";
                    }
                    goto next;
                }
                if (model.role_id == 1 && !RoleCheck.CheckIsSuperAdmin(userid, db))//添加系统管理员权限
                {
                    err = "只有系统管理员才可以添加系统管理员权限。";
                }
                else
                {
                    var uvr = db.User_vs_Roles.Where(x => x.uvr_user_id == model.user_id);
                    db.User_vs_Roles.RemoveRange(uvr);
                    User_vs_Role Nuvr = new User_vs_Role
                    {
                        uvr_user_id = model.user_id,
                        uvr_role_id = model.role_id
                    };
                    db.User_vs_Roles.Add(Nuvr);
                    try
                    {
                        db.SaveChanges();
                    }catch (Exception e)
                    {
                        err = "角色添加失败。";
                    }
                }
next:
                if (err == "")
                {
                    ViewBag.msg = "修改成功。";
                }
                else
                {
                    ViewBag.msg = err;
                }
            }
            return(View(model));
        }