public static void TaoCaTuDo(cShift pCa, DateTime pCheckInTime, TimeSpan pWorkingTime, TimeSpan pchophepvaotreTS, TimeSpan pchopheprasomTS, TimeSpan pbatdaulamthemTS, float pWorkingDay)
 {
     pCa.OnnDutyTS       = pCheckInTime.TimeOfDay;
     pCa.OffDutyTS       = pCheckInTime.TimeOfDay + pWorkingTime;
     pCa.LateGraceTS     = pchophepvaotreTS;
     pCa.EarlyGraceTS    = pchopheprasomTS;
     pCa.AfterOTTS       = pbatdaulamthemTS;
     pCa.chophepvaotreTS = pCa.OnnDutyTS.Add(pchophepvaotreTS);
     pCa.chopheprasomTS  = pCa.OffDutyTS.Subtract(pchopheprasomTS);
     pCa.batdaulamthemTS = pCa.OffDutyTS.Add(pbatdaulamthemTS);
     pCa.DayCount        = pCa.OffDutyTS.Days;
     pCa.QuaDem          = (pCa.OffDutyTS.Days == 1);
     pCa.WorkingTimeTS   = pWorkingTime;
     pCa.Workingday      = pWorkingDay;
     pCa.LunchMinute     = ThamSo._0gio;
 }
 public void XetCa(List <cChkInOut_A> dsCIO, List <cShift> dsca)
 {
     for (int i = 0; i < dsCIO.Count; i++)
     {
         cChkInOut_A CIO = dsCIO[i];
         cShift      ca  = XetCa_1(CIO, dsca);
         if (ca != null)
         {
             if (ca.Workingday == 2f && ca.OnnDutyTS > ThamSo._20h00)
             {
                 cChk raaca3 = new cChkOut_A()
                 {
                     GioLienQuan = null, MachineNo = 22, Source = "O", TimeStr = CIO.Vao.TimeStr.Date.Add(ca.OnnDutyTS).Add(ThamSo._8gio)
                 };
                 cChk vaoca1 = new cChkInn_A()
                 {
                     GioLienQuan = null, MachineNo = 21, Source = "I", TimeStr = CIO.Vao.TimeStr.Date.Add(ca.OnnDutyTS).Add(ThamSo._8gio1giay)
                 };
                 CIO.Raa = raaca3;
                 i       = i - 1;
                 cChkInOut_A newCIO = new cChkInOut_A()
                 {
                     Vao = vaoca1, Raa = CIO.Raa, HaveINOUT = 1,
                 };
                 dsCIO.Insert(i, newCIO);
             }
             else
             {
                 CIO.ThuocCa = ca;
             }
         }
         else
         {
             ca = new cShift()
             {
                 ShiftID = int.MinValue, ShiftCode = "Ca 8 tiếng"
             };
             TaoCaTuDo(ca, CIO.Vao.TimeStr, ThamSo._8gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1f);
             CIO.ThuocCa = ca;
         }
     }
 }
