Exemplo n.º 1
0
        public Money Exchange(Money pieniadz, Waluta wal)
        {
            Money a = new Money(pieniadz.Value, pieniadz.NameOfCurrency);

            a.ChengeCurrency(wal);
            return(a);
        }
Exemplo n.º 2
0
 private double Find(Waluta Name)
 {
     foreach (Currency a in ListOfCurrency)
     {
         if (a.Name == Name)
         {
             return(a.ExchangeInTheRelationToPLN);
         }
     }
     return(-1.0f);
 }
Exemplo n.º 3
0
 public void ChengeCurrency(Waluta curr)
 {
     try
     {
         Value          = GetValueIn(curr);
         NameOfCurrency = curr;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 4
0
 public Money(float val, Waluta waluta)
 {
     NameOfCurrency = waluta;
     if (val < 0.0f)
     {
         throw new Exception("Zła wartość.\n");
     }
     else
     {
         Value = val;
         Curr  = Currencies.GetInstance();
     }
 }
Exemplo n.º 5
0
        public double Swap(Waluta from, Waluta to)
        {
            double przelicznik = 0.0f;
            double xfrom       = Find(from);
            double xto         = Find(to);

            if (xfrom == -1.0f || xto == -1.0f)
            {
                throw new Exception("Nie ma informacji to tych walutach.\n");
            }
            przelicznik = xfrom / xto;
            return(przelicznik);
        }
Exemplo n.º 6
0
        public double GetCourse(Waluta name)
        {
            double pomocnicza = Find(name);

            if (pomocnicza == -1.0f)
            {
                throw new Exception("Nie znaleziono waluty.\n");
            }
            else
            {
                return(pomocnicza);
            }
        }
Exemplo n.º 7
0
 public float GetValueIn(Waluta waluta)
 {
     if (waluta == NameOfCurrency)
     {
         return(Value);
     }
     else
     {
         try
         {
             return((float)(Curr.Swap(NameOfCurrency, waluta)) * Value);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemplo n.º 8
0
 public Price(float val, Waluta waluta, float vat)
 {
     try
     {
         this.NetPrice = new Money(val, waluta);
     }
     catch (Exception e)
     {
         throw e;
     }
     if (vat >= 0.0f && vat < 1.0f)
     {
         VAT = vat;
     }
     else
     {
         VAT = 0.0f;
         throw new Exception("Zła wartośc VAT, ustawiono na 0%");
     }
 }
Exemplo n.º 9
0
        public static async Task <double> KursEuro()
        {
            string BaseAddress = "http://api.nbp.pl/api/exchangerates/rates/a/eur/?format=json";

            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage res = await client.GetAsync(BaseAddress))
                {
                    using (HttpContent content = res.Content)
                    {
                        string data = await content.ReadAsStringAsync();

                        var    dataObj    = JObject.Parse(data);
                        Waluta waluta     = new Waluta(kurs: $"{dataObj["rates"]}");
                        string JsonString = waluta.Kurs.ToString();
                        JsonString = JsonString.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' });
                        var    dataObj2 = JObject.Parse(JsonString);
                        Waluta waluta2  = new Waluta(kurs: $"{dataObj2["mid"]}");
                        double wartosc  = Convert.ToDouble(waluta2.Kurs);
                        return(wartosc);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void ChangeCurrency(Waluta nowa)
        {
            Money a = new Money(NetPrice.GetValueIn(nowa), nowa);

            NetPrice = a;
        }
Exemplo n.º 11
0
 public void ChangeCurrency(Waluta a)
 {
     PriceOfProduct.ChangeCurrency(a);
 }
Exemplo n.º 12
0
 private void Waluta_SelectedIndexChanged(object sender, EventArgs e)
 {
     WalutaA = Waluta.GetItemText(Waluta.SelectedItem);
 }