Пример #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (_them)
            {
                DV.MaDV  = txtMa.Text;
                DV.TenDV = txtTen.Text;
                DV.Gia   = txtGia.Text;
                if (!string.IsNullOrEmpty(txtMa.Text) && !string.IsNullOrEmpty(txtTen.Text))
                {
                    DV_DAO.ThemThongTin(DV);
                    MessageBox.Show("Thêm thành công");
                    dgvDanhSach.DataSource = DV_DAO.GetAll();
                }
                else
                {
                    MessageBox.Show("Bạn phải nhập đầy đủ thông tin dịch vụ!");
                }

                _them = false;
            }
            else
            {
                DV.MaDV  = txtMa.Text;
                DV.TenDV = txtTen.Text;
                DV.Gia   = txtGia.Text;
                if (!string.IsNullOrEmpty(txtTen.Text))
                {
                    DV_DAO.SuaThongTin(DV);
                    MessageBox.Show("Sửa thành công");
                    dgvDanhSach.DataSource = DV_DAO.GetAll();
                }
                else
                {
                    MessageBox.Show("Tên dịch vụ không được bỏ trống!");
                }
            }

            btnLuu.Enabled  = false;
            btnThem.Enabled = true;
            btnSua.Enabled  = true;

            txtGia.Enabled = false;
            txtMa.Enabled  = false;
            txtTen.Enabled = false;
            _them          = false;

            dgvDanhSach.Enabled = true;
        }