示例#1
0
 private void btThem_Click(object sender, EventArgs e)
 {
     if (txtMaPhong.Text.Trim() == "")
     {
         MessageBox.Show("Bạn chưa nhập mã phòng!", "THÔNG BÁO!", MessageBoxButtons.OK);
     }
     else
     {
         if (PHBLL.Dembanghi(txtMaPhong.Text) == 1)
         {
             MessageBox.Show("Mã phòng đã tồn tại.Hãy nhập lại mã khác!", "THÔNG BÁO!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtMaPhong.Text = "";
         }
         else
         {
             if (txtTenPhong.Text.Trim() == "" || cbMaToaNha.Text.Trim() == "" || cbLoaiPhong.Text.Trim() == "" || txtSoLuongNguoi.Text.Trim() == "" || txtTinhTrang.Text.Trim() == "")
             {
                 MessageBox.Show("Bạn chưa nhập đầy đủ thông tin cho phòng!", "THÔNG BÁO!", MessageBoxButtons.OK);
             }
             else
             {
                 PHBLL.ThemPhong(txtMaPhong.Text, txtTenPhong.Text, cbMaToaNha.Text, cbLoaiPhong.Text, txtSoLuongNguoi.Text, txtTinhTrang.Text);
                 dgQLPhong.DataSource = PHBLL.Load();
                 btLamMoi_Click(sender, e);
             }
         }
     }
 }
示例#2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (click == "Them")
            {
                if (KiemTraDuLieu() == false)
                {
                    return;
                }
                if (dt.Rows.Count == 0)
                {
                    return;
                }
                dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
                DataRow r = dt.Rows.Find(txtSoPhong.Text);
                if (r != null)
                {
                    MessageBox.Show("Lỗi! Phòng đã tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtSoPhong.Focus();
                    return;
                }


                Phong P = new Phong(int.Parse(txtSoPhong.Text), int.Parse(cbSucChua.Text), 0, cbMaDay.Text, cbTrangThai.Text);
                if (PBLL.ThemPhong(P) == true)
                {
                    MessageBox.Show("Thêm thành công !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnMoi_Click(sender, e);
                    txtSoPhong.Focus();
                    CapNhatThongTinTrang();
                    chisotrang = tongsotrang;
                    LoadGridView();
                }
                else
                {
                    MessageBox.Show("Đã xảy ra lỗi!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            if (click == "Sua")
            {
                if (KiemTraDuLieu() == false)
                {
                    return;
                }
                if (int.Parse(cbSucChua.Text) < int.Parse(txtSoSVHT.Text))
                {
                    MessageBox.Show("Lỗi! Số sinh viên hiện tại vượt quá Sức chứa", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    cbSucChua.Focus();
                    return;
                }

                if ((cbTrangThai.Text == "Bảo trì") && (int.Parse(txtSoSVHT.Text) > 0))
                {
                    MessageBox.Show("Lỗi! Không thể Bảo trì khi phòng vẫn còn sinh viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    cbTrangThai.Focus();
                    return;
                }

                Phong P = new Phong(int.Parse(txtSoPhong.Text), int.Parse(cbSucChua.Text), 0, cbMaDay.Text, cbTrangThai.Text);
                if (PBLL.SuaPhong(P) == true)
                {
                    MessageBox.Show("Cập nhật thành công !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CapNhatThongTinTrang();
                    LoadGridView();
                }
                else
                {
                    MessageBox.Show("Đã xảy ra lỗi !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            if (click == "Xoa")
            {
                if (KiemTraDuLieu() == false)
                {
                    return;
                }
                if (int.Parse(txtSoSVHT.Text) > 0)
                {
                    MessageBox.Show("Lỗi! Không thể xóa phòng có sinh viên ở ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show("Xác nhận xóa?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (PBLL.XoaPhong(int.Parse(txtSoPhong.Text)) == true)
                    {
                        MessageBox.Show("Xóa thành công !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if ((soluongphong % sodong == 1) && (chisotrang * sodong >= soluongphong) && (chisotrang != 1))
                        {
                            chisotrang--;
                        }
                        CapNhatThongTinTrang();
                        LoadGridView();
                        btnMoi_Click(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Đã xảy ra lỗi!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }