/// <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> /// 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); }