a struct used to describe information about city
Пример #1
0
        private static readonly int DefaultPrecision = 3; //default precision

        #endregion Fields

        #region Methods

        /// <summary>
        /// convert CityInfo into CityInfoString
        /// </summary>
        /// <param name="cityInfo">CityInfo need to convert</param>
        /// <returns>conversion result</returns>
        public static CityInfoString ConvertFrom(CityInfo cityInfo)
        {
            CityInfoString cityInfoString = new CityInfoString();
            cityInfoString.Latitude = DoubleToString(cityInfo.Latitude, ValueType.Angle);
            cityInfoString.Longitude = DoubleToString(cityInfo.Longitude, ValueType.Angle);
            return cityInfoString;
        }
Пример #2
0
        private SiteLocation m_siteLocation; //reference to SiteLocation

        #endregion Fields

        #region Constructors

        /// <summary>
        /// override constructor
        /// </summary>
        /// <param name="data">a instance of CoordinateSystemData class</param>
        public CoordinateSystemDataForm(CoordinateSystemData data, CitySet citySet, SiteLocation siteLocation)
        {
            m_data = data;
            m_currentName = null;

            //create new members about place information
            m_placeInfo = new PlaceInfo(citySet);
            m_siteLocation = siteLocation;
            m_currentCityInfo = new CityInfo();
            InitializeComponent();
        }
Пример #3
0
        /// <summary>
        /// try to get city name according to CityInfo
        /// </summary>
        /// <param name="cityInfo">store information about city</param>
        /// <param name="cityName">city's name</param>
        /// <param name="timeZone">city's timezone</param>
        /// <returns>figure out whether this function successful</returns>
        public bool TryGetCityNameTimeZone(CityInfo cityInfo, out string cityName, out double timeZone)
        {
            cityName = null;
            timeZone = m_invalidTimeZone;

            //loop to find cityinfo matched
            foreach (CityInfo temp in m_citiesInfo)
            {
                //compare Latitude and longitude,and if difference < Diff
                // the two CityInfo are equal
                if (Math.Abs(temp.Latitude - cityInfo.Latitude) < Diff &&
                    Math.Abs(temp.Longitude - cityInfo.Longitude) < Diff)
                {
                    cityName = temp.CityName;
                    timeZone = temp.TimeZone;
                    return true;
                }
            }
            return false;
        }
Пример #4
0
 /// <summary>
 /// try to get city info according to city name
 /// </summary>
 /// <param name="cityName">city name</param>
 /// <param name="cityInfo">city's information</param>
 /// <returns>figure out whether this function successful</returns>
 public bool TryGetCityInfo(string cityName, out CityInfo cityInfo)
 {
     //compare cityName with element's CityName of m_citiesInfo
     //if they are equal, that element is matched
     foreach (CityInfo temp in m_citiesInfo)
     {
         if (cityName == temp.CityName)
         {
             cityInfo = temp;
             return true;
         }
     }
     cityInfo = new CityInfo();
     return false;
 }
Пример #5
0
 /// <summary>
 /// Add a city info to city info List
 /// </summary>
 /// <param name="cityInfo">the city info need to add</param>
 public void AddCityInfo(CityInfo cityInfo)
 {
     if(m_citiesInfo.Contains(cityInfo))
     {
         return;
     }
     m_citiesInfo.Add(cityInfo);
 }
Пример #6
0
        /// <summary>
        /// convert CityInfoString into CityInfo
        /// </summary>
        /// <param name="cityInfoString">CityInfoString need to convert</param>
        /// <returns>conversion result</returns>
        public static CityInfo ConvertTo(CityInfoString cityInfoString)
        {
            CityInfo cityInfo = new CityInfo();
            double temp;

            //convert Latitude
            if (StringToDouble(cityInfoString.Latitude, ValueType.Angle, out temp))
            {
                cityInfo.Latitude = temp;
            }
            else
            {
                cityInfo.Latitude = Double.NaN;
            }

            //convert Longitude
            if (StringToDouble(cityInfoString.Longitude, ValueType.Angle, out temp))
            {
                cityInfo.Longitude = temp;
            }
            else
            {
                cityInfo.Longitude = Double.NaN;
            }

            return cityInfo;
        }
Пример #7
0
        /// <summary>
        /// used when city name changed
        /// </summary>
        /// <param name="cityName">city name which changed</param>
        /// <param name="cityInfoString">city information want to get according to city name</param>
        /// <returns>check whether is successful</returns>
        private bool GetCityInfo(string cityName, out CityInfoString cityInfoString)
        {
            CityInfo cityInfo = new CityInfo();

            //try to get CityInfo according to cityName
            if (m_placeInfo.TryGetCityInfo(cityName, out cityInfo))
            {
                //do conversion from CityInfo to CityInfoString
                cityInfoString = UnitConversion.ConvertFrom(cityInfo);

                //do TimeZone conversion from double to string
                cityInfoString.TimeZone = m_placeInfo.TryGetTimeZoneString(cityInfo.TimeZone);

                //set current CityInfo
                m_currentCityInfo = cityInfo;
                m_currentCityInfo.CityName = cityName;
                return true;
            }

            //if failed, also set current CityInfo
            m_currentCityInfo.CityName = null;
            cityInfoString = new CityInfoString();
            return false;
        }
Пример #8
0
        /// <summary>
        /// display the location information on the form
        /// </summary>
        private void DisplayInformation()
        {
            //initialize the listbox
            locationListBox.Items.Clear();
            foreach (string itemName in m_data.LocationNames)
            {
                if (itemName == m_data.LocationName)
                {
                    m_currentName = itemName + " (current)"; //indicate the current project location
                    locationListBox.Items.Add(m_currentName);
                }
                else
                {
                    locationListBox.Items.Add(itemName);
                }
            }

            //set the selected item to current location
            for (int i = 0; i < locationListBox.Items.Count; i++)
            {
                string itemName = null;
                itemName = locationListBox.Items[i].ToString();
                if (itemName.Contains("(current)"))
                {
                    locationListBox.SelectedIndex = i;
                }
            }

            //get the offset values of the selected item
            string selecteName = locationListBox.SelectedItem.ToString();
            m_data.GetOffset(selecteName);
            this.ShowOffsetValue();

            //set control in placeTabPage
            //convert values get from API and set them to controls
            CityInfo cityInfo = new CityInfo(m_siteLocation.Latitude, m_siteLocation.Longitude);
            CityInfoString cityInfoString = UnitConversion.ConvertFrom(cityInfo);

            //set Text of Latitude and Longitude TextBox
            latitudeTextBox.Text = cityInfoString.Latitude;
            longitudeTextBox.Text = cityInfoString.Longitude;

            //set DataSource of CitiesName ComboBox and TimeZones ComboBox
            cityNameComboBox.DataSource = m_placeInfo.CitiesName;
            timeZoneComboBox.DataSource = m_placeInfo.TimeZones;

            //try use Method DoTextBoxChanged to Set CitiesName ComboBox
            DoTextBoxChanged();
            m_isFormLoading = false;

            //get timezone from double value and set control
            string timeZoneString = m_placeInfo.TryGetTimeZoneString(m_siteLocation.TimeZone);

            //set selectItem of TimeZones ComboBox
            timeZoneComboBox.SelectedItem = timeZoneString;
            timeZoneComboBox.Enabled = false;
        }