public static void Main(string[] args) { //InsertDatatoFile(); //Console.ReadLine(); FileOperation fO = new FileOperation(); TaxCalculation tC = new TaxCalculation(); string fileName = fO.GetFile(); IDictionary <string, string> MunicipalTaxDetails = fO.ReadDataFromFile(fileName); //GetSpecificMunicipalTax(MunicipalTaxDetails); //Console.WriteLine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); Console.WriteLine("Choose Your Options : 1 - Get Tax, 2 - Add Municipal \n"); var option = Console.ReadLine(); switch (option) { case "1": Console.WriteLine("Enter Municipal Name: "); string municipal = Console.ReadLine(); Console.WriteLine("Enter a date eg. 2016.12.31: "); DateTime userDateTime; string taxdate = null; if (DateTime.TryParse(Console.ReadLine(), out userDateTime)) { taxdate = userDateTime.ToString("yyyyMMdd"); } else { Console.WriteLine("You have entered an incorrect value."); } decimal tax = tC.GetSpecificMunicipalTax(MunicipalTaxDetails, municipal, taxdate); Console.WriteLine("The tax for the {0} is {1}", municipal, tax); break; case "2": InsertNewMunicipal iNM = new InsertNewMunicipal(); iNM.InsertDatatoFile(); break; default: Main(null); break; } Console.ReadLine(); Console.ReadLine(); }
public void InsertDatatoFile() { try { //string newEntrymunicipal = "Lipskus"; //string newEntryTaxDetails = "Yearly = 0.2, Monthly = 0.4, Daily = 0.1"; string yearly = "Yearly="; string monthly = "Monthly="; string daily = "Daily="; Console.WriteLine("Enter Municipal Name to Add: "); string newEntrymunicipal = Console.ReadLine(); Console.WriteLine("Enter Yearly Tax for {0}: ", newEntrymunicipal); decimal YearlyTax; if (decimal.TryParse(Console.ReadLine(), out YearlyTax)) { yearly = yearly + YearlyTax; } else { Console.WriteLine("incorrent tax entered, Please resubmit the details"); Console.ReadKey(); Environment.Exit(1); } Console.WriteLine("Enter Monthly Tax for {0}: ", newEntrymunicipal); decimal MonthlyTax; if (decimal.TryParse(Console.ReadLine(), out MonthlyTax)) { monthly = monthly + MonthlyTax; } else { Console.WriteLine("incorrent tax entered, Please resubmit the details"); Console.ReadKey(); Environment.Exit(1); } Console.WriteLine("Enter Daily Tax for {0}: ", newEntrymunicipal); decimal DailyTax; if (decimal.TryParse(Console.ReadLine(), out DailyTax)) { daily = daily + DailyTax; } else { Console.WriteLine("incorrent tax entered, Please resubmit the details"); Console.ReadKey(); Environment.Exit(1); } string newEntryTaxDetails = string.Join(",", new string[] { yearly, monthly, daily }); FileOperation fO = new FileOperation(); string fileName = fO.GetFile(); IDictionary <string, string> MunicipalTaxDetails = fO.ReadDataFromFile(fileName); MunicipalTaxDetails.Add(newEntrymunicipal, newEntryTaxDetails); string dateToWrite = JsonConvert.SerializeObject(MunicipalTaxDetails); File.WriteAllText(fileName, dateToWrite); //string Json = System.IO.File.ReadAllText(filePath); //IDictionary<string, string> fileDetails = JsonConvert.DeserializeObject<IDictionary<string, string>>(Json); } catch (Exception) { throw; } }