Ejemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (lenh == ADD)
            {
                try
                {
                    //id_SanPham = Int32.Parse(txtID_SanPham.Text);
                    maSanPham  = txtMaSP.Text;
                    tenSanPham = txtTenSP.Text;
                    giaSanPham = Int32.Parse(txtGiaSP.Text);
                    soLuongSP  = Int32.Parse(txtSoLuong.Text);
                    SanPham_ET sanPham = new SanPham_ET(maSanPham, tenSanPham, giaSanPham, soLuongSP);
                    if (bus_SanPham.AddSanPham(sanPham) == true)
                    {
                        MessageBox.Show("Thêm sản phẩm thành công!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showButton(false);
                        clearText();
                        dtgvHangHoa.DataSource = bus_SanPham.GetAllSanPham();
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (lenh == EDIT)
            {
                try
                {
                    id_SanPham = Int32.Parse(txtID_SanPham.Text);
                    maSanPham  = txtMaSP.Text;
                    tenSanPham = txtTenSP.Text;
                    giaSanPham = Int32.Parse(txtGiaSP.Text);
                    soLuongSP  = Int32.Parse(txtSoLuong.Text);
                    SanPham_ET sanPham = new SanPham_ET(id_SanPham, maSanPham, tenSanPham, giaSanPham, soLuongSP);
                    if (bus_SanPham.UpdateSanPham(sanPham) == true)
                    {
                        MessageBox.Show("Sửa sản phẩm thành công!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showButton(false);
                        clearText();
                        dtgvHangHoa.DataSource = bus_SanPham.GetAllSanPham();
                    }
                    else
                    {
                        MessageBox.Show("Sửa thất bại!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }