Exemple #1
0
        //Edit supplier of product
        private void btnEditProductSupplier_Click(object sender, EventArgs e)
        {
            frmAddEditProductSuppliers addProductSupplierForm = new frmAddEditProductSuppliers();

            addProductSupplierForm.addProductSupplier = false;

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                // Index of the current row

                var prodsupid = (from m in db.Products_Suppliers
                                 join p in db.Products on m.ProductId equals p.ProductId

                                 where p.ProdName == products_SupplierDataGridView.SelectedRows.ToString()
                                 select p);

                var prods = (from m in db.Products_Suppliers
                             join p in db.Suppliers on m.SupplierId equals p.SupplierId

                             where p.SupName == products_SupplierDataGridView.SelectedRows.ToString()
                             select p);

                int prodsuprowNum = Convert.ToInt32(products_SupplierDataGridView.CurrentCell.RowIndex);

                // Column for productsupplier Id
                int prosupordernum = Convert.ToInt32(products_SupplierDataGridView["dataGridViewTextBoxColumn8", prodsuprowNum].Value);

                addProductSupplierForm.cur = (from p in db.Products_Suppliers
                                              where p.ProductId == Convert.ToInt32(prodsupid) && p.SupplierId == Convert.ToInt32(prods)
                                              select p).Single();
            }

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

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                // Update is successful
                if (result == DialogResult.OK)
                {
                    // Refresh grid
                    products_SupplierDataGridView.DataSource = db.Products_Suppliers;
                    MessageBox.Show("Supplier Name Edited in Product Successfully");
                }
            }
        }
Exemple #2
0
        //Add Supplier to product
        private void btnAddProductSupplier_Click(object sender, EventArgs e)
        {
            frmAddEditProductSuppliers addProductSupplierForm = new frmAddEditProductSuppliers();

            addProductSupplierForm.addProductSupplier = true;

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

            using (TravelExpertDBDataContext db = new TravelExpertDBDataContext())
            {
                // Update is successful
                if (result == DialogResult.OK)
                {
                    // Refresh grid
                    Products_Supplier prosu = null;
                    prosu = new Products_Supplier();

                    var prodsup = from ps in db.Products_Suppliers
                                  join sup in db.Suppliers
                                  on ps.SupplierId equals sup.SupplierId
                                  join p in db.Products
                                  on ps.ProductId equals p.ProductId
                                  into dbGroup
                                  select new
                    {
                        ProductSupplierID = ps.ProductSupplierId,
                        ProductId         = ps.Product.ProdName,
                        SupplierId        = sup.SupName,
                    };

                    products_SupplierDataGridView.DataSource = prodsup.ToList();

                    MessageBox.Show("New Supplier Added to Product Successfully");
                }
            }
        }