public ActionResult AddJob(string jobid) //在修改时传递的为jobid { if (jobid == "-1") //-1为添加,自动生成PositionCategoryID { string id, idnum; int num, n; V_HR_JobWithDutyName list = (from o in entities.V_HR_JobWithDutyName orderby o.JobID descending select o).First(); id = list.JobID.ToString(); num = int.Parse(id.Substring(2, 4)) + 1; idnum = num.ToString(); n = idnum.Length; for (int i = 0; i < 4 - n; i++) { idnum = "0" + idnum; } id = "JO" + idnum; ViewData["AutoID"] = id; return(View()); } else//否则为修改 { V_HR_JobWithDutyName item = (from o in entities.V_HR_JobWithDutyName where o.JobID == jobid select o).First(); ViewData["AutoID"] = jobid; return(View(item)); } }
public ActionResult AddOrEditJob(V_HR_JobWithDutyName job)//保存相应 { DirectResult r = new DirectResult(); T_HR_Job jobupdate = entities.T_HR_Job.Find(job.JobID); if (jobupdate == null)//为空为添加 { T_HR_Job jobadd = new T_HR_Job(); jobadd.JobID = job.JobID; jobadd.JobName = job.JobName; jobadd.DutyID = job.DutyID; jobadd.Remark = job.Remark; jobadd.CreaterName = "admin";//后期改为用户名 jobadd.CreateTime = DateTime.Now; entities.T_HR_Job.Add(jobadd); try { entities.SaveChanges(); r.Success = true; X.Msg.Alert("提示", "保存成功!", new JFunction { Fn = "closewindow" }).Show(); } catch (Exception e) { X.Msg.Alert("警告", "数据保存失败!<br /> note:" + e.Message, new JFunction { Fn = "closewindow" }).Show(); r.Success = false; } } else//否则为修改 { jobupdate.JobName = job.JobName; jobupdate.DutyID = job.DutyID; jobupdate.Remark = job.Remark; jobupdate.EditorName = "admin";//后期改为用户名 jobupdate.EditorTime = DateTime.Now; try { entities.SaveChanges(); r.Success = true; X.Msg.Alert("提示", "修改成功!", new JFunction { Fn = "closewindow" }).Show(); } catch (Exception e) { X.Msg.Alert("警告", "数据修改失败!<br /> note:" + e.Message, new JFunction { Fn = "closewindow" }).Show(); r.Success = false; } } return(r); }