Exemplo n.º 1
0
        public ConversionModel GetMeByFromTo(int from, int to)
        {
            ConversionModel cm = new ConversionModel();
            List <KeyValuePair <string, string[]> > conditions = new List <KeyValuePair <string, string[]> >();

            string[] value = new string[2] {
                "number", from.ToString()
            };
            conditions.Add(new KeyValuePair <string, string[]>("currency_id_first", value));
            value = new string[2] {
                "number", to.ToString()
            };
            conditions.Add(new KeyValuePair <string, string[]>("currency_id_second", value));
            cm = ReturnMeFromDataTable(cm.FindByParameters(conditions));
            if (cm != null && cm.First.ToString() != "0" && cm.Second.ToString() != "0" && cm.Ratio.ToString() != "0")
            {
                return(cm);
            }
            else
            {
                conditions = new List <KeyValuePair <string, string[]> >();
                value      = new string[2] {
                    "number", to.ToString()
                };
                conditions.Add(new KeyValuePair <string, string[]>("currency_id_first", value));
                value = new string[2] {
                    "number", from.ToString()
                };
                conditions.Add(new KeyValuePair <string, string[]>("currency_id_second", value));
                cm = ReturnMeFromDataTable(cm.FindByParameters(conditions));
                if (cm != null && cm.First.ToString() != "0" && cm.Second.ToString() != "0" && cm.Ratio.ToString() != "0")
                {
                    return(cm);
                }
                else
                {
                    CurrencyModel first  = new CurrencyModel();
                    CurrencyModel second = new CurrencyModel();
                    first  = first.Get(from);
                    second = second.Get(to);
                    string msg = "Please add a currency conversion from " + first.Name + " to " + second.Name;
                    throw new Exception(msg);
                }
            }
        }
Exemplo n.º 2
0
 public decimal Convert(decimal number, int from, int to)
 {
     if (from != to)
     {
         ConversionModel cm = GetMeByFromTo(from, to);
         if (cm.First != from && cm.Second != to)
         {
             Ratio = 1 / cm.Ratio;
         }
         else
         {
             Ratio = cm.Ratio;
         }
         number *= (decimal)Ratio;
         return(number);
     }
     return(number);
 }
Exemplo n.º 3
0
        public float?GetTotalFloat(int currency)
        {
            decimal total = Price * Quantity;

            if (currency != Currency)
            {
                try
                {
                    ConversionModel cm = new ConversionModel();
                    total = cm.Convert(total, Currency, currency);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
            }
            return((float)total);
        }
Exemplo n.º 4
0
        public void SetFullAmount(int currency)
        {
            decimal amount = (decimal)Amount;

            if (currency != Currency)
            {
                try
                {
                    ConversionModel cm = new ConversionModel();
                    amount = cm.Convert((decimal)Amount, (int)Currency, currency);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            CurrencyModel c = new CurrencyModel();

            c          = c.Get(currency);
            FullAmount = amount + " " + c.Symbol;
        }
Exemplo n.º 5
0
        public BindableCollection <ConversionModel> GiveCollection(DataTable cs)
        {
            List <ConversionModel> output = new List <ConversionModel>();

            foreach (DataRow row in cs.Rows)
            {
                CurrencyModel   currency  = new CurrencyModel();
                CurrencyModel   currency2 = new CurrencyModel();
                ConversionModel cm        = new ConversionModel
                {
                    First  = System.Convert.ToInt32(row[0].ToString()),
                    Second = System.Convert.ToInt32(row[1].ToString()),
                    Ratio  = System.Convert.ToDecimal(row[2].ToString())
                };
                cm.FirstCurrency  = currency.Get(cm.First);
                cm.SecondCurrency = currency2.Get(cm.Second);
                cm.FirstSymbol    = cm.FirstCurrency.Symbol;
                cm.SecondSymbol   = cm.SecondCurrency.Symbol;
                output.Add(cm);
            }
            return(new BindableCollection <ConversionModel>(output));
        }