示例#3
0
        public void XetCa(List <cChkInOut_A> dsCIO, List <cShift> dsca, bool macdinhtinhPC150)
        {
            int i = 0;

            while (i < dsCIO.Count)
            {
                cChkInOut_A CIO = dsCIO[i];
                if (CIO.HaveINOUT < 0)
                {
                    if (CIO.HaveINOUT == -1)
                    {
                        //CIO.kiem
                    }
                    else
                    {
                    }
                    i++;
                    continue;
                }
                cShift ca = KiemtraThuocKhoangHieuCa(CIO, dsca);
                if (ca != null)
                {
                    if (ca.Workingday == 2f && ca.OnnDutyTS > ThamSo._20h00)
                    {
                        List <cChk> gioLQvaoca3 = (CIO.Vao.GioLienQuan != null)
                                                                                                         ? new List <cChk>(CIO.Vao.GioLienQuan)
                                                                                                         : new List <cChk>();
                        List <cChk> gioLQraaca1 = (CIO.Raa.GioLienQuan != null)
                                                                                                        ? new List <cChk>(CIO.Raa.GioLienQuan)
                                                                                                         : new List <cChk>();

                        cChk raaca3 = new cChkOut_A()
                        {
                            GioLienQuan = null, MachineNo = 22, Source = "PC", TimeStr = CIO.Vao.TimeStr.Date.Add(ca.OnnDutyTS).Add(ThamSo._8gio)
                        };
                        cChk vaoca1 = new cChkInn_A()
                        {
                            GioLienQuan = null, MachineNo = 21, Source = "PC", TimeStr = CIO.Vao.TimeStr.Date.Add(ca.OnnDutyTS).Add(ThamSo._8gio1giay)
                        };
                        cChk vaoca3 = new cChkInn_A()
                        {
                            GioLienQuan = gioLQvaoca3, MachineNo = CIO.Vao.MachineNo, Source = CIO.Vao.Source, TimeStr = CIO.Vao.TimeStr
                        };
                        cChk raaca1 = new cChkInn_A()
                        {
                            GioLienQuan = gioLQraaca1, MachineNo = CIO.Raa.MachineNo, Source = CIO.Raa.Source, TimeStr = CIO.Raa.TimeStr
                        };
                        dsCIO[i] = new cChkInOut_A()
                        {
                            TinhPC150 = macdinhtinhPC150, Vao = vaoca3, Raa = raaca3, TG = new ThoiGian(), HaveINOUT = 1, TongGioThuc = raaca3.TimeStr - vaoca3.TimeStr, ThuocNgayCong = vaoca3.TimeStr.Date, TimeStrDaiDien = vaoca3.TimeStr
                        };
                        cShift ca3 = dsca.Find(o => o.OnnDutyTS > ThamSo._20h00 && o.Workingday == 1f);
                        dsCIO[i].ThuocCa = ca3;
                        dsCIO[i].QuaDem  = true;

                        cChkInOut_A newCIO = new cChkInOut_A()
                        {
                            TinhPC150 = macdinhtinhPC150, Vao = vaoca1, Raa = raaca1, TG = new ThoiGian(), HaveINOUT = 1, TongGioThuc = raaca1.TimeStr - vaoca1.TimeStr, ThuocNgayCong = vaoca1.TimeStr.Date, TimeStrDaiDien = vaoca1.TimeStr
                        };
                        cShift ca1 = dsca.Find(o => o.OnnDutyTS <= ThamSo._05h45 && o.Workingday == 1f);
                        newCIO.ThuocCa = ca1;
                        newCIO.QuaDem  = false;

                        // vì hàm insert ko cho phép chèn ở vị trí > số lượng phần tử
                        // => nên nếu i là phần tử cuối thì add vào cuối danh sách, ngược lại thì insert vào vị trí i+1
                        if (i == (dsCIO.Count - 1))
                        {
                            dsCIO.Add(newCIO);
                        }
                        else
                        {
                            dsCIO.Insert(i + 1, newCIO);
                        }
                        i = i + 2;                         // +2 vì i là ca3, i+1 là ca 1
                    }
                    else
                    {
                        CIO.TinhPC150 = macdinhtinhPC150;
                        CIO.ThuocCa   = ca;
                        i++;
                    }
                }
                else
                {
                    ca = new cShift()
                    {
                        ShiftID = int.MinValue, ShiftCode = "Ca 8 tiếng"
                    };
                    TaoCaTuDo(ca, CIO.Vao.TimeStr, ThamSo._8gio, ThamSo._05phut, ThamSo._10phut, ThamSo._30phut, 1f);
                    CIO.TinhPC150 = macdinhtinhPC150;
                    CIO.ThuocCa   = ca;
                    i++;
                }
            }
        }
        public void ArrayRowsToDS_CIO_V(DataRow[] arrRows)   // cấu trúc là cấu trúc ghép 2 bảng checkinout và xác nhận
        {
            if (DS_CIO_V == null)
            {
                DS_CIO_V = new List <cChkInOut_V>();
            }
            else
            {
                DS_CIO_V.Clear();
            }

            if (arrRows.Length != 0)
            {
                for (int i = 0; i < arrRows.Length; i = i + 2)
                {
                    DataRow rowInn = arrRows[i];
                    if (i + 1 >= arrRows.Length)
                    {
                        continue;                          // ko có phần tử kế tiếp để xét
                    }
                    DataRow rowOut = arrRows[i + 1];
                    int     IDinn  = (int)rowInn["IDXacNhanCaVaLamThem"];
                    int     IDout  = (int)rowOut["IDXacNhanCaVaLamThem"];
                    if (IDinn != IDout)// bị mất cặp -> giảm 1 để tăng 2 là thằng kế tiếp
                    {
                        i = i - 1;
                        continue;
                    }
                    // đủ điều kiện ghép  cặp
                    #region lấy thông tin
                    int      shiftID = (int)rowInn["ShiftID"];
                    string   shiftCode = rowInn["ShiftCode"].ToString();
                    int      dayCount = (int)rowInn["DayCount"];
                    Single   workingday = (Single)rowInn["Workingday"];
                    TimeSpan onnDutyTs, offDutyTs;
                    TimeSpan.TryParse(rowInn["Onduty"].ToString(), out onnDutyTs);
                    TimeSpan.TryParse(rowInn["Offduty"].ToString(), out offDutyTs);

                    TimeSpan afterOTTs    = new TimeSpan(0, (int)rowInn["AfterOT"], 0);
                    TimeSpan lateGraceTSS = new TimeSpan(0, (int)rowInn["LateGrace"], 0);
                    TimeSpan earlyGraceTS = new TimeSpan(0, (int)rowInn["EarlyGrace"], 0);

                    lateGraceTSS = onnDutyTs.Add(lateGraceTSS);
                    offDutyTs    = offDutyTs.Add(new TimeSpan(dayCount, 0, 0, 0));
                    earlyGraceTS = offDutyTs.Subtract(earlyGraceTS);
                    afterOTTs    = offDutyTs.Add(afterOTTs);
                    int  pOTMin        = (int)rowInn["OTMin"];
                    bool tempTinhPC150 = false;
                    if (rowInn["TinhPC150"] == DBNull.Value)
                    {
                        tempTinhPC150 = false;
                    }
                    else
                    {
                        tempTinhPC150 = (bool)rowInn["TinhPC150"];
                    }

                    int      wkt          = int.Parse(rowInn["WorkingTime"].ToString());
                    TimeSpan pWorkingTime = new TimeSpan(0, wkt, 0, 0);

                    string   SourceInn    = (string)rowInn["Source"];
                    string   SourceOut    = (string)rowOut["Source"];
                    int      MachineNoInn = (int)rowInn["MachineNo"];
                    int      MachineNoOut = (int)rowOut["MachineNo"];
                    DateTime timeInn      = (DateTime)rowInn["TimeStr"];
                    DateTime timeOut      = (DateTime)rowOut["TimeStr"];
                    #endregion

                    cChkInn_V chkInnV = new cChkInn_V()
                    {
                        GioLienQuan = null, ID = IDinn, MachineNo = MachineNoInn, Source = SourceInn, TimeStr = timeInn
                    };
                    cChkOut_V chkOutV = new cChkOut_V()
                    {
                        GioLienQuan = null, ID = IDout, MachineNo = MachineNoOut, Source = SourceOut, TimeStr = timeOut
                    };
                    cChkInOut_V chkInOutV = new cChkInOut_V()
                    {
                        Vao       = chkInnV, Raa = chkOutV, HaveINOUT = 1, TongGioThuc = chkOutV.TimeStr - chkInnV.TimeStr, TimeStrDaiDien = chkInnV.TimeStr,
                        TinhPC150 = tempTinhPC150, LamThem = new TimeSpan(0, 0, pOTMin, 0), ThuocNgayCong = ThamSo.GetDate(chkInnV.TimeStr),
                    }; // [TBD] xem lại thuộc ngày công

                    cShift tmpThuocCa;
                    if (shiftID > 0)
                    {
                        tmpThuocCa = DSCa.Find(item => item.ShiftID == shiftID);
                    }
                    else if (shiftID > int.MinValue + 100 && shiftID < 0) // ca tách và ca kết hợp  [Chú ý] + 100 vì chừa khoảng này cho các loại khác
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 0
                        }
                    }
                    ;                                      //[TBD]
                    else if (shiftID < int.MinValue + 100) // ca tự do 8 tiếng
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1
                        }
                    }
                    ;
                    else
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = "XacNhan8h", OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1
                        };                                                                                                                                                                                                                                                                                                                                                                //[TBD]
                    }
                    if (tmpThuocCa == null)
                    {
                        log4net.ILog log = log4net.LogManager.GetLogger("ERROR function Check_GioDaXN ");
                        log.Fatal("ERROR function Check_GioDaXN");
                    }
                    chkInOutV.ThuocCa = tmpThuocCa;
                    chkInOutV.QuaDem  = tmpThuocCa.QuaDem;
                    XL.TinhCongTheoCa(chkInOutV, chkInOutV.ThuocCa);//[TBD]
                    DS_CIO_V.Add(chkInOutV);
                }
            }
        }
