Exemplo n.º 1
0
        public void DITaxesCalculator()
        {
            // Define flag to stop reading the rest of the document after DI1 entries are read
            bool entriesFlagDI1 = false;

            foreach (string line in File.ReadLines(bdfilePath))
            {
                if (line.Substring(21, 3).Equals("DI1"))
                {
                    entriesFlagDI1 = true;
                    // Now calculating each tax
                    string taxDate     = line.Substring(36, 8);
                    int    cotationAj  = int.Parse(line.Substring(231, 13));
                    int    workingDays = int.Parse(line.Substring(388, 5));
                    double DITax       = Math.Pow((10000000.0 / (cotationAj)), (252.0 / workingDays)) - 1;
                    DITaxes.Add(taxDate, DITax);
                }
                else
                {
                    if (entriesFlagDI1)
                    {
                        // There are no more DI1 entries to read on the file, interrupt in order to have better performance
                        break;
                    }
                }
            }
            // Saving the computed results on a XML file for faster retrieval if the same Date is requested later
            BDDownloader.SaveDates(DITaxes, curveDate);
        }
Exemplo n.º 2
0
        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;
        }