public JsonResult JoinedAddSave(T_Joined model, string jsonStr) { using (TransactionScope sc = new TransactionScope()) { try { //主表保存 model.SetGroup = model.Department; model.IsDelete = 0; model.Step = 0; model.Status = -1; model.PostTime = DateTime.Now; db.T_Joined.Add(model); int i = db.SaveChanges(); if (i > 0) { //审核保存 T_JoinedApprove modelApprove = new T_JoinedApprove(); modelApprove.Status = -1; modelApprove.Memo = ""; modelApprove.Oid = model.ID; modelApprove.ApproveName = model.FirstApprove; db.T_JoinedApprove.Add(modelApprove); db.SaveChanges(); //附件保存 if (!string.IsNullOrEmpty(jsonStr)) { List <T_JoinedOptions> details = Deserialize <T_JoinedOptions>(jsonStr); foreach (var item in details) { item.Oid = model.ID; db.T_JoinedOptions.Add(item); } db.SaveChanges(); } string Name = model.FirstApprove; T_User UserModel = db.T_User.SingleOrDefault(a => a.Name == Name); string[] msg = new string[] { "你有一条入职未审批:请及时审核," }; string res = Lib.SendSMS.Send(msg, "162067", UserModel.Tel); //ModularByZP(); sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }
public JsonResult JoinedCheck(int id, int status, string memo) { using (TransactionScope sc = new TransactionScope()) { try { T_JoinedApprove modelApprove = db.T_JoinedApprove.SingleOrDefault(a => a.Oid == id && a.ApproveTime == null); string curName = Server.UrlDecode(Request.Cookies["Name"].Value); string result = ""; if (modelApprove == null) { return(Json("数据可能被删除", JsonRequestBehavior.AllowGet)); } modelApprove.Memo = memo; modelApprove.ApproveTime = DateTime.Now; modelApprove.Status = status; db.Entry <T_JoinedApprove>(modelApprove).State = System.Data.Entity.EntityState.Modified; int i = db.SaveChanges(); if (i > 0) { T_Joined model = db.T_Joined.Find(id); T_JoinedApprove newApprove = new T_JoinedApprove(); if (model == null) { return(Json("数据可能被删除", JsonRequestBehavior.AllowGet)); } if (status == 1) { //同意 int step = int.Parse(model.Step.ToString()); step++; IQueryable <T_JoinedApproveConfig> config = db.T_JoinedApproveConfig.AsQueryable(); int stepLength = config.Count();//总共步骤 if (step < stepLength) { //不是最后一步,主表状态为0 =>审核中 model.Status = 0; T_JoinedApproveConfig stepMod = db.T_JoinedApproveConfig.SingleOrDefault(a => a.Step == step); string nextName = stepMod.Name; //下一步审核人不是null 审核记录插入一条新纪录 newApprove.Memo = ""; newApprove.Oid = id; newApprove.Status = -1; if (nextName != null) { newApprove.ApproveName = nextName; } db.T_JoinedApprove.Add(newApprove); //T_JoinedApproveConfig stepMods = db.T_JoinedApproveConfig.SingleOrDefault(a => a.Step == step); //string Name = stepMods.Name; //发送短信给下一步审核人 T_User UserModel = db.T_User.SingleOrDefault(a => a.Name == nextName); if (UserModel != null && UserModel.Tel != null) { string[] msg = new string[] { "你有一条入职未审批:请及时审核," }; string res = Lib.SendSMS.Send(msg, "162067", UserModel.Tel); } db.SaveChanges(); } else { //最后一步,主表状态改为 1 => 同意 model.Status = status; T_Department deptModel = db.T_Department.FirstOrDefault(a => a.Name == model.Department); //找到部门 if (deptModel == null) //如果没有就放在好护士下 { deptModel = db.T_Department.Find(1); } T_User used = db.T_User.FirstOrDefault(a => a.Nickname == model.Nickname); //入职时该员工未建立账号的 T_User newUser = new T_User(); //新建一个账号 int UserId = 0; if (used == null) { newUser.DepartmentId = deptModel.ID.ToString(); newUser.IsManagers = "0"; newUser.Name = model.Name; newUser.Nickname = model.Nickname; newUser.PassWord = "******"; newUser.Power = ""; newUser.Tel = model.Tel; db.T_User.Add(newUser); db.SaveChanges(); string uIDstr = "";//给部门添加员工ID uIDstr = "," + newUser.ID; deptModel.employees += uIDstr; db.Entry <T_Department>(deptModel).State = System.Data.Entity.EntityState.Modified; addEmployeesToDepartmentForEidt(deptModel.ID, newUser.ID.ToString()); UserId = newUser.ID; } else { UserId = used.ID; } if (model.PID > 0)//修改档案信息 { T_PersonnelFile pModel = db.T_PersonnelFile.Find(model.PID); pModel.Department = model.Department; pModel.Job = model.Job; pModel.OnJob = 0; pModel.oid = UserId; pModel.Hiredate = model.Hiredate; pModel.Probation = model.Probation; pModel.ProbationSalary = model.ProbationSalary; // pModel.Salary = model.Salary; pModel.ContractFirstDeadline = model.ContractFirstDeadline; pModel.ContractFirstStartTime = model.ContractFirstStartTime; pModel.Code = WorkNum(); string DataStr = ""; #region 给DataStr赋值(入职资料) if (model.DataUserRegister) { if (DataStr == "") { DataStr += "员工登记"; } else { DataStr += ",员工登记"; } } if (model.DataPost) { if (DataStr == "") { DataStr += "应聘申请"; } else { DataStr += ",应聘申请"; } } if (model.DataResult) { if (DataStr == "") { DataStr += "简历"; } else { DataStr += ",简历"; } } if (model.DataIdcard) { if (DataStr == "") { DataStr += "身份证复印"; } else { DataStr += ",身份证复印"; } } if (model.DataQualifications) { if (DataStr == "") { DataStr += "学历证书"; } else { DataStr += ",学历证书"; } } if (model.DataPhoto) { if (DataStr == "") { DataStr += "寸照"; } else { DataStr += ",寸照"; } } if (model.DataDrivingLicense) { if (DataStr == "") { DataStr += "驾驶证"; } else { DataStr += ",驾驶证"; } } if (model.DataExaminationReport) { if (DataStr == "") { DataStr += "体检报告"; } else { DataStr += ",体检报告"; } } #endregion pModel.EntryData = DataStr; pModel.NickName = model.Nickname; db.Entry <T_PersonnelFile>(pModel).State = System.Data.Entity.EntityState.Modified; } } model.Step = step; db.Entry <T_Joined>(model).State = System.Data.Entity.EntityState.Modified; int j = db.SaveChanges(); if (j > 0) { result = "保存成功"; } else { result = "保存失败"; } } else { //不同意 model.Step = 0; model.Status = 2; db.Entry <T_Joined>(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //审核流程结束 申请人编辑后插入下一条记录 result = "保存成功"; } } else { result = "保存失败"; } // ModularByZP(); sc.Complete(); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json("保存失败", JsonRequestBehavior.AllowGet)); } } }
public JsonResult JoinedEditSave(T_Joined model, string jsonStr, int ID) { using (TransactionScope sc = new TransactionScope()) { try { //主表修改 int editStatus = model.Status; //原记录的状态 int editID = model.ID; //原记录的ID T_Joined modelJoined = db.T_Joined.Find(ID); modelJoined.Address = model.Address; modelJoined.Code = model.Code; modelJoined.DataDrivingLicense = model.DataDrivingLicense; modelJoined.DataExaminationReport = model.DataExaminationReport; modelJoined.DataIdcard = model.DataIdcard; modelJoined.DataPhoto = model.DataPhoto; modelJoined.DataPost = model.DataPost; modelJoined.DataQualifications = model.DataQualifications; modelJoined.DataResult = model.DataResult; modelJoined.DataUserRegister = model.DataUserRegister; modelJoined.Department = model.Department; modelJoined.EmergencyContact = model.EmergencyContact; modelJoined.EmergencyTel = model.EmergencyTel; modelJoined.FirstApprove = model.FirstApprove; modelJoined.IdcardAddress = model.IdcardAddress; modelJoined.Information = model.Information; modelJoined.Job = model.Job; modelJoined.Memo = model.Memo; modelJoined.Name = model.Name; modelJoined.Nickname = model.Nickname; modelJoined.SetGroup = model.SetGroup; modelJoined.Sex = model.Sex; modelJoined.Tel = model.Tel; modelJoined.Status = -1; db.Entry <T_Joined>(modelJoined).State = System.Data.Entity.EntityState.Modified; int i = db.SaveChanges(); if (i > 0) { //审核保存 不同意修改 新添加一条审核记录。未审核的则不添加而是修改 T_JoinedApprove Approvemodel = db.T_JoinedApprove.SingleOrDefault(a => a.Oid == editID && a.ApproveTime == null); if (Approvemodel == null) { //不同意 修改 T_JoinedApprove modelApprove = new T_JoinedApprove(); modelApprove.Status = -1; modelApprove.Memo = ""; modelApprove.Oid = model.ID; modelApprove.ApproveName = model.FirstApprove; db.T_JoinedApprove.Add(modelApprove); db.SaveChanges(); } else { //新增修改 Approvemodel.ApproveName = model.FirstApprove; db.Entry <T_JoinedApprove>(Approvemodel).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //附件保存 先删除原有的附件 List <T_JoinedOptions> delMod = db.T_JoinedOptions.Where(a => a.Oid == editID).ToList(); foreach (var item in delMod) { db.T_JoinedOptions.Remove(item); } db.SaveChanges(); if (!string.IsNullOrEmpty(jsonStr)) { List <T_JoinedOptions> details = Deserialize <T_JoinedOptions>(jsonStr); foreach (var item in details) { item.Oid = model.ID; db.T_JoinedOptions.Add(item); } db.SaveChanges(); } // ModularByZP(); sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }