Пример #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            // Mở kết nối
            // Thêm dữ liệu
            if (Them)
            {
                try
                {
                    // Thực hiện lệnh
                    BLXe   blXe     = new BLXe();
                    string madongxe = dt.Tables[0].Rows[cboDongXe.SelectedIndex]["MaDongXe"].ToString();

                    blXe.ThemXe(this.txtMaXe.Text, this.txtTenXe.Text, madongxe, this.txtNamRaMat.Text, this.cboMauSac.Items[cboMauSac.SelectedIndex].ToString(), this.txtSoLuong.Text, Convert.ToInt32(txtGiaXe.Text), ref err);
                    //blXe.ThemXe("ba","con","co",1,1, ref err);
                    // Load lại dữ liệu trên DataGridView

                    LoadData();
                    // Thông báo
                    MessageBox.Show("Đã thêm xong!");
                }
                catch
                {
                    MessageBox.Show("Không thêm được. Lỗi rồi!");
                }
            }
            else
            {
                // Thực hiện lệnh
                BLXe   blXe     = new BLXe();
                string madongxe = dt.Tables[0].Rows[cboDongXe.SelectedIndex]["MaDongXe"].ToString();

                if (!blXe.CapNhatXe(this.txtMaXe.Text, this.txtTenXe.Text, madongxe, this.txtNamRaMat.Text, this.cboMauSac.Items[cboMauSac.SelectedIndex].ToString(), this.txtSoLuong.Text, Convert.ToInt32(txtGiaXe.Text), ref err))// Load lại dữ liệu trên DataGridView
                {
                    MessageBox.Show("Có lỗi phát sinh,Cập nhật thất bại!");
                    return;
                }
                LoadData();
                // Thông báo
                MessageBox.Show("Đã sửa xong!");
            }
            // Đóng kết nối
        }