public static void Main(string[] args) { //this populates the DB only if it is empty: SeedData.SeedDB(); //am instance of db Interface to call DB methods: DBInterface db = new DBInterface(); //read all clients: db.ReadClientsFromDB(); //read all contracts: db.ReadContractsFromDB(); Console.WriteLine("\nDeserialized Clients with Contracts List:"); //deserialize the database: List <Client> clientsList = db.DeserializeDB(); foreach (Client client in clientsList) { Console.WriteLine(client); } //an instance of Calculate to call the various calculation methods: Calculate calc = new Calculate(); //overeall average number of contracts per client: double result = calc.OverallAverageNumberOfContractsPerCleint(clientsList); Console.WriteLine("The result is: " + result + "\n"); //average contract duration (in days): int averageInDays = calc.AverageContractDurarion(clientsList); Console.WriteLine("The average contract duration in days is: " + averageInDays + "\n"); //time remaining on contract: TimeSpan daysRemaining = calc.TimeRemainingOnContract(clientsList[0].MyContracts[2]); Console.WriteLine("Days remining on contract # " + clientsList[0].MyContracts[2].Client_Id + " is: " + daysRemaining.Days + "\n"); //average contract value per client: foreach (Client client in clientsList) { double average = calc.AverageContractValuePerClient(client); Console.WriteLine("The average contract value for " + client.Client_Name + " is: €" + Math.Round(average, 2)); } Console.WriteLine(); //number open contracts: int numberOpenContracts = calc.TotalNumberContractsCurrentlyOpen(clientsList); Console.WriteLine("There are currently " + numberOpenContracts + " open contracts."); }
public static void SeedDB() { DBInterface db = new DBInterface(); if (db.CheckIfDBEmpty()) { List <Client> clientList = new List <Client>(); List <Contract> contractList = new List <Contract>(); //clients; clientList.Add(new Client("Jane Park", "1980-05-20", "Salthill, Galway")); clientList.Add(new Client("Sam Lake", "1995-02-10", "Tuam, Galway")); clientList.Add(new Client("Liam Burke", "2000-05-20", "Kinvarra, Galway")); clientList.Add(new Client("Linda Larkin", "2000-05-20", "Loughrea, Galway")); //add all clients to DB foreach (Client client in clientList) { db.AddClientToDB(client); } //contracts: contractList.Add(new Contract("BT Sport", new DateTime(2018, 01, 01), new DateTime(2020, 01, 01), 200.50, 1)); contractList.Add(new Contract("Eir Phone", new DateTime(2019, 04, 01), new DateTime(2020, 06, 01), 355.56, 1)); contractList.Add(new Contract("Electricty", new DateTime(2017, 06, 01), new DateTime(2020, 07, 01), 400.90, 1)); contractList.Add(new Contract("BT Sport", new DateTime(2019, 05, 01), new DateTime(2020, 01, 01), 200.50, 2)); contractList.Add(new Contract("Eir Phone", new DateTime(2019, 06, 01), new DateTime(2020, 09, 01), 450.90, 2)); contractList.Add(new Contract("Natural Gas", new DateTime(2019, 01, 01), new DateTime(2019, 01, 01), 355.56, 2)); contractList.Add(new Contract("Eir Phone", new DateTime(2017, 05, 01), new DateTime(2019, 02, 01), 900.05, 3)); contractList.Add(new Contract("Insurance", new DateTime(2019, 04, 01), new DateTime(2022, 05, 01), 250.50, 3)); contractList.Add(new Contract("Greyhound", new DateTime(2018, 06, 01), new DateTime(2021, 03, 01), 100.00, 4)); contractList.Add(new Contract("Insurance", new DateTime(2015, 06, 01), new DateTime(2025, 03, 01), 4500.00, 4)); //add all contracts to DB foreach (Contract contract in contractList) { db.AddContractToDB(contract); } } }