public ActionResult AddFund(string id) //在修改时传递的为contractid { if (id == "-1") //-1为添加 { return(View()); } else//否则为修改 { V_HR_Fund item = (from o in entities.V_HR_Fund where o.ID == id select o).First(); return(View(item)); } }
public ActionResult AddOrEditFund(V_HR_Fund re) { DirectResult r = new DirectResult(); T_HR_Fund reupdate = entities.T_HR_Fund.Find(re.ID); if (reupdate == null)//为空为添加 { var ft = (from o in entities.V_HR_Fund where o.StaffID == re.StaffID && o.Valid == true select o).ToList(); if (!ft.Any()) { T_HR_Fund readd = new T_HR_Fund(); readd.ID = Guid.NewGuid().ToString(); readd.StaffID = re.StaffID; readd.StartDate = re.StartDate; if (re.EndDate != null) { readd.EndDate = re.EndDate; readd.Months = GetMonths(Convert.ToDateTime(re.StartDate), Convert.ToDateTime(re.EndDate)); } //readd.Months = re.Months; readd.Valid = true; readd.Remark = re.Remark; readd.CreaterName = new LoginUser().EmployeeId; readd.CreateTime = DateTime.Now; T_HR_Staff s = entities.T_HR_Staff.Find(re.StaffID); s.FundValid = true; entities.T_HR_Fund.Add(readd); 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 { X.Msg.Alert("警告", "该员工基金记录已存在,不可重复添加!").Show(); return(this.Direct()); } } else//否则为修改 { reupdate.StaffID = re.StaffID; reupdate.StartDate = re.StartDate; if (re.EndDate != null) { reupdate.EndDate = re.EndDate; reupdate.Months = GetMonths(Convert.ToDateTime(re.StartDate), Convert.ToDateTime(re.EndDate)); } //reupdate.Months = re.Months; reupdate.Remark = re.Remark; reupdate.Valid = true; reupdate.EditorName = new LoginUser().EmployeeId; reupdate.EditeTime = 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); }