public bool DealException() { DateTime dateTime; if (!DateTime.TryParse(AttendTime, out dateTime)) { return(false); } using (Entities db = new Entities()) { try { var user = new LoginUser(); var obj = db.T_HR_AttendInsert.Find(Id); T_HR_AttendanceExceptionHandleRecords record = new T_HR_AttendanceExceptionHandleRecords() { BeforeTime = obj.AttendTime, Date = obj.AttendTime.Date, Editor = user.EmployeeId, EmployeeID = obj.UserId, ExceptionState = obj.State, FinalTime = dateTime, PunchedOrder = obj.PunchedOrder, UpdateTime = DateTime.Now, Remark = Remark }; obj.AttendTime = obj.AttendTime.Date + dateTime.TimeOfDay; obj.EditUserId = user.EmployeeId; obj.EditTime = DateTime.Now; obj.Solved = true; db.T_HR_AttendanceExceptionHandleRecords.Add(record); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public ActionResult SaveAttend(string date, string order, string isdep, string id1, string id2, string id3, string id4, string id5) { if (id1 == "null") { id1 = null; } if (id2 == "null") { id2 = null; } if (id3 == "null") { id3 = null; } if (id4 == "null") { id4 = null; } if (id5 == "null") { id5 = null; } bool dep = Convert.ToBoolean(isdep); DirectResult r = new DirectResult(); LoginUser lu = new LoginUser(); DateTime dt = Convert.ToDateTime(date); int or = Convert.ToInt32(order); string[] staffid = null; if (dep) { if (NoNullDep(id1, id2, id3, id4, id5)) { staffid = GetStaffIDFromDep(id1, id2, id3, id4, id5); } else { X.Msg.Alert("警告", "部门不可跳过为空!").Show(); return(this.Direct()); } } else { if (Session["xgw_attendstaffid"] != null) { staffid = (string[])Session["xgw_attendstaffid"]; } } #region if (staffid != null) { foreach (string id in staffid) { bool four = false; var schstaff = from o in entities.T_HR_SchListWithStaff where o.StaffID == id select o; if (schstaff.Any()) { string schlistid = schstaff.First().SchListID; var sch = from o in entities.T_HR_SchList where o.ID == schlistid select o; if (sch.Any()) { four = Convert.ToBoolean(sch.First().Four); } } if (!four && or > 2) { continue; } var ats = from o in entities.T_HR_AttendInsert where o.UserId == id && o.PunchedOrder == or select o; if (ats.Any()) { T_HR_AttendInsert atup = entities.T_HR_AttendInsert.Find(ats.First().ID); T_HR_AttendanceExceptionHandleRecords aehrup = new T_HR_AttendanceExceptionHandleRecords(); aehrup.EmployeeID = id; aehrup.Date = dt.Date; aehrup.BeforeTime = atup.AttendTime; aehrup.FinalTime = dt; aehrup.ExceptionState = 6; aehrup.PunchedOrder = or; aehrup.Editor = new LoginUser().EmployeeId; aehrup.UpdateTime = DateTime.Now; aehrup.Remark = "补签"; entities.T_HR_AttendanceExceptionHandleRecords.Add(aehrup); atup.AttendTime = dt; atup.EditUserId = new LoginUser().EmployeeId; atup.EditTime = DateTime.Now; atup.State = 1; atup.Solved = false; atup.PunchedOrder = or; } else { T_HR_AttendanceExceptionHandleRecords aehradd = new T_HR_AttendanceExceptionHandleRecords(); aehradd.EmployeeID = id; aehradd.Date = dt.Date; aehradd.FinalTime = dt; aehradd.ExceptionState = 6; aehradd.PunchedOrder = or; aehradd.Editor = new LoginUser().EmployeeId; aehradd.UpdateTime = DateTime.Now; aehradd.Remark = "补签"; entities.T_HR_AttendanceExceptionHandleRecords.Add(aehradd); T_HR_AttendInsert at = new T_HR_AttendInsert(); at.ID = Tool.ProduceSed64(); at.UserId = id; at.AttendTime = dt; at.EditUserId = new LoginUser().EmployeeId; at.EditTime = DateTime.Now; at.State = 1; at.Solved = false; at.PunchedOrder = or; entities.T_HR_AttendInsert.Add(at); } } 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; } } #endregion return(r); }