Ejemplo n.º 1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            dgvQuanLyLoaiSanh.Focus();
            DTO_LoaiSanh loaiSanh = new DTO_LoaiSanh();

            loaiSanh.tenLoaiSanh = dgvQuanLyLoaiSanh.CurrentRow.Cells["TenLoaiSanh"].Value.ToString();
            loaiSanh.maLoaiSanh  = int.Parse(dgvQuanLyLoaiSanh.CurrentRow.Cells["MaLoaiSanh"].Value.ToString());

            DialogResult dr = MessageBox.Show(string.Format("Bạn có muốn xóa loại sảnh '{0}' không?", loaiSanh.tenLoaiSanh), "Xóa loại sảnh", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dr == DialogResult.No)
            {
                return;
            }
            if (BUS_QuanLyLoaiSanh.DeleteLoaiSanh(loaiSanh))
            {
                dgvQuanLyLoaiSanh.DataSource = BUS_QuanLyLoaiSanh.GetLoaiSanhTable();
                MessageBox.Show("Xóa loại sảnh '" + loaiSanh.tenLoaiSanh + "' thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearAllInputs();
            }
            else
            {
                MessageBox.Show(string.Format("Không thể xóa, vui lòng xóa dữ liệu liên qua đến loại sảnh '{0}' trong bảng 'Sảnh' trước.",
                                              loaiSanh.tenLoaiSanh),
                                "Lỗi khóa ngoại", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
 private void frmQuanLyLoaiSanh_Load(object sender, EventArgs e)
 {
     SetDisplayControls(MODE.AT_HOME);
     dgvQuanLyLoaiSanh.DataSource = BUS_QuanLyLoaiSanh.GetLoaiSanhTable();
     dgvQuanLyLoaiSanh.Columns["MaLoaiSanh"].Visible           = false;
     dgvQuanLyLoaiSanh.Columns["TenLoaiSanh"].HeaderText       = "Tên loại sảnh";
     dgvQuanLyLoaiSanh.Columns["DonGiaBanToiThieu"].HeaderText = "Đơn giá bàn tối thiểu";
 }
Ejemplo n.º 3
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtTenLoaiSanh.Text == "" || txtDonGiaBanTT.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int temp;

            if (!int.TryParse(txtDonGiaBanTT.Text, out temp))
            {
                MessageBox.Show("'Đơn giá bàn tối đa' phải là số nguyên, vui lòng nhập lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDonGiaBanTT.Focus();
                txtDonGiaBanTT.SelectAll();
                return;
            }

            switch (mCurrentMode)
            {
            case MODE.AT_HOME:
                break;

            case MODE.INSERTING:
            {
                DialogResult dr = MessageBox.Show("Bạn có muốn lưu loại sảnh '" + txtTenLoaiSanh.Text + "' không?", "Thêm loại sảnh", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No)
                {
                    return;
                }
                DTO_LoaiSanh loaiSanh = new DTO_LoaiSanh(txtTenLoaiSanh.Text, decimal.Parse(txtDonGiaBanTT.Text));
                if (BUS_QuanLyLoaiSanh.InsertLoaiSanh(loaiSanh))
                {
                    dgvQuanLyLoaiSanh.DataSource = BUS_QuanLyLoaiSanh.GetLoaiSanhTable();
                    ClearAllInputs();
                    MessageBox.Show("Thêm loại sảnh '" + loaiSanh.tenLoaiSanh + "' thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SetDisplayControls(MODE.AT_HOME);
                    mCurrentMode = MODE.AT_HOME;
                }
                else
                {
                    MessageBox.Show("Loại sảnh '" + loaiSanh.tenLoaiSanh + "' đã tồn tại. Vui lòng sửa lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTenLoaiSanh.Focus();
                    txtTenLoaiSanh.SelectAll();
                }

                break;
            }

            case MODE.EDITING:
            {
                DialogResult dr = MessageBox.Show("Bạn có muốn lưu lại không?", "Sửa loại sảnh", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No)
                {
                    return;
                }
                DTO_LoaiSanh loaiSanh = new DTO_LoaiSanh(txtTenLoaiSanh.Text, decimal.Parse(txtDonGiaBanTT.Text));
                loaiSanh.maLoaiSanh = int.Parse(dgvQuanLyLoaiSanh.CurrentRow.Cells["MaLoaiSanh"].Value.ToString());
                if (BUS_QuanLyLoaiSanh.UpdateLoaiSanh(loaiSanh))
                {
                    dgvQuanLyLoaiSanh.DataSource = BUS_QuanLyLoaiSanh.GetLoaiSanhTable();
                    ClearAllInputs();
                    MessageBox.Show("Sửa loại sảnh '" + loaiSanh.tenLoaiSanh + "' thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SetDisplayControls(MODE.AT_HOME);
                    mCurrentMode = MODE.AT_HOME;
                }
                else
                {
                    MessageBox.Show("Loại sảnh '" + loaiSanh.tenLoaiSanh + "' đã tồn tại. Vui lòng sửa lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTenLoaiSanh.Focus();
                    txtTenLoaiSanh.SelectAll();
                }

                break;
            }

            default:
                break;
            }
            dgvQuanLyLoaiSanh.ClearSelection();
        }