protected void LoadDate_Click(object sender, EventArgs e) { // First check if the date is already on the server as a XML file. If thats the case, wont need to parse the whole BD txt file from string XMLFile = BDDownloader.findDateOnServer(Calendar1.SelectedDate); if (!(XMLFile.Equals("XML NOT FOUND"))) { // XML is on the server, only need to retrieve the taxes from the file // Updating flag DateisLoded = true; // DI1 taxes calculator init TaxesCalc = new TaxesCalculator(XMLFile, Calendar1.SelectedDate); TaxesCalc.DITaxesRetrieve(); } // If XML file is not found, download de BD from the internet else { string downloadedFile = BDDownloader.GetBDfromDate(Calendar1.SelectedDate); // If there are results from previous iteration, clean it Clean_Results(); if (downloadedFile.Equals("WebException ERROR")) { // Write something to text in the middle Clean_Results(); TaxesTitle.Text = "<h2>" + "Não foi possível obter as taxas do dia carregado (" + Calendar1.SelectedDate.ToShortDateString() + ") </h2>"; // Early return, did not succeed in getting taxes of the SelectedDate, also saving variable states ViewState["DateisLoaded"] = false; ViewState["TaxesCalc"] = TaxesCalc; return; } else { // Updating flag DateisLoded = true; // DI1 taxes calculator init TaxesCalc = new TaxesCalculator(downloadedFile, Calendar1.SelectedDate); TaxesCalc.DITaxesCalculator(); } } // Writing the Taxes table TaxesTitle.Text = "<h2>" + "Taxas DI de " + Calendar1.SelectedDate.ToShortDateString() + "</h2>"; StringBuilder TaxesListTemp = new StringBuilder(); TaxesListTemp.Append("<div id = \"DITaxesTable\" style=\"overflow: auto; max-height: 19em;\"> <table class=\"table table-bordered\"><thead> <tr> <th>Data</th><th>Taxa DI</th></tr></thead><tbody>"); foreach (KeyValuePair <string, double> tax in TaxesCalc.GetDITaxes()) { TaxesListTemp.Append("<tr><td>" + (tax.Key.Substring(6, 2) + @"/" + tax.Key.Substring(4, 2) + @"/" + tax.Key.Substring(0, 4)) + "</td> <td>" + (tax.Value).ToString("P") + " </td></tr>"); } TaxesListTemp.Append("</tbody></table></div>"); TaxesList.Text = TaxesListTemp.ToString(); // Saving the variables values between Sessions ViewState["DateisLoaded"] = DateisLoded; ViewState["TaxesCalc"] = TaxesCalc; }