public ActionResult Create([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.User_Infos.Add(user_Info); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user_Info)); }
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"); } }
public ActionResult Create([Bind(Include = "code,name,source,amount,balance,processId,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) { if (db.Funds.Where(x => x.f_code == funds.code).Count() > 0) { ViewBag.msg = "该代码已被使用"; return(View(funds)); } if (db.Funds.Where(x => x.f_name == funds.name).Count() > 0) { ViewBag.msg = "该名称已被使用"; return(View(funds)); } //if (funds.processId == null || funds.processId == 0) //{ // ViewBag.msg = "未选择批复流程。"; // return View(funds); //} if (funds.amount == 0) { ViewBag.msg = "请设置经费总额。"; return(View(funds)); } Funds model = new Funds(); funds.toDBModel(model); model.f_manager = user; db.Funds.Add(model); db.SaveChanges(); SysLog.WriteLog(user, string.Format("经费添加[{0}]", model.f_code), IpHelper.GetIP(), model.f_id.ToString(), 6, "", db); ViewBag.msg = "经费添加成功。"; } return(View(funds)); }
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 ActionResult Create([Bind(Include = "name,sex,birthday,photo,phone,email,school,grade,address,cardType,IdCard")] ViewModel.StudentsModel StudentsModel) { if (ModelState.IsValid) { if (db.Student_Infos.Where(x => x.stu_card_type == StudentsModel.cardType && x.stu_idCard == StudentsModel.IdCard).Count() > 0) { ViewBag.msg = "该证件号已存在,请勿重新添加。"; CreateSelect(); return(View(StudentsModel)); } Student_Info student_info = new Student_Info(); 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_photo_path = PageValidate.InputText(StudentsModel.photo, 50); 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 (!string.IsNullOrEmpty(up_photo)) { 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; } if (db.Student_Infos.Count() == 0) { student_info.stu_id = DateTime.Now.ToString("yyyy") + "100001"; } else { string strNum = db.Student_Infos.OrderByDescending(x => x.stu_id).First().stu_id.Substring(4, 6); int Num = Int32.Parse(strNum) + 1; student_info.stu_id = DateTime.Now.ToString("yyyy") + Num.ToString(); } db.Student_Infos.Add(student_info); db.SaveChanges(); ViewBag.msg = "添加成功。"; DataCache.RemoveCache("cache_student"); //return RedirectToAction("Index"); } CreateSelect(); return(View(StudentsModel)); }
public ActionResult Create([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) { setSelect(); if (!User.Identity.IsAuthenticated) { return(RedirectToRoute(new { controller = "Login", action = "LogOut" })); } int userid = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(userid, db, "用户管理")) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" })); } if (ModelState.IsValid) { if (db.User_Infos.Where(x => x.user_email == user_Info.user_email && x.user_id != user_Info.user_id).Count() > 0) { ViewBag.msg = "该邮箱已注册。"; goto next; } if (db.User_Infos.Where(x => x.user_phone == user_Info.user_phone && x.user_id != user_Info.user_id).Count() > 0) { ViewBag.msg = "该手机号已注册。"; goto next; } var salt = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper(); user_Info.user_password = PasswordUnit.getPassword(user_Info.user_password.ToUpper(), salt); user_Info.user_salt = salt; db.User_Infos.Add(user_Info); db.SaveChanges(); return(RedirectToAction("Index")); } next: return(View(user_Info)); }
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 SiteSet([Bind(Include = "name,company,introduce,companyAddress,companyPhone,companyEmail,managerName,managerPhone,managerEmail")] ViewModels.SiteInfo info) { 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 = "没有权限执行当前操作。" })); } Sys_SiteInfo model = db.Sys_SiteInfo.FirstOrDefault(); if (model != null) { db.Sys_SiteInfo.Remove(model); db.SaveChanges(); } model = new Sys_SiteInfo(); info.toDBModel(model); db.Sys_SiteInfo.Add(model); try { db.SaveChanges(); DBCaches <Sys_SiteInfo> .ClearCache("site-name"); DBCaches <Sys_SiteInfo> .ClearCache("site-info"); } catch (Exception ex) { @ViewBag.msg = "修改失败。"; } SysLog.WriteLog(user, "修改网站信息", IpHelper.GetIP(), "", 5, "", db); @ViewBag.msg = "修改成功。"; return(View(info)); }
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)); }
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)); }
public ActionResult Create([Bind(Include = "CardTypes,CourseStates,CourseTypes,Grades,levelSubject,Levels,Relations,RollCalls,Schools,Subject,Roles")] ViewModel.DictionaryModel dicModel) { StringBuilder sbMsg = new StringBuilder(); if (ModelState.IsValid) { string[] dicList; if (dicModel.CardTypes != null) { dicList = PageValidate.InputText(dicModel.CardTypes, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_CardTypes.Where(x => x.ctype_name == ct.Trim()).Count() == 0) { db.Dic_CardTypes.Add(new Dic_CardType { ctype_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.CourseStates != null) { dicList = PageValidate.InputText(dicModel.CourseStates, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Course_States.Where(x => x.cstate_name == ct.Trim()).Count() == 0) { db.Dic_Course_States.Add(new Dic_Course_State { cstate_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.CourseTypes != null) { dicList = PageValidate.InputText(dicModel.CourseTypes, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Course_Types.Where(x => x.ct_name == ct.Trim()).Count() == 0) { db.Dic_Course_Types.Add(new Dic_Course_Type { ct_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Grades != null) { dicList = PageValidate.InputText(dicModel.Grades, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Grades.Where(x => x.grade_name == ct.Trim()).Count() == 0) { db.Dic_Grades.Add(new Dic_Grade { grade_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Levels != null && dicModel.levelSubject > 0) { dicList = PageValidate.InputText(dicModel.Levels, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Levels.Where(x => x.level_name == ct.Trim() && x.level_sub_id == dicModel.levelSubject).Count() == 0) { db.Dic_Levels.Add(new Dic_Level { level_name = ct.Trim(), level_sub_id = (int)dicModel.levelSubject }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Relations != null) { dicList = PageValidate.InputText(dicModel.Relations, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Relations.Where(x => x.relation_name == ct.Trim()).Count() == 0) { db.Dic_Relations.Add(new Dic_Relation { relation_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Roles != null) { dicList = PageValidate.InputText(dicModel.Roles, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Sys_Roles.Where(x => x.role_name == ct.Trim()).Count() == 0) { db.Sys_Roles.Add(new Sys_Roles { role_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.RollCalls != null) { dicList = PageValidate.InputText(dicModel.RollCalls, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Roll_Calls.Where(x => x.rc_name == ct.Trim()).Count() == 0) { db.Dic_Roll_Calls.Add(new Dic_Roll_Call { rc_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Schools != null) { dicList = PageValidate.InputText(dicModel.Schools, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Schools.Where(x => x.school_name == ct.Trim()).Count() == 0) { db.Dic_Schools.Add(new Dic_School { school_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("已存在。<br />"); } } } } if (dicModel.Subject != null) { dicList = PageValidate.InputText(dicModel.Subject, 8000).Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); if (dicList != null && dicList.Length > 0) { foreach (string ct in dicList) { if (db.Dic_Subjects.Where(x => x.sub_name == ct.Trim()).Count() == 0) { db.Dic_Subjects.Add(new Dic_Subject { sub_name = ct.Trim() }); db.SaveChanges(); } else { sbMsg.Append("名称【").Append(ct).Append("】已存在。<br />"); } } } } if (sbMsg.Length > 0) { CreateSelect(); ViewBag.msg = sbMsg.ToString(); return(View()); } return(RedirectToAction("Index")); } else { var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError err in errors) { sbMsg.Append(err.ErrorMessage).Append("<br />"); } ViewBag.msg = sbMsg.ToString(); } CreateSelect(); return(View()); }
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)); }