Пример #1
0
        //Edit package
        private void btnEditPackage_Click(object sender, EventArgs e)
        {
            frmAddEditPackages addPackageForm = new frmAddEditPackages();

            addPackageForm.addPackage = false;

            // get the key of the current package in the data grid view
            // Index of the current row
            int pkgrowNum = Convert.ToInt32(packageDataGridView.CurrentCell.RowIndex);
            // Column for package Id
            int pkgordernum = Convert.ToInt32(packageDataGridView["dataGridViewTextBoxColumn1", pkgrowNum].Value);

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                addPackageForm.currentPackage = (from pk in db.Packages
                                                 where pk.PackageId == pkgordernum
                                                 select pk).Single();
            }

            // Display second form modal
            DialogResult result = addPackageForm.ShowDialog();

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                // Update is successful
                if (result == DialogResult.OK)
                {
                    // Refresh grid
                    packageDataGridView.DataSource = db.Packages;
                    //package_ProductsDataGridView.DataSource = db.Package_Products;
                    MessageBox.Show("Package Edited Successfully");
                }
            }
        }
Пример #2
0
        //Add package
        private void btnAddPackage_Click(object sender, EventArgs e)
        {
            frmAddEditPackages addPackageForm = new frmAddEditPackages();

            addPackageForm.addPackage = true;

            // Display second form model
            DialogResult result = addPackageForm.ShowDialog();

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                // Update is successful
                if (result == DialogResult.OK)
                {
                    // Refresh grid
                    packageDataGridView.DataSource = db.Packages;
                    MessageBox.Show("New Package Inserted Successfully");
                    //packages = db.Packages.ToList();
                }
            }
        }