Ejemplo n.º 1
0
        private void btnThue_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvThongtin.RowCount; i++)
            {
                if (Convert.ToBoolean(dgvThongtin.Rows[i].Cells["Thue"].Value) == true)
                {
                    if (dgvThongtin.Rows[i].Cells["TrangThai"].Value.ToString() == "Đã thuê")
                    {
                        MessageBox.Show("Phòng " + dgvThongtin.Rows[i].Cells["SoPhong"].Value.ToString() + " đã được thuê rồi. Chọn phòng khác!");
                        dgvThongtin.Rows[i].Cells["Thue"].Value = false;
                        return;
                    }
                    if (dgvThongtin.Rows[i].Cells["TrangThai"].Value.ToString() == "Hỏng")
                    {
                        MessageBox.Show("Phòng " + dgvThongtin.Rows[i].Cells["SoPhong"].Value.ToString() + " đang hỏng. Chọn phòng khác!");
                        dgvThongtin.Rows[i].Cells["Thue"].Value = false;
                        return;
                    }
                    ecPT.MaPh = dgvThongtin.Rows[i].Cells["MaPh"].Value.ToString();
                    ecPT.MaKH = txtMaKH.Text;
                    ecPT.MaPT = txtMaPT.Text;
                    DateTime date = DateTime.Now;
                    ecPT.MaPhieu = date.Day.ToString() + date.Month.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + dgvThongtin.Rows[i].Cells["SoPhong"].Value.ToString();

                    DAL_PhieuThue dalPhieuthue = new DAL_PhieuThue();
                    dalPhieuthue.ThemThongTin(ecPT);

                    EC_Phong ecPh = new EC_Phong();
                    ecPh.MaPh      = dgvThongtin.Rows[i].Cells["MaPh"].Value.ToString();
                    ecPh.SoPhong   = dgvThongtin.Rows[i].Cells["SoPhong"].Value.ToString();
                    ecPh.TrangThai = "Đã thuê";
                    dalPh.SuaThongTin(ecPh);

                    ecHD.MaHD        = ecPT.MaPhieu;
                    ecHD.MaPhieuThue = ecPT.MaPhieu;
                    ecHD.ThanhTien   = "0";
                    ecHD.Gia         = _Gia;
                    ecHD.NgayRa      = dtpNgayra.Value;

                    dalHD.ThemThongTin(ecHD);
                }
            }
            MessageBox.Show("Thuê OK!");

            DataTable tb = dalPh.ThongTinPhong("");

            dgvThongtin.DataSource = tb;
            //for (int i = 0; i < dgvThongtin.RowCount; i++)
            //{
            //    dgvThongtin.Rows[i].Cells["STT"].Value = i + 1;
            //    if (dgvThongtin.Rows[i].Cells["TrangThai"].Value.ToString() == "Tốt") dgvThongtin.Rows[i].DefaultCellStyle.BackColor = Color.Lime;
            //    else
            //        if (dgvThongtin.Rows[i].Cells["TrangThai"].Value.ToString() == "Đã thuê") dgvThongtin.Rows[i].DefaultCellStyle.BackColor = Color.LightSkyBlue;
            //        else
            //            if (dgvThongtin.Rows[i].Cells["TrangThai"].Value.ToString() == "Hỏng") dgvThongtin.Rows[i].DefaultCellStyle.BackColor = Color.Red;
            //}
        }
Ejemplo n.º 2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMaPhong.Text == "" || txtSoPhong.Text == "" || txtTrangThai.Text == "")
            {
                MessageBox.Show("Xin mời nhập thông tin đầy đủ");
                //KhoaChucNang();
                return;
            }
            else
            {
                if (themmoi == true)/*đang ở trang thái thêm mới*/
                {
                    try
                    {
                        ec_Ph.MaPh      = txtMaPhong.Text;
                        ec_Ph.SoPhong   = txtSoPhong.Text;
                        ec_Ph.TrangThai = txtTrangThai.Text;


                        dal_Ph.ThemThongTin(ec_Ph);
                        MessageBox.Show("Đã thêm mới thành công");/*dòng thông báo*/
                        btnLamMoi_Click(sender, e);
                        MoChucNang();
                        btnThem.Enabled = true;
                        btnSua.Enabled  = true;
                        btnXoa.Enabled  = true;
                        SetNull();
                    }
                    catch
                    {
                        MessageBox.Show("Lỗi");
                        return;
                    }
                }
                else
                {
                    try
                    {
                        ec_Ph.MaPh      = txtMaPhong.Text;
                        ec_Ph.SoPhong   = txtSoPhong.Text;
                        ec_Ph.TrangThai = txtTrangThai.Text;
                        dal_Ph.SuaThongTin(ec_Ph);
                        MessageBox.Show("Đã sửa thành công");
                        btnLamMoi_Click(sender, e);
                        MoChucNang();
                        btnThem.Enabled = true;
                        btnSua.Enabled  = true;
                        btnXoa.Enabled  = true;
                        SetNull();
                    }
                    catch
                    {
                        MessageBox.Show("Lỗi");
                        return;
                    }
                }
                SetNull();
                KhoaChucNang();/*không cho thao tác*/
                HienThi("");
            }
            dgvDanhSach.Enabled = true;
        }