Example #1
0
        /// <summary>
        /// Traverse all rows and save geo data
        /// </summary>
        private void SaveGeoData()
        {
            SqlConnection objConnection = new SqlConnection(UserSession.ProviderConnection);
            objConnection.Open();

            m_objGridView = (DevExpress.XtraGrid.Views.Grid.GridView)gcCompany.FocusedView;
            for (int i = 0; i < m_objGridView.RowCount; i++)
            {
                m_objCompany = null;
                m_objCompany = (CTGetGeographicalDataCompany)m_objGridView.GetRow(i);

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

                    ObjectGeographicalData.SaveGeoData(m_objGeoDataInstance, objConnection);
                }
            }

            objConnection.Close();
            objConnection = null;

            //this.PopulateCompanyView(null, 1);
            MessageBox.Show("Successfully updated!", m_MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #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)gcCompany.FocusedView;
            for (int i = 0; i < m_objGridView.RowCount; i++)
            {
                m_objCompany = null;
                m_objCompany = (CTGetGeographicalDataCompany)m_objGridView.GetRow(i);

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

                string strAddress = m_objCompany.address + ", " + m_objCompany.city + " " + m_objCompany.zip + ", " + m_objCompany.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");
            }
        }