Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
                        }
                    }
                }
            }
        }