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);
                }
            }
        }
        internal void Check_GioDaXN(DateTime pTimeStr, string pSource, int tempMachineNo
                                    , int pIDXacnhan, int pShiftID, string pShiftCode,
                                    TimeSpan pOnduty, TimeSpan pOffduty, TimeSpan pLateGrace, TimeSpan pEarlyGrace, TimeSpan pAfterOT, bool pTinhPC150,
                                    int pDayCount, TimeSpan pWorkingTime, Single pWorkingday
                                    , DateTime pTimeStrIn, DateTime pTimeStrOut, int pOTMin, string pNote)
        {
            if (tempMachineNo % 2 == 1)
            {
                cChkIn tChkIn = new cChkIn()
                {
                    TimeStr = pTimeStr, Source = pSource, MachineNo = tempMachineNo
                };
                ds_Check_ID.Add(tChkIn);
            }
            else
            {
                cChkOut tChkOut = new cChkOut()
                {
                    TimeStr = pTimeStr, Source = pSource, MachineNo = tempMachineNo
                };
                ds_Check_ID.Add(tChkOut);

                if (ds_Check_ID.Count > 1 && ds_Check_ID[ds_Check_ID.Count - 2].GetType() == typeof(cChkIn))
                {
                    cChkIn    tmpChkIn    = (cChkIn)ds_Check_ID[ds_Check_ID.Count - 2];
                    cChkOut   tmpChkOut   = (cChkOut)ds_Check_ID[ds_Check_ID.Count - 1];
                    cChkInOut tmpChkINOUT = new cChkInOut()
                    {
                        Vao           = tmpChkIn, Raa = tmpChkOut, HaveINOUT = 1,
                        TongGioThuc   = tmpChkOut.TimeStr - tmpChkIn.TimeStr,
                        DaXN          = true, IsOT = true, TinhPC150 = pTinhPC150,
                        LamThem       = new TimeSpan(0, pOTMin, 0),
                        ThuocNgayCong = ThamSo.GetDate(tmpChkIn.TimeStr),                         // [TBD] xem lại thuộc ngày công
                    };
                    cShift tmpThuocCa;
                    if (pShiftID > 0)                       // ca trong ds ca
                    {
                        tmpThuocCa = DSCa.Find(item => item.ShiftID == pShiftID);
                    }
                    else if (pShiftID > int.MinValue + 100 && pShiftID < 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       = pShiftID, ShiftCode = pShiftCode,
                            OnnDutyTS     = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT,
                            WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 0
                        }
                    }
                    ;                             //[TBD]
                    else if (pShiftID < int.MinValue + 100)
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID       = pShiftID, ShiftCode = pShiftCode,
                            OnnDutyTS     = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT,
                            WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1
                        }
                    }
                    ;
                    else
                    {
                        tmpThuocCa = new cShift()
                        {
                            ShiftID       = pShiftID, ShiftCode = "XacNhan8h",
                            OnnDutyTS     = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT,
                            WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 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");
                    }

                    tmpChkINOUT.ThuocCa = tmpThuocCa;
                    tmpChkINOUT.QuaDem  = tmpThuocCa.QuaDem;
                    XL.TinhCongTheoCa(tmpChkINOUT, tmpChkINOUT.ThuocCa);
                    DSVaoRa.Add(tmpChkINOUT);
                }
            }
        }