コード例 #1
0
        //end thêm thiết bị

        //cập nhật và xóa thiết bị

        private void btnSua_Click(object sender, EventArgs e)
        {
            Product tb  = new Product();
            int     idx = dgvDSTB.CurrentRow.Index;

            if (txtTenTB.Text != "")
            {
                if (txtSLTon.Text != "")
                {
                    tb.Id       = dgvDSTB.Rows[idx].Cells[0].Value.ToString();
                    tb.Id_cate  = CategoryBLL.LayMaLoaiTuTenLoai(cmbLoaiTB.Text);
                    tb.Name_pro = txtTenTB.Text;
                    tb.Qty      = int.Parse(txtSLTon.Text);

                    bool kt;
                    kt = ProductBLL.KiemTraTenTBCapNhat(txtTenTB.Text, tb.Id);
                    if (kt == true)
                    {
                        try
                        {
                            int gia = int.Parse(txtDonGia.Text);
                            if (gia > 0)
                            {
                                tb.Price = gia;
                                bool kq1 = ProductBLL.CapNhatThietBi(tb);
                                if (kq1 == true)
                                {
                                    MessageBox.Show("Cập nhật thiết bị thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    txtTenTB.Text  = "";
                                    txtSLTon.Text  = "";
                                    txtDonGia.Text = "";
                                    cmbTraCuuLoaiTB_SelectedValueChanged(sender, e);
                                }
                                else
                                {
                                    MessageBox.Show("Cập nhật thiết bị thất bại!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Đơn giá phải lớn hơn 0!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtDonGia.Text = "";
                                txtDonGia.Focus();
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Chưa nhập đơn giá hoặc kiểu dữ liệu đơn giá không đúng!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtDonGia.Text = "";
                            txtDonGia.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Tên thiết bị bị trùng!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtTenTB.Text = "";
                        txtTenTB.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Chưa nhập số lượng tồn!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtSLTon.Text = "";
                    txtSLTon.Focus();
                }
            }
            else
            {
                MessageBox.Show("Chưa nhập tên thiết bị!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTenTB.Text = "";
                txtTenTB.Focus();
            }
        }