public wndSearch() { InitializeComponent(); // New instance of Search Logic class clsSL = new clsSearchLogic(); // Getting all invoice records from the Db Invoices = clsSL.GetAllInvoices(); foreach (var invoice in Invoices) { // need to display all invoices in each drop down InvoiceCB.Items.Add(invoice.InvoiceNum); TotalChargesCB.Items.Add(invoice.InvoiceCost); DateCB.Items.Add(invoice.InvoiceDate); } // Populating the data grid srchDataGrid.CanUserAddRows = false; srchDataGrid.IsReadOnly = true; srchDataGrid.ItemsSource = clsSL.GetAllInvoices(); }
/// <summary> /// This method is called to each time the user determines search /// criteria and updates the data grid /// </summary> private void updateDG() { try { // The user has specified at least one constraint for their search selectionMade = true; if (resetSelected) { // Resetting the data grid back to initial state srchDataGrid.ItemsSource = clsSL.GetAllInvoices(); // reset selected indexes InvoiceCB.SelectedIndex = -1; TotalChargesCB.SelectedIndex = -1; DateCB.SelectedIndex = -1; // Resetting all boolean values to false InvoiceNumChosen = false; TotalChargesChosen = false; InvoiceDateChosen = false; selectionMade = false; // resetting the reset boolean resetSelected = false; } // this checks each boolean variable to determine with SQL statement should be executed if (InvoiceNumChosen && !TotalChargesChosen && !InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getInvoice(InvoiceCB.SelectedItem as string); } else if (!InvoiceNumChosen && TotalChargesChosen && !InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getTotalCharges(TotalChargesCB.SelectedItem as string); } else if (!InvoiceNumChosen && !TotalChargesChosen && InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getInvoiceDate(dateChosen); } else if (InvoiceNumChosen && !TotalChargesChosen && InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getInvoiceNumDate(InvoiceCB.SelectedItem as string, dateChosen); } else if (InvoiceNumChosen && TotalChargesChosen && InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getAllData(InvoiceCB.SelectedItem as string, TotalChargesCB.SelectedItem as string, dateChosen); } else if (!InvoiceNumChosen && TotalChargesChosen && InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getCostDate(TotalChargesCB.SelectedItem as string, dateChosen); } else if (InvoiceNumChosen && TotalChargesChosen && !InvoiceDateChosen) { srchDataGrid.ItemsSource = clsSL.getNumCost(InvoiceCB.SelectedItem as string, TotalChargesCB.SelectedItem as string); } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }