コード例 #1
0
        public static void GetExchangeRatesFromFile()
        {
            CurrencyYearList = new List <CurrencyYear>();

            // Load exchange rate array

            var text = File.ReadAllText(currPath);

            string[] lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string line in lines)
            {
                if (!line.StartsWith("#") && line.Length > 30)
                {
                    string[]     lineParam = line.Split(new[] { "/" }, StringSplitOptions.None);
                    CurrencyYear CY        = new CurrencyYear(GetCurrency(lineParam[0]), Convert.ToInt32(lineParam[1]));

                    // Add 12 periods
                    for (int i = 0; i < 12; i++)
                    {
                        try
                        {
                            CY.ExchangeRates.Add(Convert.ToDouble(lineParam[i + 2]));
                        }
                        catch
                        {
                        }
                    }

                    CurrencyYearList.Add(CY);
                }
            }
        }
コード例 #2
0
        // convert rate from 1 PESO to x CAD
        public static double PESOtoCAD(ExcoCalendar calendar, int year1 = 0, int month1 = 0)
        {
            int year  = 0;
            int month = 0;

            // if not provided
            if (year1 == 0 && month1 == 0)
            {
                year  = calendar.GetCalendarYear();
                month = calendar.GetCalendarMonth();
            }
            else
            {
                year = year1 - 1;
                if ((month1 + 10) > 12)
                {
                    month = (month1 + 10) - 12;
                    year  = year1++;
                }
                else
                {
                    month = month1 + 10;
                }
            }

            CurrencyYear refCy = CurrencyYearList.First(x => x.Year - 2000 == year && x.CurrencyType == Currency.COP);

            return(refCy.ExchangeRates[month - 1]);

            /*
             * //string USD_exch_path = "\\\\10.0.0.6\\inetpub\\report system\\usdexchrate.txt";
             * string COP_exch_path = "\\\\10.0.0.6\\inetpub\\report system\\copexchrate.txt";
             * bool got_year = false;
             * double exch_rate = 0;
             *
             * var text = File.ReadAllText(COP_exch_path);
             * string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
             * foreach (string line in lines)
             * {
             *  if (line.Length > 1)
             *  {
             *      if (line.Substring(1, 4) == year.ToString())
             *      {z
             *          got_year = true;
             *      }
             *      if (got_year) //found year, begin getting exchange rate
             *      {
             *          string[] entries = line.Split(new string[] { ":" }, StringSplitOptions.None);
             *          if (entries[0] == month.ToString())
             *          {
             *              exch_rate = Convert.ToDouble(entries[1]);
             *              got_year = false;
             *              break;
             *          }
             *      }
             *  }
             * }
             *
             * return exch_rate;
             * }
             */

            switch (year)
            {
            case 2010:
            case 10:
            case 2011:
            case 11:
                return(0.0);

            case 2012:
            case 12:
                switch (month)
                {
                case 1:
                    return(0.000525);

                case 2:
                    return(0.000556);

                case 3:
                    return(0.000558);

                case 4:
                    return(0.000557);

                case 5:
                    return(0.000560);

                case 6:
                    return(0.000564);

                case 7:
                    return(0.000571);

                case 8:
                    return(0.000559);

                case 9:
                    return(0.000540);

                case 10:
                    return(0.000546);

                case 11:
                    return(0.000546);

                case 12:
                    return(0.000548);

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            case 2013:
            case 13:
                switch (month)
                {
                case 1:
                    return(0.000563);

                case 2:
                    return(0.000562);

                case 3:
                    return(0.000567);

                case 4:
                    return(0.000556);

                case 5:
                    return(0.000551);

                case 6:
                    return(0.000543);

                case 7:
                    return(0.000546);

                case 8:
                    return(0.000542);

                case 9:
                    return(0.000545);

                case 10:
                    return(0.000539);

                case 11:
                    return(0.000552);

                case 12:
                    return(0.000548);

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            case 2014:
            case 14:
                switch (month)
                {
                case 1:
                    return(0.000551);

                case 2:
                    return(0.000551);

                case 3:
                    return(0.000541);

                case 4:
                    return(0.000561);

                case 5:
                    return(0.000567);

                case 6:
                    return(0.000572);

                case 7:
                    return(0.000568);

                case 8:
                    return(0.000580);

                case 9:
                    return(0.000567);

                case 10:
                    return(0.000555);

                case 11:
                    return(0.000547);

                case 12:
                    return(0.000515);

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            case 2015:
            case 15:
                switch (month)
                {
                case 1:
                    return(0.000486);        //next

                case 2:
                    return(0.000520);

                case 3:
                    return(0.000520);

                case 4:
                    return(0.000489);

                case 5:
                    return(0.000505);

                case 6:
                    return(0.000492);       //<--- MAY

                case 7:
                    return(0.00048);        //<--- JUNE

                case 8:
                    return(0.000456);        //<--- JULY

                case 9:
                    return(0.000432);        //<--- AUG

                case 10:
                    return(0.000435);        //<--- SEPT

                case 11:
                    return(0.000453);        //<--- OCT

                case 12:
                    return(0.000424);        //<--- NOV

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            case 2016:
            case 16:
                switch (month)
                {
                case 1:
                    return(0.000436);        // DEC

                case 2:
                    return(0.000426);

                case 3:
                    return(0.000407);

                case 4:
                    return(0.000431);

                case 5:
                    return(0.000440);

                case 6:
                    return(0.000424);       //<--- MAY

                case 7:
                    return(0.000445);       //<--- JUNE *check income statement

                case 8:
                    return(0.000425);

                case 9:
                    return(0.000444);

                case 10:
                    return(0.000458);

                case 11:
                    return(0.000447);

                case 12:
                    return(0.000437);

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            case 2017:
            case 17:
                switch (month)
                {
                case 1:
                    return(0.000448);        // DEC

                case 2:
                    return(0.000446);

                case 3:
                    return(0.000453);

                case 4:
                    return(0.000462);

                case 5:
                    return(0.000463);

                case 6:
                    return(0.000463);       //<--- MAY

                case 7:
                    return(0.000443);       //<--- JUNE *check income statement

                case 8:
                    return(0.000420);

                case 9:
                    return(0.000424);

                case 10:
                    return(0.000425);

                case 11:
                    return(0.000425);

                case 12:
                    return(0.000425);

                default:
                    throw new Exception("Invalid month " + month.ToString());
                }

            default:
                throw new Exception("Invalid year " + year.ToString());
            }
        }