//"Tools -> Merge -> Merge Databases" menu item private void menu_ToolsMergeMergeDBMenuItem_Click(object sender, EventArgs e) { MergeDialog mdialog = new MergeDialog(GuiPrefs.DefaultDBDir, Mydb); mdialog.StartPosition = FormStartPosition.CenterParent; if (mdialog.ShowDialog() == DialogResult.OK) { if (!Mydb.IsOpen()) { Mydb.OpenDB(Mydb.MyPath); } UpdateAfterOpenDB(); } }
/// <summary> /// Click event for the File->Restore menu item /// </summary> private void menu_FileRestoreMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = GuiPrefs.DefaultBackupDir; ofd.Filter = "Second Sight Database Files (*.ssd, *.ssb)|*.ssd;*.ssb|All files (*.*)|*.*"; ofd.Title = "Restore the current database from a backup."; ofd.Multiselect = false; ofd.CheckFileExists = true; ofd.CheckPathExists = true; if (!Mydb.IsOpen()) { MessageBox.Show("No database is currently loaded. Please load a database " + "before attempting to restore a database from a backup.", "No Loaded Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //If no database is loaded if (ofd.ShowDialog() == DialogResult.OK) { if (MessageBox.Show("The current database will be permanently replaced with the backup you selected. Are you sure you want to continue?", "Confirm Restore", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { string currentdbpath = GuiPrefs.OpenDBPath; try { Mydb.CloseDB(); File.Copy(ofd.FileName, currentdbpath, true); Mydb.OpenDB(currentdbpath); MessageBox.Show("The database was successfully restored.", "Restore Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("The database could not be restored. Make sure you have permission to write to the destination folder.", "Restore Unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { Mydb.OpenDB(currentdbpath); UpdateAfterOpenDB(); } } } } }
///<summary> /// Click event for the File -> Backup Database menu item. /// </summary> private void menu_FileBackupMenuItem_Click(object sender, EventArgs e) { string tdate = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = GuiPrefs.DefaultBackupDir; sfd.Filter = "Second Sight Database Files (*.ssd)|*.ssd|All files (*.*)|*.*"; sfd.Title = "Back up the currently open database."; tdate = DateTime.Today.ToShortDateString(); tdate = tdate.Replace("/", "-"); sfd.FileName = String.Format("{1}({2})-{0}.ssd", tdate, GuiPrefs.OpenDBName, GuiPrefs.OpenDBLoc); if (!Mydb.IsOpen()) { //If no database is loaded MessageBox.Show("No database is currently loaded. Please load a database " + "before attempting to back up the database.", "No Loaded Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (sfd.ShowDialog() == DialogResult.OK) { try { File.Delete(sfd.FileName); File.Copy(GuiPrefs.OpenDBPath, sfd.FileName); MessageBox.Show("The database was successfully backed up.", "Backup Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("The database could not be backed up. Make sure you have permission to write to the destination folder.", "Backup Unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <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; } }