Add csvhelper nuget package
Update exit (Alt-F4) to Environment.Exit(0) Add: Generate report from SQL Database. Add: Input validation
This commit is contained in:
parent
d0b12a0141
commit
f499a53fc6
@ -117,6 +117,17 @@ namespace QueueSys
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReportView> QueryReports()
|
||||
{
|
||||
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||
{
|
||||
string strQuery = "SELECT *,Cast ((JulianDay(end_time) - JulianDay(start_time)) * 24 * 60 As Integer) as time_elapsed from archive";
|
||||
|
||||
var output = cnn.Query<ReportView>(strQuery, new DynamicParameters());
|
||||
return output.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private static string LoadConnectionString(string id="Default")
|
||||
{
|
||||
return ConfigurationManager.ConnectionStrings[id].ConnectionString;
|
||||
|
34
QueueSys/frmEmployeeView.Designer.cs
generated
34
QueueSys/frmEmployeeView.Designer.cs
generated
@ -28,6 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmEmployeeView));
|
||||
this.lblCustomerName = new System.Windows.Forms.Label();
|
||||
this.lblNumBags = new System.Windows.Forms.Label();
|
||||
@ -44,8 +45,11 @@
|
||||
this.dgvEmployeeView = new System.Windows.Forms.DataGridView();
|
||||
this.CustomerID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.CustomerName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components);
|
||||
this.saveFileDialogReport = new System.Windows.Forms.SaveFileDialog();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvEmployeeView)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lblCustomerName
|
||||
@ -86,6 +90,7 @@
|
||||
this.tbCustomerName.Name = "tbCustomerName";
|
||||
this.tbCustomerName.Size = new System.Drawing.Size(228, 26);
|
||||
this.tbCustomerName.TabIndex = 0;
|
||||
this.tbCustomerName.Validating += new System.ComponentModel.CancelEventHandler(this.tbCustomerName_Validating);
|
||||
//
|
||||
// cbNumBags
|
||||
//
|
||||
@ -103,6 +108,7 @@
|
||||
this.cbNumBags.Name = "cbNumBags";
|
||||
this.cbNumBags.Size = new System.Drawing.Size(180, 28);
|
||||
this.cbNumBags.TabIndex = 1;
|
||||
this.cbNumBags.Validating += new System.ComponentModel.CancelEventHandler(this.cbNumBags_Validating);
|
||||
//
|
||||
// btnAdd
|
||||
//
|
||||
@ -123,7 +129,7 @@
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(882, 36);
|
||||
this.menuStrip1.Size = new System.Drawing.Size(882, 33);
|
||||
this.menuStrip1.TabIndex = 5;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
@ -134,28 +140,29 @@
|
||||
this.optionsToolStripMenuItem,
|
||||
this.exitAltF4ToolStripMenuItem});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 32);
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 29);
|
||||
this.fileToolStripMenuItem.Text = "&File";
|
||||
//
|
||||
// generateReportToolStripMenuItem
|
||||
//
|
||||
this.generateReportToolStripMenuItem.Name = "generateReportToolStripMenuItem";
|
||||
this.generateReportToolStripMenuItem.Size = new System.Drawing.Size(242, 34);
|
||||
this.generateReportToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.generateReportToolStripMenuItem.Text = "&Generate Report";
|
||||
this.generateReportToolStripMenuItem.Click += new System.EventHandler(this.generateReportToolStripMenuItem_Click);
|
||||
//
|
||||
// optionsToolStripMenuItem
|
||||
//
|
||||
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
|
||||
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(242, 34);
|
||||
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.optionsToolStripMenuItem.Text = "Options";
|
||||
this.optionsToolStripMenuItem.Click += new System.EventHandler(this.optionsToolStripMenuItem_Click);
|
||||
//
|
||||
// exitAltF4ToolStripMenuItem
|
||||
//
|
||||
this.exitAltF4ToolStripMenuItem.Name = "exitAltF4ToolStripMenuItem";
|
||||
this.exitAltF4ToolStripMenuItem.Size = new System.Drawing.Size(242, 34);
|
||||
this.exitAltF4ToolStripMenuItem.Text = "E&xit (Alt-F4)";
|
||||
this.exitAltF4ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
|
||||
this.exitAltF4ToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.exitAltF4ToolStripMenuItem.Text = "E&xit";
|
||||
this.exitAltF4ToolStripMenuItem.Click += new System.EventHandler(this.exitAltF4ToolStripMenuItem_Click);
|
||||
//
|
||||
// tbEmployeeName
|
||||
@ -164,6 +171,7 @@
|
||||
this.tbEmployeeName.Name = "tbEmployeeName";
|
||||
this.tbEmployeeName.Size = new System.Drawing.Size(199, 26);
|
||||
this.tbEmployeeName.TabIndex = 2;
|
||||
this.tbEmployeeName.Validating += new System.ComponentModel.CancelEventHandler(this.tbEmployeeName_Validating);
|
||||
//
|
||||
// dgvEmployeeView
|
||||
//
|
||||
@ -198,6 +206,17 @@
|
||||
this.CustomerName.ReadOnly = true;
|
||||
this.CustomerName.Width = 150;
|
||||
//
|
||||
// errorProvider1
|
||||
//
|
||||
this.errorProvider1.ContainerControl = this;
|
||||
//
|
||||
// saveFileDialogReport
|
||||
//
|
||||
this.saveFileDialogReport.DefaultExt = "CSV";
|
||||
this.saveFileDialogReport.Filter = "CSV Files|*.csv";
|
||||
this.saveFileDialogReport.InitialDirectory = ".";
|
||||
this.saveFileDialogReport.Title = "Save Report";
|
||||
//
|
||||
// frmEmployeeView
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
@ -222,6 +241,7 @@
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvEmployeeView)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -246,6 +266,8 @@
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn CustomerID;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn CustomerName;
|
||||
private System.Windows.Forms.ErrorProvider errorProvider1;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialogReport;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using CsvHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@ -49,15 +52,51 @@ namespace QueueSys
|
||||
}
|
||||
|
||||
// Exits the application.
|
||||
private void exitAltF4ToolStripMenuItem_Click(object sender, EventArgs e) => Application.Exit();
|
||||
private void exitAltF4ToolStripMenuItem_Click(object sender, EventArgs e) => Environment.Exit(0);
|
||||
|
||||
private void generateReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("To-do: Generate excel report from SQL Database.");
|
||||
//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;
|
||||
|
||||
SqliteDataAccess sdaGenRep = new SqliteDataAccess();
|
||||
List<ReportView> report = new List<ReportView>();
|
||||
report = sdaGenRep.QueryReports();
|
||||
|
||||
TextWriter textWriter = new StreamWriter(filename);
|
||||
CsvWriter csvWriter = new CsvWriter(textWriter);
|
||||
csvWriter.WriteRecords(report);
|
||||
|
||||
textWriter.Close();
|
||||
MessageBox.Show("Report Generated", "Queue System", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(tbCustomerName.Text == ""
|
||||
|| cbNumBags.Text == ""
|
||||
|| tbEmployeeName.Text == "")
|
||||
{
|
||||
MessageBox.Show("Please fill in the customer intake fields");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if any control is in error.
|
||||
foreach(Control c in errorProvider1.ContainerControl.Controls)
|
||||
{
|
||||
if(errorProvider1.GetError(c) != "")
|
||||
{
|
||||
MessageBox.Show("Please fix the errors on the customer intake form!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SqliteDataAccess sda = new SqliteDataAccess();
|
||||
ReportView evNewCx = new ReportView();
|
||||
|
||||
@ -210,5 +249,29 @@ namespace QueueSys
|
||||
//Invoke the delegate to update customer view with updated data.
|
||||
OnSendMessage?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void tbCustomerName_Validating(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (!Regex.IsMatch(tbCustomerName.Text, "[A-Za-z]{2,}"))
|
||||
{ errorProvider1.SetError(tbCustomerName, "Enter customer name a-z only!"); }
|
||||
else
|
||||
{ errorProvider1.SetError(tbCustomerName, ""); }
|
||||
}
|
||||
private void cbNumBags_Validating(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (cbNumBags.SelectedIndex < 0)
|
||||
{ errorProvider1.SetError(cbNumBags, "Select the number of bags."); }
|
||||
else
|
||||
{ errorProvider1.SetError(cbNumBags, ""); }
|
||||
}
|
||||
|
||||
private void tbEmployeeName_Validating(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (!Regex.IsMatch(tbEmployeeName.Text, "[A-Za-z]{2,}"))
|
||||
{ errorProvider1.SetError(tbEmployeeName, "Enter the employee name a-z only!"); }
|
||||
else
|
||||
{ errorProvider1.SetError(tbEmployeeName, ""); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,9 @@
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="errorProvider1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>173, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>49</value>
|
||||
</metadata>
|
||||
@ -572,4 +575,7 @@
|
||||
i2yLNBpNQOgE3gE22eGZLuAwIiMwCYiUbZ1Goxk2uoE/AC8CF/4/Y88lwR2p3FsAAAAASUVORK5CYII=
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="saveFileDialogReport.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>352, 17</value>
|
||||
</metadata>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user