public static double ConvertPriceToYen(double price) { net.webservicex.www.CurrencyConvertor converter = new net.webservicex.www.CurrencyConvertor(); double euroToYen = converter.ConversionRate(net.webservicex.www.Currency.EUR, net.webservicex.www.Currency.JPY); double totalAmount = euroToYen * price; return totalAmount; }
/// <summary> /// 获取及时汇率 /// </summary> /// <param name="from"> 要转换的币种 </param> /// <param name="to"> 转换成的币种 </param> /// <returns> 汇率 </returns> public static double GetCurrency(int from, int to) { if (System.Web.HttpContext.Current.Application["CurrencySetting"] == null) { return(BLL.other.Company.SetRateBLL.GetCurrencyBySql(from, to)); } else if (System.Web.HttpContext.Current.Application["CurrencySetting"].ToString() == "Currency") { string fromcu = DAL.CurrencyDAL.GetJieCheng(from); string tocu = DAL.CurrencyDAL.GetJieCheng(to); net.webservicex.www.CurrencyConvertor CC = new net.webservicex.www.CurrencyConvertor(); return(CC.ConversionRate((net.webservicex.www.Currency)Enum.Parse(typeof(net.webservicex.www.Currency), fromcu), (net.webservicex.www.Currency)Enum.Parse(typeof(net.webservicex.www.Currency), tocu))); } else { return(1); } }
/// <summary> /// Handles the page load event of the form /// </summary> protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { //Create an instance of the external web service net.webservicex.www.CurrencyConvertor currencyConverter = new net.webservicex.www.CurrencyConvertor(); //Display the current exchange rate lblExchangeRate.Text = string.Format("The exchange rate between Canada and the United States is currently {0}", currencyConverter.ConversionRate(net.webservicex.www.Currency.USD, net.webservicex.www.Currency.CAD)); long clientNumber = long.Parse(Page.User.Identity.Name); Client client = db.Clients.Where(x => x.ClientNumber == clientNumber).SingleOrDefault(); lblClient.Text = client.FullName; int clientId = client.ClientId; Session["ClientId"] = clientId; Session["FullName"] = lblClient.Text; IQueryable<BankAccount> query = db.BankAccounts.Where(x => x.ClientId == clientId); gvClient.DataSource = query.ToList(); this.DataBind(); } } catch (Exception) { lblClient.Text = string.Empty; lblErrorException.Text = "Error fetching banking information from the database."; lblErrorException.Visible = true; } }
protected void btnUpdateRate_Click(object sender, EventArgs e) { IList <CurrencyModel> list = new List <CurrencyModel>(); string curr = SetRateBLL.GetDefaultCurrency(); foreach (DataRow dr in SetRateBLL.GetAllCurrency().Rows) { CurrencyModel cm = new CurrencyModel(); cm.JianCheng = dr["jiecheng"].ToString(); net.webservicex.www.CurrencyConvertor CC = new net.webservicex.www.CurrencyConvertor(); cm.Rate = CC.ConversionRate((net.webservicex.www.Currency)Enum.Parse(typeof(net.webservicex.www.Currency), cm.JianCheng), (net.webservicex.www.Currency)Enum.Parse(typeof(net.webservicex.www.Currency), curr)); list.Add(cm); } if (SetRateBLL.UpdCurrencyRateAll(list)) { msg = "<script>alert('" + GetTran("006594", "同步成功!") + "');</script>"; GetCurrencyInfo(); } else { msg = "<script>alert('" + GetTran("006595", "同步失败!") + "');</script>"; } }