void Initialize() { using (var db = new NorthwindEntities2()) { customers = db.Customer.ToList(); foreach (var customer in customers) { if (!cityDictionary.ContainsKey(customer.City)) { cityDictionary.Add(customer.City, customer.Country); } if (!titles.Contains(customer.ContactTitle)) { titles.Add(customer.ContactTitle); ids.Add(customer.CustomerID); } foreach (var element in cityDictionary) { City.Items.Add(element.Key); } foreach (var element in titles) { Title.Items.Add(element); } } } }
void Initialize() { using (var db = new NorthwindEntities2()) { customers = db.Customer.ToList(); ListBox01.ItemsSource = customers; ListBox01.DisplayMemberPath = "ContactName"; } }
private void ListBox03_SelectionChanged(object sender, SelectionChangedEventArgs e) { details = (Order_Detail)ListBox03.SelectedItem; using (var db = new NorthwindEntities2()) { product = db.Products.Where(product => product.ProductID == details.ProductID).ToList <Product>(); ListBox04.ItemsSource = product; ListBox04.DisplayMemberPath = "ProductName"; } }
private void ListBox02_SelectionChanged(object sender, SelectionChangedEventArgs e) { order = (Order)ListBox02.SelectedItem; using (var db = new NorthwindEntities2()) { orderDetails = db.Order_Details.Where(OrderDetails => OrderDetails.OrderID == order.OrderID).ToList <Order_Detail>(); ListBox03.ItemsSource = orderDetails; ListBox03.DisplayMemberPath = "ProductID"; } }
private void ListBox01_SelectionChanged(object sender, SelectionChangedEventArgs e) { customer = (Customer)ListBox01.SelectedItem; //ListBox01.SelectedItem as Customer; DisplayData(); using (var db = new NorthwindEntities2()) { orders = db.Orders.Where(o => o.CustomerID == customer.CustomerID).ToList <Order>(); ListBox02.ItemsSource = orders; ListBox02.DisplayMemberPath = "OrderID"; } }
private void AddCustomer_Click(object sender, RoutedEventArgs e) { string name = Name.Text; string company = Company.Text; string contactTitle; try { contactTitle = Title.SelectedItem.ToString(); } catch { contactTitle = ""; } string address = Address.Text; string postCode = PostCode.Text; string region = Region.Text; string city; string country; try { city = City.SelectedItem.ToString(); country = cityDictionary[city]; } catch { city = ""; country = ""; } string id; while (true) { id = RandomID(); if (!ids.Contains(id)) { break; } } ids.Add(id); int.TryParse(ContactNo.Text, out int contactNo); int.TryParse(FaxNo.Text, out int faxNo); MessageBox.Show(contactNo.ToString() + " " + faxNo); MessageBox.Show(id); if (name == "" || company == "" || contactTitle == "" || address == "" || postCode == "" || region == "" || city == "") { MessageBox.Show("All fields mush be completed"); } else { using (var db = new NorthwindEntities2()) { Customer customer = new Customer() { CustomerID = id, ContactName = name, CompanyName = company, ContactTitle = contactTitle, Phone = contactNo.ToString(), Fax = faxNo.ToString(), Address = address, PostalCode = postCode, Region = region, City = city, Country = country }; db.Customer.Add(customer); db.SaveChanges(); } } }