static void PrintDataTable(UtilitiesList utilitiesList, ResidentsList residentsList, string file) { using (var writer = new StreamWriter(file, false, Encoding.UTF8)) { writer.WriteLine("Pradiniai Duomenys"); writer.WriteLine(); writer.WriteLine("Komunalines Paslaugos"); writer.WriteLine(new string('-', 80)); writer.WriteLine("| {0, 15} | {1,25} | {2,30} |", "Paslaugos kodas", "Paslaugos pavadinimas", "Vieno menesio vieneto kaina"); writer.WriteLine(new string('-', 80)); for (utilitiesList.StartOfList(); utilitiesList.Contains(); utilitiesList.NextListNode()) { writer.WriteLine(utilitiesList.GetData().UtilitiesPrintToTable()); } writer.WriteLine(new string('-', 80)); writer.WriteLine(); writer.WriteLine("Gyventoju duomenys"); writer.WriteLine(new string('-', 119)); writer.WriteLine("| {0,15} | {1,15} | {2,15} | {3,15} | {4,15} | {5,25} |", "Pavardė", "Vardas", "Adresas", "Mėnuo", "Paslaugos kodas", "Sunaudotų vienetų kiekis"); writer.WriteLine(new string('-', 119)); for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { writer.WriteLine(residentsList.GetData().ResidentsPrintToTable()); } writer.WriteLine(new string('-', 119)); } }
static string CalculateCheapestMonth(ResidentsList residentsList, UtilitiesList utilitiesList) { var cheapestMonth = new Dictionary <string, Dictionary <string, double> >(); var cheapestMonthList = new List <CheapestMonth>(); var temp = residentsList; for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { if (cheapestMonth.ContainsKey(residentsList.GetData().Month)) { if (cheapestMonth[residentsList.GetData().Month].ContainsKey(residentsList.GetData().UtilityCode)) { cheapestMonth[residentsList.GetData().Month][residentsList.GetData().UtilityCode] += FindUtilityPrice(utilitiesList, residentsList.GetData().UtilityCode) * residentsList.GetData().ServiceCount; } else { cheapestMonth[residentsList.GetData().Month].Add( residentsList.GetData().UtilityCode, FindUtilityPrice(utilitiesList, residentsList.GetData().UtilityCode) * residentsList.GetData().ServiceCount ); } } else { cheapestMonth.Add(residentsList.GetData().Month, new Dictionary <string, double>()); cheapestMonth[residentsList.GetData().Month].Add( residentsList.GetData().UtilityCode, FindUtilityPrice(utilitiesList, residentsList.GetData().UtilityCode) * residentsList.GetData().ServiceCount ); } } foreach (KeyValuePair <string, Dictionary <string, double> > item in cheapestMonth) { foreach (KeyValuePair <string, double> utility in cheapestMonth[item.Key]) { cheapestMonthList.Add(new CheapestMonth(item.Key, utility.Key, utility.Value)); } } var cheapestMonthUtility = cheapestMonthList.OrderBy(x => x.Price).FirstOrDefault(); for (utilitiesList.StartOfList(); utilitiesList.Contains(); utilitiesList.NextListNode()) { if (cheapestMonthUtility.UtilityCode == utilitiesList.GetData().ServiceCode) { cheapestMonthUtility.UtilityCode = utilitiesList.GetData().ServiceName; } } if (cheapestMonthUtility != null) { return($"{cheapestMonthUtility.Month} mėnesį {cheapestMonthUtility.UtilityCode} kainavo pigiausiai"); } return("Nerasta"); }
static void CalculateResidentsMoneySpent(ResidentsList residentsList, UtilitiesList utilitiesList) { for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { for (utilitiesList.StartOfList(); utilitiesList.Contains(); utilitiesList.NextListNode()) { residentsList.CalculateMoneySpent(utilitiesList.GetData()); } } }
static double FindUtilityPrice(UtilitiesList utilitiesList, string residentUtilityCode) { var utilityPrice = 0.0; for (utilitiesList.StartOfList(); utilitiesList.Contains(); utilitiesList.NextListNode()) { if (residentUtilityCode == utilitiesList.GetData().ServiceCode) { utilityPrice = utilitiesList.GetData().ServiceUnitPrice; break; } } return(utilityPrice); }
static void RemoveResidents(ResidentsList residentsList, UtilitiesList utilitiesList, string chosenMonth, string chosenUtility) { var utilityCode = ""; for (utilitiesList.StartOfList(); utilitiesList.Contains(); utilitiesList.NextListNode()) { if (utilitiesList.GetData().ServiceName == chosenUtility) { utilityCode = utilitiesList.GetData().ServiceCode; break; } } for (residentsList.StartOfList(); residentsList.ContainsEverywhere(); residentsList.NextList()) { if (residentsList.GetData().Month != chosenMonth || residentsList.GetData().ServiceCount <= 0 || residentsList.GetData().UtilityCode != utilityCode) { residentsList.RemoveResident(residentsList.GetNodeLocation(residentsList.GetData())); residentsList.StartOfList(); } } }