private void button1_Click(object sender, EventArgs e) { try { using (var objProvider = new BankProvider()) { Bank objBank = objProvider.GetBankByName(((Bank)comboBox1.Items[comboBox1.SelectedIndex]).Name); var objExchanger = new CurrencyExchanger() { Number = (int)numericUpDown1.Value, Bank = objBank, X = Convert.ToDouble(textBox1.Text), Y = Convert.ToDouble(textBox2.Text), Phone = textBox3.Text, Address = textBox4.Text, OpenDate = monthCalendar1.SelectionStart.Date, WorkTime = textBox6.Text }; objProvider.AddExchanger(objExchanger); } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void UpdateExchangedCurrency() { int rawAmountOfNeededCurrency = 0; rawAmountOfNeededCurrency = CurrencyExchanger.GetRequiredCurrency(WantedCurrency, quantityOfWantedCurrency); neededCurrencyText.text = rawAmountOfNeededCurrency.ToString(); }
private void InfoForm_Load(object sender, EventArgs e) { try { using (var objProvider = new BankProvider()) { List <Bank> objBanks = objProvider.GetAllBanks(); comboBox1.Items.AddRange(objBanks.ToArray()); CurrencyExchanger objExchanger = objProvider.GetExchangerById(iExchangerId); comboBox1.SelectedIndex = comboBox1.Items.IndexOf(objExchanger.Bank); textBox1.Text = objExchanger.X.ToString(); textBox2.Text = objExchanger.Y.ToString(); textBox3.Text = objExchanger.Phone; textBox4.Text = objExchanger.Address; textBox6.Text = objExchanger.WorkTime; textBox5.Text = objExchanger.OpenDate.ToString(); if (objExchanger.Number != null) { numericUpDown1.Value = (decimal)objExchanger.Number; } //usd label14.Text = objProvider.GetRateByBank("USD", objExchanger.Bank).Buy.ToString(); label15.Text = objProvider.GetRateByBank("USD", objExchanger.Bank).Sale.ToString(); //eur label16.Text = objProvider.GetRateByBank("EUR", objExchanger.Bank).Buy.ToString(); label17.Text = objProvider.GetRateByBank("EUR", objExchanger.Bank).Sale.ToString(); //rur label18.Text = objProvider.GetRateByBank("RUR", objExchanger.Bank).Buy.ToString(); label19.Text = objProvider.GetRateByBank("RUR", objExchanger.Bank).Sale.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public TestCurrencyExchange() { _repository = new CurrencyExchangeRepository(); _repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); _exchanger = new CurrencyExchanger(_repository); }
public NewPortfolio(CurrencyExchanger ce) { InitializeComponent(); this.Icon = Properties.Resources.Stocks; comboBox1.DataSource = ce.GetCurrenciesRetrieved(); }
public TestSum() { var repository = new CurrencyExchangeRepository(); var exchanger = new CurrencyExchanger(repository); _calculation = new Calculation(exchanger); repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); }
public void Exchange_ShouldThrow_WhenCurrencyIsNotFound(FxExchange exchange, IExchangeRateHolder rateHolder) { // arrange var sut = new CurrencyExchanger(rateHolder); // act // assert Should.Throw <InvalidCurrencyException>(() => sut.Exchange(exchange)); }
static Calculation GetCalculation() { var repository = new CurrencyExchangeRepository(); repository.AddExchangeRate(Currency.USD, Currency.CHF, 1.5); var exchanger = new CurrencyExchanger(repository); return(new Calculation(exchanger)); }
public void ExchangeFromUsdToEur() { string USD = "USD"; string EUR = "EUR"; float ammount = 2.45F; CurrencyExchanger ce = new CurrencyExchanger(); Assert.AreEqual(ce.ExchangeValue(USD, EUR, ammount), (ce.GetRate(USD) / ce.GetRate(EUR)) * ammount); }
public void OnExchange() { AudioHandler.Instance.PlaySound(acceptSFX); Debug.Log("Exchange"); CurrencyExchanger.CommenceExchange(WantedCurrency, quantityOfWantedCurrency); quantityOfWantedCurrency = 0; ResetScreen(); }
public void OnSubtractWantedCurrency() { AudioHandler.Instance.PlaySound(acceptSFX); quantityOfWantedCurrency--; quantityOfWantedCurrency = Mathf.Max(quantityOfWantedCurrency, 0); int rawAmountOfCurrency = CurrencyExchanger.GetAmountWithConversion(WantedCurrency, quantityOfWantedCurrency); wantedCurrencyText.text = rawAmountOfCurrency.ToString(); UpdateExchangedCurrency(); }
private static void ExecuteExchange(FxExchange fxExchange) { var exchanger = new CurrencyExchanger(new ExchangeRateHolder(100)); try { Console.WriteLine(exchanger.Exchange(fxExchange)); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void Exchange_ShouldReturnTheSameAmount_AsRequested(FxExchange exchange, IExchangeRateHolder rateHolder) { // arrange var sut = new CurrencyExchanger(rateHolder); exchange.CurrencyPair.From = exchange.CurrencyPair.To; // act var result = sut.Exchange(exchange); // assert result.ShouldBe(exchange.Amount); }
/// <summary> /// Renders the graph on the Main Menu /// </summary> /// <param name="c">Reference to the chart to be Rendered</param> /// <param name="p">Portfolio Object to be Rendered in the graph</param> public static void renderMainMenuGraph(ref Chart c, Portfolio p, CurrencyExchanger ce, Dictionary<Investment, string> data) { c.Series["Profit"].Points.Clear(); List<ProfitDay> points = p.calculateProfit(ce, data); foreach(ProfitDay pd in points) { if (((pd.Day.DayOfWeek == DayOfWeek.Saturday || pd.Day.DayOfWeek == DayOfWeek.Sunday ) && pd.Profit == 0)) { //empty days, what to do? } else c.Series["Profit"].Points.AddXY(pd.Day, pd.Profit); } }
public void Exchange_IsCase_Insensitive(string from, string to) { // arrange var exchange = new FxExchange { Amount = 1, CurrencyPair = new CurrencyPair { From = from, To = to } }; var sut = new CurrencyExchanger(new ExchangeRateHolder(100)); // act // assert Should.NotThrow(() => sut.Exchange(exchange)); }
static void Main(string[] args) { var app = new App(); app.Run(); var CurrencyEx = new CurrencyExchanger(); var currEx = CurrencyEx.GetCurrencyExchanged(); //var c = new Class1(); //c.Go(); Console.WriteLine("Just nu står kursen i: " + currEx); }
private void LoadExchangersPositionInfo() { //gets data from GoogleMaps API, but I can use only geodata(GPS), without details about object //method gets first 20 objects const string API_KEY = "AIzaSyDX98l2EABQiA28ogGNFHSjVlGfVF7DdlY"; string strUri = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=банк+минск&language=rus&key=" + API_KEY; var objRequest = HttpWebRequest.CreateHttp(strUri); objRequest.Method = "GET"; objRequest.ContentType = new ContentType("application/json").ToString(); HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); XmlDocument objXml = new XmlDocument(); using (Stream objResponseStream = objResponse.GetResponseStream()) { using (var objReader = new StreamReader(objResponseStream)) { string strResponse = objReader.ReadToEnd(); objXml.LoadXml(strResponse); XmlNodeList objNodes = objXml.GetElementsByTagName("result"); using (var objProvider = new BankProvider()) { var objBank = objProvider.GetBankByName("Альфа-Банк"); foreach (XmlNode node in objNodes) { double dX = Convert.ToDouble(node["geometry"]["location"]["lat"].InnerText); double dY = Convert.ToDouble(node["geometry"]["location"]["lng"].InnerText); string strPlaceId = node["place_id"].InnerText; //if bank office with current GooglePlaceId exists in base - break if (objProvider.GetExchangerByPlaceId(strPlaceId) != null) { break; } var objExchanger = new CurrencyExchanger() { Bank = objBank, X = dX, Y = dY, GMapId = strPlaceId }; objProvider.AddExchanger(objExchanger); } } } } }
public void Exchange_ShouldExchangeTheAmount_AsRequested(string from, string to, int ammount, double expected) { // arrange var exchange = new FxExchange { Amount = ammount, CurrencyPair = new CurrencyPair { From = from, To = to } }; var sut = new CurrencyExchanger(new ExchangeRateHolder(100)); // act var result = sut.Exchange(exchange); // assert result.ShouldBe(expected); }
public void OnAddWantedCurrency() { AudioHandler.Instance.PlaySound(acceptSFX); quantityOfWantedCurrency++; bool isExchangeValid = CurrencyExchanger.CheckForAffordability(WantedCurrency, quantityOfWantedCurrency, GameManager.Instance.PlayerData.PlayerCurrency); if (!isExchangeValid) { quantityOfWantedCurrency--; } int rawAmountOfCurrency = CurrencyExchanger.GetAmountWithConversion(WantedCurrency, quantityOfWantedCurrency); wantedCurrencyText.text = rawAmountOfCurrency.ToString(); UpdateExchangedCurrency(); }
public void Exchange_ShouldThrow_WithMessage(string currency, string expected) { // arrange var exchange = new FxExchange { Amount = 1, CurrencyPair = new CurrencyPair { From = currency, To = "USD" } }; var sut = new CurrencyExchanger(new ExchangeRateHolder(100)); // act // assert var exception = Should.Throw <InvalidCurrencyException>(() => sut.Exchange(exchange)); exception.Message.ShouldBe(string.Format(expected, currency)); }
public PortfolioUI(ref Portfolio portfolio, ref CurrencyExchanger ce) { InitializeComponent(); this.Icon = Properties.Resources.Stocks; this.thisPortfolio = portfolio; UpdateGraph(); updateGrid(thisPortfolio); tbName.Text = thisPortfolio.Name; cbCurrency.DataSource = ce.GetCurrenciesRetrieved(); cbCurrency.SelectedItem = thisPortfolio.PreferredCurrency; }
public void GetInvalidCurrencyRate() { string NonValidCurrency = "ABC"; float result; Exception ex = null; CurrencyExchanger ce = new CurrencyExchanger(); try { result = ce.GetRate(NonValidCurrency); } catch (Exception e) { ex = e; } Assert.IsInstanceOfType(ex, typeof(CurrencyNotFoundException)); }
private void button1_Click(object sender, EventArgs e) { try { using (var objProvider = new BankProvider()) { Bank objBank = objProvider.GetBankByName(((Bank)comboBox1.Items[comboBox1.SelectedIndex]).Name); CurrencyExchanger objExchanger = objProvider.GetExchangerById(iExchangerId); objExchanger.Bank = objBank; objExchanger.Address = textBox4.Text; objExchanger.Number = (int)numericUpDown1.Value; objExchanger.Phone = textBox3.Text; objExchanger.WorkTime = textBox6.Text; objExchanger.X = Convert.ToDouble(textBox1.Text); objExchanger.Y = Convert.ToDouble(textBox2.Text); } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ExchangeToInvalidCurrency() { string NonValidCurrency = "ABC"; string EUR = "EUR"; float ammount = 2.45F; float result; Exception ex = null; CurrencyExchanger ce = new CurrencyExchanger(); try { result = ce.ExchangeValue(EUR, NonValidCurrency, ammount); } catch (Exception e) { ex = e; } Assert.IsInstanceOfType(ex, typeof(CurrencyNotFoundException)); }
public static void AnalysePortfolio(ref Chart c, Dictionary<Investment, string> invData, Portfolio p) { c.Series.Clear(); CurrencyExchanger ce = new CurrencyExchanger(); Dictionary<string, int> times = new Dictionary<string, int>(); c.Series.Add("Profits up to latest Information"); c.Series[0].ChartType = SeriesChartType.Bar; foreach (KeyValuePair<Investment, string> i in invData) { if (!times.ContainsKey(i.Key.Stock.StockName)) times.Add(i.Key.Stock.StockName, 0); List<ProfitDay> l = p.calculateProfits(ce, i.Key, i.Value); c.Series[0].Points.AddXY(i.Key.Stock.StockName, l[l.Count-1].Profit); } }
/// <summary> /// update marker info /// </summary> private void UpdateMarkers() { try { using (var objProvider = new BankProvider()) { foreach (var marker in objMarkersOverlay.Markers) { CurrencyExchanger objExchanger = objProvider.GetExchangerById((int)marker.Tag); ExchangeRate objUsd = objProvider.GetRateByBank("USD", objExchanger.Bank); ExchangeRate objEur = objProvider.GetRateByBank("EUR", objExchanger.Bank); ExchangeRate objRur = objProvider.GetRateByBank("RUR", objExchanger.Bank); marker.ToolTipText = String.Format( "{0} office:{1}\nBuy\n" + "USD:{2}\nEUR:{3}\nRUR:{4}\n" + "Sell\n" + "USD:{5}\nEUR:{6}\nRUR:{7}", objExchanger.Bank.Name, objExchanger.Number, objUsd.Buy, objEur.Buy, objRur.Buy, objUsd.Sale, objEur.Sale, objRur.Sale ); var objPositon = new PointLatLng(objExchanger.X, objExchanger.Y); if (marker.Position != objPositon) { marker.Position = objPositon; } gMapControl1.UpdateMarkerLocalPosition(marker); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// find nearest exhanger from current mouse position /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void findNearestToolStripMenuItem_Click(object sender, EventArgs e) { PointLatLng objPosition = GetCursorPosition(); using (var objProvider = new BankProvider()) { List <CurrencyExchanger> objExchangers = new List <CurrencyExchanger>(); foreach (var marker in objMarkersOverlay.Markers) { CurrencyExchanger exchanger = objProvider.GetExchangerById((int)marker.Tag); if (exchanger != null) { objExchangers.Add(exchanger); } } CurrencyExchanger objNearestExchanger = objProvider.GetNearestExchanger(objPosition.Lat, objPosition.Lng, objExchangers); var objMarker = new GMarkerGoogle(new PointLatLng(objNearestExchanger.X, objNearestExchanger.Y), GMarkerGoogleType.blue); objMarker.Tag = objNearestExchanger.Id; gMapControl1.UpdateMarkerLocalPosition(objMarker); var markersOverlay = new GMapOverlay(); markersOverlay.Markers.Add(objMarker); gMapControl1.Overlays.Add(markersOverlay); } }
public Main_Menu(ref Portfolio portfolio) { InitializeComponent(); this.Icon = Properties.Resources.Stocks; try { ce = new CurrencyExchanger(); } catch(WebException) { MessageBox.Show("Could not connect to the Internet!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } if(portfolio != null) this.mainPortfolio = portfolio; else { newPortfolio(); } }
/// <summary> /// Renders the graph on the Portfolio UI /// </summary> /// <param name="c">Reference to the chart to be Rendered</param> /// <param name="p">Portfolio Object to be Rendered in the graph</param> public static void renderPortfolioGraph(ref Chart c, Portfolio p, CurrencyExchanger ce, Dictionary<Investment, string> data) { renderMainMenuGraph(ref c, p, ce, data); }
public List<ProfitDay> calculateProfits(CurrencyExchanger ce, Investment i, string data) { float stockProfit = 0; List<ProfitDay> thisCompanyProfits = new List<ProfitDay>(); DateTime calculateDate = i.BuyTime; QueryResult qr = new QueryResult(data, i.Stock.StockName); foreach (StockDay sd in qr.StockDays) { if (sd.Date >= i.BuyTime) { stockProfit = (float)(sd.ClosingValue - i.UnitStockValue) * i.Quantity; if (i.Stock.Currency != preferedCurrency) { stockProfit = ce.ExchangeValue(i.Stock.Currency, preferedCurrency, stockProfit); } thisCompanyProfits.Add(new ProfitDay(new DateTime(calculateDate.Year, calculateDate.Month, calculateDate.Day), stockProfit)); } } return thisCompanyProfits; }
public Calculation(CurrencyExchanger currencyExchanger) { _currencyExchanger = currencyExchanger; }
public List<ProfitDay> calculateProfit(CurrencyExchanger ce, Dictionary<Investment, string> invData) { List<ProfitDay> points = new List<ProfitDay>(); float profit = 0; List<Dictionary<string, float>> ld = new List<Dictionary<string, float>>(); DateTime calculateDate = getOldestInvestmentDate(); foreach (KeyValuePair<Investment, string> inv in invData) { float stockProfit = 0; Dictionary<string, float> thisCompanyProfits = new Dictionary<string, float>(); QueryResult qr = new QueryResult(inv.Value, inv.Key.Stock.StockName); foreach (StockDay sd in qr.StockDays) { if (sd.Date >= inv.Key.BuyTime) { stockProfit = (float)(sd.ClosingValue - inv.Key.UnitStockValue) * inv.Key.Quantity; if (inv.Key.Stock.Currency != preferedCurrency) { stockProfit = ce.ExchangeValue(inv.Key.Stock.Currency, preferedCurrency, stockProfit); } thisCompanyProfits.Add(sd.Date.ToString("dd-MM-yyyy"), stockProfit); } } ld.Add(thisCompanyProfits); } while (calculateDate < DateTime.Today) { profit = 0; foreach (Dictionary<string, float> dic in ld) { if(dic.ContainsKey(calculateDate.ToString("dd-MM-yyyy"))) { profit += dic[calculateDate.ToString("dd-MM-yyyy")]; } } points.Add(new ProfitDay(new DateTime(calculateDate.Year, calculateDate.Month, calculateDate.Day), profit)); calculateDate = calculateDate.AddDays(1); } points.Sort(); return points; }