Esempio n. 1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            int soluong;
            int dongia;

            if (txtGia.Text == "" || txtMaSP.Text == "" || txtSoLuong.Text == "" || txtTenSp.Text == "" || txtXuatXu.Text == "")
            {
                MessageBox.Show("Vui long nhap du lieu con thieu");
            }
            else if (!int.TryParse(txtSoLuong.Text, out soluong))
            {
                MessageBox.Show("Vui long nhap lai So Luong.");
            }
            else if (!int.TryParse(txtGia.Text, out dongia))
            {
                MessageBox.Show("Vui long nhap lai Gia.");
            }
            else
            {
                SanPham sp = new SanPham(txtMaSP.Text, txtTenSp.Text, soluong, dongia, txtXuatXu.Text, cboDanhMuc.SelectedValue.ToString());
                if (objSP.AddSanPham(sp))
                {
                    MessageBox.Show("Thanh Cong");
                    dataGridView1.DataSource = objSP.GetSanPhamByMADM(MainForm.strMaDanhMuc_Chon);
                }
                else
                {
                    MessageBox.Show("That Bai");
                }
            }
        }