Esempio n. 1
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (this.state == 0)
            {
                //Cap nhat
                if (string.IsNullOrWhiteSpace(txtIdPhong.Text) ||
                    string.IsNullOrWhiteSpace(txtTenPhong.Text) ||
                    string.IsNullOrWhiteSpace(cbbTrangThai.Text) ||
                    string.IsNullOrWhiteSpace(txtDonGia.Text)
                    )
                {
                    MessageBox.Show("Vui lòng nhập đầy đủ thông tin của dịch vụ", "Lỗi thông tin",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (!txtDonGia.Text.All(char.IsDigit))
                    {
                        MessageBox.Show("Đơn giá phải là số", "Lỗi thông tin",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        DichVuDTO _data = new DichVuDTO();
                        _data.IdDichVu  = txtIdPhong.Text;
                        _data.TenDichVu = txtTenPhong.Text;
                        _data.TinhTrang = cbbTrangThai.Text;
                        _data.Gia       = Int32.Parse(txtDonGia.Text);


                        if (!dvBus.CapNhatThongTinDichVu(_data))
                        {
                            MessageBox.Show("Cập nhật thông tin dịch vụ vào cơ sở dữ liệu thất bại", "Thất bại",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            DocDuLieu(dvBus.LayDuDieu());
                            MessageBox.Show("Thông tin dịch vụ đã được cập nhật vào cơ sở dữ liệu", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            else
            if (this.state == 1)
            {
                //Them
                if (string.IsNullOrWhiteSpace(txtIdPhong.Text) ||
                    string.IsNullOrWhiteSpace(txtTenPhong.Text) ||
                    string.IsNullOrWhiteSpace(cbbTrangThai.Text) ||
                    string.IsNullOrWhiteSpace(txtDonGia.Text)
                    )
                {
                    MessageBox.Show("Vui lòng nhập đầy đủ thông tin của dịch vụ", "Lỗi thông tin",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (!txtDonGia.Text.All(char.IsDigit))
                    {
                        MessageBox.Show("Đơn giá phải là số", "Lỗi thông tin",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        DichVuDTO _data = new DichVuDTO();
                        _data.IdDichVu  = txtIdPhong.Text;
                        _data.TenDichVu = txtTenPhong.Text;

                        _data.TinhTrang = cbbTrangThai.Text;
                        _data.Gia       = Int32.Parse(txtDonGia.Text);


                        if (!dvBus.ThemThongTinDivhVu(_data))
                        {
                            MessageBox.Show("Thêm thông tin dịch vụ vào cơ sở dữ liệu thất bại hoặc ID Phòng bị trùng", "Thất bại",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            DocDuLieu(dvBus.LayDuDieu());
                            MessageBox.Show("Thông tin dịch vụ đã được thêm vào cơ sở dữ liệu", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            btnNhapLai_Click(sender, e);
        }