Пример #1
0
        /// <summary>
        /// Traverse all rows and save geo data
        /// </summary>
        private void SaveGeoData()
        {
            //SqlConnection objConnection = new SqlConnection(ConfigurationManager.AppSettings["DatabaseConnectionString"].ToString());
            SqlConnection objConnection = new SqlConnection(UserSession.ProviderConnection);
            objConnection.Open();

            m_objGridView = (DevExpress.XtraGrid.Views.Grid.GridView)gcContact.FocusedView;
            for (int i = 0; i < m_objGridView.RowCount; i++)
            {
                m_objContact = null;
                m_objContact = (CTGeographicalDataContact)m_objGridView.GetRow(i);

                if ((bool)m_objContact.include && (m_objContact.geo_latitude != 0 && m_objContact.geo_longitude != 0))
                {
                    m_objGeoDataInstance = null;
                    m_objGeoDataInstance = new ObjectGeographicalData.GeoDataInstance();
                    m_objGeoDataInstance.table_source = (int)ObjectGeographicalData.eTableSource.Contacts;
                    m_objGeoDataInstance.table_id = m_objContact.id;
                    m_objGeoDataInstance.latitude = (decimal)m_objContact.geo_latitude;
                    m_objGeoDataInstance.longitude = (decimal)m_objContact.geo_longitude;
                    ObjectGeographicalData.SaveGeoData(m_objGeoDataInstance, objConnection);
                }
            }

            objConnection.Close();
            objConnection = null;

            //this.PopulateContactView(null, 1);
            MessageBox.Show("Successfully updated!", m_MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Пример #2
0
        /// <summary>
        /// Traverse all rows and get geo data
        /// </summary>
        private void GetGeoData(eFetchType FetchType)
        {
            double Latitude = 0;
            double Longitude = 0;
            m_objGridView = (DevExpress.XtraGrid.Views.Grid.GridView)gcContact.FocusedView;
            for (int i = 0; i < m_objGridView.RowCount; i++)
            {
                m_objContact = null;
                m_objContact = (CTGeographicalDataContact)m_objGridView.GetRow(i);

                if (FetchType == eFetchType.BySelected && (bool)!m_objContact.include)
                    continue;

                string strAddress = m_objContact.address + ", " + m_objContact.city + " " + m_objContact.zip + ", " + m_objContact.country;
                if (string.IsNullOrEmpty(strAddress) || !GoogleMapUtility.IsValidGeoAddress(strAddress))
                    continue;

                string[] objGeoData = m_objGoogleMapUtility.GetGeographicalData(strAddress).Split(',');

                /**
                 * where:
                 * objGeoData[2] = latitude
                 * objGeoData[3] = longitude
                 */

                Latitude = 0;
                Longitude = 0;

                if (objGeoData[2] != null)
                    if (ValidationUtility.IsCurrency(objGeoData[2]))
                        Latitude = Convert.ToDouble(objGeoData[2], CultureInfo.InvariantCulture);

                if (objGeoData[3] != null)
                    if (ValidationUtility.IsCurrency(objGeoData[3]))
                        Longitude = Convert.ToDouble(objGeoData[3], CultureInfo.InvariantCulture);

                // display geo data on grid
                m_objGridView.SetRowCellValue(i, "geo_latitude", Latitude.ToString());
                m_objGridView.SetRowCellValue(i, "geo_longitude", Longitude.ToString());
                m_objGridView.SetRowCellValue(i, "geo_status", objGeoData[2].Equals("0") && objGeoData[3].Equals("0") ? "not found" : "found");
            }
        }