Exemple #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int    id          = 1;
            string name        = string.Empty;
            double price       = 0;
            int    proQuantity = 0;

            if (dtProduct.Rows.Count > 0)
            {
                id = int.Parse(dtProduct.Compute("MAX(ProductID)", "").ToString()) + 1;
            }
            Product pro = new Product
            {
                ProductID       = id,
                ProductName     = name,
                UnitPrice       = price,
                ProductQuantity = proQuantity
            };

            searchFrm productDetails = new searchFrm(true, pro);

            DialogResult r = productDetails.ShowDialog();

            if (r == DialogResult.OK)
            {
                pro = productDetails.ProductAddorEdit;
                dtProduct.Rows.Add(pro.ProductID, pro.ProductName, pro.UnitPrice, pro.ProductQuantity);
            }
            loadData();
        }
Exemple #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int     id       = int.Parse(txtProductID.Text);
            string  name     = txtProductName.Text;
            double  price    = double.Parse(txtPrice.Text);
            int     quantity = int.Parse(txtQuantity.Text);
            Product pro      = new Product
            {
                ProductID       = id,
                ProductName     = name,
                UnitPrice       = price,
                ProductQuantity = quantity
            };

            searchFrm    productDetails = new searchFrm(false, pro);
            DialogResult r = productDetails.ShowDialog();

            if (r == DialogResult.OK)
            {
                DataRow row = dtProduct.Rows.Find(pro.ProductID);
                row["ProductName"] = pro.ProductName;
                row["UnitPrice"]   = pro.UnitPrice;
                row["Quantity"]    = pro.ProductQuantity;
            }
            loadData();
        }
Exemple #3
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     try
     {
         int id = 0;
         if (!int.TryParse(txtSearch.Text, out id))
         {
             MessageBox.Show("ID must be in number type.");
             return;
         }
         Product pro = data.findProductbyID(id);
         if (pro == null || string.IsNullOrEmpty(pro.ToString()))
         {
             MessageBox.Show("Can not found product.");
         }
         else
         {
             searchFrm    productDetails = new searchFrm(false, pro);
             DialogResult r = productDetails.ShowDialog();
             if (r == DialogResult.OK)
             {
                 DataRow row = dtProduct.Rows.Find(pro.ProductID);
                 row["ProductName"] = pro.ProductName;
                 row["UnitPrice"]   = pro.UnitPrice;
                 row["Quantity"]    = pro.ProductQuantity;
             }
         }
     }
     catch (NullReferenceException)
     {
         MessageBox.Show("Can not found this product.");
     }
 }