1 of 2 CS140 Joes Automotive performs the following routine
Solution
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JoesAutomotive
{
public partial class frmAutomotive : Form
{
public frmAutomotive()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
//call methods to clear all inputs on form
ClearOilLube(); // Clear OilLube group
ClearFlushes(); // Clear Flushes group
ClearMisc(); // Clear Misc group
ClearOther(); // Clear Other Fees group
ClearFees(); //Clear Summary group
}
public void ClearCheckBoxAndTextBoxControls(Control parent)
{
//Loops there all the controls within a groupbox revewing each control
foreach (Control control in parent.Controls)
{
//Checkbox controls are reset
if (control is CheckBox)
{
((CheckBox)control).Checked = false;
}
//Textbox controls are cleared of any text
else if (control is TextBox)
{
((TextBox)control).Text = \"\";
}
}
}
private void ClearOilLube()
{
ClearCheckBoxAndTextBoxControls(grpbxOil_Lube);
}
private void ClearFlushes()
{
ClearCheckBoxAndTextBoxControls(grpbxFlushes);
}
private void ClearMisc()
{
ClearCheckBoxAndTextBoxControls(grpbxMisc);
}
private void ClearOther()
{
ClearCheckBoxAndTextBoxControls(grpbxParts_Labor);
}
private void ClearFees()
{
lblParts.Text = \"\";
lblService_Labor.Text = \"\";
lblTax.Text = \"\";
lblTotalFees.Text = \"\";
}
private void btnCalculateTotal_Click(object sender, EventArgs e)
{
//Check to make sure the textboxes are valid
if (CheckTextBoxes())
{
double otherCharges = OtherCharges(); // Calls method to calculate Other Group Charges
double oilLubeCharges = OilLubeCharges(); // Calls method to calculate Oil and Lube Group Charges
double flushCharges = FlushCharges(); // Calls method to caclulate Flush Group Charges
double miscCharges = MiscCharges(); // Calls method to calculate Misc Group Charges
double taxCharges = TaxCharges(); // Call method to calculate Tax
double laborCharges = LaborCharges(); // Call Method for Labor Charges
//Assign Total Service and Labor Charges to Lable
lblService_Labor.Text = TotalCharges(oilLubeCharges, flushCharges, miscCharges, laborCharges);
//Assign Total Fees to Lable
lblTotalFees.Text = TotalCharges(oilLubeCharges, flushCharges, miscCharges, otherCharges, taxCharges);
}
// Invalid input in textboxes following message will show
else
{
MessageBox.Show(\"Check values in Labor and Parts field.\");
}
}
private bool CheckTextBoxes()
{
double labor, parts;
bool boolLabor = true; //retun variable
bool boolParts = true; //return variable
//Checks to make sure something is entered by user in either textbox
if (!string.IsNullOrWhiteSpace(txtbxParts.Text)) // !string.IsNullOrWhiteSpace(txtbxLabor.Text))
boolParts = (double.TryParse(txtbxParts.Text, out parts)); //Checks to make sure input is valid
if (!string.IsNullOrWhiteSpace(txtbxLabor.Text)) // !string.IsNullOrWhiteSpace(txtbxLabor.Text))
boolLabor = (double.TryParse(txtbxLabor.Text, out labor)); //Checks to make sure input is valid
return (boolParts && boolLabor);
}
private string TotalCharges(double oilLubeCharges, double flushCharges, double miscCharges, double laborCharges)
{
double dbltotal = oilLubeCharges + flushCharges + miscCharges + laborCharges;
string strTotal = dbltotal.ToString(\"c\");
return strTotal;
}
private string TotalCharges(double oilLubeCharges, double flushCharges, double miscCharges, double otherCharges, double taxCharges)
{
double dbltotal = oilLubeCharges + flushCharges + miscCharges + otherCharges + taxCharges;
string strTotal = dbltotal.ToString(\"c\");
return strTotal;
}
private double TaxCharges()
{
const double TAXRATE = .06;
double partCosts = 0 ;
if(!string.IsNullOrWhiteSpace(txtbxParts.Text))
partCosts = double.Parse(txtbxParts.Text);
partCosts *= TAXRATE;
lblTax.Text = partCosts.ToString(\"c\");
return partCosts;
}
private double OtherCharges()
{
double laborCosts = LaborCharges(); // Calls method to Calculate Labor Charges
double partCosts = PartCharges(); // Calls method to Calculate Part Charges
double charges;
return charges = laborCosts + partCosts;
}
private double PartCharges()
{
double partCosts = 0;
if (!string.IsNullOrWhiteSpace(txtbxParts.Text))
partCosts = double.Parse(txtbxParts.Text);
lblParts.Text = partCosts.ToString(\"c\");
return partCosts;
}
private double LaborCharges()
{
double laborCosts = 0;
if (!string.IsNullOrWhiteSpace(txtbxLabor.Text))
laborCosts = double.Parse(txtbxLabor.Text);
return laborCosts;
}
private double MiscCharges()
{
double charges = 0;
double inspectionPrice = 15.00;
double replaceMufflerPrice = 100.00;
double tireRotationPrice = 20.00;
if (chkbxInspection.Checked == true)
{
charges += inspectionPrice;
}
if (chkbxReplaceMuffler.Checked == true)
{
charges += replaceMufflerPrice;
}
if (chkbxTireRotation.Checked == true)
{
charges += tireRotationPrice;
}
return charges;
}
private double FlushCharges()
{
double charges = 0;
double radiatorFlush = 30.00;
double transmissionFlush = 80.00;
if (chkbxRadiatorFlush.Checked == true)
{
charges += radiatorFlush;
}
if (chkbxTransmissionFlush.Checked == true)
{
charges += transmissionFlush;
}
return charges;
}
private double OilLubeCharges()
{
double charges = 0;
double oilChange = 26.00;
double lubeJob = 18.00;
if (chkbxOilChange.Checked == true)
{
charges += oilChange;
}
if (chkbxLubeJob.Checked == true)
{
charges += lubeJob;
}
return charges;
}
}
}
Form1.Designer.cs
namespace JoesAutomotive
{
partial class frmAutomotive
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.grpbxOil_Lube = new System.Windows.Forms.GroupBox();
this.chkbxLubeJob = new System.Windows.Forms.CheckBox();
this.chkbxOilChange = new System.Windows.Forms.CheckBox();
this.grpbxFlushes = new System.Windows.Forms.GroupBox();
this.chkbxTransmissionFlush = new System.Windows.Forms.CheckBox();
this.chkbxRadiatorFlush = new System.Windows.Forms.CheckBox();
this.grpbxMisc = new System.Windows.Forms.GroupBox();
this.chkbxTireRotation = new System.Windows.Forms.CheckBox();
this.chkbxReplaceMuffler = new System.Windows.Forms.CheckBox();
this.chkbxInspection = new System.Windows.Forms.CheckBox();
this.grpbxParts_Labor = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtbxLabor = new System.Windows.Forms.TextBox();
this.txtbxParts = new System.Windows.Forms.TextBox();
this.grpboxSummary = new System.Windows.Forms.GroupBox();
this.lblTotalFees = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.lblTax = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.lblParts = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.lblService_Labor = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnExit = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.btnCalculateTotal = new System.Windows.Forms.Button();
this.grpbxOil_Lube.SuspendLayout();
this.grpbxFlushes.SuspendLayout();
this.grpbxMisc.SuspendLayout();
this.grpbxParts_Labor.SuspendLayout();
this.grpboxSummary.SuspendLayout();
this.SuspendLayout();
//
// grpbxOil_Lube
//
this.grpbxOil_Lube.Controls.Add(this.chkbxLubeJob);
this.grpbxOil_Lube.Controls.Add(this.chkbxOilChange);
this.grpbxOil_Lube.Location = new System.Drawing.Point(13, 13);
this.grpbxOil_Lube.Name = \"grpbxOil_Lube\";
this.grpbxOil_Lube.Size = new System.Drawing.Size(200, 100);
this.grpbxOil_Lube.TabIndex = 0;
this.grpbxOil_Lube.TabStop = false;
this.grpbxOil_Lube.Text = \"Oil && Lube\";
//
// chkbxLubeJob
//
this.chkbxLubeJob.AutoSize = true;
this.chkbxLubeJob.Location = new System.Drawing.Point(16, 59);
this.chkbxLubeJob.Name = \"chkbxLubeJob\";
this.chkbxLubeJob.Size = new System.Drawing.Size(112, 17);
this.chkbxLubeJob.TabIndex = 1;
this.chkbxLubeJob.Text = \"Lube Job ($18.00)\";
this.chkbxLubeJob.UseVisualStyleBackColor = true;
//
// chkbxOilChange
//
this.chkbxOilChange.AutoSize = true;
this.chkbxOilChange.Location = new System.Drawing.Point(16, 19);
this.chkbxOilChange.Name = \"chkbxOilChange\";
this.chkbxOilChange.Size = new System.Drawing.Size(120, 17);
this.chkbxOilChange.TabIndex = 0;
this.chkbxOilChange.Text = \"Oil Change ($26.00)\";
this.chkbxOilChange.UseVisualStyleBackColor = true;
//
// grpbxFlushes
//
this.grpbxFlushes.Controls.Add(this.chkbxTransmissionFlush);
this.grpbxFlushes.Controls.Add(this.chkbxRadiatorFlush);
this.grpbxFlushes.Location = new System.Drawing.Point(219, 13);
this.grpbxFlushes.Name = \"grpbxFlushes\";
this.grpbxFlushes.Size = new System.Drawing.Size(200, 100);
this.grpbxFlushes.TabIndex = 1;
this.grpbxFlushes.TabStop = false;
this.grpbxFlushes.Text = \"Flushes\";
//
// chkbxTransmissionFlush
//
this.chkbxTransmissionFlush.AutoSize = true;
this.chkbxTransmissionFlush.Location = new System.Drawing.Point(19, 59);
this.chkbxTransmissionFlush.Name = \"chkbxTransmissionFlush\";
this.chkbxTransmissionFlush.Size = new System.Drawing.Size(157, 17);
this.chkbxTransmissionFlush.TabIndex = 1;
this.chkbxTransmissionFlush.Text = \"Transmission Flush ($80.00)\";
this.chkbxTransmissionFlush.UseVisualStyleBackColor = true;
//
// chkbxRadiatorFlush
//
this.chkbxRadiatorFlush.AutoSize = true;
this.chkbxRadiatorFlush.Location = new System.Drawing.Point(19, 19);
this.chkbxRadiatorFlush.Name = \"chkbxRadiatorFlush\";
this.chkbxRadiatorFlush.Size = new System.Drawing.Size(136, 17);
this.chkbxRadiatorFlush.TabIndex = 0;
this.chkbxRadiatorFlush.Text = \"Radiator Flush ($30.00)\";
this.chkbxRadiatorFlush.UseVisualStyleBackColor = true;
//
// grpbxMisc
//
this.grpbxMisc.Controls.Add(this.chkbxTireRotation);
this.grpbxMisc.Controls.Add(this.chkbxReplaceMuffler);
this.grpbxMisc.Controls.Add(this.chkbxInspection);
this.grpbxMisc.Location = new System.Drawing.Point(13, 120);
this.grpbxMisc.Name = \"grpbxMisc\";
this.grpbxMisc.Size = new System.Drawing.Size(200, 135);
this.grpbxMisc.TabIndex = 2;
this.grpbxMisc.TabStop = false;
this.grpbxMisc.Text = \"Misc\";
//
// chkbxTireRotation
//
this.chkbxTireRotation.Location = new System.Drawing.Point(16, 91);
this.chkbxTireRotation.Name = \"chkbxTireRotation\";
this.chkbxTireRotation.Size = new System.Drawing.Size(104, 38);
this.chkbxTireRotation.TabIndex = 2;
this.chkbxTireRotation.Text = \"Tire Rotation ($20.00)\";
this.chkbxTireRotation.UseVisualStyleBackColor = true;
//
// chkbxReplaceMuffler
//
this.chkbxReplaceMuffler.Location = new System.Drawing.Point(16, 55);
this.chkbxReplaceMuffler.Name = \"chkbxReplaceMuffler\";
this.chkbxReplaceMuffler.Size = new System.Drawing.Size(104, 30);
this.chkbxReplaceMuffler.TabIndex = 1;
this.chkbxReplaceMuffler.Text = \"Replace Muffler ($100.00)\";
this.chkbxReplaceMuffler.UseVisualStyleBackColor = true;
//
// chkbxInspection
//
this.chkbxInspection.AutoSize = true;
this.chkbxInspection.Location = new System.Drawing.Point(16, 19);
this.chkbxInspection.Name = \"chkbxInspection\";
this.chkbxInspection.Size = new System.Drawing.Size(117, 17);
this.chkbxInspection.TabIndex = 0;
this.chkbxInspection.Text = \"Inspection ($15.00)\";
this.chkbxInspection.UseVisualStyleBackColor = true;
//
// grpbxParts_Labor
//
this.grpbxParts_Labor.Controls.Add(this.label2);
this.grpbxParts_Labor.Controls.Add(this.label1);
this.grpbxParts_Labor.Controls.Add(this.txtbxLabor);
this.grpbxParts_Labor.Controls.Add(this.txtbxParts);
this.grpbxParts_Labor.Location = new System.Drawing.Point(220, 120);
this.grpbxParts_Labor.Name = \"grpbxParts_Labor\";
this.grpbxParts_Labor.Size = new System.Drawing.Size(200, 135);
this.grpbxParts_Labor.TabIndex = 3;
this.grpbxParts_Labor.TabStop = false;
this.grpbxParts_Labor.Text = \"Parts and Labor\";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 82);
this.label2.Name = \"label2\";
this.label2.Size = new System.Drawing.Size(49, 13);
this.label2.TabIndex = 3;
this.label2.Text = \"Labor ($)\";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(36, 34);
this.label1.Name = \"label1\";
this.label1.Size = new System.Drawing.Size(31, 13);
this.label1.TabIndex = 2;
this.label1.Text = \"Parts\";
//
// txtbxLabor
//
this.txtbxLabor.Location = new System.Drawing.Point(79, 79);
this.txtbxLabor.Name = \"txtbxLabor\";
this.txtbxLabor.Size = new System.Drawing.Size(75, 20);
this.txtbxLabor.TabIndex = 1;
//
// txtbxParts
//
this.txtbxParts.Location = new System.Drawing.Point(79, 28);
this.txtbxParts.Name = \"txtbxParts\";
this.txtbxParts.Size = new System.Drawing.Size(75, 20);
this.txtbxParts.TabIndex = 0;
//
// grpboxSummary
//
this.grpboxSummary.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpboxSummary.Controls.Add(this.lblTotalFees);
this.grpboxSummary.Controls.Add(this.label10);
this.grpboxSummary.Controls.Add(this.lblTax);
this.grpboxSummary.Controls.Add(this.label8);
this.grpboxSummary.Controls.Add(this.lblParts);
this.grpboxSummary.Controls.Add(this.label6);
this.grpboxSummary.Controls.Add(this.lblService_Labor);
this.grpboxSummary.Controls.Add(this.label3);
this.grpboxSummary.Location = new System.Drawing.Point(13, 262);
this.grpboxSummary.Name = \"grpboxSummary\";
this.grpboxSummary.Size = new System.Drawing.Size(409, 166);
this.grpboxSummary.TabIndex = 4;
this.grpboxSummary.TabStop = false;
this.grpboxSummary.Text = \"Summary\";
//
// lblTotalFees
//
this.lblTotalFees.AllowDrop = true;
this.lblTotalFees.BackColor = System.Drawing.SystemColors.Control;
this.lblTotalFees.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblTotalFees.Location = new System.Drawing.Point(153, 125);
this.lblTotalFees.Name = \"lblTotalFees\";
this.lblTotalFees.Size = new System.Drawing.Size(100, 23);
this.lblTotalFees.TabIndex = 7;
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(79, 135);
this.label10.Name = \"label10\";
this.label10.Size = new System.Drawing.Size(57, 13);
this.label10.TabIndex = 6;
this.label10.Text = \"Total Fees\";
//
// lblTax
//
this.lblTax.AllowDrop = true;
this.lblTax.BackColor = System.Drawing.SystemColors.Control;
this.lblTax.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblTax.Location = new System.Drawing.Point(153, 90);
this.lblTax.Name = \"lblTax\";
this.lblTax.Size = new System.Drawing.Size(100, 23);
this.lblTax.TabIndex = 5;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(64, 100);
this.label8.Name = \"label8\";
this.label8.Size = new System.Drawing.Size(72, 13);
this.label8.TabIndex = 4;
this.label8.Text = \"Tax (on parts)\";
//
// lblParts
//
this.lblParts.AllowDrop = true;
this.lblParts.BackColor = System.Drawing.SystemColors.Control;
this.lblParts.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblParts.Location = new System.Drawing.Point(153, 52);
this.lblParts.Name = \"lblParts\";
this.lblParts.Size = new System.Drawing.Size(100, 23);
this.lblParts.TabIndex = 3;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(105, 62);
this.label6.Name = \"label6\";
this.label6.Size = new System.Drawing.Size(31, 13);
this.label6.TabIndex = 2;
this.label6.Text = \"Parts\";
//
// lblService_Labor
//
this.lblService_Labor.AllowDrop = true;
this.lblService_Labor.BackColor = System.Drawing.SystemColors.Control;
this.lblService_Labor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblService_Labor.Location = new System.Drawing.Point(153, 16);
this.lblService_Labor.Name = \"lblService_Labor\";
this.lblService_Labor.Size = new System.Drawing.Size(100, 23);
this.lblService_Labor.TabIndex = 1;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(54, 26);
this.label3.Name = \"label3\";
this.label3.Size = new System.Drawing.Size(82, 13);
this.label3.TabIndex = 0;
this.label3.Text = \"Service && Labor\";
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(259, 439);
this.btnExit.Name = \"btnExit\";
this.btnExit.Size = new System.Drawing.Size(75, 32);
this.btnExit.TabIndex = 5;
this.btnExit.Text = \"Exit\";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(166, 439);
this.btnClear.Name = \"btnClear\";
this.btnClear.Size = new System.Drawing.Size(75, 32);
this.btnClear.TabIndex = 6;
this.btnClear.Text = \"Clear\";
this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// btnCalculateTotal
//
this.btnCalculateTotal.Location = new System.Drawing.Point(54, 439);
this.btnCalculateTotal.Name = \"btnCalculateTotal\";
this.btnCalculateTotal.Size = new System.Drawing.Size(95, 32);
this.btnCalculateTotal.TabIndex = 7;
this.btnCalculateTotal.Text = \"Calculate Total\";
this.btnCalculateTotal.UseVisualStyleBackColor = true;
this.btnCalculateTotal.Click += new System.EventHandler(this.btnCalculateTotal_Click);
//
// frmAutomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(434, 483);
this.Controls.Add(this.btnCalculateTotal);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.grpboxSummary);
this.Controls.Add(this.grpbxParts_Labor);
this.Controls.Add(this.grpbxMisc);
this.Controls.Add(this.grpbxFlushes);
this.Controls.Add(this.grpbxOil_Lube);
this.Name = \"frmAutomotive\";
this.Text = \"Automotive\";
this.Load += new System.EventHandler(this.frmAutomotive_Load);
this.grpbxOil_Lube.ResumeLayout(false);
this.grpbxOil_Lube.PerformLayout();
this.grpbxFlushes.ResumeLayout(false);
this.grpbxFlushes.PerformLayout();
this.grpbxMisc.ResumeLayout(false);
this.grpbxMisc.PerformLayout();
this.grpbxParts_Labor.ResumeLayout(false);
this.grpbxParts_Labor.PerformLayout();
this.grpboxSummary.ResumeLayout(false);
this.grpboxSummary.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox grpbxOil_Lube;
private System.Windows.Forms.CheckBox chkbxLubeJob;
private System.Windows.Forms.CheckBox chkbxOilChange;
private System.Windows.Forms.GroupBox grpbxFlushes;
private System.Windows.Forms.CheckBox chkbxTransmissionFlush;
private System.Windows.Forms.CheckBox chkbxRadiatorFlush;
private System.Windows.Forms.GroupBox grpbxMisc;
private System.Windows.Forms.CheckBox chkbxTireRotation;
private System.Windows.Forms.CheckBox chkbxReplaceMuffler;
private System.Windows.Forms.CheckBox chkbxInspection;
private System.Windows.Forms.GroupBox grpbxParts_Labor;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtbxLabor;
private System.Windows.Forms.TextBox txtbxParts;
private System.Windows.Forms.GroupBox grpboxSummary;
private System.Windows.Forms.Label lblTotalFees;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label lblTax;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label lblParts;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label lblService_Labor;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Button btnCalculateTotal;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace JoesAutomotive
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmAutomotive());
}
}
}










