Beispiel #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);
            }
        }
Beispiel #2
0
 public static bool UpdateLoaiSanh(DTO_LoaiSanh loaiSanh)
 {
     if (DAO_QuanLyLoaiSanh.NumbersOfTenLoaiSanhInLoaiSanh(loaiSanh) > 0)
     {
         return(false);
     }
     DAO_QuanLyLoaiSanh.UpdateLoaiSanh(loaiSanh);
     return(true);
 }
Beispiel #3
0
        public static bool DeleteLoaiSanh(DTO_LoaiSanh loaiSanh)
        {
            if (DAO_QuanLyLoaiSanh.NumbersOfMaLoaiSanhInSanh(loaiSanh) > 0)
            {
                return(false);
            }

            DAO_QuanLyLoaiSanh.DeleteLoaiSanh(loaiSanh);
            return(true);
        }
        public static int NumbersOfTenLoaiSanhInLoaiSanh(DTO_LoaiSanh loaiSanh)
        {
            string sqlCommand = string.Format(@"SELECT COUNT(*) FROM LoaiSanh WHERE TenLoaiSanh=N'{0}'", loaiSanh.tenLoaiSanh);

            return(DatabaseHelper.CountRecord(sqlCommand));
        }
        public static void DeleteLoaiSanh(DTO_LoaiSanh loaiSanh)
        {
            string sqlCommand = string.Format(@"DELETE FROM LoaiSanh WHERE MaLoaiSanh={0}", loaiSanh.maLoaiSanh);

            DatabaseHelper.ExcuteSql(sqlCommand);
        }
        public static void UpdateLoaiSanh(DTO_LoaiSanh loaiSanh)
        {
            string sqlCommand = string.Format(@"UPDATE LoaiSanh SET TenLoaiSanh=N'{0}', DonGiaBanToiThieu={1} WHERE MaLoaiSanh={2}", loaiSanh.tenLoaiSanh, loaiSanh.donGiaBanToiThieu, loaiSanh.maLoaiSanh);

            DatabaseHelper.ExcuteSql(sqlCommand);
        }
        public static void InsertLoaiSanh(DTO_LoaiSanh loaiSanh)
        {
            string sqlCommand = string.Format(@"INSERT INTO LoaiSanh (TenLoaiSanh,DonGiaBanToiThieu) VALUES (N'{0}',{1})", loaiSanh.tenLoaiSanh, loaiSanh.donGiaBanToiThieu);

            DatabaseHelper.ExcuteSql(sqlCommand);
        }
Beispiel #8
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();
        }