Пример #1
0
/*
 *
 *      public void FindBestAndWorst(ref string cur1Min, ref string cur2Min, ref string cur1Max, ref string cur2Max, ref double ratio)
 *      {
 *          Currency90DaysWithCurrencyList firstDay = currency90DaysWithCurrencyList.First();
 *          Currency90DaysWithCurrencyList lastDay = currency90DaysWithCurrencyList.Last();
 *
 *          double max = 0;
 *          double min = 0;
 *          double result;
 *
 *          foreach (Currency curFirst in firstDay.GetCurrencyList())
 *          {
 *              foreach (Currency curLast in lastDay.GetCurrencyList())
 *              {
 *                  if (curFirst.GetCurrencyName() != curLast.GetCurrencyName())
 *                  {
 *                      result = ReturnRate(curFirst, curLast);
 *                      result = result / Convert.ToDouble(curFirst.GetCurrencyRate(), System.Globalization.CultureInfo.InvariantCulture);
 *                      if (result > max)
 *                      {
 *                          max = result;
 *                          cur1Max = curFirst.GetCurrencyName();
 *                          cur2Max = curLast.GetCurrencyName();
 *                          ratio = result;
 *                      }
 *                      if (result < min)
 *                      {
 *                          min = result;
 *                          cur1Min = curFirst.GetCurrencyName();
 *                          cur2Min = curLast.GetCurrencyName();
 *                          ratio = result;
 *                      }
 *                  }
 *              }
 *          }
 *      }
 *
 */

        public Currency ReturnElement(string CurrencyName)
        {
            Currency currencyResult = null;
            Currency90DaysWithCurrencyList lastDay = currency90DaysWithCurrencyList.Last();

            foreach (Currency cur in lastDay.GetCurrencyList())
            {
                if (cur.GetCurrencyName() == CurrencyName)
                {
                    currencyResult = cur;
                }
            }
            return(currencyResult);
        }
Пример #2
0
        /// <summary>
        /// /////////////////////////////////////////////////////////
        /// ////////////////////////////////////
        ///
        ///
        ///
        /// ///////////////////////////////////////////////////////////////////////////
        /// </summary>

        public bool Create90DaysWithCurrencyList()
        {
            if (CheckForInternetConnection())
            {
                XmlReader xmlReader = XmlReader.Create("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml?8e98690e32f6914990146c9b53a350b9");
                int       i         = 31;

                Currency90DaysWithCurrencyList currencyOneDay = new Currency90DaysWithCurrencyList();
                currencyOneDay.CreateCurrencyList();
                while (xmlReader.Read())
                {
                    if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "Cube"))
                    {
                        if (xmlReader.HasAttributes)
                        {
                            if (i == 31)
                            {
                                i = 0;
                                Currency90DaysWithCurrencyList.Add(currencyOneDay);
                                currencyOneDay = new Currency90DaysWithCurrencyList();
                                currencyOneDay.CreateCurrencyList();
                                Currency cur = new Currency();
                                cur.SetCurrencyName("EUR");
                                cur.SetCurrencyRate("1.00");
                                currencyOneDay.AddToCurrencyList(cur);
                                currencyOneDay.SetCurrencyDate(xmlReader.GetAttribute("time"));
                            }
                            else
                            {
                                Currency cur = new Currency();

                                cur.SetCurrencyName(xmlReader.GetAttribute("currency"));
                                cur.SetCurrencyRate(xmlReader.GetAttribute("rate"));

                                currencyOneDay.AddToCurrencyList(cur);
                                i++;
                            }
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        public void FindBestAndWorst(ref string cur1Min, ref string cur2Min, ref string cur1Max, ref string cur2Max, ref double ratioMax, ref double ratioMin)
        {
            Currency90DaysWithCurrencyList firstDay = currency90DaysWithCurrencyList.First();
            Currency90DaysWithCurrencyList lastDay  = currency90DaysWithCurrencyList.Last();

            double max = 0;
            double min = 100;
            double result;
            double FirstDayRatio;
            double LastDayRatio;

            foreach (Currency curFirst in firstDay.GetCurrencyList())
            {
                foreach (Currency curFirst2 in firstDay.GetCurrencyList())
                {
                    if (curFirst.GetCurrencyName() != curFirst2.GetCurrencyName())
                    {
                        FirstDayRatio = ReturnRate(curFirst, curFirst2);
                        LastDayRatio  = ReturnRate(ReturnElement(curFirst.GetCurrencyName()), ReturnElement(curFirst2.GetCurrencyName()));
                        // result = result / Convert.ToDouble(curFirst.GetCurrencyRate(), System.Globalization.CultureInfo.InvariantCulture);
                        result = FirstDayRatio / LastDayRatio;
                        if (result > max)
                        {
                            max      = result;
                            cur1Max  = curFirst.GetCurrencyName();
                            cur2Max  = curFirst2.GetCurrencyName();
                            ratioMax = result;
                        }
                        if (result < min)
                        {
                            min      = result;
                            cur1Min  = curFirst.GetCurrencyName();
                            cur2Min  = curFirst2.GetCurrencyName();
                            ratioMin = result;
                        }
                    }
                }
            }
        }