/// <summary> /// Click event for the Generate Report button. Validates all input and then assembles the /// data structure that is passed into the SSDataBase.CustomQuery function /// </summary> private void btn_R_GenerateReport_Click(object sender, EventArgs e) { SSTable querytable; Dictionary <int, LinkedList <string> > filterparams = new Dictionary <int, LinkedList <string> >(); if (!Mydb.IsOpen()) { MessageBox.Show("Please load a database before attempting to generate a report.", "No database loaded.", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (cb_R_ReportSource.SelectedIndex == 0) { querytable = SSTable.Current; } else { querytable = SSTable.Dispensed; } //Validate inputs where necessary try { repf_R_Filter.ValidateItems(); } catch (FormatException fex) { MessageBox.Show("Invalid filter value. Selected filter value " + fex.Message); return; } //Build and store the plain english version of the new query R_LastPlainEnglishQuery = BuildPlainEnglishQuery(); //Loop through each filter, validate inputs as necessary, and add the parameters to the Dictionary foreach (ReportFilterItem rfi in repf_R_Filter.FilterItems) { //If the "filter by" parameter doesn't exist in the dictionary yet, add it if (!filterparams.ContainsKey(rfi.cb_FilterBy.SelectedIndex)) { filterparams.Add(rfi.cb_FilterBy.SelectedIndex, new LinkedList <string>()); } if (rfi.cb_FilterBy.SelectedIndex < 9) { //Rx fields - validate and add values from TextBoxes filterparams[rfi.cb_FilterBy.SelectedIndex].AddLast(rfi.tb_FilterA.Text); filterparams[rfi.cb_FilterBy.SelectedIndex].AddLast(rfi.tb_FilterB.Text); } else if (rfi.cb_FilterBy.SelectedIndex > 12) { //Date fields - add values from DateTimePickers filterparams[rfi.cb_FilterBy.SelectedIndex].AddLast(rfi.dtp_FilterA.Value.Date.ToString("yyyy-MM-dd")); filterparams[rfi.cb_FilterBy.SelectedIndex].AddLast(rfi.dtp_FilterB.Value.Date.ToString("yyyy-MM-dd")); } else { //Selection fields - type, gender, size, tint - add values from ComboBox filterparams[rfi.cb_FilterBy.SelectedIndex].AddLast(rfi.cb_Selections.SelectedValue.ToString()); } } DataTable resultstable = new DataTable(); //Run the query resultstable = Mydb.ReportQuery(querytable, cb_R_ReportType.SelectedIndex == 1, cb_R_GroupBy.SelectedIndex + 1, filterparams); //Configure the results display if (cb_R_ReportType.SelectedIndex == 1) { //Summarries - configure results to display in small DGV DataTable sortedtable = new DataTable(); sortedtable = SortSummaryResults(resultstable); bs_R_Summaries.DataSource = sortedtable; //resultstable; bs_R_FullLists.DataSource = null; //Null this so Export Report can figure out which data to export R_LastGroupBy = cb_R_GroupBy.Text; dgv_R_Summaries.Columns[0].HeaderText = cb_R_GroupBy.Text; dgv_R_Summaries.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; dgv_R_Summaries.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; panel_R_Summarries.Visible = true; dgv_R_FullLists.Visible = false; //Graph configuration ConfigureReportGraph(sortedtable); } else { //Full lists - configure results to display in full SSDGV if (cb_R_ReportSource.SelectedIndex == 0) { dgv_R_FullLists.Columns["DateDispensed"].Visible = false; } else { dgv_R_FullLists.Columns["DateDispensed"].Visible = true; } bs_R_FullLists.DataSource = resultstable; bs_R_Summaries.DataSource = null; //Null this so Export Report can figure out which data to export R_LastGroupBy = ""; dgv_R_FullLists.Visible = true; panel_R_Summarries.Visible = false; } }