Пример #1
0
        // Initial form setup
        private void frmProdSupplierAddEdit_Load(object sender, EventArgs e)
        {
            // On load, populate data for all data displays
            rootDB = new travelexpertsDataContext(); // create a new context

            //get product_supplier data for top datagrid
            products_SupplierBindingSource.DataSource = TravelExpertsQueryManager.GetProductsSuppliersExtended(rootDB);

            selectedProdID             = Convert.ToInt32(grdProductSuppliers.Rows[0].Cells[0].Value);   // set selectedProdID as ID of top row
            lblSelectedProdsTitle.Text = $"Modify details for selected product (ID #{selectedProdID})"; // Set display for that ID

            supplierIdComboBox.DataSource = rootDB.Suppliers;                                           // get supplier data for suppliers details dropbox
            productIdComboBox.DataSource  = rootDB.Products;                                            // get product data for products details dropbox
            RefreshPackagesByProdSuppGrid();                                                            // get package data for selected product_supplier row (in this case, top one)
            SetDataGridToFirstEntry();                                                                  // Selects the first row of the main datagrid
        }
Пример #2
0
        // Checking off the top filter button will toggle filtering all products in the product_supplier datagrid (either all of them, or just those with packages)
        private void checkboxFilterProducts_CheckedChanged(object sender, EventArgs e)
        {
            // Update the persisting db image (used as a data source)
            rootDB = new travelexpertsDataContext();

            // If the user checks off the option to filter
            if (checkboxFilterProducts.Checked == true)
            {
                // Query PPS to find all ProductSuppliers associated to packages
                List <int> prodSupIDsWithPackages = rootDB.Packages_Products_Suppliers.Select(pps =>
                                                                                              pps.ProductSupplierId) // just need ids
                                                    .ToList();

                // Filter the datagrid to only show those entries
                products_SupplierBindingSource.DataSource = TravelExpertsQueryManager.GetProductsSuppliersExtended(rootDB, prodSupIDsWithPackages);
            }
            else
            {
                products_SupplierBindingSource.DataSource = TravelExpertsQueryManager.GetProductsSuppliersExtended(rootDB);
            }
        }