I am building an Automative application that lets the user select the options from the check boxes etc. and the price is shown at the end for charges.
Problem is that the way I completed this application is awkward. For example, see my if else statements they don't cover every aspect of the decision.
For example, here is the part of my code
private decimal RushesMethod(out decimal radiatorRush_var, out decimal transmissionFlush_var, out decimal both_var)
{
radiatorRush_var = 0m;
transmissionFlush_var = 0m;
both_var = 0m;
if (radiatorRushCheckBox.Checked)
{
radiatorRush_var = 30.00m;
}
else if (transmissionFlushCheckBox.Checked)
{
transmissionFlush_var = 80.00m;
}
else if (radiatorRushCheckBox.Checked && transmissionFlushCheckBox.Checked)
{
radiatorRush_var = 30.00m;
transmissionFlush_var = 80.00m;
both_var = radiatorRush_var + transmissionFlush_var;
}
return both_var + transmissionFlush_var + radiatorRush_var;
}
What if the user selects the radiatorRushCheckBox.Checked option and some other options ONLY which are not it this method let's say oilChangeCheckBox.Checked then how will I cover all of that decision. It will be a way too lengthy to make if else statements for all because who knows what the user selects.
Here is what happens if I select all the options then it doesn't show the correct price.
Here is the FULL application CODE:
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 Automative_APP
{
public partial class automativeForm : Form
{
public automativeForm()
{
InitializeComponent();
}
private void ClearOilLube()
{
oilChangeCheckBox.CheckState = CheckState.Unchecked;
lubeJobCheckBox.CheckState = CheckState.Unchecked;
}
private void ClearFlushes()
{
radiatorRushCheckBox.CheckState = CheckState.Unchecked;
transmissionFlushCheckBox.CheckState = CheckState.Unchecked;
}
private void ClearMisc()
{
inspectionCheckBox.CheckState = CheckState.Unchecked;
replaceMufflerCheckBox.CheckState = CheckState.Unchecked;
tireRotationCheckBox.CheckState = CheckState.Unchecked;
}
private void ClearOthers()
{
partsTextBox.Text = "";
laborTextBox.Text = "";
}
private void ClearFees()
{
serviceLaborAnsLabelBox.Text = "";
partsSummaryAnsLabelBox.Text = "";
taxPartsAnsLabelBox.Text = "";
totalFeesAnsLabelBox.Text = "";
}
private decimal TotalCharges()
{
decimal rushesVar = RushesMethod();
decimal oiLAndLubeVar = OilLubeCharges();
decimal miscVar = MiscMethod();
decimal partsLaborVar = PartsLaborMethod();
decimal storeTaxCharges = TaxCharges();
decimal totalSum;
decimal totalSum1;
totalSum1 = (rushesVar + oiLAndLubeVar + miscVar);
totalSum = (rushesVar + oiLAndLubeVar + miscVar + partsLaborVar);
partsSummaryAnsLabelBox.Text = partsLaborVar.ToString();
partsSummaryAnsLabelBox.Text = partsTextBox.Text;
serviceLaborAnsLabelBox.Text = "Total Services fee is " + " " + totalFeesAnsLabelBox.Text + " " + "and Labor amount is" + " " + laborTextBox.Text;
taxPartsAnsLabelBox.Text = storeTaxCharges.ToString();
return totalSum;
}
private decimal TaxCharges()
{
const decimal PARTS_TAX_VAR = 0.6m;
decimal storeTax;
decimal taxCal;
storeTax = decimal.Parse(partsTextBox.Text);
taxCal = PARTS_TAX_VAR * storeTax;
return taxCal;
}
private decimal PartsLaborMethod()
{
decimal PL=0m;
decimal labor;
decimal totalPL = 0m;
PL = decimal.Parse(partsTextBox.Text);
labor = decimal.Parse(laborTextBox.Text);
totalPL= PL* labor;
return totalPL;
}
private decimal MiscMethod()
{
decimal valueTotal2 = 0m;
if (inspectionCheckBox.Checked && replaceMufflerCheckBox.Checked && tireRotationCheckBox.Checked)
{
valueTotal2 += (15.00m + 100.00m + 20.00m);
}
else if (inspectionCheckBox.Checked)
{
valueTotal2 += 15.00m;
}
else if (replaceMufflerCheckBox.Checked)
{
valueTotal2 += 100.00m;
}
else if (tireRotationCheckBox.Checked)
{
valueTotal2 += 20.00m;
}
return valueTotal2;
}
private decimal RushesMethod()
{
decimal valueTotal = 0m;
if (radiatorRushCheckBox.Checked)
{
valueTotal += 30.00m;
}
else if (transmissionFlushCheckBox.Checked)
{
valueTotal += 80.00m;
}
else if (radiatorRushCheckBox.Checked && transmissionFlushCheckBox.Checked)
{
valueTotal += (80.00m + 30.00m);
}
return valueTotal;
}
private decimal OilLubeCharges()
{
decimal valueTotalOL=0m;
if (oilChangeCheckBox.Checked && lubeJobCheckBox.Checked)
{
valueTotalOL += (26.00m + 18.00m);
}
else if (oilChangeCheckBox.Checked)
{
valueTotalOL += 26.00m;
}
else if (lubeJobCheckBox.Checked)
{
valueTotalOL += 18.00m;
}
return valueTotalOL;
}
private void partsSummaryLabelBox_Click(object sender, EventArgs e)
{
}
private void taxPartsLabelBox_Click(object sender, EventArgs e)
{
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close(); //close the form
}
private void calculateButton_Click(object sender, EventArgs e)
{
decimal totalStore= TotalCharges();
totalFeesAnsLabelBox.Text = totalStore.ToString();
}
private void clearButton_Click(object sender, EventArgs e)
{
ClearOilLube();
ClearFlushes();
ClearMisc();
ClearOthers();
ClearFees();
}
}
}
Aucun commentaire:
Enregistrer un commentaire