/// <summary> /// Funcion que muestra el dialogo para agregar un nuevo currency a la lista de Exchange Rate /// </summary> /// <history> /// [vipacheco] 03/14/2016 Created /// </history> private void btnAdd_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Se verifica si esta en modo edicion if (!btnEdit.IsEnabled) { UIHelper.ShowMessage("This form is currently in edit mode. Please save or undo your changes before closing it.", MessageBoxImage.Information); return; } List <Currency> lstDistict = frmHost._lstCurrencies.Where(x => !grdExchangeRate.ItemsSource.OfType <ExchangeRateData>().Select(s => s.excu).ToList().Contains(x.cuID) && x.cuID != "US").ToList(); if (lstDistict.Any()) { // Mandamos ejecutar el formulario para agregar nuevo Exchange Rate ExchangeRateData exchangeCurrent = grdExchangeRate.SelectedItem as ExchangeRateData; frmExchangeRateDetail frmExchangeEdit = new frmExchangeRateDetail(EnumMode.Add) { Owner = this }; frmExchangeEdit.lstCurrencies = lstDistict; // Si se agregó un nuevo item if (frmExchangeEdit.ShowDialog().Value) { //Actualizamos el Data Source. calDate_SelectedDatesChanged(null, null); } } // Todos los currency estan agregados else { UIHelper.ShowMessage("All currencies already added", MessageBoxImage.Information); } }
/// <summary> /// Despliega el formulario de detalles /// </summary> /// <history> /// [vipacheco] 03/14/2016 Created /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { //Verificamos que este en modo Edición! if (!btnEdit.IsEnabled) { // Construimos el formulario a mostrar ExchangeRateData exchangeCurrent = grdExchangeRate.SelectedItem as ExchangeRateData; // Verificamos que no sea currency MEX if (!exchangeCurrent.excu.Equals("MEX")) { frmExchangeRateDetail frmExchangeEdit = new frmExchangeRateDetail(EnumMode.Edit) { Owner = this }; // clonamos las propiedades del ExchangeRateData a editar frmExchangeEdit.exchangeDate = ObjectHelper.CopyProperties(exchangeCurrent); if (frmExchangeEdit.ShowDialog().Value) { // Si son diferentes if (!ObjectHelper.IsEquals(frmExchangeEdit.exchangeDate, exchangeCurrent)) { //Recargamos el datagrid! calDate_SelectedDatesChanged(null, null); } } } } }
public static void TCMBDovizKuruAl() { db.ExchangeRateDatas.RemoveRange(db.ExchangeRateDatas.ToList()); string today = "http://www.tcmb.gov.tr/kurlar/today.xml"; var xmlDoc = new XmlDocument(); xmlDoc.Load(today); ExchangeRateData rateData = new ExchangeRateData(); rateData.Buying = Convert.ToDouble(xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='USD']/BanknoteBuying").InnerXml); rateData.Selling = Convert.ToDouble(xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='USD']/BanknoteSelling").InnerXml); rateData.CurrencyCode = "USD/TRY"; rateData.Currency = new Currency(); rateData.Currency.Unit = 1; rateData.CurrencyName = xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='USD']/CurrencyName").InnerXml; // rateData.CurrencyId = db.Currency.Find(1).Id; rateData.CreatedDate = DateTime.Now; db.ExchangeRateDatas.Add(rateData); db.SaveChanges(); ExchangeRateData rateData1 = new ExchangeRateData(); rateData1.Buying = Convert.ToDouble(xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='EUR']/BanknoteBuying").InnerXml); rateData1.Selling = Convert.ToDouble(xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='EUR']/BanknoteSelling").InnerXml); rateData.Currency = new Currency(); rateData.Currency.Unit = 1; rateData1.CurrencyCode = "EUR/TRY"; rateData1.CurrencyName = xmlDoc.SelectSingleNode("Tarih_Date/Currency[@Kod='EUR']/CurrencyName").InnerXml; rateData1.CreatedDate = DateTime.Now; db.ExchangeRateDatas.Add(rateData1); db.SaveChanges(); }
public static ExchangeRateData ParseExchangeRate(string str) { string[] arr = str.Split('|'); string date = ""; Dictionary <string, float> rates = new Dictionary <string, float>(); for (int i = 0; i < arr.Length; i++) { string data = arr[i]; if (i == 0) { date = data; } else { rates[i.ToString()] = float.Parse(data); } } ExchangeRateData exchangeRate = new ExchangeRateData(); exchangeRate.date = date; exchangeRate.ratesByID = rates; return(exchangeRate); }
/// <summary> /// Updates exchange informations /// </summary> /// <param name="baseCurrency">The currency all other currencies are depending</param> /// <param name="currencies">The dependent currencies</param> /// <remarks></remarks> public void Update(CurrencyInfo baseCurrency, IEnumerable<CurrencyInfo> currencies) { mDownloader.CancelAsyncAll(); mDonwloadCounter += 1; mExchangeItems = new ExchangeRateData[] { }; ExchangeRateResponse resp = mDownloader.Download(this.GetCurrencyList(baseCurrency, currencies)); if (resp.Connection.State == Base.ConnectionState.Success) mExchangeItems = resp.Result.Items; }
private void ExchangeRateHandler(ExchangeRateData data) { if (data.CurrencyPairId != (uint)TrackedSymbol.CurrencyPairId) { return; } SpotPrice = data.MarkPrice; SpotPriceUpdated?.Invoke(this); }
public double GetCurrencyExchange(int amount, string from, string to) { string url = $"https://v3.exchangerate-api.com/pair/{APIKey}/{from}/{to}"; ExchangeRateData data = JsonConvert.DeserializeObject <ExchangeRateData>(GetResponse(url)); double num = Double.Parse(data.rate) * amount; return(Math.Round(num, 2)); }
public async Task<double> CalculateRate(double value, string fromCurrency, string toCurrency) { // Get all rate values from API ExchangeRateData exchangeRates = await _exchangeRateApi.GetExchagneRates(toCurrency); // Get "FromCurrency" rate var rate = exchangeRates.Rates[fromCurrency]; // Calculate and return return value * rate; }
public async Task <string> RenderAsync(string model) { using (ExchangeRateDataProvider dp = new ExchangeRateDataProvider()) { ExchangeRateData data = await dp.GetItemAsync(); List <SelectionItem <string> > list = (from r in data.Rates orderby r.CurrencyName select new SelectionItem <string> { Text = r.CurrencyName, Value = r.Code }).ToList(); return(await DropDownListComponent.RenderDropDownListAsync(this, model, list, "yt_yetawf_currencyconverter_country")); } }
public async Task <string> RenderAsync(string model) { using (ExchangeRateDataProvider dp = new ExchangeRateDataProvider()) { ExchangeRateData data = await dp.GetItemAsync(); string currency = (from r in data.Rates where r.Code == model select r.CurrencyName).FirstOrDefault(); if (string.IsNullOrEmpty(model)) { return(null); } return(HE(currency)); } }
public async Task <ActionResult> CurrencyConverter(decimal?amount) { decimal specificAmount = (amount == null) ? Module.DefaultAmount : (decimal)amount; using (ExchangeRateDataProvider dp = new ExchangeRateDataProvider()) { ExchangeRateData data = await dp.GetItemAsync(); Model model = new Model() { Rates = data.Rates, FromCountry = Module.FromCountry, ToCountry = Module.ToCountry, Amount = specificAmount, }; return(View(model)); } }
/// <summary> /// Función evento click encargado llamar al formulario Log /// </summary> /// <history> /// [vipacheco] 05/03/2016 Created /// </history> private void btnLog_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ExchangeRateData itemRow = grdExchangeRate.SelectedItem as ExchangeRateData; if (itemRow != null) { frmExchangeRateLog _frmExchangeRateLog = new frmExchangeRateLog(itemRow.excu) { Owner = this }; _frmExchangeRateLog.Title += frmHost._lstCurrencies.Where(x => x.cuID == itemRow.excu).Select(s => s.cuN).Single(); _frmExchangeRateLog.ShowDialog(); } else { UIHelper.ShowMessage("Select an exchange rate", MessageBoxImage.Information); } }
/// <summary> /// Converts as value of a currenciy to the ratio value of another currency; both ExchangeRataData have same base currency /// </summary> /// <param name="value">The value to convert</param> /// <param name="currencyOfValue">The base currency</param> /// <param name="returnCurrency">The dependent currency</param> /// <returns></returns> /// <remarks>Returns 0, if the base currency of both is not equal</remarks> public static double ConvertCurrency(double value, ExchangeRateData currencyOfValue, ExchangeRateData returnCurrency) { try { if (currencyOfValue.CurrencyRelation.BaseCurrency.ID == returnCurrency.CurrencyRelation.BaseCurrency.ID) { if (currencyOfValue.CurrencyRelation.DepCurrency.ID != returnCurrency.CurrencyRelation.DepCurrency.ID) { double fromRatio = currencyOfValue.DependencyValue; double toRatio = returnCurrency.DependencyValue; if (fromRatio != 0 & toRatio != 0) { return (value / fromRatio * toRatio); } else { return 0; } } else { return value; } } else { throw new ArgumentException("The exchange rates have not the same base currency."); } } catch (Exception ex) { return 0; } }
public static double ConvertCurrency(double value, ExchangeRateData exchangeRate, bool reverse = false) { if (exchangeRate != null && exchangeRate.LastTradePriceOnly != 0) { if (!reverse) { return value * exchangeRate.LastTradePriceOnly; } else { return value / exchangeRate.LastTradePriceOnly; } } else { throw new ArgumentException("The exchange rate is invalid", "exchangeRate"); } }
private void Process_ExchangeRate() { ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); for (int i = 0; i <= (dg_xc.Items.Count - 1); i++) { CheckBox chkUpdate = (CheckBox)dg_xc.Items[i].FindControl("chk_email"); HiddenField hdnCurrency = (HiddenField)dg_xc.Items[i].FindControl("hdn_currencyId"); long currentCurrencyId = Convert.ToInt64(hdnCurrency.Value); if (chkUpdate.Checked && Util_IsActiveExchangeCurrency(currentCurrencyId)) { // If Request.Form("chk_email_" & currencyList(i).Id) <> "" Then if (dg_xc.Items[i].FindControl("txt_exchange") != null) { TextBox txtXCRate = (TextBox)dg_xc.Items[i].FindControl("txt_exchange"); decimal newRate = decimal.Parse(txtXCRate.Text); ExchangeRateData exchangeRateData = new ExchangeRateData(exchangeRateApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId, Convert.ToInt32(currentCurrencyId), newRate, DateTime.Now); exchangeRateApi.Add(exchangeRateData); } } } ltr_js.Text = "self.parent.location.reload(); self.parent.ektb_remove();"; }
private void Process_Edit() { CurrencyData currency = null; currency = m_refCurrency.GetItem(Convert.ToInt32(m_iID)); ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); ExchangeRateData exchangeRateData = new ExchangeRateData(exchangeRateApi.RequestInformationRef.CommerceSettings.DefaultCurrencyId, currency.Id, Convert.ToDecimal(txt_exchangerate.Text), DateTime.Now); exchangeRateApi.Add(exchangeRateData); currency.Name = (string) txt_name.Text; currency.Id = System.Convert.ToInt32(txt_numericisocode.Text); currency.AlphaIsoCode = (string) txt_alphaisocode.Text; currency.Enabled = System.Convert.ToBoolean(chk_enabled.Checked); m_refCurrency.Update(currency); ltr_js.Text = "self.parent.location.reload(); self.parent.ektb_remove();"; }
protected void Util_PopulateData(CurrencyData currency) { ExchangeRateData exchangeRateData = new ExchangeRateData(); decimal rate = (decimal) 0.0; ExchangeRateApi exchangeRateApi = new ExchangeRateApi(); exchangeRateData = exchangeRateApi.GetCurrentExchangeRate(currency.Id); if (exchangeRateData != null) { rate = exchangeRateData.Rate; } txt_name.Text = currency.Name; txt_numericisocode.Text = currency.Id.ToString(); txt_alphaisocode.Text = currency.AlphaIsoCode; chk_enabled.Checked = currency.Enabled; txt_exchangerate.Text = rate.ToString(); //txt_exchangerate.Text = txt_exchangerate.Text.Substring(0, txt_exchangerate.Text.LastIndexOf(".") + 3) }