public ActionResult Edit([Bind(Include = "sub_id,sub_name")] Dic_Subject dic_Subject) { if (ModelState.IsValid) { db.Entry(dic_Subject).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dic_Subject)); }
public ActionResult Edit([Bind(Include = "company_id,company_name,company_introduce,company_address,company_phone")] Sys_Info sys_Info) { if (ModelState.IsValid) { db.Entry(sys_Info).State = EntityState.Modified; db.SaveChanges(); ViewBag.msg = "更新成功。"; return(RedirectToAction("Index", new { id = sys_Info.company_id })); } return(View(sys_Info)); }
public JsonResult UpdatePost(Dic_Post post) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; goto next; } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { json.msg_text = "没有权限。"; json.msg_code = "NoPower"; goto next; } if (post.post_id == 0) { json.msg_text = "获取部门/科室的ID出错。"; json.msg_code = "IDError"; goto next; } var same = db.Dic_Post.Where(x => x.post_name == post.post_name && x.post_id != post.post_id); if (same.Count() > 0) { json.msg_text = "该名称已存在。"; json.msg_code = "NameExists"; goto next; } db.Entry(post).State = EntityState.Modified; try { db.SaveChanges(); DBCaches <Dic_Post> .ClearCache("cache_post"); } catch { json.msg_text = "更新,请重新操作。"; json.msg_code = "UpdateErr"; goto next; } SysLog.WriteLog(user, string.Format("更新职务[{0}]", post.post_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "更新成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit([Bind(Include = "user_id,user_name,user_photo_path,user_phone,user_info,user_email,user_password,user_Occupation,user_home_address,user_work_unit,user_add_time,user_add_user,user_update_time,user_update_user,user_login_times")] User_Info user_Info) { if (ModelState.IsValid) { db.Entry(user_Info).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user_Info)); }
public ActionResult Edit([Bind(Include = "id,name,sex,birthday,photo,phone,email,school,grade,address,cardType,IdCard")] ViewModel.StudentsModel StudentsModel) { if (ModelState.IsValid) { try { Student_Info student_info = db.Student_Infos.Find(StudentsModel.id); if (student_info == null) { ViewBag.msg = "没有查到该学生信息,可能已被删除。"; CreateSelect(); return(View(StudentsModel)); } if (db.Student_Infos.Where(x => x.stu_id != StudentsModel.id && x.stu_card_type == StudentsModel.cardType && x.stu_idCard == StudentsModel.IdCard).Count() > 0) { ViewBag.msg = "该证件号已存在,请勿重新添加。"; CreateSelect(); return(View(StudentsModel)); } student_info.stu_id = StudentsModel.id; student_info.stu_card_type = StudentsModel.cardType; student_info.stu_idCard = PageValidate.InputText(StudentsModel.IdCard, 18); student_info.stu_birthday = StudentsModel.birthday; student_info.stu_email = PageValidate.InputText(StudentsModel.email, 200); student_info.stu_grade_id = StudentsModel.grade; student_info.stu_home_address = PageValidate.InputText(StudentsModel.address, 500); student_info.stu_name = PageValidate.InputText(StudentsModel.name, 50); student_info.stu_phone = PageValidate.InputText(StudentsModel.phone, 20); student_info.stu_school_id = StudentsModel.school; student_info.stu_sex = PageValidate.InputText(StudentsModel.sex, 2); string up_photo = PageValidate.InputText(StudentsModel.photo, 50); if (up_photo != student_info.stu_photo_path) { string file_name = string.Format("{0}.jpg", student_info.stu_idCard); string save_name = string.Format(Server.MapPath(string.Format("~/images/stu/{0}", file_name))); string old_path = string.Format(Server.MapPath(string.Format("~/images/temp/{0}", up_photo))); FileInfo fi = new FileInfo(old_path); fi.CopyTo(save_name, true); student_info.stu_photo_path = file_name; } db.Entry(student_info).State = EntityState.Modified; db.SaveChanges(); DataCache.RemoveCache("cache_student"); } catch (Exception e) { ViewBag.msg = e.ToString(); CreateSelect(); return(View(StudentsModel)); } } return(RedirectToAction("ViewList")); }
public ActionResult Index([Bind(Include = "userName,password,checkCode,isRemember")] LoginModel model) { if (Session["ErrorPsw"] == null) { Session["ErrorPsw"] = 0; } int errTimes = (int)Session["ErrorPsw"]; //if (errTimes >= 5) //{ // ViewBag.msg = "失败次数过多,请1小时后再尝试。"; // return View(model); //} //List<SelectOption> options = DropDownList.SysRolesSelect(); //ViewBag.ddlRoles = DropDownList.SetDropDownList(options); if (Session["checkCode"] == null) { ViewBag.msg = "验证码已过期,请点击验证码刷新后重新输入密码码。"; errTimes++; Session["ErrorPsw"] = errTimes; return(View(model)); } if (model.checkCode.ToUpper() != Session["checkCode"].ToString()) { ViewBag.msg = "验证码不正确。"; return(View(model)); } //验证帐号密码 var user = (from p in db.User_Info join uvr in db.User_vs_Role on p.user_id equals uvr.uvr_user_id where p.user_name == model.userName select p ).FirstOrDefault(); if (user == null) { ViewBag.msg = "用户不存在。"; return(View(model)); } string password = AESEncrypt.Encrypt(PasswordUnit.getPassword(PageValidate.InputText(model.password, 40).ToUpper(), user.user_salt)); if (password != user.user_password) { ViewBag.msg = "用户密码不正确,请重新输入。"; return(View(model)); } if (user.user_state == 0) { ViewBag.msg = "您的帐号被锁定,暂时无法登陆。"; return(View(model)); } if (user.user_state != 1) { ViewBag.msg = "您的帐号异常,暂时无法登陆。"; return(View(model)); } //验证权限 var role = (from uvr in db.User_vs_Role join r in db.Dic_Role on uvr.uvr_role_id equals r.role_id where uvr.uvr_user_id == user.user_id select new LoginRole { roleId = r.role_id, roleName = r.role_name }).FirstOrDefault(); if (role == null || role.roleId == 0) { ViewBag.msg = "没有权限登陆所选角色。"; return(View(model)); } //功能权限 var controlroles = (from r in db.Dic_Role join rvc in db.Role_vs_Controller on r.role_id equals rvc.rvc_role_id where r.role_id == role.roleId select rvc.rvc_controller ).ToArray(); string ip = IpHelper.GetIP(); string loginDev = string.Format("{0}-{1}-{2}-{3}-{4}" , Request.Browser.Id , Request.Browser.MobileDeviceManufacturer , Request.Browser.MobileDeviceModel , Request.Browser.Platform , Request.Browser.Type ); Sys_Log log = new Sys_Log { log_content = "登陆", log_time = DateTime.Now, log_user_id = user.user_id, log_ip = ip, log_target = user.user_id.ToString(), log_type = 1, log_device = loginDev }; user.user_login_times++; db.Sys_Log.Add(log); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); user.ToDecrypt(); user.DeletePassword(); Session["LoginRole"] = role; Session["ControlRoles"] = controlroles; Session["UserInfo"] = user; DataCache.SetCache("user-roles-" + user.user_id, role); HttpCookie cookie; if (model.isRemember) { cookie = new HttpCookie("name", Server.UrlEncode(model.userName)); cookie.Expires = DateTime.Now.AddHours(1); Response.AppendCookie(cookie); } else if (Request.Cookies["name"] != null) { Response.Cookies.Remove("name"); } cookie = new HttpCookie("realname", Server.UrlEncode(user.real_name)); cookie.Expires = DateTime.Now.AddHours(1); Response.AppendCookie(cookie); FormsAuthentication.SetAuthCookie(user.user_id.ToString(), true); return(RedirectToRoute(new { controller = "Home", action = "Index" })); }
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 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 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 Create(CourseModel courseModel) { BaseJsonData json = new BaseJsonData(); if (ModelState.IsValid) { Course_Info cmodel = new Course_Info(); if (db.Course_Infos.Where(x => x.course_name == courseModel.name).Count() > 0) { json.msg_text = "课程名称已存在。"; return(Json(json, JsonRequestBehavior.AllowGet)); } string time_info = ""; cmodel.course_cost = courseModel.cost; cmodel.course_introduce = courseModel.introduce; cmodel.course_max_num = courseModel.max; cmodel.course_name = courseModel.name; cmodel.c_assistant_id = courseModel.assistant; cmodel.c_cs_id = courseModel.season; cmodel.c_sub_id = courseModel.subject; cmodel.c_room = courseModel.room; cmodel.c_teacher_id = courseModel.teacher; cmodel.c_room = courseModel.room; cmodel.c_type_id = courseModel.type; db.Course_Infos.Add(cmodel); db.SaveChanges(); int group = 1; foreach (ListTime lTiem in courseModel.ListTimes) { if (lTiem.count > 1) { time_info += "每"; } time_info += string.Format("{0}{1} ", WeeK.GetCHNDay(lTiem.day), lTiem.lessonTime); if (lTiem.times != null && lTiem.times.Count > 0) { foreach (ListDetailTime time in lTiem.times) { Course_vs_Time cvt = new Course_vs_Time(); cvt.cvt_course_id = courseModel.id; cvt.cvt_dayofweek = lTiem.day; cvt.cvt_duration = lTiem.lastlong; cvt.cvt_info = time.info; cvt.cvt_is_extra = time.isextra; cvt.cvt_state = time.state == 0 ? 1 : time.state; cvt.cvt_time = time.time; if (time.room == 0) { cvt.cvt_room_id = courseModel.room; } else { cvt.cvt_room_id = time.room; } cvt.cvt_group = group; db.Course_vs_Times.Add(cvt); db.SaveChanges(); } } else { Course_vs_Time cvtModel; List <DateTime> ListTime = CreateTimeDetail(courseModel.SuspendDays, courseModel.beginDate, lTiem.lessonTime, lTiem.day, lTiem.count); List <Course_vs_Time> cvtList = new List <Course_vs_Time>(); foreach (DateTime dtLesson in ListTime) { cvtModel = new Course_vs_Time(); cvtModel.cvt_course_id = courseModel.id; cvtModel.cvt_dayofweek = lTiem.day; cvtModel.cvt_is_extra = false; cvtModel.cvt_state = 1; cvtModel.cvt_time = dtLesson; cvtModel.cvt_duration = lTiem.lastlong; cvtModel.cvt_room_id = courseModel.room; cvtModel.cvt_group = group; cvtList.Add(cvtModel); } try { db.Course_vs_Times.AddRange(cvtList); db.SaveChanges(); } catch (Exception e) { json.msg_text = "课程时间编排出错,请重新操作。"; return(Json(json, JsonRequestBehavior.AllowGet)); } } group++; } cmodel.c_time_info = time_info; db.Entry(cmodel).State = EntityState.Modified; //录入停课日期 if (courseModel.SuspendDays != null && courseModel.SuspendDays.Count() > 0) { foreach (DateTime dt in courseModel.SuspendDays) { if (db.Course_SuspendTimes.Where(x => x.cst_course_id == courseModel.id && x.cst_suspend_time.Year == dt.Year && x.cst_suspend_time.Month == dt.Month && x.cst_suspend_time.Day == dt.Day).Count() == 0) { db.Course_SuspendTimes.Add(new Course_SuspendTime { cst_course_id = courseModel.id, cst_suspend_time = dt }); } } } db.SaveChanges(); json.state = 1; json.msg_text = "添加完成。"; RemoveCache(courseModel.subject); } else { var errors = ModelState.Where(x => x.Value.Errors.Count() > 0); StringBuilder sbMsg = new StringBuilder(); foreach (var modelstate in errors) { if (modelstate.Value.Errors.Count() > 0) { foreach (ModelError err in modelstate.Value.Errors) { sbMsg.Append(modelstate.Key).Append(" ").Append(err.ErrorMessage).Append("<br />"); } } } //foreach (ModelError err in errors) //{ // sbMsg.Append(err.ErrorMessage).Append("<br />"); //} json.state = 0; json.msg_text = sbMsg.ToString(); } 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)); }
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)); }