コード例 #1
0
        private void buttonLuu_Click(object sender, EventArgs e)
        {
            if (XL2.KiemtraKetnoiCSDL() == false)
            {
                return;
            }

            #region lấy dữ liệu từ form và xử lý trước khi lưu

            var      shiftid = (lbShiftID.Tag != null) ? (int)(lbShiftID.Tag) : -1;
            var      shiftcode = textBoxShiftcode.Text;
            var      mota = textBoxMoTa.Text;
            var      kyhieucc = textBoxKyhieu.Text;
            bool     tachcadem = checkBoxTachCaDem.Checked;
            bool     isenable = checkBoxEnable.Checked;
            bool     isextended = checkBoxCaMR.Checked;
            TimeSpan OnnDuty = TimeSpan.Zero, OffDuty = TimeSpan.Zero;
            TimeSpan OnnInn = TimeSpan.Zero, CutInn = TimeSpan.Zero;
            TimeSpan OnnOut = TimeSpan.Zero, CutOut = TimeSpan.Zero;
            TimeSpan OnnLun = TimeSpan.Zero, OffLun = TimeSpan.Zero;
            float    wkday = 0f;
            int      daycount = 0, wktime = 0, shiftid1 = -1, shiftid2 = -1;

            #region validate giờ
            if (TimeSpan.TryParse(maskedTextBoxVao.Text, out OnnDuty) == false)
            {
                ACMessageBox.Show(Resources.Text_GioVaoKoHL, Resources.Caption_Loi, 2000);
                return;
            }
            if (TimeSpan.TryParse(maskedTextBoxRaa.Text, out OffDuty) == false)
            {
                ACMessageBox.Show(Resources.Text_GioRaaKoHL, Resources.Caption_Loi, 2000);
                return;
            }
            if (TimeSpan.TryParse(maskedTextBoxBDLunch.Text, out OnnLun) == false)
            {
                ACMessageBox.Show(Resources.Text_OnnLunKoHL, Resources.Caption_Loi, 2000);
                return;
            }
            if (TimeSpan.TryParse(maskedTextBoxKTLunch.Text, out OffLun) == false)
            {
                ACMessageBox.Show(Resources.Text_OffLunKoHL, Resources.Caption_Loi, 2000);
                return;
            }
            if (float.TryParse(maskedTextBoxWKDay.Text, out wkday) == false)
            {
                ACMessageBox.Show(Resources.Text_WKDayKoHL, Resources.Caption_Loi, 2000);
                return;
            }
            #endregion

            //tính daycount , wktime
            if (OffDuty < OnnDuty)
            {
                daycount = 1;
            }
            OffDuty = OffDuty.Add(new TimeSpan(daycount, 0, 0, 0));

            wktime = Convert.ToInt32((OffDuty - OnnDuty - (OffLun - OnnLun)).TotalMinutes);

            int iOnnInn = Convert.ToInt32(numOnnInn.Value);            // bug onn in qua đêm
            int iCutInn = Convert.ToInt32(numCutInn.Value);            // bug cut in qua đêm
            int iOnnOut = Convert.ToInt32(numOnnOut.Value);            // bug onn out qua đêm
            int iCutOut = Convert.ToInt32(numCutOut.Value);            // bug cut out qua đêm
            int iCPTre  = Convert.ToInt32(numLateGrace.Value);
            int iCPSom  = Convert.ToInt32(numEarlyGrace.Value);
            int afterot = Convert.ToInt32(numAfterOT.Value);
            if (tachcadem)
            {
                shiftid1 = (int)comboBoxCaTruoc.SelectedValue;
                shiftid2 = (int)comboBoxCaSau.SelectedValue;
            }

            #endregion

            //MessageBox.Show(shiftid + " " + shiftcode + " " + mota + " " + kyhieucc + " " + OnnDuty + " " + OffDuty + " " + wktime);// fortesting
            if (themmoi)             // đang thêm
            {
                int n = DAO5.InsCa(shiftcode, OnnDuty, OffDuty, daycount, wktime, wkday, iOnnInn, iCutInn, iOnnOut, iCutOut, iCPTre, iCPSom, afterot,
                                   mota, kyhieucc, OnnLun, OffLun, tachcadem, shiftid1, shiftid2, isenable, isextended);
                if (n == 0)
                {
                    MessageBox.Show(Resources.Text_CoLoi, Resources.Caption_Loi, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // sau khi lưu xong thì set về false
                themmoi = false;
            }
            else             // đang sửa
            {
                int n = DAO5.UpdCa(shiftid, shiftcode, OnnDuty, OffDuty, daycount, wktime, wkday, iOnnInn, iCutInn, iOnnOut, iCutOut, iCPTre, iCPSom, afterot,
                                   mota, kyhieucc, OnnLun, OffLun, tachcadem, shiftid1, shiftid2, isenable, isextended);
                if (n == 0)
                {
                    MessageBox.Show(Resources.Text_CoLoi, Resources.Caption_Loi, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            LoadGrid();            // thêm hoặc sửa xong thì load lại grid
        }