Esempio n. 1
0
        private void rad_CheckedChanged(object sender, EventArgs e)
        {
            if (cbCa_Vao.SelectedIndex == 0)
            {
                return;                                          // neu chon tuỳ chinh thi thoat ko lam gi het
            }
            cCaChuan ca = cbCa_Vao.SelectedItem as cCaChuan;     // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko.

            // neu ko hieu ca chuyen combo ve tùy chỉnh

            if (ca == null)
            {
                return;
            }

            bool kieugio = radVao.Checked;

            //kiểm tra coi thuộc ca nào, kiểu gì để thay đổi combox
            dtpGioMoi.ValueChanged -= DtpGioMoiValueChanged;
            DateTime x = DateTime.MinValue;

            x = (kieugio) ? DateTime.Today.Add(ca.OnnTS) : DateTime.Today.Add(ca.OffTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)));              //

            dtpGioMoi.Value = x;
            dtpGioMoi.Update();

            dtpGioMoi.ValueChanged += DtpGioMoiValueChanged;
        }
Esempio n. 2
0
        void dtpGio_Vao_ValueChanged(object sender, EventArgs e)
        {
            if (cbCa_Vao.SelectedIndex == 0)
            {
                return;                                      // neu chon tuỳ chinh thi thoat ko lam gi het
            }
            cCaChuan ca = cbCa_Vao.SelectedItem as cCaChuan; // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko.

            // neu ko hieu ca chuyen combo ve tùy chỉnh

            if (ca == null)
            {
                return;
            }
            DateTime x = dtpGio_Vao.Value;

            if (x.TimeOfDay >= ca.OnnInnTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) &&
                x.TimeOfDay <= ca.CutInnTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)))
            {
                // nằm trong khoảng hiểu thì ko làm gì hết
            }
            else  // nằm ngoài khoảng hiểu, chuyển về tùy chọn tùy chỉnh
            {
                cbCa_Vao.SelectedIndex = 0;
            }
        }
Esempio n. 3
0
        void DtpGioMoiValueChanged(object sender, EventArgs e)
        {
            if (cbCa_Vao.SelectedIndex == 0)
            {
                return;                                          // neu chon tuỳ chinh thi thoat ko lam gi het
            }
            cCaChuan ca = cbCa_Vao.SelectedItem as cCaChuan;     // lay ca duoc chon và kiem tra xem gio vao có nằm trong khoảng hiểu ca ko.

            // neu ko hieu ca chuyen combo ve tùy chỉnh

            if (ca == null)
            {
                return;
            }

            bool     kieugio = radVao.Checked;
            DateTime x       = dtpGioMoi.Value;

            if (kieugio)              // nếu chọn kiểu vào thì so sánh với ontimein, cutin
            {
                if (x.TimeOfDay >= ca.OnnInnTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) &&
                    x.TimeOfDay <= ca.CutInnTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)))
                {
                    // nằm trong khoảng hiểu thì ko làm gì hết
                }
                else                  // nằm ngoài khoảng hiểu, chuyển về tùy chọn tùy chỉnh
                {
                    cbCa_Vao.SelectedIndex = 0;
                }
            }
            else               // nếu chọn kiểu ra thì so sánh với ontimeout, cutout
            {
                if (x.TimeOfDay >= ca.OnnOutTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)) &&
                    x.TimeOfDay <= ca.CutOutTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)))
                {
                }
                else
                {
                    cbCa_Vao.SelectedIndex = 0;
                }
            }
        }
Esempio n. 4
0
        private void cbCa_Raa_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (cbCa_Raa.SelectedIndex == 0)
            {
                return;                                      // neu chon tuỳ chinh thi thoat ko lam gi het
            }
            cCaChuan ca = cbCa_Raa.SelectedItem as cCaChuan; // lay ca chon

            if (ca == null)
            {
                return;
            }
            // gán giờ theo ca, huỷ rồi bật lại sự kiện datetimepicker change
            dtpGio_Raa.ValueChanged -= dtpGio_Raa_ValueChanged;
            DateTime x = DateTime.Today.Add(ca.OffTS);

            dtpGio_Raa.Value = x;
            dtpGio_Raa.Update();
            dtpGio_Raa.ValueChanged += dtpGio_Raa_ValueChanged;
        }
Esempio n. 5
0
        private void cbCa_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (cbCa_Vao.SelectedIndex == 0)
            {
                return;                                           // neu chon tuỳ chinh thi thoat ko lam gi het
            }
            cCaChuan ca      = cbCa_Vao.SelectedItem as cCaChuan; // lay ca chon
            bool     kieugio = radVao.Checked;

            if (ca == null)
            {
                return;
            }
            // gán giờ theo ca, huỷ rồi bật lại sự kiện datetimepicker change
            dtpGioMoi.ValueChanged -= DtpGioMoiValueChanged;
            DateTime x = DateTime.MinValue;

            x = (kieugio) ? DateTime.Today.Add(ca.OnnTS) : DateTime.Today.Add(ca.OffTS.Subtract(new TimeSpan(ca.DayCount, 0, 0, 0)));              //

            dtpGioMoi.Value = x;
            dtpGioMoi.Update();
            dtpGioMoi.ValueChanged += DtpGioMoiValueChanged;
        }
