Add export/reporting feature.

This commit is contained in:
kougyokugentou 2020-05-14 14:34:18 -07:00
parent 77b432e1c0
commit beb4828249
3 changed files with 73 additions and 63 deletions

70
Form1.Designer.cs generated
View File

@ -48,16 +48,12 @@
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.newStudentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveStudentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.studentBySchoolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.studentsByProgramToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitWithoutSavingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitsavesDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.studentDbID = new System.Windows.Forms.NumericUpDown();
this.parentDbID = new System.Windows.Forms.NumericUpDown();
this.student_pictureBox = new System.Windows.Forms.PictureBox();
this.lastNameTextBox = new System.Windows.Forms.TextBox();
this.studentBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.firstNameTextBox = new System.Windows.Forms.TextBox();
this.student_idTextBox = new System.Windows.Forms.TextBox();
this.dob_dateTimePicker = new System.Windows.Forms.DateTimePicker();
@ -81,6 +77,9 @@
this.toolTips = new System.Windows.Forms.ToolTip(this.components);
this.foundStudents_comboBox = new System.Windows.Forms.ComboBox();
this.lblFoundStudents = new System.Windows.Forms.Label();
this.studentBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.exportAllDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveFileDialogReport = new System.Windows.Forms.SaveFileDialog();
lastNameLabel = new System.Windows.Forms.Label();
firstNameLabel = new System.Windows.Forms.Label();
student_idLabel = new System.Windows.Forms.Label();
@ -99,10 +98,10 @@
((System.ComponentModel.ISupportInitialize)(this.studentDbID)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.parentDbID)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.student_pictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.studentBindingSource)).BeginInit();
this.parent_groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.phoneNumberNumericUpDown)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.studentBindingSource)).BeginInit();
this.SuspendLayout();
//
// lastNameLabel
@ -290,7 +289,7 @@
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.newStudentToolStripMenuItem,
this.saveStudentToolStripMenuItem,
this.reportsToolStripMenuItem,
this.exportAllDataToolStripMenuItem,
this.exitWithoutSavingToolStripMenuItem,
this.exitsavesDataToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
@ -300,51 +299,28 @@
// newStudentToolStripMenuItem
//
this.newStudentToolStripMenuItem.Name = "newStudentToolStripMenuItem";
this.newStudentToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
this.newStudentToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.newStudentToolStripMenuItem.Text = "&New Student";
this.newStudentToolStripMenuItem.Click += new System.EventHandler(this.clear_button_Click);
//
// saveStudentToolStripMenuItem
//
this.saveStudentToolStripMenuItem.Name = "saveStudentToolStripMenuItem";
this.saveStudentToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
this.saveStudentToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.saveStudentToolStripMenuItem.Text = "&Save Student";
this.saveStudentToolStripMenuItem.Click += new System.EventHandler(this.save_button_Click);
//
// reportsToolStripMenuItem
//
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.studentBySchoolToolStripMenuItem,
this.studentsByProgramToolStripMenuItem});
this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
this.reportsToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
this.reportsToolStripMenuItem.Text = "Reports";
//
// studentBySchoolToolStripMenuItem
//
this.studentBySchoolToolStripMenuItem.Name = "studentBySchoolToolStripMenuItem";
this.studentBySchoolToolStripMenuItem.Size = new System.Drawing.Size(283, 34);
this.studentBySchoolToolStripMenuItem.Text = "Students by school";
this.studentBySchoolToolStripMenuItem.Click += new System.EventHandler(this.studentBySchoolToolStripMenuItem_Click);
//
// studentsByProgramToolStripMenuItem
//
this.studentsByProgramToolStripMenuItem.Name = "studentsByProgramToolStripMenuItem";
this.studentsByProgramToolStripMenuItem.Size = new System.Drawing.Size(283, 34);
this.studentsByProgramToolStripMenuItem.Text = "Students by program";
this.studentsByProgramToolStripMenuItem.Click += new System.EventHandler(this.studentsByProgramToolStripMenuItem_Click);
//
// exitWithoutSavingToolStripMenuItem
//
this.exitWithoutSavingToolStripMenuItem.Name = "exitWithoutSavingToolStripMenuItem";
this.exitWithoutSavingToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
this.exitWithoutSavingToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.exitWithoutSavingToolStripMenuItem.Text = "Exit without saving";
this.exitWithoutSavingToolStripMenuItem.Click += new System.EventHandler(this.exitWithoutSavingToolStripMenuItem_Click);
//
// exitsavesDataToolStripMenuItem
//
this.exitsavesDataToolStripMenuItem.Name = "exitsavesDataToolStripMenuItem";
this.exitsavesDataToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
this.exitsavesDataToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.exitsavesDataToolStripMenuItem.Text = "E&xit (saves data)";
this.exitsavesDataToolStripMenuItem.Click += new System.EventHandler(this.exitsavesDataToolStripMenuItem_Click);
//
@ -392,10 +368,6 @@
this.lastNameTextBox.TabIndex = 1;
this.lastNameTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.String_TextBox_Validating);
//
// studentBindingSource
//
this.studentBindingSource.DataSource = typeof(DBWizard.Models.Student);
//
// firstNameTextBox
//
this.firstNameTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
@ -679,6 +651,23 @@
this.lblFoundStudents.TabIndex = 28;
this.lblFoundStudents.Text = "Found Students:";
//
// studentBindingSource
//
this.studentBindingSource.DataSource = typeof(DBWizard.Models.Student);
//
// exportAllDataToolStripMenuItem
//
this.exportAllDataToolStripMenuItem.Name = "exportAllDataToolStripMenuItem";
this.exportAllDataToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.exportAllDataToolStripMenuItem.Text = "Export All Data";
this.exportAllDataToolStripMenuItem.Click += new System.EventHandler(this.exportAllDataToolStripMenuItem_Click);
//
// saveFileDialogReport
//
this.saveFileDialogReport.DefaultExt = "CSV";
this.saveFileDialogReport.Filter = "CSV Files|*.csv";
this.saveFileDialogReport.Title = "Save Report";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
@ -725,11 +714,11 @@
((System.ComponentModel.ISupportInitialize)(this.studentDbID)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.parentDbID)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.student_pictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.studentBindingSource)).EndInit();
this.parent_groupBox.ResumeLayout(false);
this.parent_groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.phoneNumberNumericUpDown)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.studentBindingSource)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -753,9 +742,6 @@
private System.Windows.Forms.ComboBox gradeLevelComboBox;
private System.Windows.Forms.ToolStripMenuItem newStudentToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveStudentToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem reportsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem studentBySchoolToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem studentsByProgramToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitsavesDataToolStripMenuItem;
private System.Windows.Forms.Button save_button;
private System.Windows.Forms.GroupBox parent_groupBox;
@ -775,6 +761,8 @@
private System.Windows.Forms.NumericUpDown studentDbID;
private System.Windows.Forms.ToolStripMenuItem exitWithoutSavingToolStripMenuItem;
private System.Windows.Forms.NumericUpDown parentDbID;
private System.Windows.Forms.ToolStripMenuItem exportAllDataToolStripMenuItem;
private System.Windows.Forms.SaveFileDialog saveFileDialogReport;
}
}