示例#5
0
        public void ArrayRowsToDS_CIO_V(DataRow[] arrRows)           // cấu trúc là cấu trúc ghép 2 bảng checkinout và xác nhận
        {
            DS_CIO_V.Clear();

            if (arrRows.Length != 0)
            {
                for (int i = 0, j = 1; i < arrRows.Length;)                    //i là index rowInn, j là index row out

                {
                    DataRow rowInn = arrRows[i];
                    if (j >= arrRows.Length)
                    {
                        break;                                          // ko có phần tử kế tiếp để xét
                    }
                    DataRow  rowOut       = arrRows[j];
                    int      IDinn        = (int)rowInn["ID"];
                    int      IDout        = (int)rowOut["ID"];
                    string   SourceInn    = (string)rowInn["Source"];
                    string   SourceOut    = (string)rowOut["Source"];
                    int      MachineNoInn = (int)rowInn["MachineNo"];
                    int      MachineNoOut = (int)rowOut["MachineNo"];
                    DateTime timeInn      = (DateTime)rowInn["TimeStr"];
                    DateTime timeOut      = (DateTime)rowOut["TimeStr"];
                    if (IDinn != IDout)                    // bị mất cặp -> bỏ qua đến cặp kế tiếp, phải tăng i, j vì i+1=j ==> j+1
                    {
                        i = i + 1;
                        j = j + 1;
                        continue;
                    }
                    // cùng id --> xét có gần nhau ko
                    if (MachineNoInn % 2 == MachineNoOut % 2)
                    {
                        j = j + 1;
                        continue;
                    }
                    // đủ điều kiện ghép  cặp
                    #region lấy thông tin
                    int      shiftID = (int)rowInn["ShiftID"];
                    string   shiftCode = rowInn["ShiftCode"].ToString();
                    int      dayCount = (int)rowInn["DayCount"];
                    Single   workingday = (Single)rowInn["Workingday"];
                    TimeSpan onnDutyTs, offDutyTs;
                    TimeSpan.TryParse(rowInn["Onduty"].ToString(), out onnDutyTs);
                    TimeSpan.TryParse(rowInn["Offduty"].ToString(), out offDutyTs);

                    TimeSpan afterOTTs    = new TimeSpan(0, (int)rowInn["AfterOT"], 0);
                    TimeSpan lateGraceTSS = new TimeSpan(0, (int)rowInn["LateGrace"], 0);
                    TimeSpan earlyGraceTS = new TimeSpan(0, (int)rowInn["EarlyGrace"], 0);

                    lateGraceTSS = onnDutyTs.Add(lateGraceTSS);
                    // add thêm 1 ngày daycount nếu có
                    offDutyTs    = offDutyTs.Add(new TimeSpan(dayCount, 0, 0, 0));
                    earlyGraceTS = offDutyTs.Subtract(earlyGraceTS);
                    afterOTTs    = offDutyTs.Add(afterOTTs);
                    int  pOTMin        = (int)rowInn["OTMin"];
                    bool tempTinhPC150 = false;
                    if (rowInn["TinhPC150"] == DBNull.Value)
                    {
                        tempTinhPC150 = false;
                    }
                    else
                    {
                        tempTinhPC150 = (bool)rowInn["TinhPC150"];
                    }

                    int      wkt          = int.Parse(rowInn["WorkingTime"].ToString());
                    TimeSpan pWorkingTime = new TimeSpan(0, wkt, 0);

                    #endregion

                    cChkInn_V chkInnV = new cChkInn_V()
                    {
                        GioLienQuan = null, ID = IDinn, MachineNo = MachineNoInn, Source = SourceInn, TimeStr = timeInn
                    };
                    cChkOut_V chkOutV = new cChkOut_V()
                    {
                        GioLienQuan = null, ID = IDout, MachineNo = MachineNoOut, Source = SourceOut, TimeStr = timeOut
                    };
                    cChkInOut_V chkInOutV = new cChkInOut_V()
                    {
                        Vao            = chkInnV,
                        Raa            = chkOutV,
                        TG             = new ThoiGian(),
                        HaveINOUT      = 1,
                        TongGioThuc    = chkOutV.TimeStr - chkInnV.TimeStr,
                        TimeStrDaiDien = chkInnV.TimeStr,
                        TinhPC150      = tempTinhPC150,
                        LamThem        = new TimeSpan(0, 0, pOTMin, 0),
                        ThuocNgayCong  = chkInnV.TimeStr.Date,
                    };                     // [TBD] xem lại thuộc ngày công

                    cShift tmpThuocCa;
                    if (shiftID > 0)
                    {
                        tmpThuocCa = DSCa.Find(item => item.ShiftID == shiftID);
                    }
                    else if (shiftID > int.MinValue + 100 && shiftID < 0)                     // ca tách và ca kết hợp  [Chú ý] + 100 vì chừa khoảng này cho các loại khác
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 0
                        }
                    }
                    ;                                                          //[TBD]
                    else if (shiftID < int.MinValue + 100)                     // ca tự do 8 tiếng
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1
                        }
                    }
                    ;
                    else
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID = shiftID, ShiftCode = "XacNhan8h", OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1
                        };                                                                                                                                                                                                                                                                                                                                                                                        //[TBD]
                    }
                    if (tmpThuocCa == null)
                    {
                        log.Fatal("ERROR function Check_GioDaXN");
                    }
                    chkInOutV.ThuocCa = tmpThuocCa;
                    chkInOutV.QuaDem  = tmpThuocCa.QuaDem;
                    XL.TinhCongTheoCa(chkInOutV, chkInOutV.ThuocCa);                    //[TBD]
                    DS_CIO_V.Add(chkInOutV);

                    // sau khi thực hiện xong thì tăng
                    i = i + 2;
                    j = j + 2;
                }
            }
        }