void PrintDataTable(UtilitiesList utilitiesList, ResidentsList residentsList, string file) { using (var writer = new StreamWriter(Server.MapPath(file))) { 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 CalculateResidentsAverageMoneySpent(ResidentsList residentsList) { var count = 0; for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { count++; } return(CalculateResidentsAllMoneySpent(residentsList) / count); }
static double CalculateResidentsAllMoneySpent(ResidentsList residentsList) { var sum = 0.0; for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { sum += residentsList.GetData().MoneySpent; } return(sum); }
static ResidentsList FilterResidentsByMoneySpent(ResidentsList residentsList) { var filteredResidents = new ResidentsList(); var averageMoneySpent = CalculateResidentsAverageMoneySpent(residentsList); for (residentsList.StartOfList(); residentsList.Contains(); residentsList.NextListNode()) { if (averageMoneySpent > residentsList.GetData().MoneySpent) { filteredResidents.AddData(residentsList.GetData()); } } return(filteredResidents); }
void PrinteRemovedListTable(ResidentsList residentsList, string file, string chosenMonth, string chosenUtlity) { using (var writer = new StreamWriter(Server.MapPath(file))) { writer.WriteLine("Rezultatai"); writer.WriteLine(); writer.WriteLine($"Gyventojai po pašalinimo, pašalinti buvo tie, kurie nemokėjo už nurodyta mėnesį ({chosenMonth}) ir paslaugą ({chosenUtlity})"); 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)); } }
void PrintResultsTable(string cheapestMonth, UtilitiesList utilitiesList, ResidentsList residentsList, ResidentsList filteredResidentsList, string file) { using (StreamWriter writer = new StreamWriter(Server.MapPath(file))) { 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)); writer.WriteLine("Rezultatai"); writer.WriteLine(); writer.WriteLine("Gyventojų sąrašas, kurie už komunalines paslaugas per metus mokėjo sumą, mažesnę už vidutinę, ir surikiuoti pagal pavardę ir vardą abėcėlės tvarka"); 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 (filteredResidentsList.StartOfList(); filteredResidentsList.Contains(); filteredResidentsList.NextListNode()) { writer.WriteLine(filteredResidentsList.GetData().ResidentsPrintToTable()); } writer.WriteLine(new string('-', 119)); writer.WriteLine("Nustatytas menesis ir komunalines paslaugos, kainavusios pigiausiai"); writer.WriteLine(cheapestMonth); } }
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.Contains(); residentsList.NextListNode()) { if (residentsList.GetData().Month != chosenMonth || residentsList.GetData().ServiceCount <= 0 || residentsList.GetData().UtilityCode != utilityCode) { residentsList.RemoveResident(residentsList.GetNodeLocation(residentsList.GetData())); residentsList.StartOfList(); } } }
ResidentsList ReadResidentsData(string file) { var residentsList = new ResidentsList(); using (StreamReader reader = new StreamReader(Server.MapPath(file))) { var line = reader.ReadLine(); while (line != null) { var values = line.Split(' '); var surname = values[0]; var name = values[1]; var address = values[2]; var month = values[3]; var utilityCode = values[4]; var serviceCount = int.Parse(values[5]); residentsList.AddData(new Residents(surname, name, address, month, utilityCode, serviceCount)); line = reader.ReadLine(); } } return(residentsList); }