WPF中的货币转换 [英] Currency conversion in WPF

查看:99
本文介绍了WPF中的货币转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我!!!!!!!

我想创建一个项目,从用户那里获取货币类型,并使用WPF应用程序将其转换为另一种货币,并且在运行此项目时不需要互联网。



以下是我的代码的一部分...



Can anyone help me!!!!!!!
I want to make a project that get the currency type from user and convert this to another type of currency using WPF application and without any need of internet while running this project.

Here is a part of my code...

void OnClick_Convert(object sender, RoutedEventArgs e)
       {
           try
           {
               double dResult = 0;
               //store the default brush for the convert button before call
               Brush dbrush=this.btnConvert.Background;
               //change the background of convert button before call
               this.btnConvert.Background = Brushes.LightBlue;
               //create the CurrencyConvertor webserivce
               CurrencyConvertorSoapClient wsCurrencyConverter = new CurrencyConvertorSoapClient();
               //call the webmethod
               dResult = wsCurrencyConverter.ConversionRate((Currency)Enum.Parse(typeof(Currency), cmbFromCurrency.SelectionBoxItem.ToString().Substring(0, 3)), (Currency)Enum.Parse(typeof(Currency), cmbToCurrency.SelectionBoxItem.ToString().Substring(0, 3)));
               txtResults.Text = cmbFromCurrency.SelectionBoxItem.ToString() + " To " + cmbToCurrency.SelectionBoxItem.ToString() + " = " + Convert.ToString(dResult);
               //change back the to default brush
               this.btnConvert.Background = dbrush;
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
           }





这是我不想在我的项目中使用的网络服务.....



this is the webservice that i dont want to use in my project.....

public double ConversionRate(www.webservicex.net.Currency FromCurrency, www.webservicex.net.Currency ToCurrency)
   {
       return base.Channel.ConversionRate(FromCurrency, ToCurrency);
   }

推荐答案

不,没有人可以帮到你。 (我认为这回答了你的问题)。



原因是货币就像股票一样,利率交换在任何一天使用外汇交易市场 [ ^ ]



因此,您无法设计能够正确转换货币而无需调用服务的应用程序检查当前的汇率。



您可能会在本地系统上缓存一些费用并在系统离线时使用这些费率,但它需要先在线上线获得缓存它们的费率,你想告诉用户数据有多陈旧(10分钟,10小时,10天等)
No, nobody can help you. (I think that answers your question).

The reason being is currency is like stock and the rate exchange changes significantly through out any given day using the Foriegn Exchange Market[^]

So there is no way you can design an application that would correctly convert currencies without calling out to a service that is checking the current exchange rate.

You could potentially cache some rates on the local system and use those while the system is offline, but it would need to get online first to get the rates to cache them and you would want to inform the user how stale the data is (10 min, 10 hours, 10 days etc.)


这篇关于WPF中的货币转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