private void frmPackageProducts_Load(object sender, EventArgs e)
        {
            using (TravelExpertsDataContext dbContext = new TravelExpertsDataContext())
            {
                dbContext.DeferredLoadingEnabled   = false;
                PackageProductsGridView.DataSource = (from pack in dbContext.Packages
                                                      join psi in dbContext.Packages_Products_Suppliers on pack.PackageId equals psi.PackageId
                                                      join ps in dbContext.Products_Suppliers on psi.ProductSupplierId equals ps.ProductSupplierId
                                                      join p in dbContext.Products on ps.ProductId equals p.ProductId
                                                      join s in dbContext.Suppliers on ps.SupplierId equals s.SupplierId

                                                      select new
                {
                    pack.PkgName,
                    p.ProdName,
                    s.SupName
                });



                //where psi.ProductSupplierId
                //join ps in dbContext.Products_Suppliers on psi.ProductSupplierId equals ps.ProductSupplierId
                //orderby psi.PackageId
                // statment where products = value passed from package ID?
            }
        }
Esempio n. 2
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            //find column and row location of ID
            int rowNum = packageDataGridView.CurrentCell.RowIndex;
            int packID = (int)packageDataGridView["dataGridViewTextBoxColumn1", rowNum].Value;

            //Select ID
            Package currentPackage;

            using (TravelExpertsDataContext dbContext = new TravelExpertsDataContext())
            {
                currentPackage = (from pack in dbContext.Packages
                                  where pack.PackageId == packID
                                  select pack).Single();
            }

            //Open new form to view products by package ID
            frmPackageAddModify secondForm = new frmPackageAddModify();

            secondForm.currentPackage = currentPackage;
            DialogResult result = secondForm.ShowDialog();

            if (result == DialogResult.OK || result == DialogResult.Retry)
            {
                RefreshGridView();
            }
        }
Esempio n. 3
0
 private void frmPackageView_Load(object sender, EventArgs e)
 {
     // load package list to grid
     using (TravelExpertsDataContext dbContext = new TravelExpertsDataContext())
     {
         // select all packages ordered by start date
         packageDataGridView.DataSource = from pack in dbContext.Packages
                                          orderby pack.PkgStartDate
                                          select pack;
     }
 }
Esempio n. 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (TravelExpertsDataContext dbContext = new TravelExpertsDataContext())
                {
                    if (isAdd)
                    {
                        Package newPackage = new Package()
                        {
                            PkgAgencyCommission = Convert.ToDecimal(txbPkgAgencyCommission.Text),
                            PkgBasePrice        = Convert.ToDecimal(txbPkgBasePrice.Text),
                            PkgDesc             = txbPkgDesc.Text,
                            PkgName             = txbPkgName.Text,
                            PkgStartDate        = startTmpDate,
                            PkgEndDate          = endTmpDate
                        };

                        using (TravelExpertsDataContext dataContext = new TravelExpertsDataContext())
                        {
                            dbContext.Packages.InsertOnSubmit(newPackage);
                            dbContext.SubmitChanges();
                        }
                        DialogResult = DialogResult.OK;
                    }

                    else
                    {
                        Package pkg = dbContext.Packages.SingleOrDefault(p => p.PackageId == Convert.ToInt32(txbPackageId.Text));
                        pkg.PkgAgencyCommission = Convert.ToDecimal(txbPkgAgencyCommission.Text);
                        pkg.PkgBasePrice        = Convert.ToDecimal(txbPkgBasePrice.Text);
                        pkg.PkgDesc             = txbPkgDesc.Text;
                        pkg.PkgName             = txbPkgName.Text;
                        pkg.PkgStartDate        = startTmpDate;
                        pkg.PkgEndDate          = endTmpDate;

                        dbContext.SubmitChanges();
                        DialogResult = DialogResult.OK;
                    }
                }
            }

            catch (ChangeConflictException)
            {
                MessageBox.Show("Another user changed or deleted the current record", "Concurrency Exception");
                DialogResult = DialogResult.Retry;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Esempio n. 5
0
        private void RefreshGridView()
        {
            TravelExpertsDataContext dbContext = new TravelExpertsDataContext();

            packageDataGridView.DataSource = dbContext.Packages;
        }