public ActionResult AddDuty(string dutyid) //在修改时传递的为dutyID { if (dutyid == "-1") //-1为添加,自动生成PositionCategoryID { string id, idnum; int num, n; V_HR_DutyWithPCName list = (from o in entities.V_HR_DutyWithPCName orderby o.DutyID descending select o).First(); id = list.DutyID.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 = "ZW" + idnum; ViewData["AutoID"] = id; return(View()); } else//否则为修改 { V_HR_DutyWithPCName item = (from o in entities.V_HR_DutyWithPCName where o.DutyID == dutyid select o).First(); ViewData["AutoID"] = dutyid; return(View(item)); } }
public ActionResult AddOrEditDuty(V_HR_DutyWithPCName duty)//AddPositionCategory保存相应 { DirectResult r = new DirectResult(); T_HR_Duty dutyupdate = entities.T_HR_Duty.Find(duty.DutyID); if (dutyupdate == null)//为空为添加 { T_HR_Duty dutyadd = new T_HR_Duty(); dutyadd.DutyID = duty.DutyID; dutyadd.DutyName = duty.DutyName; dutyadd.DutyLevel = duty.DutyLevel; dutyadd.DutyRank = duty.DutyRank; dutyadd.FunctionList = duty.FunctionList; dutyadd.DutyType = duty.DutyType; dutyadd.Remark = duty.Remark; dutyadd.PositionCategoryID = duty.PositionCategoryID; dutyadd.CreaterName = "admin";//后期改为用户名 dutyadd.CreateTime = DateTime.Now; entities.T_HR_Duty.Add(dutyadd); 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//否则为修改 { dutyupdate.DutyName = duty.DutyName; dutyupdate.DutyLevel = duty.DutyLevel; dutyupdate.DutyRank = duty.DutyRank; dutyupdate.FunctionList = duty.FunctionList; dutyupdate.DutyType = duty.DutyType; dutyupdate.Remark = duty.Remark; dutyupdate.PositionCategoryID = duty.PositionCategoryID; dutyupdate.EditorName = "admin";//后期改为用户名 dutyupdate.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); }