Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddModify secondForm = new frmAddModify();

            secondForm.isAdd          = true;
            secondForm.currentPackage = null;              // no current product when inserting
            DialogResult result = secondForm.ShowDialog(); // display second form modal

            if (result == DialogResult.OK)                 // new row got inserted
            {
                RefreshView();
            }
        }
Ejemplo n.º 2
0
        //Allows modifications to Packages
        private void btnModify_Click(object sender, EventArgs e)
        {
            //Package currentPackage;
            using (travelexpertsDataContext dbContext = new travelexpertsDataContext())
            {
                currentPackage = (from p in dbContext.Packages           // LINQ query that returns one record
                                  where p.PackageId == selectedPackageId // use ID of selected row in Packages
                                  select p).Single();                    // method Single runs the LINQ query, only when receiving one value


                frmAddModify secondForm = new frmAddModify();
                secondForm.isAdd          = false;                             // Modify mode
                secondForm.currentPackage = currentPackage;
                DialogResult result = secondForm.ShowDialog();                 // display second form modal
                if (result == DialogResult.OK || result == DialogResult.Retry) // successful update or concurrency exception
                {
                    RefreshView();
                }
            }
        }
Ejemplo n.º 3
0
        //Adds new Packages to Database
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddModify secondForm = new frmAddModify();

            secondForm.isAdd = true;

            // Because we give the user the option to add products to the new package before saving it,
            // we need to do a preliminary insert into the database in order to get a valid PackageID
            // for the PackageProductsSuppliers table.
            // We don't use the current highest PackageID + 1, in order to avoid concurrency issues.
            // These alterations done by [Eric]
            Package newPackage = new Package
            {
                PkgName             = "DEFAULT",
                PkgStartDate        = DateTime.Now,
                PkgEndDate          = DateTime.Now,
                PkgDesc             = "DEFAULT",
                PkgBasePrice        = 0,
                PkgAgencyCommission = 0
            };

            // submit changes to database
            using (travelexpertsDataContext db = new travelexpertsDataContext())
            {
                db.Packages.InsertOnSubmit(newPackage); // insert the new package through data context object
                db.SubmitChanges();                     //submit to database
            }
            secondForm.currentPackage = newPackage;     // Now that the new package has been added to the database, the Object has an Id (magic!)


            DialogResult result = secondForm.ShowDialog(); // display second form modal

            if (result == DialogResult.OK)                 // new row got inserted
            {
                secondForm.Close();
                RefreshView();
            }
        }