public HttpResponseMessage Get() { ExchangeRateResponseBody model = new ExchangeRateResponseBody(); try { CurrencyConvertor exchangerate = new CurrencyConvertor(); double exchangevalue = exchangerate.ConversionRate(Currency.JPY, Currency.VND); model.message = "ExchangeRate successfull !!!"; model.code = HttpStatusCodeDefine.SUCCESS.GetHashCode(); model.data = new ExchangeRateResponse() { rate = exchangevalue.ToString() }; } catch (Exception ex) { #region error system model.code = HttpStatusCodeDefine.SERVER_ERROR.GetHashCode(); model.message = ex.Message; model.data = null; #endregion } return(Request.CreateResponse(HttpStatusCode.OK, model)); }
/// <summary> /// /// </summary> /// <exception cref="WebException">Throws when there is no internet connection</exception> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public double GetCurrencyRate(string from, string to) { try { _currencyClient = new CurrencyConvertor(); Currency fromEnum; Currency toEnum; if (!Enum.TryParse <Currency>(from, out fromEnum)) { throw new ArgumentException(Resources.Exception_Could_not_indetify_currency_code, "from"); } if (!Enum.TryParse <Currency>(to, out toEnum)) { throw new ArgumentException(Resources.Exception_Could_not_indetify_currency_code, "to"); } return(_currencyClient.ConversionRate(fromEnum, toEnum)); } catch (ArgumentException e) { return(-1); } catch (WebException e) { Debug.WriteLine(e.Message); // throw new WebException("No internet connection", e); MessageBox.Show("Could not connect to web service, please try again later", "Internet connection (Currency rate"); return(-1); } }
private async Task <List <dto.ProductModel> > GetProducts(string type, string category, string dollar) { string toCurrency = dollar; Single price = 0; float exchangeRate = 1; if ((toCurrency != "") && (toCurrency.ToUpper() != "NZD")) { exchangeRate = CurrencyConvertor.GetExchangeRate(toCurrency); } if (category != null) { category = category.Replace("-", " "); } var ret = new List <dto.ProductModel>(); var cmd = this.MySqlDB.Connection.CreateCommand() as MySqlCommand; string query = @"SELECT p.ProductId, p.ProductName, p.ProductPrice, p.ProductImage, p.ProductCode, c.CategoryID, c.categoryname from products p inner join productcategories c on p.ProductCategoryID=c.categoryid "; if (type == "featured") { query += "where productID = 15 or productID = 8 or productID = 9"; } if ((type == "category") && (category.ToLower() != "all")) { query += "where categoryname = '" + category + "'"; } query += ";"; System.Diagnostics.Debug.WriteLine("Type: " + type); System.Diagnostics.Debug.WriteLine("Category: " + category); System.Diagnostics.Debug.WriteLine("Query: " + query); cmd.CommandText = query; using (var reader = await cmd.ExecuteReaderAsync()) while (await reader.ReadAsync()) { price = reader.GetFieldValue <Single>(2); var t = new dto.ProductModel() { ProductId = reader.GetFieldValue <int>(0), ProductName = reader.GetFieldValue <string>(1).ToUpper(), ProductPrice = price * exchangeRate, ProductImage = reader.GetFieldValue <string>(3), ProductCode = reader.GetFieldValue <string>(4), CategoryID = reader.GetFieldValue <int>(5), CategoryName = reader.GetFieldValue <string>(6) }; ret.Add(t); } return(ret); }
private void btnObtenerCotizacion_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; CurrencyConvertor currencyConvertor = new CurrencyConvertor(); double convertion = currencyConvertor.ConversionRate(Currency.USD, Currency.ARS); txtCotizacionUS.Text = convertion.ToString(); Cursor.Current = Cursors.Default; }
public void Dispose() { if (_currencyService != null) { _currencyService.ConversionRateCompleted -= new ConversionRateCompletedEventHandler(_currencyService_ConversionRateCompleted); _currencyService.Dispose(); _currencyService = null; } }
public static double GetRate(CurrencyConvertor.Currency fromCurrency, CurrencyConvertor.Currency toCurrency) { CurrencyConvertor.CurrencyConvertorSoap client = new CurrencyConvertor.CurrencyConvertorSoapClient("CurrencyConvertorSoap"); double rate = client.ConversionRate(fromCurrency, toCurrency); if (rate <= 0.0) throw new Exception("Invalid rate"); return rate; }
public ProductSearch(string searchTerm, int pageNumber, int productsOnPage, CurrencyConvertor.Currency currency) { ProductsOnPage = productsOnPage; SearchTerm = searchTerm; PageNumber = pageNumber; Currency = currency; ConversionRate = CurrencyHelper.convertFrom(ApplicationProperties.AmazonReturnedCurrency, Currency); }
public static double convertFrom(CurrencyConvertor.Currency from, CurrencyConvertor.Currency to) { var client = new CurrencyConvertor.CurrencyConvertorSoapClient( new BasicHttpBinding(), new EndpointAddress(endpointAddress) ); var rate = client.ConversionRate(from, to); return rate; }
protected void Button4_Click(object sender, EventArgs e) { double strRate; string str; CurrencyConvertor ccv = new CurrencyConvertor(); strRate=ccv.ConversionRate(Currency.USD,Currency.INR); str = strRate.ToString(); TextBox1.Text = str; }
/// <summary> /// Handles the load event of the web form /// </summary> protected void Page_Load(object sender, EventArgs e) { //Ensures that instances are only created once when the page loads if (!IsPostBack) { try { //Getting the client's logging in Id (client number) int clientNumber = int.Parse(Page.User.Identity.Name); //Creating an instance of a client and getting the client info from the database using the client number Client client = db.Clients.Where(x => x.ClientNumber == clientNumber).SingleOrDefault(); //Getting client's full name and storing it into a session variable. Session["FullName"] = client.FullName; //Getting the client's id and storing it in a variable for easier use later. int clientId = client.ClientId; //Storing the client's id into a session variable Session["ClientId"] = clientId; //Displaying the client's full name into the client lable lblClientFullName.Text = Session["FullName"].ToString(); //Getting a collection of BankAccount records whose client id matches IQueryable <BankAccount> recordsQuery = db.BankAccounts.Where(x => x.ClientId == clientId); //Showing the data collection to the gridview list gvClient.DataSource = recordsQuery.ToList(); //Binding the data this.DataBind(); //Creating an instance of web service currency convertor CurrencyConvertor convertor = new CurrencyConvertor(); //Displays the current value of the exchange eate between CAD and USD lblRate.Text = string.Format("The exchange rate between Canada and the United States is currently {0:c}", convertor.ConversionRate(Currency.CAD, Currency.USD)); } catch (Exception ex) { //Enabling the error button lblError.Visible = true; //Displaying an error message if an exeption occures lblError.Text = ex.Message; } } }
protected void btnConvert_Click(object sender, EventArgs e) { double fromAmout = Convert.ToDouble(txtFromAmount.Text); double toAmount; double conversionRate; Currency currencyFrom; Currency currencyTo; CurrencyConvertor currencyConvertor = new CurrencyConvertor(); currencyFrom = (Currency)Enum.Parse(typeof(Currency), drpFromCurrency.Text); //将选择的货币转换成相应的枚举型 currencyTo = (Currency)Enum.Parse(typeof(Currency), drpToCurrency.Text); //将选择的货币转换成相应的枚举型 conversionRate = currencyConvertor.ConversionRate(currencyFrom, currencyTo); toAmount = fromAmout * conversionRate; txtToAmount.Text = toAmount.ToString("F2"); }
protected void btnConvert_Click(object sender, EventArgs e) { double fromAmount = Convert.ToDouble(txtFromAmount.Text); double toAmount; double converstionRate; Currency fromCurrency; Currency toCurrency; CurrencyConvertor currencyConvertor = new CurrencyConvertor(); //string conversionRate = currencyConvertor.ConversionRate(Currency.)); 不能直接这么写 fromCurrency = (Currency)Enum.Parse(typeof(Currency), drpFromCurrency.Text); //将选择的货币转换成相应的枚举型 toCurrency = (Currency)Enum.Parse(typeof(Currency), drpToCurrency.Text); converstionRate = currencyConvertor.ConversionRate(fromCurrency, toCurrency); //调用Web服务的ConversionRate方法,得到汇率 toAmount = fromAmount * converstionRate; txtToAmount.Text = toAmount.ToString("F2"); //输出转换后的数量 }
public FreeAgentMarketplaceModelBuilder(MP_FreeAgentExpenseCategoryRepository freeAgentExpenseCategoryRepository, CurrencyRateRepository currencyRateRepository, ISession session) : base(session) { _currencyConverter = new CurrencyConvertor(currencyRateRepository); foreach (MP_FreeAgentExpenseCategory dbCategory in freeAgentExpenseCategoryRepository.GetAll()) { var category = new FreeAgentExpenseCategory { Id = dbCategory.Id, category_group = dbCategory.category_group, url = dbCategory.url, description = dbCategory.description, nominal_code = dbCategory.nominal_code, allowable_for_tax = dbCategory.allowable_for_tax, tax_reporting_name = dbCategory.tax_reporting_name, auto_sales_tax_rate = dbCategory.auto_sales_tax_rate }; _expenseCategories.Add(category.url, category); } }
public async Task <IViewComponentResult> InvokeAsync() { var cart = SessionHelper.GetObjectFromJson <List <ShoppingCartItemModel> >(HttpContext.Session, "cart"); if (cart == null) { cart = new List <ShoppingCartItemModel>(); } string culture = CultureInfo.CurrentCulture.Name.ToLower(); string currency = ""; //currency = HttpContext.Request.Query["currency"].ToString().ToUpper(); currency = MShopClass.getCurrency(culture); //culture = MShopClass.currencyList()[currency.ToUpper()]; // culture = MShopClass.currencyList()[currency.ToUpper()]; float exchangeRate = 1; if ((currency != "") && (currency.ToUpper() != "NZD")) { exchangeRate = CurrencyConvertor.GetExchangeRate(currency); } ViewBag.Culture = culture; ViewBag.Currency = currency; ViewBag.ExchangeRate = exchangeRate; ViewBag.cart = cart; ViewBag.total = cart.Sum(ShoppingCartItem => ShoppingCartItem.Product.ProductPrice * ShoppingCartItem.Quantity); return(View()); }
protected void Page_Load(object sender, EventArgs e) { string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(connStr); SqlCommand selectId = new SqlCommand("SELECT MAX(idcomm) FROM[commandes] ", cnn); int idcommande; cnn.Open(); try { idcommande = (int)selectId.ExecuteScalar(); } catch { SqlCommand insertCommandesComm = new SqlCommand("INSERT into commandes(total) values(@total)", cnn); //insertCommandesComm.Parameters.AddWithValue("@idcomm", Convert.ToInt32(Session["idcommande"].ToString())); insertCommandesComm.Parameters.AddWithValue("@total", 0); insertCommandesComm.ExecuteNonQuery(); idcommande = (int)selectId.ExecuteScalar(); } cnn.Close(); Session["idcommande"] = idcommande; foreach (DataListItem item in DataList1.Items) { Label prixLabel = (Label)item.FindControl("prixLabel"); Label prixLabelUSD = (Label)item.FindControl("prixLabelUSD"); string prix = prixLabel.Text; CurrencyConvertor conv = new CurrencyConvertor(); double rate = (conv.ConversionRate(Currency.EUR, Currency.USD)); string prixUSD = Convert.ToString(Convert.ToDouble(prix) * rate); prixLabelUSD.Text = "(" + prixUSD + " )"; } }
public YodleeMarketplaceModelBuilder(ISession session = null) : base(session) { customerMarketPlaceRepository = new CustomerMarketPlaceRepository(_session); _currencyConvertor = new CurrencyConvertor(new CurrencyRateRepository(_session)); }
public double ConvertEuroTo(double europrice,CurrencyConvertor.Currency exchange) { CurrencyConvertor.CurrencyConvertorSoapClient service = new CurrencyConvertor.CurrencyConvertorSoapClient(); double rate = service.ConversionRate(CurrencyConvertor.Currency.EUR, exchange); return (europrice*rate); }
/// <summary> /// Accepts a string of currency to be converted to. /// </summary> /// <param name="convertTo"></param> /// <returns></returns> public Money Convert(string convertTo) { double exchangeRate = new CurrencyConvertor().GetConversion(Currency, convertTo); return(new Money(exchangeRate * Amount, convertTo)); }
public static double GetExchangeRate(CurrencyConvertor.Currency fromCurrency, CurrencyConvertor.Currency toCurrency) { CurrencyConvertor.CurrencyConvertorSoap ccClient = new CurrencyConvertor.CurrencyConvertorSoapClient("CurrencyConvertorSoap"); double rate = ccClient.ConversionRate(fromCurrency, toCurrency); if(rate <= 0.0) { throw new Exception("Bad rate " + rate + " (" + fromCurrency + " -> " + toCurrency + ")"); } return rate; }
public void Initialize() { _currencyConvertor = new CurrencyConvertor(); }