Beispiel #1
0
 public Report(Dictionary<string, MachineItem> vmInventory)
 {
     foreach(var item in vmInventory)
     {
         ReportDict.Add(item.Value.Name, 0);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Reads in Sales Report historical file, and combines current session data.
        /// </summary>
        public void CombineReport()
        {
            #region ReadingFileIn]

            if (File.Exists(@"..\..\..\etc\SalesReport.txt"))
            {
                using (StreamReader sr = new StreamReader(@"..\..\..\etc\SalesReport.txt"))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.Contains("**TOTAL SALES**"))
                        {
                            string[] lineArray = line.Split('$');
                            string money = lineArray[1];
                            money = money.Replace(",", "");
                            SalesTotal += decimal.Parse(money);
                        }
                        else if (line != "")
                        {
                            string[] lineArray = line.Split('|');
                            if (ReportDict.ContainsKey(lineArray[0]))
                            {
                                ReportDict[lineArray[0]] += int.Parse(lineArray[1]);
                            }
                            else
                            {
                                ReportDict.Add(lineArray[0], int.Parse(lineArray[1]));
                            }

                        }
                    }
                }
            }
            
            
            #endregion
            #region OverwriteFile
            using (FileStream fs = File.Open(@"..\..\..\etc\SalesReport.txt", FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (var item in ReportDict)
                    {
                        sw.WriteLine($"{item.Key}|{item.Value}");
                    }
                    sw.WriteLine();
                    sw.Write($"**TOTAL SALES** {SalesTotal.ToString("C")}");
                }
            }
            
            #endregion
        }