View File

@ -1,4 +1,5 @@
using DBWizard.Models;
using CsvHelper;
using DBWizard.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -91,7 +92,7 @@ namespace DBWizard
}
catch (Exception ex)
{
MessageBox.Show("Unable to read selected file, try again.");
MessageBox.Show("Unable to read selected file, try again.", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
}
@ -110,7 +111,7 @@ namespace DBWizard
dickpic = ImageToByteArray(student_pictureBox.Image);
if (dickpic.Length >= 2147483647) //THAT'S WHAT SHE SAID
{
MessageBox.Show("The selected student photo size is too large. Choose a smaller photo size or shrink the photo.");
MessageBox.Show("The selected student photo size is too large. Choose a smaller photo size or shrink the photo.", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
}
@ -134,7 +135,7 @@ namespace DBWizard
{
if (errorProvider1.GetError(c) != "")
{
MessageBox.Show("Please fix the errors on the form!");
MessageBox.Show("Student not saved due to errors on the form!", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
}
@ -146,7 +147,7 @@ namespace DBWizard
dickpic = ImageToByteArray(student_pictureBox.Image);
if (dickpic.Length >= 2147483647) //THAT'S WHAT SHE SAID
{
MessageBox.Show("The selected student photo size is too large. Choose a smaller photo size or shrink the photo.");
MessageBox.Show("The selected student photo size is too large. Choose a smaller photo size or shrink the photo.", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
}
@ -184,13 +185,13 @@ namespace DBWizard
SqliteDataAccess.UpdateStudent(student);
SqliteDataAccess.UpdateParent(parent);
MessageBox.Show("Student and parent successfully updated.");
MessageBox.Show("Student and parent successfully updated.", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
}
else //new student
{
student.parent_id = SqliteDataAccess.InsertNewParent(parent);
SqliteDataAccess.InsertNewStudent(student);
MessageBox.Show("Student successfully added");
MessageBox.Show("Student successfully added", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
ClearForm();
}
}
@ -480,7 +481,7 @@ namespace DBWizard
//Dispose of the objects.
ClearForm();
MessageBox.Show("Student deleted from database.");
MessageBox.Show("Student deleted from database.", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
}
#region redundancy
@ -495,6 +496,7 @@ namespace DBWizard
private void exitsavesDataToolStripMenuItem_Click(object sender, EventArgs e)
{
//Error handling happens on the save_button_Click event, so no need to do it here.
save_button_Click(save_button, EventArgs.Empty);
@ -503,16 +505,33 @@ namespace DBWizard
}
#endregion
private void studentBySchoolToolStripMenuItem_Click(object sender, EventArgs e)
/* Exports the data from the database into readable format.
* INPUT: no args
* OUTPUT: File to disk.
*/
private void exportAllDataToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This function will generate a report of students by school.\nIt's not done yet.");
return;
}
//Build the default filename
saveFileDialogReport.FileName = DateTime.Now.ToString("yy.MM.dd") + "-report.csv";
if (saveFileDialogReport.ShowDialog() == DialogResult.OK
&& saveFileDialogReport.FileName != "")
{
string filename = saveFileDialogReport.FileName;
List<ReportFull> report = new List<ReportFull>();
report = SqliteDataAccess.GetFullDBDump();
TextWriter textWriter = new StreamWriter(filename);
CsvWriter csvWriter = new CsvWriter(textWriter);
csvWriter.WriteRecords(report);
textWriter.Close();
MessageBox.Show("Report Generated", "KentYouthDB", MessageBoxButtons.OK, MessageBoxIcon.None);
}
private void studentsByProgramToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This function will generate a report of students by program.\nIt's not done yet.");
return;
}
} //Form1
}

View File

@ -216,18 +216,12 @@
<metadata name="studentBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>204, 17</value>
</metadata>
<metadata name="studentBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>204, 17</value>
</metadata>
<metadata name="toolTips.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>490, 20</value>
</metadata>
<metadata name="pic_openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>713, 17</value>
</metadata>
<metadata name="toolTips.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>490, 20</value>
</metadata>
<metadata name="errorProvider1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>929, 17</value>
</metadata>
@ -2185,4 +2179,13 @@
AAA=
</value>
</data>
<metadata name="toolTips.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>490, 20</value>
</metadata>
<metadata name="studentBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>204, 17</value>
</metadata>
<metadata name="saveFileDialogReport.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 65</value>
</metadata>
</root>