private void CalcOvertime(DataRow row, string colName) { var sqlUpdate = new Action <int, decimal>((timeCodeId, val) => { if (row[colId.FieldName] != DBNull.Value) { if (TimeCode.GetTimeCode(timeCodeId).ValueType == EnumValueType.Hours) { LabourTimeDetail.SqlUpdateHours((int)row[colId.FieldName], timeCodeId, val); } else { LabourTimeDetail.SqlUpdateAmount((int)row[colId.FieldName], timeCodeId, val); } } }); bool handled = false; if ((bool)row[colManual.FieldName] == false) { var ot = OvertimeLimit.GetOvertime(_headerRecord.ProjectId, (int)row[colEmpNum.FieldName]); var regTimeCode = TimeCode.GetTimeCodeList(EnumBillingRateType.Regular).SingleOrDefault(x => colName == EnterHoursI(x)); if (regTimeCode != null && regTimeCode.OvertimeId != null && ot != null) { int? currId = ConvertEx.ToNullable <int>(row[colId.FieldName]); decimal dayHours = LabourTimeEntry.GetDayHours(_headerRecord.ProjectId, (int)row[colEmpNum.FieldName], _headerRecord.LogDate, currId); decimal weekHours = LabourTimeEntry.GetWeekHours(_headerRecord.ProjectId, (int)row[colEmpNum.FieldName], _headerRecord.LogDate, currId); dayHours += ConvertEx.ToNullable <decimal>(row[colName]) ?? 0; weekHours += ConvertEx.ToNullable <decimal>(row[colName]) ?? 0; decimal overHours = ot.Calc(dayHours, weekHours); row[EnterHoursI(regTimeCode.OvertimeId.Value)] = overHours; sqlUpdate(regTimeCode.OvertimeId.Value, overHours); dayHours -= overHours; row[colName] = dayHours; sqlUpdate(regTimeCode.MatchId, dayHours); handled = true; } } if (!handled) { sqlUpdate(int.Parse(colName.Replace(strEnterHours, "")), ConvertEx.ToNullable <decimal>(row[colName]) ?? 0); } }