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);
            }
        }
Пример #3
0
        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;
        }
Пример #4
0
    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;
    }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Currency currencyFrom = (Currency)comboBox1.SelectedItem;
            Currency currencyTo   = (Currency)comboBox2.SelectedItem;

            double value = currencyconverter.ConversionRate(currencyFrom, currencyTo);

            labelResult.Text  = "The difference with the two different coins is:";
            labelResult2.Text = value + "   ";
        }
        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");
        }
Пример #7
0
        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");                                    //输出转换后的数量
        }
Пример #8
0
        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 + " )";
            }
        }
    /// <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;
            }
        }
    }