private void btn变更允许调休小时数_Click(object sender, EventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog(); DataTable dt = ExcelHelperP.RenderFromExcel(dialog); if (dt != null) { List <HR_AttendanceSummary> lstSummary = new List <HR_AttendanceSummary>(); for (int i = 0; i < dt.Rows.Count; i++) { if ((dt.Rows[i]["工号"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dt.Rows[i]["工号"].ToString())) || (dt.Rows[i]["年份"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dt.Rows[i]["年份"].ToString())) || (dt.Rows[i]["月份"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dt.Rows[i]["月份"].ToString())) || (dt.Rows[i]["允许调休小时数"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dt.Rows[i]["允许调休小时数"].ToString()))) { throw new Exception("第" + (i + 2).ToString() + "行记录存在【空数据】"); } if (UniversalFunction.GetPersonnelInfo(dt.Rows[i]["工号"].ToString()) == null) { throw new Exception("【工号】:" + dt.Rows[i]["工号"].ToString() + ", 不存在"); } HR_AttendanceSummary summary = new HR_AttendanceSummary(); summary.WorkID = dt.Rows[i]["工号"].ToString(); summary.Year = Convert.ToInt32(dt.Rows[i]["年份"]); summary.Month = Convert.ToInt32(dt.Rows[i]["月份"]); summary.AllowMobileVacationHours = Convert.ToDouble(dt.Rows[i]["允许调休小时数"]); lstSummary.Add(summary); } m_attendanceServer.UpdateAllowMobileHours(lstSummary); MessageDialog.ShowPromptMessage("修改【允许调休小时数】成功"); } } catch (Exception exce) { MessageDialog.ShowErrorMessage(exce.Message); } }
/// <summary> /// 更新员工允许调休小时数 /// </summary> /// <param name="lstUpdate">要更新的数据列表</param> public void UpdateAllowMobileHours(List <HR_AttendanceSummary> lstUpdate) { using (DepotManagementDataContext ctx = CommentParameter.DepotDataContext) { foreach (var summary in lstUpdate) { var info = from r in ctx.HR_AttendanceSummary where r.WorkID == summary.WorkID && r.Year == summary.Year && r.Month == summary.Month select r; if (info.Count() == 1) { HR_AttendanceSummary updatedInfo = info.Single(); string log = string.Format("将工号{0},{1}年{2}月允许调休小时数从{3}变更为{4}", summary.WorkID, summary.Year, summary.Month, updatedInfo.AllowMobileVacationHours, summary.AllowMobileVacationHours); updatedInfo.AllowMobileVacationHours = summary.AllowMobileVacationHours; _Sys_Log sysLog = new _Sys_Log(); sysLog.Date = ServerTime.Time; sysLog.EventInfo = log; sysLog.EventType = "变更考勤统计数据"; sysLog.HostName = sysLog.EventType; sysLog.LoginName = BasicInfo.LoginName; ctx._Sys_Log.InsertOnSubmit(sysLog); } else { string exce = string.Format("考勤统计表中【工号{0},{1}年{2}月】数据记录不等于1,可能不存在或存在多条记录", summary.WorkID, summary.Year, summary.Month); throw new Exception(exce); } } ctx.SubmitChanges(); } }