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);
                }
            }
        }
示例#2
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;
                }
            }
        }