public void Note(string st) { // if(thaisan.rows<=0) // { if (NOT_DR.IndexOf(st) < 0) { NOT_DR += st; } // } }
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 + "'"; }
public void GetNote() { double cc = IsN(rsca[0].OnnTm); if (T_String.IsNullTo00(ToDayDTTime.ToString("yyyyMMddHHmm")) < T_String.IsNullTo00(DateTime.Parse(ATT_DT).ToString("yyyyMMdd") + cc.ToString("0000"))) { return; } double ONN_MN = IsD(SYS_SETTING_ATT.ONN_MN); double OFF_MN = IsD(SYS_SETTING_ATT.OFF_MN); ASB_MN = IsD(SYS_SETTING_ATT.ABS_MN); int index = -1; 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(); var phep_l = phep.Select(x => x.leave).ToList(); if (phep.Count() > 0 && phep[0].leave.DayBt + "" == "True") { return; } LEA_OUT = T_String.CongTG(OTR_HR, LEA_OUT); LEA_OUT = T_String.CongTG(OTR_HR, LEA_H1); LEA_OUT = T_String.CongTG(OTR_HR, LEA_H2); LEA_OUT = T_String.CongTG(OTR_HR, LEA_H3); Double tt = T_String.CongTG(ATT_MAX, NIG_MAX); if (LEA_OUT >= tt && tt > 0) { return; } if (NOT_DR.IndexOf("Abnormal") >= 0) { return; } double m = 0, max = 0, min = 0, m1 = 0;//m1 so lan quet the , m= la thoi gian quet the truoc do double c = 0; Boolean QD = false; for (int j = 0; j < ATT.Count; j++) // thoi gian quet the { double t1 = IsN(ATT[j] + ""); if (j > 0 && t1 < IsN(ATT[j - 1]) && IsN(ATT[j]) > 0) { t1 = t1 + 2400; } if (t1 != 0) { if (t1 > max) { max = t1; } m = t1; m1 = j; if (min == 0) { min = t1; } } c = 0; QD = false; for (int i = 0; i < rsca.Count(); i++) // chay theo ca { double c01 = -1; if (i >= 1) { c01 = IsN(rsca[i - 1].OffTm); // gio vao } double c1 = IsN(rsca[i].OnnTm); // gio vao double c2 = IsN(rsca[i].OffTm); // gio ra double giothaisanIN = IsN(rsca[i].ManIn); double giothaisanOU = IsN(rsca[i].ManOu); if (c1 < c)// qua dem { QD = true; } if (c2 < c1) // qua dem { c2 = c2 + 2400; QD = true; } else { if (QD) { c2 = c2 + 2400; //c1=c2+2400; c1 = c1 + 2400; //NhuY } } c = c2; if (giothaisan > 0) { c1 = (giothaisanIN > 0 ? giothaisanIN : c1); c2 = (giothaisanOU > 0 ? giothaisanOU : c2); } if (rsca[i].LatBt + "" == "True" && (rsca[i].TypId == "ATT_HR" || rsca[i].TypId == "NIG_HR")) { if (j % 2 == 0 && t1 <= c1)// Late { break; } if ((j % 2 == 0 && t1 < c2 && t1 > c1) || (min != 0 && t1 == min)) // Late | (min!=0 && t1==min) | gio vao dau tien { if ((T_String.CongTG(c1, ASB_MN)) <= t1 && ASB_MN != 0) { if (phep.Count() > 0 /*|| OutTrip.rows > 0*/) { if (phep.Count() > 0 && phep[i].leave.DayBt + "" == "True") { return; } else { //if (!CheckPhep(t1, phep, j) && !(CheckPhep(c1, phep, j) && (min != 0 && t1 == min))) if (!CheckPhep(t1, phep_l, j) && (min != 0 && t1 == min)) { //if (!CheckPhep(t1, OutTrip, j) && !(CheckPhep(c1, OutTrip, j) && (min != 0 && t1 == min)))//Xét công tác: bỏ, vì ko sử dụng chức năng này { NOT_DR += "Absent" + ";"; //GetPhep(phep); NOT_D1 += j.ToString("00"); ABS_TM++; EAR_TO_ABS(); return; } } } } else { NOT_DR += "Absent" + ";"; //GetPhep(phep); NOT_D1 += j.ToString("00"); ABS_TM++; EAR_TO_ABS(); return; } } if (T_String.CongTG(c1, ONN_MN) <= t1) { if (!CheckPhep(t1, phep_l, j) && !(CheckPhep(c1, phep_l, j) && (min != 0 && t1 == min))) { //if (/*!CheckPhep(t1, OutTrip, j) &&*/ !(/*CheckPhep(c1, OutTrip, j) &&*/ (min != 0 && t1 == min))) //{ Double LT = GetHourAndPhep(c1, t1, phep_l); if (t1 > c2) { LT = GetHourAndPhep(c1, c2, phep_l); } else { LT = GetHourAndPhep(c1, t1, phep_l); } Note("Late" + ";"); NOT_D1 += j.ToString("00"); LAT_MN = T_String.CongTG(LT, LAT_MN); LAT_TM++; //} } } } if (j % 2 == 1 && t1 > c1 && t1 < c2) // early cu Tan doi { if (T_String.CongTG(t1, OFF_MN) <= c2) { if (!CheckPhep(t1, phep_l, j)) { //if (!CheckPhep(t1, OutTrip, j)) //{ index = i; Double EA = GetHourAndPhep(t1, c2, phep_l); Note("Early" + ";"); NOT_D1 += j.ToString("00"); EAR_MN = T_String.CongTG(EA, EAR_MN); EAR_TM++; EAR_TO_ABS(); return; //} } } break; } } } } if (m == 0) // neu ko quet the gi het { double t1; if (ATT.Count == 0) { t1 = 0; } else { t1 = IsN(ATT[0] + ""); } // //NhuY: Neu la ca cn hoac le thi ko xet absent // if(phep.record(0,"DAY_BT")+""=="True" || T_String.GetDataFromSQL("COUNT(*)", "FILC02B", // "SHI_ID=N'" + rsca.record(0, "SHI_ID") + "' AND (TYP_ID='ATT_HR' OR TYP_ID='NIG_HR')")=="0") // { // return; // } //NhuY: Neu la ca cn hoac le thi ko xet absent if (phep_l[0].DayBt + "" == "True" || !IsWorkShift) { return; } else // ko quet the { if (phep.Count() <= 0 /*&& OutTrip.rows <= 0*/) { NOT_DR += "Absent" + ";"; //GetPhep(phep); ABS_TM++; return; } Boolean QD1 = false; c = 0; for (int i = 0; i < rsca.Count(); i++) { double c1 = IsN(rsca[i].OnnTm); // gio vao double c2 = IsN(rsca[i].OffTm); // gio ra double giothaisanIN = IsN(rsca[i].ManIn); double giothaisanOU = IsN(rsca[i].ManOu); if (c1 < c)// qua dem { QD1 = true; } if (c2 < c1) // qua dem { c2 = c2 + 2400; QD1 = true; } else { if (QD1) { c2 = c2 + 2400; c1 = c2 + 2400; } } c = c2; if (giothaisan > 0) { // c1=T_String.CongTG(c1,giothaisanIN); // c2=T_String.TruTG(c2,giothaisanOU); //NhuY 2017/03/28 c1 = (giothaisanIN > 0 ? giothaisanIN : c1); c2 = (giothaisanOU > 0 ? giothaisanOU : c2); } if (rsca[i].LatBt + "" == "True" || (rsca[i].TypId == "ATT_HR" || rsca[i].TypId == "NIG_HR")) { if (phep.Count() > 0 /*|| OutTrip.rows > 0*/) { if (!CheckPhep(c1, phep_l, 0)) { //if (!CheckPhep(c1, OutTrip, 0)) //{ NOT_DR += "Absent" + ";"; //GetPhep(phep); ABS_TM++; NOT_D1 = "00"; EAR_TO_ABS(); return; //} } if (!CheckPhep(c2, phep_l, 0)) { //if (!CheckPhep(c2, OutTrip, 0)) //{ NOT_DR += "Absent" + ";"; //GetPhep(phep); ABS_TM++; NOT_D1 = "00"; EAR_TO_ABS(); return; //} } } } } } } else // co quet the kiem tra xem co phai chuyen du lieu ngay hien tai ko { if (ATT_DT != ToDayDT) { QD = false; for (int i = rsca.Count() - 1; i >= 0; i--) { if (rsca[i].LatBt + "" == "True" || (rsca[i].TypId == "ATT_HR" || rsca[i].TypId == "NIG_HR")) { double c1 = IsN(rsca[i].OnnTm); // gio vao double c2 = IsN(rsca[i].OffTm); // gio ra double giothaisanIN = IsN(rsca[i].ManIn); double giothaisanOU = IsN(rsca[i].ManOu); if (QD) { if (c1 > c2) { c2 = c2 + 2400; QD = true; } else { c2 = c2 + 2400; c1 = c1 + 2400; } } if (giothaisan > 0) { // c1=T_String.CongTG(c1,giothaisanIN); // c2=T_String.TruTG(c2,giothaisanOU); //NhuY 2017/03/28 c1 = (giothaisanIN > 0 ? giothaisanIN : c1); c2 = (giothaisanOU > 0 ? giothaisanOU : c2); } // if (max > c1 + 2400 && max > c2 + 2400) { max -= 2400; } if (index + 1 <= i) { double max11 = 0; if (max < c1) { max11 = c1; } else { max11 = max; } if (T_String.CongTG(max11, OFF_MN) <= c2) // max la gio quet the sau cung { if (!CheckPhep(max11, phep_l, 0)) { //if (!CheckPhep(max11, OutTrip, 0)) //{ Double v1 = 0, v2 = c2; if (max11 >= c1) { v1 = max11; } else { v1 = c1; } Double EA = GetHourAndPhep(v1, v2, phep_l); // if(T_String.CongTG(EA,OFF_MN)<0)// thai san // { Note("Early" + ";"); //NOT_D1+=i.ToString("00"); EAR_MN = T_String.CongTG(EA, EAR_MN); EAR_TM++; // } //} } } } else { if (index + 1 > i) { break; } } } } } } EAR_TO_ABS(); // //NhuY (2017/02/07): xét quy định số phút vắng // if (EAR_MN >= ABS_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"); // } }