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 AddExchangerForm(double dX, double dY) { InitializeComponent(); using(var objProvider = new BankProvider()) { List<Bank> objBanks = objProvider.GetAllBanks(); foreach(var bank in objBanks) { comboBox1.Items.Add(bank); } } comboBox1.SelectedIndex = 0; textBox1.Text = dX.ToString(); textBox2.Text = dY.ToString(); }
private void Form2_Load(object sender, EventArgs e) { comboBox1.SelectedIndex = 0; //Пример честно скопипащен //Настройки для компонента GMap. gMapControl1.Bearing = 0; gMapControl1.Dock = DockStyle.Fill; //Указываем что перетаскивание карты осуществляется //с использованием левой клавишей мыши. //По умолчанию - правая. gMapControl1.DragButton = MouseButtons.Left; //Указываем, что будем использовать карты Google. gMapControl1.MapProvider = GMapProviders.GoogleMap; //указываем источник данных - только интернет GMaps.Instance.Mode = AccessMode.ServerOnly; //Указываем элементу управления, //что необходимо при открытии карты прейти //к Площади победы в Минске gMapControl1.Position = new PointLatLng(53.9085385, 27.5744717); //fill best Buy and Sell rates using(var objProvider = new BankProvider()) { List<Bank> objBanks = objProvider.GetAllBanks(); comboBox2.SelectedIndex = 0; comboBox2.Items.AddRange(objBanks.ToArray()); //best buy rate label7.Text = objProvider.GetBestBuyRate("USD").Buy.ToString(); label18.Text = objProvider.GetBestBuyRate("USD").Bank.ToString(); label8.Text = objProvider.GetBestBuyRate("EUR").Buy.ToString(); label17.Text = objProvider.GetBestBuyRate("EUR").Bank.ToString(); label9.Text = objProvider.GetBestBuyRate("RUR").Buy.ToString(); label16.Text = objProvider.GetBestBuyRate("RUR").Bank.ToString(); //best sell rate label6.Text = objProvider.GetBestSellRate("USD").Sale.ToString(); label20.Text = objProvider.GetBestSellRate("USD").Bank.ToString(); label14.Text = objProvider.GetBestSellRate("EUR").Sale.ToString(); label15.Text = objProvider.GetBestSellRate("EUR").Bank.ToString(); label19.Text = objProvider.GetBestSellRate("RUR").Sale.ToString(); label10.Text = objProvider.GetBestSellRate("RUR").Bank.ToString(); } DrawMarkers(); }
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); } }
private async void MainForm_Load(object sender, EventArgs e) { try { using(var objProvider = new BankProvider()) { var objLoadingForm = new LoadingForm(); objLoadingForm.MdiParent = this; objLoadingForm.Show(); await objProvider.LoadCurrencyRateInfo(); objLoadingForm.Close(); } var objGmapForm = new GmapForm(); objGmapForm.MdiParent = this; googleMapToolStripMenuItem.Enabled = true; loadGoogleMapToolStripMenuItem.Enabled = true; objGmapForm.Show(); } catch(Exception ex) { MessageBox.Show(ex.Message); } }
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); } } } } }
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); } }
/// <summary> /// draw all CurrencyExchangers markers on map /// </summary> private void DrawMarkers() { try { using(var objProvider = new BankProvider()) { objMarkersOverlay.Clear(); List<CurrencyExchanger> objExchangers = objProvider.GetAllExchangers(); foreach(var exchanger in objExchangers) { ExchangeRate objUsd = objProvider.GetRateByBank("USD", exchanger.Bank); ExchangeRate objEur = objProvider.GetRateByBank("EUR", exchanger.Bank); ExchangeRate objRur = objProvider.GetRateByBank("RUR", exchanger.Bank); var objMarker = new GMarkerGoogle(new PointLatLng(exchanger.X, exchanger.Y), GMarkerGoogleType.yellow) { ToolTipText = String.Format( "{0} office:{1}\nBuy\n" + "USD:{2}\nEUR:{3}\nRUR:{4}\n" + "Sell\n" + "USD:{5}\nEUR:{6}\nRUR:{7}", exchanger.Bank.Name, exchanger.Number, objUsd.Buy, objEur.Buy, objRur.Buy, objUsd.Sale, objEur.Sale, objRur.Sale ), Tag = exchanger.Id }; objMarkersOverlay.Markers.Add(objMarker); gMapControl1.UpdateMarkerLocalPosition(objMarker); } } gMapControl1.Overlays.Clear(); gMapControl1.Overlays.Add(objMarkersOverlay); } catch(Exception ex) { MessageBox.Show(ex.Message); } }
/// <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> /// Show exchangers with best sell price /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void radioButton2_CheckedChanged(object sender, EventArgs e) { try { using(var objProvider = new BankProvider()) { List<ExchangeRate> objBestSellRates = new List<ExchangeRate>(); objBestSellRates.Add(objProvider.GetBestSellRate("USD")); objBestSellRates.Add(objProvider.GetBestSellRate("EUR")); objBestSellRates.Add(objProvider.GetBestSellRate("RUR")); List<CurrencyExchanger> objExchangers = new List<CurrencyExchanger>(); foreach(var rate in objBestSellRates) { objExchangers.AddRange(objProvider.DataBase.CurrencyExchangers.Where(ce => ce.Bank.Id == rate.Bank.Id).ToArray()); } objMarkersOverlay = new GMapOverlay(); foreach(var exchanger in objExchangers) { var objMarker = new GMarkerGoogle(new PointLatLng(exchanger.X, exchanger.Y), GMarkerGoogleType.green) { Tag = exchanger.Id, ToolTipText = String.Format("{0} office:{1}\nBuy\nUSD {2}\nEUR {3}\nRUR {4}", exchanger.Bank.Name, exchanger.Number, objBestSellRates[0].Buy, objBestSellRates[1].Buy, objBestSellRates[2].Buy ) }; gMapControl1.UpdateMarkerLocalPosition(objMarker); objMarkersOverlay.Markers.Add(objMarker); } gMapControl1.Overlays.Clear(); gMapControl1.Overlays.Add(objMarkersOverlay); } } 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); } }
/// <summary> /// filter exchangers by bank /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { try { DrawMarkers(); using(var objProvider = new BankProvider()) { Bank objBank = objProvider.GetBankByName(comboBox2.SelectedItem.ToString()); if(objBank == null) { DrawMarkers(); } else { for(int iI = 0; iI < objMarkersOverlay.Markers.Count; ++iI) { var exchanger = objProvider.GetExchangerById((int)objMarkersOverlay.Markers[iI].Tag); if(exchanger.Bank.Id != objBank.Id) { objMarkersOverlay.Markers.RemoveAt(iI); --iI; } } } } } catch(Exception ex) { MessageBox.Show(ex.Message); } }