/// <summary> /// A method for writing into the log file /// </summary> /// <param name="exception"></param> private void errorLog(Exception exception) { AutomotiveManager.ErrorLog(exception, "Error reading form file."); this.Shown += new EventHandler(delegate(object s, EventArgs evt) { this.Close(); }); }
/// <summary> /// Loads the data from the FragranceData.txt into a list /// </summary> private void loadDataFragranceItemsFromFile() { _fragranceItems = new List <FragranceItem>(); string record = string.Empty; string filepath = @"Data\FragranceData.txt"; FileStream stream = new FileStream(filepath, FileMode.Open); StreamReader reader = new StreamReader(stream); try { while ((record = reader.ReadLine()) != null) { string[] field = record.Split(','); // Creating an instance and set the properties of the object FragranceItem fragrance = new FragranceItem() { Fragrance = field[0], Price = decimal.Parse(field[1]) }; _fragranceItems.Add(fragrance); } } catch (FileNotFoundException exception) { AutomotiveManager.ErrorLog(exception, "Error reading from car wash data file."); showError(); } finally { if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }
/// <summary> /// Validating the textbox trade-in allowance /// </summary> void txtTradeinAllowance_Validating(object sender, CancelEventArgs e) { string errorMessage = string.Empty; if (!AutomotiveManager.IsNumeric(txtTradeinAllowance.Text)) { errorMessage = "Please enter a numeric value."; txtTradeinAllowance.Focus(); } else if (decimal.Parse(txtTradeinAllowance.Text) < 0) { errorMessage = "Please enter a value greater than or equal to zero."; txtTradeinAllowance.Focus(); } if (errorMessage != string.Empty) { e.Cancel = true; errorProvider.SetError(txtTradeinAllowance, errorMessage); } }
/// <summary> /// Handles the validating of the txtCost /// </summary> void txtCost_Validating(object sender, CancelEventArgs e) { string errorMessage = string.Empty; if (!AutomotiveManager.IsNumeric(txtCost.Text)) { errorMessage = "Please enter a numeric value."; } else if (decimal.Parse(txtCost.Text) <= 0) { errorMessage = "Please enter a value greater than zero."; } if (errorMessage != string.Empty) { e.Cancel = true; errorProvider.SetError(txtCost, errorMessage); txtCost.Focus(); txtCost.SelectAll(); } }
/// <summary> /// Loads the Exterior data from the Exterior.txt into a list /// </summary> private void loadExteriorOptionsFromFile() { _exteriorOptions = new List <ExteriorOptions>(); string record = string.Empty; string filepath = @"Data\Exterior.txt"; FileStream stream = new FileStream(filepath, FileMode.Open); StreamReader reader = new StreamReader(stream); try { while ((record = reader.ReadLine()) != null) { // Creating an instance and set the properties of the object ExteriorOptions exterior = new ExteriorOptions() { Exterior = record }; _exteriorOptions.Add(exterior); } } catch (FileNotFoundException exception) { AutomotiveManager.ErrorLog(exception, "Error reading from car wash data file."); showError(); } finally { if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }
public frmCarWash() { InitializeComponent(); try { loadDataPackageItemsFromFile(); loadDataFragranceItemsFromFile(); LoadInteriorOptionsFromFile(); loadExteriorOptionsFromFile(); this.Load += new EventHandler(frmCarWash_Load); foreach (PackageItem packageItem in _packageItems) { cboPackage.Items.Add(packageItem.ToString()); } foreach (FragranceItem fragranceItem in _fragranceItems) { cboFragrance.Items.Add(fragranceItem.ToString()); } } catch (FileNotFoundException exception) { AutomotiveManager.ErrorLog(exception, "Error reading from car wash data file."); showError(); } catch (IOException exception) { AutomotiveManager.ErrorLog(exception, "Error reading from car wash data file."); showError(); } cboPackage.SelectedIndexChanged += new EventHandler(cboPackage_SelectedIndexChanged); cboFragrance.SelectedIndexChanged += new EventHandler(cboFragrance_SelectedIndexChanged); mnuGenerateInvoice.Click += new EventHandler(mnuGenerateInvoice_Click); }
/// <summary> /// Validating the textbox vehicle sale price /// </summary> void txtVehicleSalePrice_Validating(object sender, CancelEventArgs e) { txtVehicleSalePrice.Text = txtVehicleSalePrice.Text.Trim(); string errorMessage = string.Empty; if (!AutomotiveManager.IsNumeric(txtVehicleSalePrice.Text)) { errorMessage = "Please enter a numeric value."; txtVehicleSalePrice.Focus(); } else if (decimal.Parse(txtVehicleSalePrice.Text) <= 0) { errorMessage = "Please enter a value greater than zero."; txtVehicleSalePrice.Focus(); } if (!errorMessage.Equals(string.Empty)) { e.Cancel = true; errorProvider.SetError(txtVehicleSalePrice, errorMessage); } }
/// <summary> /// Handles the event when calculate button is clicked /// </summary> void btnCalculateQuote_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { int accessories = 0; if (chkStereoSystem.Checked) { accessories += 1; } if (chkLeatherInterior.Checked) { accessories += 2; } if (chkComputerNavigation.Checked) { accessories += 4; } RadioButton[] radioButton = { radStandard, radPearlized, radDetailing }; int index = -1; for (int i = 0; i < radioButton.Length && index == -1; i++) { if (radioButton[i].Checked) { index = i + 1; } } decimal taxRate = decimal.Parse(ConfigurationManager.AppSettings["GST"]) + decimal.Parse(ConfigurationManager.AppSettings["PST"]); SalesQuote salesQuote = new SalesQuote(decimal.Parse(txtVehicleSalePrice.Text), decimal.Parse(txtTradeinAllowance.Text), taxRate, (Accessories)accessories, (ExteriorFinish)index); lblVehicleSalePrice.Text = String.Format("{0:C}", decimal.Parse(txtVehicleSalePrice.Text)); lblOptions.Text = String.Format("{0:N}", salesQuote.AccessoryCost + salesQuote.FinishCost); lblSubtotal.Text = String.Format("{0:C}", salesQuote.SubTotal); lblSalesTax.Text = String.Format("{0:N}", salesQuote.SalesTax); lblTotal.Text = String.Format("{0:C}", salesQuote.Total); lblTradeInAllowance.Text = String.Format("{0:-#0.00}", decimal.Parse(txtTradeinAllowance.Text)); lblAmountDue.Text = String.Format("{0:C}", salesQuote.AmountDue); if (salesQuote.AmountDue > 0.00M) { grpFinance.Enabled = true; hsbInterestRate_ValueChanged(sender, e); hsbNumberOfYears_ValueChanged(sender, e); lblMonthlyPayment.Text = String.Format("{0:C}", AutomotiveManager.Payment((hsbInterestRate.Value / 10000M) / 12, hsbNumberOfYears.Value * 12, salesQuote.AmountDue)); } else if (salesQuote.AmountDue < 0) { resetFinance(); grpFinance.Enabled = false; } txtVehicleSalePrice.SelectAll(); txtVehicleSalePrice.Focus(); } }