a struct used to describe information about city displayed in Form and it's members are string type
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// used when city information changed
        /// </summary>
        /// <param name="cityInfoString">city information which changed</param>
        /// <param name="cityName">city name want to get according to information</param>
        /// <param name="timeZone">city time zone gotten according to information</param>
        private void GetCityNameTimeZone(CityInfoString cityInfoString,
                                         out string cityName, out string timeZone)
        {
            CityInfo cityInfo = UnitConversion.ConvertTo(cityInfoString);
            string   tempName;
            double   tempTime;

            //try to get city name and timezone according to cityInfo
            if (m_placeInfo.TryGetCityNameTimeZone(cityInfo, out tempName, out tempTime))
            {
                cityName = tempName;

                //try to get string representing timezone according to a number
                timeZone = m_placeInfo.TryGetTimeZoneString(tempTime);

                //set current CityInfo
                m_currentCityInfo.Latitude  = cityInfo.Latitude;
                m_currentCityInfo.Longitude = cityInfo.Longitude;
                m_currentCityInfo.TimeZone  = tempTime;
                m_currentCityInfo.CityName  = tempName;
            }
            else
            {
                //set current CityInfo
                cityName = null;
                timeZone = null;
                m_currentCityInfo.Latitude  = cityInfo.Latitude;
                m_currentCityInfo.Longitude = cityInfo.Longitude;
                m_currentCityInfo.CityName  = null;
            }
        }
Beispiel #3
0
        /// <summary>
        /// call by CitiesNameSelectedChanged,when CitiesName ComboBox selected changed
        /// </summary>
        private void DoCityNameChanged()
        {
            //disable timezone ComboBox
            timeZoneComboBox.Enabled = false;
            CityInfoString cityInfoString = new CityInfoString();

            //get new CityInfoString
            if (GetCityInfo(cityNameComboBox.SelectedItem as string, out cityInfoString))
            {
                //use new CityInfoString to set TextBox and ComboBox
                latitudeTextBox.Text  = cityInfoString.Latitude;
                longitudeTextBox.Text = cityInfoString.Longitude;

                //set control timeZonesComboBox
                if (null != cityInfoString.TimeZone)
                {
                    timeZoneComboBox.Text         = null;
                    timeZoneComboBox.SelectedItem = cityInfoString.TimeZone;
                }
                else
                {
                    timeZoneComboBox.SelectedIndex = -1;
                }
            }
            //if failed, set control with nothing
            else
            {
                latitudeTextBox.Text           = null;
                longitudeTextBox.Text          = null;
                timeZoneComboBox.SelectedIndex = -1;
            }
        }
Beispiel #4
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;
        }
Beispiel #5
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;
        }
        private static readonly double AngleRatio    = 0.0174532925199433; //ratio of Angle

        /// <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);
        }
Beispiel #7
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;
        }
