private void EAR_TO_ABS() { //NhuY (2017/02/07): xét quy định số phút vắng if (ASB_MN > 0 && EAR_MN >= ASB_MN) { ABS_TM = 1; EAR_MN = EAR_TM = 0; if (NOT_DR.IndexOf("Absent") >= 0) { NOT_DR = NOT_DR.Replace("Early;", ""); } else { NOT_DR = NOT_DR.Replace("Early", "Absent"); } } }
public void UpdateSql() { string sql1 = ""; string sql = ""; Get_ATT_HR(); var phep = (from l in _db.Tblleave join tl in _db.Tbltypeleave on l.LeaId equals tl.LeaId where l.EmpId == EMP_ID && l.StrDt.Value.CompareTo(DateTime.Parse(ATT_DT)) <= 0 && l.EndDt.Value.CompareTo(DateTime.Parse(ATT_DT)) >= 0 select new ExLeave() { leave = l, leave_name = tl.LeaNm }).ToList(); GetPhep(phep); //Round(); GetNote(); var roster = _db.Tblroster.Where(x => x.ShiId == SHI_ID).FirstOrDefault(); double ADD_H1 = T_String.IsNullTo00(roster.AddH1 + ""); double ADD_H2 = T_String.IsNullTo00(roster.AddH2 + ""); double CON_H1 = T_String.IsNullTo00(roster.ConH1 + ""); double CON_H2 = T_String.IsNullTo00(roster.ConH2 + ""); if (NOT_DD + "" != "") { NOT_DR = NOT_DD + "; " + NOT_DR; } var _tdt = DateTime.Parse(ATT_DT); var att = _db.Tbldetailsattendance.Where(x => x.AttDt == _tdt && x.EmpId == EMP_ID).FirstOrDefault(); if (att == null) { return; } sql = "Update [" + tb + "] set "; double WRK_HR = 0; for (int i = 0; i < Name.Count; i++) { switch (Name[i] + "") { case "ATT_HR": if (ATT_MAX > 0) { if (ADD_H1 > 0 && (Double)Data[i] > CON_H1) { ATT_MAX = T_String.CongTG(ATT_MAX, ADD_H1); if ((Double)Data[i] > 0) { Data[i] = T_String.CongTG(ADD_H1, (Double)Data[i]); } } WRK_HR = T_String.CongTG(WRK_HR, (Double)Data[i]); //T_String.IsNullTo00(Data[i]+"")); int tam = (int)T_String.CongTG(T_String.IsNullTo0(Data[i] + ""), OTR_HR); if (sql1 != "") { sql1 += ","; } //var tmpa = T_String.DT_HourMinConvertToHour(tam); //var tmpb = T_String.DT_HourMinConvertToHour((int)ATT_MAX); sql1 += "ATT_DY=" + T_String.DT_HourMinConvertToHour(tam) / T_String.DT_HourMinConvertToHour((int)ATT_MAX); T_String.SetPropValue(att, "AttDy", T_String.DT_HourMinConvertToHour(tam) / T_String.DT_HourMinConvertToHour((int)ATT_MAX)); } else { if (sql1 != "") { sql1 += ","; } sql1 += "ATT_DY=0"; T_String.SetPropValue(att, "AttDy", 0); } break; case "NIG_HR": if ((Double)Data[i] > CON_H2) { if (NIG_MAX > 0) { if (ADD_H2 > 0) { NIG_MAX = T_String.CongTG(NIG_MAX, ADD_H2); if ((Double)Data[i] > 0) { Data[i] = T_String.CongTG(ADD_H2, (Double)Data[i]); } } WRK_HR = T_String.CongTG(WRK_HR, (Double)Data[i]); int tam = (int)T_String.CongTG(T_String.IsNullTo0(Data[i] + ""), OTR_HR); if (sql1 != "") { sql1 += ","; } sql1 += "NigDy=" + T_String.DT_HourMinConvertToHour(tam) / T_String.DT_HourMinConvertToHour((int)NIG_MAX); T_String.SetPropValue(att, "NigDy", T_String.DT_HourMinConvertToHour(tam) / T_String.DT_HourMinConvertToHour((int)NIG_MAX)); } else { if (sql1 != "") { sql1 += ","; } sql1 += "NIG_DY=0"; T_String.SetPropValue(att, "NigDy", 0); } } break; case "OTT_HR": case "OVO_HR": break; } if (sql1 != "") { sql1 += ","; } sql1 += Name[i] + "=" + Data[i]; var _name = Regex.Replace((Name[i] + "").ToLower(), @"([a-z0-9]+)_([a-z0-9]+)", m => string.Format("{0}{1}", Char.ToUpperInvariant(m.Groups[1].Value[0]) + m.Groups[1].Value.Substring(1), Char.ToUpperInvariant(m.Groups[2].Value[0]) + m.Groups[2].Value.Substring(1))); /*(Name[i] + "").ToLower();*/ T_String.SetPropValue(att, _name + "", Data[i]); } sql = sql + sql1; if (ABS_TM > 0) { double max = T_String.CongTG(ATT_MAX, NIG_MAX); ABS_MN = T_String.TruTG(max, WRK_HR); ABS_MN = T_String.TruTG(ABS_MN, LEA_H1); ABS_MN = T_String.TruTG(ABS_MN, LEA_H2); ABS_MN = T_String.TruTG(ABS_MN, LEA_H3); ABS_MN = T_String.TruTG(ABS_MN, OTR_HR); if (ABS_MN == 0) { ABS_TM = 0; NOT_DR = NOT_DR.Replace("Absent;", ""); } } sql += ",NOT_DR=N'" + NOT_DR + "'"; T_String.SetPropValue(att, "NotDr", NOT_DR); sql += ",NOT_D1=N'" + NOT_D1 + "'"; T_String.SetPropValue(att, "NotD1", NOT_D1); sql += ",LAT_MN=N'" + LAT_MN + "'"; T_String.SetPropValue(att, "LatMn", LAT_MN); sql += ",LAT_TM=N'" + LAT_TM + "'"; T_String.SetPropValue(att, "LatTm", LAT_TM); sql += ",EAR_MN=N'" + EAR_MN + "'"; T_String.SetPropValue(att, "EarMn", EAR_MN); sql += ",EAR_TM=N'" + EAR_TM + "'"; T_String.SetPropValue(att, "EarTm", EAR_TM); sql += ",ABS_MN=N'" + ABS_MN + "'"; T_String.SetPropValue(att, "AbsMn", ABS_MN); sql += ",ABS_TM=N'" + ABS_TM + "'"; T_String.SetPropValue(att, "AbsTm", ABS_TM); sql += ",OTR_HR=" + OTR_HR.ToString("#0") + ""; T_String.SetPropValue(att, "OtrHr", OTR_HR.ToString("#0")); sql += ",LEA_H1=" + LEA_H1.ToString("#0") + ""; T_String.SetPropValue(att, "LeaH1", LEA_H1.ToString("#0")); sql += ",LEA_I1=N'" + LEA_I1 + "'"; T_String.SetPropValue(att, "LeaI1", LEA_I1); sql += ",LEA_H2=" + LEA_H2.ToString("#0") + ""; T_String.SetPropValue(att, "LeaH2", LEA_H2.ToString("#0")); sql += ",LEA_I2=N'" + LEA_I2 + "'"; T_String.SetPropValue(att, "LeaI2", LEA_I2); sql += ",LEA_H3=" + LEA_H3.ToString("#0") + ""; T_String.SetPropValue(att, "LeaH3", LEA_H3.ToString("#0")); sql += ",LEA_I3=N'" + LEA_I3 + "'"; T_String.SetPropValue(att, "LeaI3", LEA_I3); _db.SaveChanges(); sql += " where EMP_ID=N'" + EMP_ID + "' and ATT_DT='" + ATT_DT + "'"; }