Esempio n. 1
0
        /// <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();
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Handles the event when fragrance selection changes
 /// </summary>
 void cboFragrance_SelectedIndexChanged(object sender, EventArgs e)
 {
     fragranceItem = _fragranceItems[cboFragrance.SelectedIndex];
     calculate();
 }