}//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 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 }