Fix C# Form Application:
-It doesn't have to be perfect and include everything. Just something that works is fine.
Code so far:
ClassMeasurements.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace WindowsFormsApp1 { class ClassMeasurement { public ClassMeasurement(String precipDate, Decimal precipAmount) { PrecipDate = precipDate; PrecipAmount = precipAmount; }
public String PrecipDate { get; set; } public Decimal PrecipAmount { get; set; } } }
FrmMeasurements.cs:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace WindowsFormsApp1 { public partial class FrmMeasurements : Form {
static List measurements = new List();
public FrmMeasurements() { InitializeComponent(); }
private void BtnClose_Click(object sender, EventArgs e) { this.Close(); }
private void BtnSaveEntry_Click(object sender, EventArgs e) {
}
private Boolean ValidateEntryForm() { ClearMessages(); Boolean isValid = true; if (String.IsNullOrEmpty(TBMeasurement.Text)) { } return isValid; }
private void ClearMessages() { LblErrorDate.Visible = false; LblMeasurementError.Visible = false; }
private void BtnEntryClose_Click(object sender, EventArgs e) { PnlEntry.Visible = false; }
private void BtnDisplayClose_Click(object sender, EventArgs e) { PnlDisplay.Visible = false; }
private void BtnViewAll_Click(object sender, EventArgs e) { }
private void BtnMeasurement_Click(object sender, EventArgs e) { PnlDisplay.Visible = false; PnlEntry.Visible = true; } } }
FrmMeasurements.Designer.cs:
amespace WindowsFormsApp1 { partial class FrmMeasurements { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null;
/// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows Form Designer generated code
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.BtnMeasurement = new System.Windows.Forms.Button(); this.BtnViewAll = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.PnlEntry = new System.Windows.Forms.Panel(); this.LblMeasurementError = new System.Windows.Forms.Label(); this.LblErrorDate = new System.Windows.Forms.Label(); this.BtnEntryClose = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.BtnSaveEntry = new System.Windows.Forms.Button(); this.TBMeasurement = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.LblPrecipDate = new System.Windows.Forms.Label(); this.DPPrecip = new System.Windows.Forms.DateTimePicker(); this.PnlDisplay = new System.Windows.Forms.Panel(); this.BtnDisplayClose = new System.Windows.Forms.Button(); this.DGViewPrecip = new System.Windows.Forms.DataGridView(); this.label4 = new System.Windows.Forms.Label(); this.BtnClose = new System.Windows.Forms.Button(); this.PnlEntry.SuspendLayout(); this.PnlDisplay.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DGViewPrecip)).BeginInit(); this.SuspendLayout(); // // BtnMeasurement // this.BtnMeasurement.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnMeasurement.ForeColor = System.Drawing.Color.DarkRed; this.BtnMeasurement.Location = new System.Drawing.Point(13, 50); this.BtnMeasurement.Name = "BtnMeasurement"; this.BtnMeasurement.Size = new System.Drawing.Size(338, 34); this.BtnMeasurement.TabIndex = 0; this.BtnMeasurement.Text = "Enter Measurement"; this.BtnMeasurement.UseVisualStyleBackColor = true; this.BtnMeasurement.Click += new System.EventHandler(this.BtnMeasurement_Click); // // BtnViewAll // this.BtnViewAll.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnViewAll.ForeColor = System.Drawing.Color.DarkRed; this.BtnViewAll.Location = new System.Drawing.Point(367, 50); this.BtnViewAll.Name = "BtnViewAll"; this.BtnViewAll.Size = new System.Drawing.Size(338, 34); this.BtnViewAll.TabIndex = 1; this.BtnViewAll.Text = "View All Measurements"; this.BtnViewAll.UseVisualStyleBackColor = true; this.BtnViewAll.Click += new System.EventHandler(this.BtnViewAll_Click); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Calibri", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.ForeColor = System.Drawing.Color.CornflowerBlue; this.label1.Location = new System.Drawing.Point(13, 13); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(374, 27); this.label1.TabIndex = 2; this.label1.Text = "Precipitation Measurement Application"; // // PnlEntry // this.PnlEntry.BackColor = System.Drawing.Color.White; this.PnlEntry.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.PnlEntry.Controls.Add(this.LblMeasurementError); this.PnlEntry.Controls.Add(this.LblErrorDate); this.PnlEntry.Controls.Add(this.BtnEntryClose); this.PnlEntry.Controls.Add(this.label3); this.PnlEntry.Controls.Add(this.BtnSaveEntry); this.PnlEntry.Controls.Add(this.TBMeasurement); this.PnlEntry.Controls.Add(this.label2); this.PnlEntry.Controls.Add(this.LblPrecipDate); this.PnlEntry.Controls.Add(this.DPPrecip); this.PnlEntry.Location = new System.Drawing.Point(13, 90); this.PnlEntry.Name = "PnlEntry"; this.PnlEntry.Size = new System.Drawing.Size(1047, 482); this.PnlEntry.TabIndex = 3; this.PnlEntry.Visible = false; // // LblMeasurementError // this.LblMeasurementError.AutoSize = true; this.LblMeasurementError.Font = new System.Drawing.Font("Calibri", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.LblMeasurementError.ForeColor = System.Drawing.Color.Red; this.LblMeasurementError.Location = new System.Drawing.Point(367, 62); this.LblMeasurementError.Name = "LblMeasurementError"; this.LblMeasurementError.Size = new System.Drawing.Size(298, 23); this.LblMeasurementError.TabIndex = 10; this.LblMeasurementError.Text = "Please enter a valid measurement!!!"; // // LblErrorDate // this.LblErrorDate.AutoSize = true; this.LblErrorDate.Font = new System.Drawing.Font("Calibri", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.LblErrorDate.ForeColor = System.Drawing.Color.Red; this.LblErrorDate.Location = new System.Drawing.Point(44, 62); this.LblErrorDate.Name = "LblErrorDate"; this.LblErrorDate.Size = new System.Drawing.Size(223, 23); this.LblErrorDate.TabIndex = 9; this.LblErrorDate.Text = "Please enter a valid date!!!"; // // BtnEntryClose // this.BtnEntryClose.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnEntryClose.ForeColor = System.Drawing.Color.DarkRed; this.BtnEntryClose.Location = new System.Drawing.Point(874, 23); this.BtnEntryClose.Name = "BtnEntryClose"; this.BtnEntryClose.Size = new System.Drawing.Size(163, 34); this.BtnEntryClose.TabIndex = 8; this.BtnEntryClose.Text = "Close"; this.BtnEntryClose.UseVisualStyleBackColor = true; this.BtnEntryClose.Click += new System.EventHandler(this.BtnEntryClose_Click); // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Calibri", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.CornflowerBlue; this.label3.Location = new System.Drawing.Point(3, 9); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(261, 23); this.label3.TabIndex = 7; this.label3.Text = "Enter Precipitation Information:"; // // BtnSaveEntry // this.BtnSaveEntry.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnSaveEntry.ForeColor = System.Drawing.Color.DarkRed; this.BtnSaveEntry.Location = new System.Drawing.Point(703, 23); this.BtnSaveEntry.Name = "BtnSaveEntry"; this.BtnSaveEntry.Size = new System.Drawing.Size(163, 34); this.BtnSaveEntry.TabIndex = 6; this.BtnSaveEntry.Text = "Save"; this.BtnSaveEntry.UseVisualStyleBackColor = true; this.BtnSaveEntry.Click += new System.EventHandler(this.BtnSaveEntry_Click); // // TBMeasurement // this.TBMeasurement.Location = new System.Drawing.Point(579, 38); this.TBMeasurement.Name = "TBMeasurement"; this.TBMeasurement.Size = new System.Drawing.Size(105, 20); this.TBMeasurement.TabIndex = 3; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Location = new System.Drawing.Point(342, 39); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(230, 20); this.label2.TabIndex = 2; this.label2.Text = "Precipitation Amount (cms):"; // // LblPrecipDate // this.LblPrecipDate.AutoSize = true; this.LblPrecipDate.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.LblPrecipDate.Location = new System.Drawing.Point(18, 39); this.LblPrecipDate.Name = "LblPrecipDate"; this.LblPrecipDate.Size = new System.Drawing.Size(179, 20); this.LblPrecipDate.TabIndex = 1; this.LblPrecipDate.Text = "Date of Precipitation:"; // // DPPrecip // this.DPPrecip.Format = System.Windows.Forms.DateTimePickerFormat.Short; this.DPPrecip.Location = new System.Drawing.Point(212, 39); this.DPPrecip.Name = "DPPrecip"; this.DPPrecip.Size = new System.Drawing.Size(105, 20); this.DPPrecip.TabIndex = 0; // // PnlDisplay // this.PnlDisplay.BackColor = System.Drawing.Color.White; this.PnlDisplay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.PnlDisplay.Controls.Add(this.BtnDisplayClose); this.PnlDisplay.Controls.Add(this.DGViewPrecip); this.PnlDisplay.Controls.Add(this.label4); this.PnlDisplay.Location = new System.Drawing.Point(13, 90); this.PnlDisplay.Name = "PnlDisplay"; this.PnlDisplay.Size = new System.Drawing.Size(1047, 474); this.PnlDisplay.TabIndex = 4; // // BtnDisplayClose // this.BtnDisplayClose.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnDisplayClose.ForeColor = System.Drawing.Color.DarkRed; this.BtnDisplayClose.Location = new System.Drawing.Point(874, 23); this.BtnDisplayClose.Name = "BtnDisplayClose"; this.BtnDisplayClose.Size = new System.Drawing.Size(163, 34); this.BtnDisplayClose.TabIndex = 10; this.BtnDisplayClose.Text = "Close"; this.BtnDisplayClose.UseVisualStyleBackColor = true; this.BtnDisplayClose.Click += new System.EventHandler(this.BtnDisplayClose_Click); // // DGViewPrecip // this.DGViewPrecip.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.DGViewPrecip.Location = new System.Drawing.Point(353, 38); this.DGViewPrecip.Name = "DGViewPrecip"; this.DGViewPrecip.Size = new System.Drawing.Size(338, 431); this.DGViewPrecip.TabIndex = 9; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Calibri", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.ForeColor = System.Drawing.Color.CornflowerBlue; this.label4.Location = new System.Drawing.Point(3, 10); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(214, 23); this.label4.TabIndex = 8; this.label4.Text = "Precipitation Information:"; // // BtnClose // this.BtnClose.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.BtnClose.ForeColor = System.Drawing.Color.DarkRed; this.BtnClose.Location = new System.Drawing.Point(721, 50); this.BtnClose.Name = "BtnClose"; this.BtnClose.Size = new System.Drawing.Size(338, 34); this.BtnClose.TabIndex = 5; this.BtnClose.Text = "Exit"; this.BtnClose.UseVisualStyleBackColor = true; this.BtnClose.Click += new System.EventHandler(this.BtnClose_Click); // // FrmMeasurements // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1071, 580); this.Controls.Add(this.BtnClose); this.Controls.Add(this.label1); this.Controls.Add(this.BtnViewAll); this.Controls.Add(this.BtnMeasurement); this.Controls.Add(this.PnlEntry); this.Controls.Add(this.PnlDisplay); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "FrmMeasurements"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Measurement Recorder"; this.TopMost = true; this.PnlEntry.ResumeLayout(false); this.PnlEntry.PerformLayout(); this.PnlDisplay.ResumeLayout(false); this.PnlDisplay.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.DGViewPrecip)).EndInit(); this.ResumeLayout(false); this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button BtnMeasurement; private System.Windows.Forms.Button BtnViewAll; private System.Windows.Forms.Label label1; private System.Windows.Forms.Panel PnlEntry; private System.Windows.Forms.Panel PnlDisplay; private System.Windows.Forms.Button BtnClose; private System.Windows.Forms.DateTimePicker DPPrecip; private System.Windows.Forms.Button BtnSaveEntry; private System.Windows.Forms.TextBox TBMeasurement; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label LblPrecipDate; private System.Windows.Forms.Button BtnEntryClose; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Button BtnDisplayClose; private System.Windows.Forms.DataGridView DGViewPrecip; private System.Windows.Forms.Label LblMeasurementError; private System.Windows.Forms.Label LblErrorDate; } }
Fix the C# windows from application The first part will allow you to enter a date [mm/dd/yyyy] and a precipitation total in centimeters and save them to a local database (.mdf file) The second part will be a data grid that displays all of the measurements by date ascending. (oldest date to newest date) A user can enter any date/measurement for any date in the past and you must sort the data somehow in ascending order before displaying it in the datagrid. Oldest date to newest date. When Enter Measurement is clicked the panel for the Enter Measurements will open (and close the view all measurement panel). The user can then enter the info and if any is missing when they click save then they will be notified by making the labels for the errors appear. When View All Measurements is clicked the panel for View all will open and the datagrid will be populated with entries from the database. Make sure to clear out the fields from the entry form and then hide that panel before making the display entries panel visible. Create a database .mfd file called measurementsdb with a table called measurements. The table will have an id (int) that auto-increments, a varchar(20) for the date (use a string) and a decimal for the measurement. To create the database use the steps outlined in this walkthrough: Add a static class to the project called DataUtilityClass. This class will contain static methods in which you will have one method to add a single entry (date and measurement) and another to select all of the entries from the db loading them into a list of ClassMeasurement that you will return back to the calling method so you can make the source of the datagrid the list. Fix the C# windows from application The first part will allow you to enter a date [mm/dd/yyyy] and a precipitation total in centimeters and save them to a local database (.mdf file) The second part will be a data grid that displays all of the measurements by date ascending. (oldest date to newest date) A user can enter any date/measurement for any date in the past and you must sort the data somehow in ascending order before displaying it in the datagrid. Oldest date to newest date. When Enter Measurement is clicked the panel for the Enter Measurements will open (and close the view all measurement panel). The user can then enter the info and if any is missing when they click save then they will be notified by making the labels for the errors appear. When View All Measurements is clicked the panel for View all will open and the datagrid will be populated with entries from the database. Make sure to clear out the fields from the entry form and then hide that panel before making the display entries panel visible. Create a database .mfd file called measurementsdb with a table called measurements. The table will have an id (int) that auto-increments, a varchar(20) for the date (use a string) and a decimal for the measurement. To create the database use the steps outlined in this walkthrough: Add a static class to the project called DataUtilityClass. This class will contain static methods in which you will have one method to add a single entry (date and measurement) and another to select all of the entries from the db loading them into a list of ClassMeasurement that you will return back to the calling method so you can make the source of the datagrid the list