Exemplo n.º 1
0
        //  Click the New Product button to add a new product
        private void btnNewProduct_Click(object sender, EventArgs e)
        {
            frmAddEditProduct secondForm = new frmAddEditProduct();

            secondForm.bIsNewProduct = true;

            DialogResult result = secondForm.ShowDialog();

            //  if the new product was added into the database, refresh the product list
            if (result == DialogResult.OK)
            {
                DisplayProducts();
            }
        }
Exemplo n.º 2
0
        //  Click the Edit Product button to edit the current product
        private void btnEdit_Click(object sender, EventArgs e)
        {
            //  if no product was selected, give warning message and return
            if (nProductID == 0)
            {
                MessageBox.Show("Please select a product first!");
                return;
            }

            //  get the current product from the database
            Product objCurrentProduct = null;

            using (TravelExpertDataDataContext dbContext1 = new TravelExpertDataDataContext())
            {
                objCurrentProduct = (from prod in dbContext1.Products
                                     where prod.ProductId == nProductID
                                     select prod).SingleOrDefault();
            }

            //  if the current product does not exist, refresh the product list and return
            if (objCurrentProduct == null)
            {
                MessageBox.Show("The product does not exist any more, please check again!");
                DisplayProducts();
                return;
            }

            //  open the new form to edit the product
            frmAddEditProduct secondFrm = new frmAddEditProduct();

            secondFrm.bIsNewProduct     = false;
            secondFrm.objCurrentProduct = objCurrentProduct;
            DialogResult result = secondFrm.ShowDialog();

            //  if the product was successfully edited, refresh the product list
            if (result == DialogResult.OK)
            {
                DisplayProducts();
            }
        }