Exemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            HangDTO h = new HangDTO();

            h.Mahang     = txtMaHH.Text;
            h.Tenhang    = txtTenHH.Text;
            h.Donvitinh  = txtDonViTinh.Text;
            h.Dongia     = Int32.Parse(txtDonGia.Text);
            h.Maloai     = cboMaLoai.SelectedValue.ToString();
            h.Nhacungcap = cboMaNCC.SelectedValue.ToString();
            h.Soluongco  = Int32.Parse(txtSoLuong.Text);

            if (!string.IsNullOrEmpty(txtMaHH.Text) && !string.IsNullOrEmpty(txtTenHH.Text) && !string.IsNullOrEmpty(txtDonGia.Text) && !string.IsNullOrEmpty(txtSoLuong.Text) && !string.IsNullOrEmpty(txtDonViTinh.Text))
            {
                int val, val1;
                if (!Int32.TryParse(txtSoLuong.Text, out val) || !Int32.TryParse(txtDonGia.Text, out val1))
                {
                    MessageBox.Show("Gía trị số lượng và đơn giá phải là số", "Sai dữ liệu", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    return;
                }
                else
                {
                    try
                    {
                        hbus.InsertHangHoa(h);
                        {
                            MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            QL_HangHoa_Load(sender, e);
                            setTXT();
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Mã hàng hóa đã tồn tại , kiểm tra lại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("Chưa điền đủ thông tin!", "Kiểm tra lại", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                return;
            }
        }