private void ChengeTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { Groups item = (GroupDataGrid.SelectedItem as Groups); if (item != null) { AddGroupWindow agw = new AddGroupWindow(item); if (agw.ShowDialog() == true) { Groups temp = agw.group; if (item.groupTitle != temp.groupTitle || item.groupDescription != temp.groupDescription) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var ppp = context.Groups.FirstOrDefault(s => s.groupID == temp.groupID); //context.Groups.FirstOrDefault(s => s.groupID == temp.groupID).groupDescription = temp.groupDescription; ppp.groupTitle = temp.groupTitle; ppp.groupDescription = temp.groupDescription; context.SaveChanges(); MessageBox.Show("Изменения сохранены"); ppp = groupList.FirstOrDefault(s => s.groupID == temp.groupID); ppp.groupTitle = temp.groupTitle; ppp.groupDescription = temp.groupDescription; GroupDataGrid.Items.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } //if } //if }
} //ShowSupliersWindow private void AddContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { Suppliers supplier = SuppliersDataGrid.SelectedItem as Suppliers; if (supplier == null) { return; } AddContactWindow scw = new AddContactWindow(supplier); if (scw.ShowDialog() == true) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { Contacts newContacts = new Contacts(); newContacts.contact = scw.newContact.contact; newContacts.ContactTypeID = scw.newContact.ContactTypeID; newContacts.description = scw.newContact.description; newContacts.employeeID = scw.newContact.employeeID; newContacts.supplierID = scw.newContact.supplierID; context.Contacts.Add(newContacts); context.SaveChanges(); MessageBox.Show("Контакт добавлен"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void MainDockPanel_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.F2: { AddGroupWindow ad = new AddGroupWindow(); if (ad.ShowDialog() == true) { Groups temp = ad.group; try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { context.Groups.Add(temp); context.SaveChanges(); MessageBox.Show("Изменения сохранены"); groupList.Add(temp); GroupDataGrid.Items.Refresh(); } //using } //try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if } //case Key.F2 break; case Key.Escape: { this.Content = null; } //case Key.Escape break; default: break; } }
public AddContactWindow(Suppliers item) { InitializeComponent(); this.contactType = new List <ContactType>(); EmployeerTextBox.IsEnabled = false; // BrowseEmployeerButton.IsEnabled = false; SupplierTextBox.IsEnabled = false; SupplierTextBox.Text = item.supplierID.ToString(); //BrowseSupplierButton.IsEnabled = false; SupplierCommentTextBox.Text = $"{item.companyName} : {item.contactName}"; using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { contactType.AddRange(context.ContactType.ToList()); ContactTypeComboBox.ItemsSource = contactType.Select(s => s.contactType1).ToList(); ContactTypeComboBox.SelectedIndex = 0; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } // using }
private void SaveInvoiceButton_Click(object sender, RoutedEventArgs e) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { this.detailsList.ForEach(d => { InvoiceDetails dummy = new InvoiceDetails { invoiceID = d.InvoiceID, productID = d.ProductID, quantity = d.Quantity, price = d.Price }; context.InvoiceDetails.Add(dummy); }); context.SaveChanges(); this.detailsList.Clear(); this.LoadInvoices(this.newInvoice.date); this.MainOrdersShowRow.Height = this.AddNewOrderRow.Height; this.AddNewOrderRow.Height = new GridLength(0); AddNewProductRow.Height = new GridLength(0); }//using } catch (Exception ex) { MessageBox.Show(ex.Message); }//catch }
} //SerchByContactVelueTextBox_TextChanged private void ChengeContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { if (ContactsDataGrid.SelectedItem is SimpleContact contact) { AddContactWindow acw = new AddContactWindow(contact); if (acw.ShowDialog() == true) { Contacts newcont = acw.newContact; if (newcont.contact != contact.contact || newcont.description != contact.description) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var ppp = context.Contacts.FirstOrDefault(s => s.ContactID == contact.ContactID); ppp.contact = newcont.contact; ppp.description = newcont.description; context.SaveChanges(); MessageBox.Show("Изменения сохранены"); contact.contact = newcont.contact;; contact.description = newcont.description; ContactsDataGrid.Items.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } //if } //if }
}//SerchByCompanyNameTextBox_TextChanged private void ChengeTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { Suppliers item = (SuppliersDataGrid.SelectedItem as Suppliers); if (item != null) { AddSuppliersWindow asw = new AddSuppliersWindow(item); if (asw.ShowDialog() == true) { Suppliers temp = asw.sup; if (item.companyName != temp.companyName || item.contactName != temp.contactName) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var ppp = context.Suppliers.FirstOrDefault(s => s.supplierID == temp.supplierID); //context.Groups.FirstOrDefault(s => s.groupID == temp.groupID).groupDescription = temp.groupDescription; ppp.companyName = temp.companyName; ppp.contactName = temp.contactName; context.SaveChanges(); MessageBox.Show("Изменения сохранены"); ppp = suppList.FirstOrDefault(s => s.supplierID == temp.supplierID); ppp.companyName = temp.companyName; ppp.contactName = temp.contactName; SuppliersDataGrid.Items.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } //if } //if } //ChengeTextBlock_MouseDown
} //ChengeTextBlock_MouseDown private void MainSupDockPanel_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.F2: { AddSuppliersWindow adsw = new AddSuppliersWindow(); if (adsw.ShowDialog() == true) { Suppliers temp = adsw.sup; try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { context.Suppliers.Add(temp); context.SaveChanges(); MessageBox.Show("Изменения сохранены"); suppList.Add(temp); SuppliersDataGrid.Items.Refresh(); } //using } //try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if } //case Key.F2 break; default: break; } //switch } //MainSupDockPanel_KeyDown
}//CreateProductWindow private void OKButton_Click(object sender, RoutedEventArgs e) { if (this.TitleTextBox.Text.Trim().Length != 0 && this.GroupNumberTextBox.Text.Trim().Length != 0) { short groupCode; if (!short.TryParse(this.GroupNumberTextBox.Text.Trim(), out groupCode)) { MessageBox.Show("Проверьте номер группы"); return; }//if this.product.groupID = groupCode; this.product.barcode = this.BarCodeTextBox.Text.Trim().Length != 0 ? this.BarCodeTextBox.Text.Trim() : "Undefined"; this.product.productTitle = this.TitleTextBox.Text.Trim(); try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { if (context.Products.ToList().FirstOrDefault(s => (s.productTitle == this.product.productTitle) && s.groupID == this.product.groupID) != null) { MessageBox.Show("Продукт с таким названием в данной группе уже существует!"); return; } //if } //using this.DialogResult = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if else { MessageBox.Show("Заполните все поля!"); return; } }//OKButton_Click
} //Button_Click // Обработка нажатия кнопок private void DockPanel_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { //Добавить новый продукт case Key.F2: { CreateProductWindow cpw = new CreateProductWindow(); if (cpw.ShowDialog() == true) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { Products prod = new Products(); prod.barcode = cpw.product.barcode; prod.groupID = cpw.product.groupID; prod.productTitle = cpw.product.productTitle; context.Products.Add(prod); context.SaveChanges(); MessageBox.Show("Продукт добавлен!"); this.productLict.Add(prod); ProductDataGrid.Items.Refresh(); } //using } catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } } break; default: break; } }
private void GroupTextBox_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter: { if (!short.TryParse(this.GroupTextBox.Text, out short groupID)) { MessageBox.Show("Введите корректную группу!"); this.GroupTextBox.Focus(); return; } //if try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var group = context.Groups.FirstOrDefault(g => g.groupID == groupID); if (group == null) { this.GroupTextBox.Focus(); return; } //if this.GroupTitleLabel.Content = (object)group.groupTitle; } //using ProductIDTextBox.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Key.F1: { ShowGroupWindow sw = new ShowGroupWindow(); if (sw.ShowDialog() == true) { this.GroupTextBox.Text = sw.number.ToString(); try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var group = context.Groups.FirstOrDefault(g => g.groupID == sw.number); this.GroupTitleLabel.Content = (object)group.groupTitle; } //using ProductIDTextBox.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } break; default: break; }//switch }
private void ProductIDTextBox_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter: { if (!int.TryParse(this.ProductIDTextBox.Text, out int prodID)) { MessageBox.Show("Введите корректный код!"); this.ProductIDTextBox.Focus(); return; } //if try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { this.ProductTitleLabel.Content = (object)context.Products.FirstOrDefault(g => g.productID == prodID).productTitle; } //using PriceTextBox.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Key.F1: { if (!short.TryParse(this.GroupTextBox.Text, out short groupID)) { MessageBox.Show("Введите корректную группу!"); this.GroupTextBox.Focus(); return; } //if GetProductWindow gpw = new GetProductWindow(groupID); if (gpw.ShowDialog() == true) { this.ProductIDTextBox.Text = gpw.currentProduct.productID.ToString(); try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { this.ProductTitleLabel.Content = (object)context.Products.FirstOrDefault(g => g.productID == gpw.currentProduct.productID).productTitle; } //using PriceTextBox.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } break; default: break; }//switch }
private void Page_Loaded(object sender, RoutedEventArgs e) { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { productLict = context.Products.ToList(); ProductDataGrid.ItemsSource = productLict; ProductDataGrid.Focus(); ProductDataGrid.SelectedIndex = 0; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //using }
public ShowSupliersWindow() { InitializeComponent(); try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { suppList = context.Suppliers.ToList(); SuppliersDataGrid.ItemsSource = suppList; SuppliersDataGrid.SelectedIndex = 0; } //using }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //ShowSupliersWindow
public GroupPage() { InitializeComponent(); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { groupList = context.Groups.ToList(); GroupDataGrid.ItemsSource = groupList; GroupDataGrid.SelectedIndex = 0; GroupDataGrid.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public AddContactWindow() { InitializeComponent(); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { this.contactType = new List <ContactType>(); contactType.AddRange(context.ContactType.ToList()); ContactTypeComboBox.ItemsSource = contactType.Select(s => s.contactType1).ToList(); ContactTypeComboBox.SelectedIndex = 0; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } // using }
}//ShowProducts public ShowProducts(short gp) { InitializeComponent(); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { GroupTextBox.Text = gp.ToString(); productLict = context.Products.Where(p => p.groupID == gp).ToList(); ProductDataGrid.ItemsSource = productLict; ProductDataGrid.SelectedIndex = 0; this.BrowseGroupButton.IsEnabled = false; GroupTextBox.IsReadOnly = true; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //using } //ShowProducts
}//FillInvoiceFields private void OrderDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (invoicesList == null || !DateTime.TryParse(sender.ToString(), out DateTime date)) { return; } MessageBox.Show(date.ToString()); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { invoicesList = (from i in context.Invoices join s in context.Suppliers on i.supplierID equals s.supplierID where i.date.Day == date.Day && i.date.Month == date.Month && i.date.Year == date.Year select new InvoisesTemplate { CompanyName = s.companyName, Date = i.date, EmployeeID = i.employeeID, InvoiceID = i.invoiceID, InvoiceNumber = i.invoiceNumber, Official = i.official, Overhead = i.overhead, Paid = i.paid, PayToDate = i.payToDate, SupplierID = i.supplierID, TotalSumm = (from inv in context.Invoices join id in context.InvoiceDetails on inv.invoiceID equals id.invoiceID where inv.invoiceID == i.invoiceID select new { quantity = id.quantity, price = id.price }).Sum(s => (s.price * s.quantity)) }).ToList(); InvoicesDataGrid.ItemsSource = invoicesList; InvoicesDataGrid.SelectedIndex = 0; if (InvoicesDataGrid.SelectedIndex != -1) { InvoicesDataGrid.Focus(); } }//using }
private void EmployeerTextBox_TextChanged(object sender, TextChangedEventArgs e) { if (int.TryParse(EmployeerTextBox.Text.Trim(), out int employeerID)) { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { Employees empl = context.Employees.FirstOrDefault(em => em.employeeID == employeerID); if (empl == null) { return; } EmployeerCommentTextBox.Text = empl.lastName + " " + empl.firstName; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //using } //if } //EmployeerTextBox_TextChanged
} //EmployeerTextBox_TextChanged private void SupplierTextBox_TextChanged(object sender, TextChangedEventArgs e) { if (int.TryParse(SupplierTextBox.Text.Trim(), out int supID)) { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { Suppliers supl = context.Suppliers.FirstOrDefault(s => s.supplierID == supID); if (supl == null) { return; } SupplierCommentTextBox.Text = supl.companyName + " " + supl.contactName; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //using } //if }
}//ShowContactWindow public ShowContactWindow(Suppliers sup) { InitializeComponent(); this.currentSupplier = sup; using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { this.contactType = context.ContactType.ToList(); //SerchByContactTypeComboBox.ItemsSource = contactType.Select(s => s.contactType1).ToList(); SerchByContactTypeComboBox.Items.Add("Все"); contactType.Select(s => s.contactType1).ToList().ForEach(x => { SerchByContactTypeComboBox.Items.Add(x); }); SerchByContactTypeComboBox.SelectedIndex = 0; contactsList = (from c in context.Contacts join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID join s in context.Suppliers on c.supplierID equals s.supplierID where s.supplierID == this.currentSupplier.supplierID select new SimpleContact() { ContactID = c.ContactID, contactType = ct.contactType1, companyName = s.companyName, contact = c.contact, description = c.description ?? "", //firstName = "", //lastName = "" }).ToList(); //contactsList.AddRange(tesr); ContactsDataGrid.ItemsSource = contactsList; ContactsDataGrid.SelectedIndex = 0; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } // using }
}//SupplierIDTextBox_SelectionChanged private void SupplierIDTextBox_TextChanged(object sender, TextChangedEventArgs e) { if (SupplierIDTextBox.Text == "F2-поиск") { return; } if (int.TryParse(SupplierIDTextBox.Text, out int supId)) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { Suppliers mySuppliers = context.Suppliers.ToList().FirstOrDefault(s => (s.supplierID == supId)); if (mySuppliers != null) { SupplierNameLabel.Content = mySuppliers.companyName; } //if } //using } catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if } //SupplierIDTextBox_TextChanged
private void LoadInvoices(DateTime date) { //date = DateTime.Parse("10.06.2018"); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { invoicesList = (from i in context.Invoices join s in context.Suppliers on i.supplierID equals s.supplierID where i.date.Day == date.Day && i.date.Month == date.Month && i.date.Year == date.Year select new InvoisesTemplate { CompanyName = s.companyName, Date = i.date, EmployeeID = i.employeeID, InvoiceID = i.invoiceID, InvoiceNumber = i.invoiceNumber, Official = i.official, Overhead = i.overhead, Paid = i.paid, PayToDate = i.payToDate, SupplierID = i.supplierID, TotalSumm = (from inv in context.Invoices join id in context.InvoiceDetails on inv.invoiceID equals id.invoiceID where inv.invoiceID == i.invoiceID select new { quantity = id.quantity, price = id.price }).Sum(s => (s.price * s.quantity)) }).ToList(); InvoicesDataGrid.ItemsSource = invoicesList; InvoicesDataGrid.Focus(); InvoicesDataGrid.SelectedIndex = invoicesList.Count - 1; //if (InvoicesDataGrid.SelectedIndex != -1) { // InvoicesDataGrid.Focus(); //} }//using }
} //BrowseButton_Click private void GroupNumberTextBox_TextChanged(object sender, TextChangedEventArgs e) { //MessageBox.Show("GroupNumberTextBox_TextChanged"); if (short.TryParse(this.GroupNumberTextBox.Text.Trim(), out short tempCode)) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { Groups groups = context.Groups.ToList().FirstOrDefault(s => s.groupID == tempCode); if (groups != null) { this.GroupTitleTextBox.Text = groups.groupTitle; } //if } //using } catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if else { this.GroupTitleTextBox.Text = ""; } }//GroupNumberTextBox_TextChanged
public AddContactWindow(SimpleContact item) { InitializeComponent(); this.contactType = new List <ContactType>(); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { contactType.AddRange(context.ContactType.ToList()); ContactTypeComboBox.ItemsSource = contactType.Select(s => s.contactType1).ToList(); ContactTypeComboBox.SelectedItem = item.contactType; ContactTypeComboBox.IsEnabled = false; Contacts contact = context.Contacts.FirstOrDefault(c => c.ContactID == item.ContactID); if (contact == null) { this.DialogResult = false; } EmployeerTextBox.Text = contact.employeeID == null ? "" : contact.employeeID.ToString(); EmployeerTextBox.IsEnabled = false; SupplierTextBox.Text = contact.supplierID == null ? "" : contact.supplierID.ToString(); SupplierTextBox.IsEnabled = false; DescriptionTextBox.Text = item.description; ContactTextBox.Text = item.contact; OKButton.Content = "Сохранить"; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } // using }
} //ShowProducts //Контекстное меню изменение продукта private void ChengeProductTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { Products item = (ProductDataGrid.SelectedItem as Products); if (item != null) { CreateProductWindow agw = new CreateProductWindow(item); if (agw.ShowDialog() == true) { Products temp = agw.product; if (item.barcode != temp.barcode || item.groupID != temp.groupID || item.productTitle != temp.productTitle) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var ppp = context.Products.FirstOrDefault(s => s.productID == temp.productID); ppp.barcode = temp.barcode; ppp.groupID = temp.groupID; ppp.productTitle = temp.productTitle; context.SaveChanges(); MessageBox.Show("Изменения сохранены"); ppp = productLict.FirstOrDefault(s => s.productID == temp.productID); ppp.barcode = temp.barcode; ppp.groupID = temp.groupID; ppp.productTitle = temp.productTitle; ProductDataGrid.Items.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } //if } //if }
private void MainDockPanel_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.F2: { CreateNewInvoiceWindow cniw = new CreateNewInvoiceWindow(this.currentEmployeer); if (cniw.ShowDialog() == true) { this.detailsList.Clear(); this.InvoiceNewDataGrid.Items.Refresh(); this.newInvoice = cniw.newInvoice; try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { context.Invoices.Add(newInvoice); context.SaveChanges(); this.newInvoice = context.Invoices.OrderByDescending(inv => inv.invoiceID).First(); this.newInvoice.Suppliers = context.Suppliers.FirstOrDefault(s => s.supplierID == this.newInvoice.supplierID); FillInvoiceFields(); this.AddNewOrderRow.Height = this.MainOrdersShowRow.Height; this.MainOrdersShowRow.Height = new GridLength(0); AddNewProductRow.Height = new GridLength(130); this.InvoiceNewDataGrid.ItemsSource = this.detailsList; } //using } catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if } //case Key.F2 break; default: break; } }
private void Button_Click(object sender, RoutedEventArgs e) { ObjectParameter result = new ObjectParameter("result", -1); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { int authResult = context.Authorize(Login.Text, Password.Password, result); if ((int)result.Value != 0) { MessageBox.Show("Пользователь не найден! (" + result.Value + " )"); return; }//if var user = context.Users.FirstOrDefault( u => u.login == Login.Text ); if (user == null) { MessageBox.Show("Пользователь не найден!"); return; }//if Employees empl = context.Employees.Find(user.ownerID); if (empl == null) { MessageBox.Show("Пользователь не найден!"); return; }//if this.employees = empl; }//using this.DialogResult = true; }
public ShowContactWindow() { InitializeComponent(); using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { try { this.contactType = context.ContactType.ToList(); //SerchByContactTypeComboBox.ItemsSource = contactType.Select(s => s.contactType1).ToList(); SerchByContactTypeComboBox.Items.Add("Все"); contactType.Select(s => s.contactType1).ToList().ForEach(x => { SerchByContactTypeComboBox.Items.Add(x); }); SerchByContactTypeComboBox.SelectedIndex = 0; contactsList = (from c in context.Contacts join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID join s in context.Suppliers on c.supplierID equals s.supplierID select new SimpleContact() { ContactID = c.ContactID, contactType = ct.contactType1, companyName = s.companyName, contact = c.contact, description = c.description ?? "", //firstName = "", //lastName = "" }).ToList(); var test = (from c in context.Contacts join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID join e in context.Employees on c.employeeID equals e.employeeID select new SimpleContact() { ContactID = c.ContactID, contactType = ct.contactType1, //companyName = "", contact = c.contact, description = c.description ?? "", firstName = e.firstName, lastName = e.lastName }).ToList(); //contactsList.AddRange(tesr); contactsList.AddRange(test); ContactsDataGrid.ItemsSource = contactsList; ContactsDataGrid.SelectedIndex = 0; }//try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } // using //using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { // try { // var tesr = from c in context.Contacts // join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID // join s in context.Suppliers on c.supplierID equals s.supplierID // select new { // ContactID = c.ContactID, // contactType = ct.contactType1, // companyName = s.companyName, // contact = c.contact, // description = c.description, // firstName = "", // lastName = "" // }; // var test = from c in context.Contacts // join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID // join e in context.Employees on c.employeeID equals e.employeeID // select new { // ContactID = c.ContactID, // contactType = ct.contactType1, // companyName = "", // contact = c.contact, // description = c.description, // firstName = e.firstName, // lastName = e.lastName // }; // var res = tesr.ToList(); // //contactsList.AddRange(tesr); // res.AddRange(test.ToList()); // ContactsDataGrid.ItemsSource = res; // ContactsDataGrid.SelectedIndex = 0; // }//try // catch (Exception ex) { // MessageBox.Show(ex.Message); // }//catch //}// using }//ShowContactWindow
private void SerchByContactTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (contactsList == null) { return; } int index = SerchByContactTypeComboBox.SelectedIndex; if (index == 0) { ContactsDataGrid.ItemsSource = contactsList; ContactsDataGrid.SelectedIndex = 0; }//if else { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { List <SimpleContact> temp; byte id = this.contactType[index - 1].contactTypeID; temp = (from c in context.Contacts join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID join s in context.Suppliers on c.supplierID equals s.supplierID where c.ContactTypeID == id select new SimpleContact() { ContactID = c.ContactID, contactType = ct.contactType1, companyName = s.companyName, contact = c.contact, description = c.description ?? "", //firstName = "", //lastName = "" }).ToList(); var test = (from c in context.Contacts join ct in context.ContactType on c.ContactTypeID equals ct.contactTypeID join em in context.Employees on c.employeeID equals em.employeeID where c.ContactTypeID == id select new SimpleContact() { ContactID = c.ContactID, contactType = ct.contactType1, //companyName = "", contact = c.contact, description = c.description ?? "", firstName = em.firstName, lastName = em.lastName }).ToList(); //contactsList.AddRange(tesr); temp.AddRange(test); ContactsDataGrid.ItemsSource = temp; ContactsDataGrid.SelectedIndex = 0; }// using } catch (Exception ex) { MessageBox.Show(ex.Message); }//catch } }