Example #1
0
        private void themPhieuDatPhong(object sender, EventArgs e)
        {
            //Thêm một phiếu đặt vào danh sách
            string manv      = txtMaNV.Text.ToString();
            string phong     = txtPhong.Text.ToString();
            string dienthoai = txtDienThoai.Text.ToString();
            string hoten     = txtHoTen.Text.ToString();
            string cmnd      = txtCMND.Text.ToString();
            string ngaythue  = dateNgayThue.Text.ToString();
            string ngaydi    = dateNgayTra.Text.ToString();
            string rgxSDT    = "^[0-9]{10,11}$";
            string rgxCMND   = "^[0-9]{9,12}$";
            string rgxTen    = @"[^\d\W_]+";
            bool   mSDT      = Regex.IsMatch(txtDienThoai.Text.ToString().Trim(), rgxSDT, RegexOptions.IgnoreCase);
            bool   mCMND     = Regex.IsMatch(txtCMND.Text.ToString().Trim(), rgxCMND, RegexOptions.IgnoreCase);
            bool   mTen      = Regex.IsMatch(txtHoTen.Text, rgxTen, RegexOptions.IgnoreCase);

            if (dateNgayThue.Value < DateTime.Now.Date)
            {
                errorNgayThue.SetError(dateNgayThue, "Thời gian thuê không hợp lệ");
            }
            else
            {
                errorNgayThue.Clear();
            }
            if (dateNgayTra.Value < dateNgayThue.Value)
            {
                errorNgay.SetError(dateNgayTra, "Thời gian lựa chọn không phù hợp..");
            }
            else
            {
                errorNgay.Clear();
            }
            if (!mSDT)
            {
                errorDienThoai.SetError(txtDienThoai, "Số điện thoại trống hoặc không đúng.");
            }
            else
            {
                errorDienThoai.Clear();
            }
            if (!mCMND)
            {
                errorCMND.SetError(txtCMND, "CMND trống hoặc không đúng.");
            }
            else
            {
                errorCMND.Clear();
            }
            if (!mTen)
            {
                errorHoTen.SetError(txtHoTen, "Họ tên nhập chưa đúng.");
            }
            else
            {
                errorHoTen.Clear();
            }
            if (tinhTrang.tblTinhTrang.CurrentRow.Cells[4].Value.ToString().Contains("Đã đặt") ||
                tinhTrang.tblTinhTrang.CurrentRow.Cells[4].Value.ToString().Contains("Đang thuê"))
            {
                MessageBox.Show("Phòng chọn không cho phép đặt phiếu mới.");
            }
            else if (mSDT && mCMND && mTen &&
                     (!tinhTrang.tblTinhTrang.CurrentRow.Cells[4].Value.ToString().Contains("Đã đặt") ||
                      !tinhTrang.tblTinhTrang.CurrentRow.Cells[4].Value.ToString().Contains("Đang thuê")) &&
                     dateNgayTra.Value >= dateNgayThue.Value)
            {
                bool themKhach = kh.themKhachHang(cmnd, hoten, dienthoai);
                bool themPhieu = dp.themPhieuDat(cmnd, manv, phong, ngaythue, ngaydi);
                if (themKhach && themPhieu)
                {
                    p.doiTrangThaiPhong(phong, Option.P_DA_DAT);
                    tinhTrang.hienThiDanhSachPhong();
                    ds.hienThiThongTin();
                    MessageBox.Show("Đặt phòng thành công");
                    ds.Enabled = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Xảy ra lỗi, vui lòng kiểm tra lại...");
                }
            }
        }