Beispiel #8
0
        /// <summary>
        /// called by some functions to do same operation
        /// </summary>
        private void DoTextBoxChanged()
        {
            //enable timezone ComboBox
            timeZoneComboBox.Enabled = true;
            CityInfoString cityInfoString = new CityInfoString(latitudeTextBox.Text, longitudeTextBox.Text);
            string         cityName;
            string         timeZone;

            //get new CityName and TimeZone
            GetCityNameTimeZone(cityInfoString, out cityName, out timeZone);

            //use new CityName to set ComboBox
            if (null != cityName)
            {
                cityNameComboBox.Text         = null;
                cityNameComboBox.SelectedItem = cityName;
                timeZoneComboBox.Enabled      = false;
            }
            else
            {
                if (m_isFormLoading)
                {
                    string userDefinedCity = "User Defined\r";
                    if (!m_placeInfo.CitiesName.Contains(userDefinedCity))
                    {
                        cityNameComboBox.DataSource = null;
                        m_placeInfo.CitiesName.Add(userDefinedCity);
                        m_placeInfo.CitiesName.Sort();
                        cityNameComboBox.DataSource = m_placeInfo.CitiesName;
                        CityInfo cityInfo = UnitConversion.ConvertTo(cityInfoString);
                        cityInfo.CityName = userDefinedCity;
                        cityInfo.TimeZone = m_siteLocation.TimeZone;
                        m_placeInfo.AddCityInfo(cityInfo);
                    }
                    cityNameComboBox.SelectedItem = userDefinedCity;
                }
                else
                {
                    cityNameComboBox.SelectedIndex = -1;
                }
            }

            //after get timeZone,set control timeZonesComboBox
            if (null != timeZone)
            {
                timeZoneComboBox.Text         = null;
                timeZoneComboBox.SelectedItem = timeZone;
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// used when city information changed
        /// </summary>
        /// <param name="cityInfoString">city information which changed</param>
        /// <param name="cityName">city name want to get according to information</param>
        /// <param name="timeZone">city time zone gotten according to information</param>
        private void GetCityNameTimeZone(CityInfoString cityInfoString,
            out string cityName, out string timeZone)
        {
            CityInfo cityInfo = UnitConversion.ConvertTo(cityInfoString);
            string tempName;
            double tempTime;

            //try to get city name and timezone according to cityInfo
            if (m_placeInfo.TryGetCityNameTimeZone(cityInfo, out tempName, out tempTime))
            {
                cityName = tempName;

                //try to get string representing timezone according to a number
                timeZone = m_placeInfo.TryGetTimeZoneString(tempTime);

                //set current CityInfo
                m_currentCityInfo.Latitude = cityInfo.Latitude;
                m_currentCityInfo.Longitude = cityInfo.Longitude;
                m_currentCityInfo.TimeZone = tempTime;
                m_currentCityInfo.CityName = tempName;
            }
            else
            {
                //set current CityInfo
                cityName = null;
                timeZone = null;
                m_currentCityInfo.Latitude = cityInfo.Latitude;
                m_currentCityInfo.Longitude = cityInfo.Longitude;
                m_currentCityInfo.CityName = null;
            }
        }
Beispiel #11
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;
        }
Beispiel #12
0
        /// <summary>
        /// called by some functions to do same operation
        /// </summary>
        private void DoTextBoxChanged()
        {
            //enable timezone ComboBox
            timeZoneComboBox.Enabled = true;
            CityInfoString cityInfoString = new CityInfoString(latitudeTextBox.Text, longitudeTextBox.Text);
            string cityName;
            string timeZone;

            //get new CityName and TimeZone
            GetCityNameTimeZone(cityInfoString, out cityName, out timeZone);

            //use new CityName to set ComboBox
            if (null != cityName)
            {
                cityNameComboBox.Text = null;
                cityNameComboBox.SelectedItem = cityName;
                timeZoneComboBox.Enabled = false;
            }
            else
            {
                if(m_isFormLoading)
                {
                    string userDefinedCity = "User Defined\r";
                    if (!m_placeInfo.CitiesName.Contains(userDefinedCity))
                    {
                        cityNameComboBox.DataSource = null;
                        m_placeInfo.CitiesName.Add(userDefinedCity);
                        m_placeInfo.CitiesName.Sort();
                        cityNameComboBox.DataSource = m_placeInfo.CitiesName;
                        CityInfo cityInfo = UnitConversion.ConvertTo(cityInfoString);
                        cityInfo.CityName = userDefinedCity;
                        cityInfo.TimeZone = m_siteLocation.TimeZone;
                        m_placeInfo.AddCityInfo(cityInfo);
                    }
                    cityNameComboBox.SelectedItem = userDefinedCity;
                }
                else
                {
                    cityNameComboBox.SelectedIndex = -1;
                }
            }

            //after get timeZone,set control timeZonesComboBox
            if (null != timeZone)
            {
                timeZoneComboBox.Text = null;
                timeZoneComboBox.SelectedItem = timeZone;
            }
        }
Beispiel #13
0
        /// <summary>
        /// call by CitiesNameSelectedChanged,when CitiesName ComboBox selected changed
        /// </summary>
        private void DoCityNameChanged()
        {
            //disable timezone ComboBox
            timeZoneComboBox.Enabled = false;
            CityInfoString cityInfoString = new CityInfoString();

            //get new CityInfoString
            if (GetCityInfo(cityNameComboBox.SelectedItem as string, out cityInfoString))
            {
                //use new CityInfoString to set TextBox and ComboBox
                latitudeTextBox.Text = cityInfoString.Latitude;
                longitudeTextBox.Text = cityInfoString.Longitude;

                //set control timeZonesComboBox
                if (null != cityInfoString.TimeZone)
                {
                    timeZoneComboBox.Text = null;
                    timeZoneComboBox.SelectedItem = cityInfoString.TimeZone;
                }
                else
                {
                    timeZoneComboBox.SelectedIndex = -1;
                }
            }
            //if failed, set control with nothing
            else
            {
                latitudeTextBox.Text = null;
                longitudeTextBox.Text = null;
                timeZoneComboBox.SelectedIndex = -1;
            }
        }