示例#1
0
        /// <summary>
        /// Gets the drink data.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static IList <DrinkItem> GetDrinkData(string fileName)
        {
            var drinklist   = new List <DrinkItem>();
            var ddataInFile = File.ReadAllLines(fileName);

            char[] separator = { ';' };

            foreach (var item in ddataInFile)
            {
                if (!item.StartsWith("//"))
                {
                    try
                    {
                        var items    = item.Split(separator);
                        var rinkItem = new DrinkItem
                        {
                            Cost      = items[0].Trim(),
                            Name      = items[1].Trim(),
                            Available = bool.Parse(items[2].Trim()),
                            Note      = items[3].Trim()
                        };

                        drinklist.Add(rinkItem);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Warning");
                    }
                }
            }

            return(drinklist);
        }
示例#2
0
        /// <summary>
        /// Builds the drink items.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        private static IList <DrinkItem> BuildDrinkItems(StreamReader stream)
        {
            IList <DrinkItem> drinkItems = new List <DrinkItem>();
            string            line       = stream.ReadLine();

            char[] separator = { ';' };

            while (!string.IsNullOrWhiteSpace(line))
            {
                try
                {
                    var items    = line.Split(separator);
                    var rinkItem = new DrinkItem
                    {
                        Cost = items[0].Trim(),
                        Name = items[1].Trim(),
                        Note = items[2].Trim()
                    };

                    drinkItems.Add(rinkItem);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning");
                    return(null);
                }

                line = stream.ReadLine();
            }

            return(drinkItems);
        }