public void LoadInvoicesTable() { string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); List <int> invoicesIds = new List <int>(); // dataBlock.invoiceTable.OpenConnection(); dataBlock.OpenConnection(); invoicesIds = dataBlock.invoiceTable.GetAllInvoices(orgId); Session["InvoicesTab_UserControl_UsersIds"] = invoicesIds; DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("NAME", typeof(string))); dt.Columns.Add(new DataColumn("INVOICEDATE", typeof(string))); dt.Columns.Add(new DataColumn("PAYTERMDATE", typeof(string))); dt.Columns.Add(new DataColumn("STATUS", typeof(string))); dt.Columns.Add(new DataColumn("PAYDATE", typeof(string))); DateTime date = new DateTime(); string dateStringToShow = ""; foreach (int invoiceId in invoicesIds) { dr = dt.NewRow(); dr["NAME"] = dataBlock.invoiceTable.GetInvoiceName(invoiceId); date = dataBlock.invoiceTable.GetDateInvoice(invoiceId); dr["INVOICEDATE"] = date.ToShortDateString(); date = dataBlock.invoiceTable.GetDatePaymentTerm(invoiceId); dr["PAYTERMDATE"] = date.ToShortDateString(); dr["STATUS"] = dataBlock.invoiceTable.GetInvoiceStatus(invoiceId); //PAYTERMDATE - Дата оплаты if (DateTime.TryParse(dataBlock.invoiceTable.GetDatePayment(invoiceId), out date)) { dateStringToShow = date.ToShortDateString(); } else { dateStringToShow = "-"; } dr["PAYDATE"] = dateStringToShow; dt.Rows.Add(dr); } InvoicesDataGrid.DataSource = dt; InvoicesDataGrid.DataBind(); //dataBlock.invoiceTable.CloseConnection(); dataBlock.CloseConnection(); }
}//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 }