Пример #1
0
        private void btnConfirmEditProduct_Click(object sender, EventArgs e)
        {
            if (btnConfirmEditProduct.Text == "Edit")
            {
                txtAddProductDescription.Enabled = true;
                txtEditProductPrice.Enabled      = true;
                txtEditProductQty.Enabled        = true;

                btnConfirmEditProduct.Text = "Save";
            }
            else
            {
                MyProduct myProduct = new MyProduct();
                bool      ok        = true;
                errorProvider1.Clear();

                try
                {
                    myProduct.ProductNo = lblEditActualProductNo.Text.Trim();
                }
                catch (MyException MyEx)
                {
                    ok = false;
                    errorProvider1.SetError(lblEditActualProductNo, MyEx.toString());
                }

                try
                {
                    myProduct.ProductDescription = txtEditProductDescription.Text.Trim();
                }
                catch (MyException MyEx)
                {
                    ok = false;
                    errorProvider1.SetError(txtEditProductDescription, MyEx.toString());
                }

                try
                {
                    myProduct.ProductPrice = Convert.ToDouble(txtEditProductPrice.Text.Trim());
                }
                catch (MyException MyEx)
                {
                    ok = false;
                    errorProvider1.SetError(txtEditProductPrice, MyEx.toString());
                }

                try
                {
                    myProduct.ProductQty = Convert.ToInt32(txtEditProductQty.Text.Trim());
                }
                catch (MyException MyEx)
                {
                    ok = false;
                    errorProvider1.SetError(txtEditProductQty, MyEx.toString());
                }

                try
                {
                    if (ok)
                    {
                        drProduct.BeginEdit();


                        drProduct["ProductNo"]          = myProduct.ProductNo;
                        drProduct["ProductDescription"] = myProduct.ProductDescription;
                        drProduct["ProductPrice"]       = myProduct.ProductPrice;
                        drProduct["ProductQty"]         = myProduct.ProductQty;


                        drProduct.EndEdit();
                        daProduct.Update(dsSurefill, "Product");

                        MessageBox.Show("Product details updated", "Product");

                        txtEditProductDescription.Enabled = false;
                        txtEditProductPrice.Enabled       = false;
                        txtEditProductQty.Enabled         = false;

                        btnConfirmEditProduct.Text = "Edit";
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        private void btnConfirmAddProduct_Click(object sender, EventArgs e)
        {
            MyProduct myProduct = new MyProduct();
            bool      ok        = true;

            errorProvider1.Clear();


            try
            {
                myProduct.ProductNo = lblAddActualProductNo1.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errorProvider1.SetError(lblAddActualProductNo1, MyEx.toString());
            }

            try
            {
                myProduct.ProductDescription = txtAddProductDescription1.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errorProvider1.SetError(txtAddProductDescription1, MyEx.toString());
            }


            try
            {
                myProduct.ProductPrice = Convert.ToDouble(txtAddProductPrice1.Text.Trim());
            }
            catch (MyException MyEx)
            {
                ok = false;
                errorProvider1.SetError(txtAddProductPrice1, MyEx.toString());
            }

            try
            {
                myProduct.ProductQty = Convert.ToInt32(txtAddProductQty1.Text.Trim());
            }
            catch (MyException MyEx)
            {
                ok = false;
                errorProvider1.SetError(txtAddProductQty1, MyEx.toString());
            }

            try
            {
                myProduct.SupplierNo = cmbSupplier.SelectedValue.ToString();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errorProvider1.SetError(cmbSupplier, MyEx.toString());
            }



            try
            {
                if (ok)
                {
                    drProduct = dsSurefill.Tables["Product"].NewRow();

                    drProduct["ProductNo"]          = myProduct.ProductNo;
                    drProduct["ProductDescription"] = myProduct.ProductDescription;
                    drProduct["ProductMeasure"]     = 1000;
                    drProduct["ProductPrice"]       = myProduct.ProductPrice;
                    drProduct["ProductQty"]         = myProduct.ProductQty;
                    drProduct["SupplierNo"]         = myProduct.SupplierNo;

                    dsSurefill.Tables["Product"].Rows.Add(drProduct);
                    daProduct.Update(dsSurefill, "Product");

                    MessageBox.Show("Product Added");

                    if (MessageBox.Show("Do you want to add another Product?", "Add Product", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        clearAddForm();

                        getNumber(dsSurefill.Tables["Product"].Rows.Count);
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
            }
        }