Esempio n. 6
0
        private void ChuanBiDSLichTrinhVaCa()
        {
            XL.DSLichTrinh.Clear();
            XL.DSCa.Clear();
            XL.DSCaMoRong.Clear();

            // lấy danh sách lịch trình, mỗi dòng là 1 ca thuộc lịch trình => để duyệt từng lịch trình thì phải lấy dicstint
            var tableLichTrinh = DAL.LayDSLichTrinh();
            var tableDSCa      = DAL.LayDSCa();

            foreach (DataRow row in tableDSCa.Rows)
            {
                #region transfer dữ liệu từ row sang đối tượng
                var iShiftID   = (int)row["ShiftID"];
                var sShiftCode = row["ShiftCode"].ToString();

                TimeSpan tsOnDuty;
                TimeSpan.TryParse(row["Onduty"].ToString(), out tsOnDuty);
                TimeSpan tOffDuty;
                TimeSpan.TryParse(row["Offduty"].ToString(), out tOffDuty);
                var iDayCount = (int)row["DayCount"];
                tOffDuty = tOffDuty.Add(new TimeSpan(iDayCount, 0, 0, 0));

                var tOnTimeIn = tsOnDuty.Subtract(new TimeSpan(0, (int)row["OnTimeIn"], 0));
                var tCutIn    = tsOnDuty.Add(new TimeSpan(0, (int)row["CutIn"], 0));

                // phải add thêm 1 ngày daycount vì trong dữ liệu chỉ có chuỗi giờ thô : 05:45 không có ngày
                var tOnTimeOut = tOffDuty.Subtract(new TimeSpan(0, (int)row["OnTimeOut"], 0));
                var tCutOut    = tOffDuty.Add(new TimeSpan(0, (int)row["CutOut"], 0));

                var tAfterOT    = new TimeSpan(0, (int)row["AfterOT"], 0);
                var tLateGrace  = new TimeSpan(0, (int)row["LateGrace"], 0);
                var tEarlyGrace = new TimeSpan(0, (int)row["EarlyGrace"], 0);

                var tOnLunch  = XL2._0gio;
                var tOffLunch = XL2._0gio;
                if (row["OnLunch"] != DBNull.Value && row["OffLunch"] != DBNull.Value)
                {
                    TimeSpan.TryParse(row["OnLunch"].ToString(), out tOnLunch);
                    TimeSpan.TryParse(row["OffLunch"].ToString(), out tOffLunch);
                }

                var iShowPosition   = (int)row["ShowPosition"];
                var tempWorkingTime = int.Parse(row["WorkingTime"].ToString());
                var kyhieucc        = row["KyHieuCC"].ToString();
                var tempShift       = new cCaChuan {
                    ID              = iShiftID,
                    Code            = sShiftCode,
                    DayCount        = iDayCount,
                    QuaDem          = (iDayCount == 1),
                    OnnTS           = tsOnDuty,
                    OffTS           = tOffDuty,
                    OnnInnTS        = tOnTimeIn,
                    CutInnTS        = tCutIn,
                    OnnOutTS        = tOnTimeOut,
                    CutOutTS        = tCutOut,
                    AfterOTMin      = tAfterOT,
                    LateeMin        = tLateGrace,
                    EarlyMin        = tEarlyGrace,
                    Workingday      = (Single)row["Workingday"],
                    ShowPosition    = iShowPosition,
                    WorkingTimeTS   = new TimeSpan(0, tempWorkingTime, 0),
                    chophepTreTS    = tsOnDuty.Add(tLateGrace),
                    chophepSomTS    = tOffDuty - tEarlyGrace,
                    batdaulamthemTS = tOffDuty + tAfterOT,                    //[TBD] thay tOffDuty + XL2._30phut thành tempOffDuty + tempAfterOT --> đã thay
                    LunchMin        = tOffLunch.Subtract(tOnLunch),
                    KyHieuCC        = kyhieucc,
                };
                #endregion

                XL.DSCa.Add(tempShift);
            }
            var ca3va1 = XL.DSCa.Find(o => o.OnnTS == XL2._21h45 && o.Workingday == 2f);
            if (ca3va1 != null)
            {
                ca3va1.TachCa = true;
                var ca3 = XL.DSCa.Find(o => o.OnnTS == XL2._21h45 && o.Workingday == 1f);
                var ca1 = XL.DSCa.Find(o => o.OnnTS == XL2._05h45 && o.Workingday == 1f);
                ((cCaChuan)ca3va1).catruoc = ca3 as cCaChuan;
                ((cCaChuan)ca3va1).casauuu = ca1 as cCaChuan;
            }


            IEnumerable <DataRow> arrRows = tableLichTrinh.Rows.Cast <DataRow>();
            var arrRows_Distinct          = (from row in arrRows select new { a = (int)(row["SchID"]), b = row["SchName"].ToString() }).Distinct();
            foreach (var row in arrRows_Distinct)
            {
                var arrRows1  = tableLichTrinh.Select("SchID=" + row.a, "");
                var lichtrinh = new cShiftSchedule {
                    SchID = row.a, TenLichTrinh = row.b, DSCa = new List <cCaAbs>(), DSCaMoRong = new List <cCaAbs>()
                };
                foreach (var row1 in arrRows1)
                {
                    var shiftid = (int)row1["T1"];
                    var ca      = XL.DSCa.Find(o => o.ID == shiftid);
                    if (ca != null)
                    {
                        lichtrinh.DSCa.Add(ca);
                    }
                }
                lichtrinh.DSCaMoRong = XL.TaoDSCaMoRong(lichtrinh.DSCa);
                XL.DSLichTrinh.Add(lichtrinh);
            }


            if (XL.DSLichTrinh.Count == 0)
            {
                throw new NullReferenceException("Không có ds lịch trình");
            }
        }