Ejemplo n.º 1
0
        public add()
        {
            InitializeComponent();
            NORTHWNDEntities1 nw = new NORTHWNDEntities1();
            var query            = from sp in nw.Suppliers
                                   select new
            {
                sp.CompanyName
            };

            foreach (var item in query)
            {
                SupplierC.Items.Add(item.CompanyName.ToString());
            }
            var result = from ct in nw.Categories
                         select new
            {
                ct.CategoryName
            };

            foreach (var item in result)
            {
                CategoryC.Items.Add(item.CategoryName.ToString());
            }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            NORTHWNDEntities1 nw = new NORTHWNDEntities1();
            var query            = from emp in nw.Employees
                                   select new
            {
                emp.TitleOfCourtesy,
                emp.FirstName,
                emp.LastName
            };
            var result = from ord in nw.Shippers
                         join t in nw.Orders on ord.ShipperID equals t.Shipper.ShipperID
                         select new
            {
                ord.ShipperID,
                ord.CompanyName,
                t.Customer.ContactName,
                t.CustomerID,
                t.Employee.FirstName,
                t.ShipAddress,
                t.ShipCity,
                t.ShipCountry
            };

            this.empDataGrid.ItemsSource = query.ToList();
            this.ordDataGrid.ItemsSource = result.ToList();
        }
Ejemplo n.º 3
0
        private void Del_Click(object sender, RoutedEventArgs e)
        {
            string            item = productC.SelectedItem.ToString();
            NORTHWNDEntities1 nw   = new NORTHWNDEntities1();
            var order = from x in nw.Order_Details
                        join v in nw.Products on x.ProductID equals v.ProductID
                        where v.ProductName == item
                        select x;

            foreach (Order_Detail res in order)
            {
                nw.Order_Details.Remove(res);
            }
            nw.SaveChanges();


            var query = from x in nw.Products
                        where x.ProductName == item
                        select x;
            Product result = query.SingleOrDefault();

            if (result != null)
            {
                nw.Products.Remove(result);
                nw.SaveChanges();
                confirmLbl.Content = "Product " + item + " Deleted from Database";
            }
            else
            {
                MessageBox.Show("An Error Occured");
            }
        }
Ejemplo n.º 4
0
        private void selc(object sender, SelectionChangedEventArgs e)
        {
            NORTHWNDEntities1 nw  = new NORTHWNDEntities1();
            string            cat = "";
            var result            = from pd in nw.Products
                                    join ct in nw.Categories on pd.CategoryID equals ct.CategoryID
                                    select new
            {
                ct.CategoryName
            };

            foreach (var item in result)
            {
                cat = item.CategoryName.ToString();
            }
            CategoryF.Text = cat;
            var res = from pd in nw.Products
                      join sp in nw.Suppliers on pd.SupplierID equals sp.SupplierID
                      select new
            {
                sp.CompanyName
            };

            foreach (var item in res)
            {
                cat = item.CompanyName.ToString();
            }
            SupplierF.Text = cat;
            var query = from pd in nw.Products
                        where pd.ProductName == NameC.SelectedItem
                        select pd;
            Product p = query.SingleOrDefault();

            if (query != null)
            {
                //p.Category = new Category()
                //{
                //    CategoryName = CategoryF.Text,
                //    CategoryID = 555
                //};
                //p.Supplier = new Supplier()
                //{
                //    SupplierID = 222,
                //    CompanyName = SupplierF.Text
                //};
                //p.UnitPrice = decimal.Parse(PriceF.Text);
                //p.QuantityPerUnit = QuantityF.Text;
            }
            nw.SaveChanges();
        }
Ejemplo n.º 5
0
        public delete()
        {
            InitializeComponent();
            NORTHWNDEntities1 nw = new NORTHWNDEntities1();

            var res = from pd in nw.Products
                      select new
            {
                pd.ProductName
            };

            foreach (var item in res)
            {
                productC.Items.Add(item.ProductName.ToString());
            }
        }
Ejemplo n.º 6
0
        public update()
        {
            InitializeComponent();
            NORTHWNDEntities1 nw = new NORTHWNDEntities1();
            int cat = 0;
            int sup = 0;

            var res = from pd in nw.Products
                      select new
            {
                pd.ProductName
            };

            foreach (var item in res)
            {
                NameC.Items.Add(item.ProductName.ToString());
            }
        }
Ejemplo n.º 7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NORTHWNDEntities1 nw = new NORTHWNDEntities1();
            int cat = 0;
            int sup = 0;

            var res = from sp in nw.Suppliers
                      where sp.CompanyName == SupplierC.SelectedItem.ToString()
                      select new
            {
                sp.SupplierID
            };

            foreach (var item in res)
            {
                sup = item.SupplierID;
            }
            var result = from ct in nw.Categories
                         where ct.CategoryName == CategoryC.SelectedItem.ToString()
                         select new
            {
                ct.CategoryID
            };

            foreach (var item in result)
            {
                cat = item.CategoryID;
            }
            Console.WriteLine(cat + "" + sup);

            nw.Products.Add(new Product()
            {
                ProductName  = NameF.Text,
                CategoryID   = cat,
                SupplierID   = sup,
                UnitsInStock = short.Parse(QuantityF.Text),
                UnitPrice    = int.Parse(PriceF.Text)
            });
            nw.SaveChanges();
        }