Beispiel #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string id, name, supplierId;
            float  purchasePrice, sellingPrice;
            int    categoryId;

            id            = txtId.Text;
            name          = txtName.Text;
            purchasePrice = float.Parse(txtPurchase.Text);
            sellingPrice  = float.Parse(txtSelling.Text);
            categoryId    = int.Parse(cboLoai.SelectedValue.ToString());
            supplierId    = cboNCC.SelectedValue.ToString();
            Product product = new Product(id, name, purchasePrice, sellingPrice, categoryId, supplierId);

            try {
                int numberOfRows = productBus.Add(product);
                if (numberOfRows > 0)
                {
                    dgvProduct.DataSource = productBus.GetProducts();
                }
            }
            catch (SqlException ex) {
                MessageBox.Show("Loi them san pham. \n" + ex.Message, "Add", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void btnProductAdd_Click(object sender, EventArgs e)
        {
            string  id          = txtProductID.Text;
            string  name        = txtProductName.Text;
            string  description = txtProductDescription.Text;
            string  filename    = ofdProductImage.FileName;
            int     quantity    = (int)nmrProductQuantity.Value;
            decimal price       = nmrProductPrice.Value;
            Catalog catalog     = cboProductCatalog.SelectedItem as Catalog;

            if (String.IsNullOrWhiteSpace(id))
            {
                MessageBox.Show("Mã không được trống");
                return;
            }
            if (String.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("Tên không được trống");
                return;
            }
            if (cboProductCatalog.SelectedIndex == -1)
            {
                MessageBox.Show("Vui lòng chọn danh mục");
                return;
            }
            if (String.IsNullOrEmpty(filename))
            {
                MessageBox.Show("Vui lòng chọn ảnh");
                return;
            }

            FileStream   fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            byte[]  image   = br.ReadBytes((int)fs.Length);
            Product product = new Product
            {
                ID          = id,
                Name        = name,
                Description = description,
                Catalog     = catalog,
                Quantity    = quantity,
                Price       = price,
                Image       = image
            };

            bool result = productBUS.Add(product);

            if (result)
            {
                MessageBox.Show("Thêm thành công");
                ShowAllProduct();
                btnProductRefresh.PerformClick();
            }
            else
            {
                MessageBox.Show("Thêm thất bại\n - Mã đã tồn tại");
            }
        }