Ejemplo n.º 1
0
        /// <summary>
        /// 选择了列表框中的某一个站点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EHListBoxSelected(object sender, EventArgs e)
        {
            this.TextChanged -= cmbStation_TextChanged;
            //this.Items.Clear();
            //this.Items.Add(m_listBoxStation.SelectedItem);
            //this.SelectedIndex = 0;
            this.Text = m_listBoxStation.SelectedItem.ToString();
            string[] idName = m_listBoxStation.SelectedItem.ToString().Split('|');

            // 匹配当前的站点赋值
            string stationId = idName[0].Substring(1).Trim();

            for (int i = 0; i < m_listStations.Count; ++i)
            {
                if (stationId == m_listStations[i].StationID)
                {
                    m_currentStation = m_listStations[i];
                    // 发消息
                    if (StationSelected != null)
                    {
                        StationSelected.Invoke(this, new CEventSingleArgs <CEntityStation>(m_currentStation));
                    }
                    break;
                }
            }
            this.TextChanged += new EventHandler(cmbStation_TextChanged);
            HideListBox();
        }
Ejemplo n.º 2
0
 private void SelectButton_Click(object sender, RoutedEventArgs e)
 {
     if (ListBoxFavourites.SelectedItem != null)
     {
         StationSelected?.Invoke(((Favourite)ListBoxFavourites.SelectedItem).Station.Id);
         DialogResult = true;
     }
     else
     {
         MessageBox.Show("No station selected!");
     }
 }
Ejemplo n.º 3
0
 public void SetCurrentStation(CEntityStation station, bool bNotify = true)
 {
     // 设置当前的站点
     if (station == null)
     {
         return;
     }
     m_currentStation  = station;
     this.TextChanged -= cmbStation_TextChanged;
     this.Text         = GetDisplayStationName(station);
     this.TextChanged += cmbStation_TextChanged;
     if (bNotify)
     {
         // 发消息
         if (StationSelected != null)
         {
             StationSelected.Invoke(this, new CEventSingleArgs <CEntityStation>(m_currentStation));
         }
     }
 }
Ejemplo n.º 4
0
        private void cmbStation_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ShowListBox();
                //this.Container.Add(m_listViewStation);

                //// 站点上面内容发生改变
                string filter = this.Text;
                Debug.WriteLine(string.Format("--->{0}", filter));
                m_listBoxStation.Items.Clear();

                //  CEntityStation lastStation = null;
                Object lastStation = null;

                foreach (CEntityStation station in m_listStations)
                {
                    string tmp = GetDisplayStationName(station);
                    if (tmp.Contains(filter))
                    {
                        m_listBoxStation.Items.Add(tmp);
                        lastStation = station;
                    }
                }

                foreach (CEntitySoilStation station in m_listSoilStations)
                {
                    string tmp = GetDisplaySoilStationName(station);
                    if (tmp.Contains(filter))
                    {
                        m_listBoxStation.Items.Add(tmp);
                        lastStation = station;
                    }
                }

                //this.SelectionStart = this.Text.Length;
                //// 如果只有一个的话,就不需要显示下拉列表了
                if (m_listBoxStation.Items.Count == 1)
                {
                    this.TextChanged -= cmbStation_TextChanged;
                    if (lastStation is CEntityStation)
                    {
                        this.Text = GetDisplayStationName((CEntityStation)lastStation);
                    }
                    else
                    {
                        this.Text = GetDisplaySoilStationName((CEntitySoilStation)lastStation);
                    }
                    HideListBox();
                    this.TextChanged += new EventHandler(cmbStation_TextChanged);
                    m_currentStation  = lastStation;
                    // 发消息
                    if (StationSelected != null)
                    {
                        StationSelected.Invoke(this, new CEventSingleArgs <Object>(lastStation));
                    }
                }
                else if (m_listBoxStation.Items.Count == 0)
                {
                    // 如果没有符合要求的站点,初始化为所有站点
                    this.TextChanged -= cmbStation_TextChanged;
                    this.Text         = "";
                    foreach (CEntityStation station in m_listStations)
                    {
                        string tmp = GetDisplayStationName(station);
                        m_listBoxStation.Items.Add(tmp);
                    }

                    foreach (CEntitySoilStation station in m_listSoilStations)
                    {
                        string tmp = GetDisplaySoilStationName(station);
                        if (tmp.Contains(filter))
                        {
                            m_listBoxStation.Items.Add(tmp);
                            lastStation = station;
                        }
                    }

                    this.TextChanged += new EventHandler(cmbStation_TextChanged);
                    // 发消息,当前没有选中站点
                    if (StationSelected != null)
                    {
                        StationSelected.Invoke(this, new CEventSingleArgs <Object>(null));
                    }
                    m_currentStation = null;
                }
                else
                {
                    // 没有选中的站点
                    this.DroppedDown = true; //显示下拉列表
                    // 发消息,当前没有选中站点
                    if (StationSelected != null)
                    {
                        StationSelected.Invoke(this, new CEventSingleArgs <Object>(null));
                    }
                    m_currentStation = null;
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
        //Draw results
        private void DrawResults(LinearLayout ResultsRoot, RtGPS GPS)
        {
            //If GPS sending position
            if ((GPS.Ready && Option_SearchLocation) || !Option_SearchLocation)
            {
                //Search stations
                RtStationData[] data = new RtStations().SearchStations(SearchInput.Text, MAXSEARCHRESULTS, (Option_SearchLocation) ? GPS : null, Option_SearchNavigable);

                //Clear Results View
                ResultsRoot.RemoveAllViews();

                //Loop through stations data
                for (int i = 0; i < data.Length; i++)
                {
                    //Create a local copy of variable for click event
                    RtStationData localdat = data[i];

                    //Result Back
                    LinearLayout ResultBack = new LinearLayout(this.Context);
                    ResultBack.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, DIALOGRESULTHEIGHT);
                    ResultBack.SetDpPadding(RtGraphicsLayouts, SMALLPADDING, SMALLPADDING, SMALLPADDING, SMALLPADDING);
                    ResultBack.SetGravity(GravityFlags.CenterVertical);
                    ResultsRoot.AddView(ResultBack);

                    //Result Station Name
                    TextView ResultStationName = new TextView(this.Context);
                    ResultStationName.Format(RtGraphicsExt.TextFormats.Paragraph);
                    ResultStationName.Text = data[i].StationName;
                    ResultBack.AddView(ResultStationName);

                    //Result Station CRS
                    TextView ResultCRS = new TextView(this.Context);
                    ResultCRS.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, RtGraphicsLayouts.CONTAIN);
                    ResultCRS.SetDpPadding(RtGraphicsLayouts, ZERO, ZERO, SMALLPADDING, ZERO);
                    ResultCRS.Format(RtGraphicsExt.TextFormats.Paragraph1);
                    ResultCRS.Text    = data[i].Code;
                    ResultCRS.Gravity = GravityFlags.Right;
                    ResultBack.AddView(ResultCRS);

                    //Result Back Event
                    ResultBack.Click += delegate
                    {
                        //If callback isn't null, invoke it, causing sleection to be returned and dialog hidden.
                        StationSelected?.Invoke(DialogID, localdat);
                        CloseDialog();
                    };
                }

                //If theres no stations
                if (data.Length == ZERO)
                {
                    ResultsRoot.RemoveAllViews();
                    ResultsRoot.AddView(DrawErrorMessage(ERROR_NOSTATIONSFOUND));
                    GPS = new RtGPS((LocationManager)ContextWrapper.GetSystemService(ContextWrapper.LocationService));
                }
            }
            else if (GPS.NoGPS)
            {
                //If no GPS
                ResultsRoot.RemoveAllViews();
                ResultsRoot.AddView(DrawErrorMessage(ERROR_GPSTURNEDOFF));
                GPS = new RtGPS((LocationManager)ContextWrapper.GetSystemService(ContextWrapper.LocationService));
            }
            else
            {
                //If GPS not ready
                ResultsRoot.RemoveAllViews();
                ResultsRoot.AddView(DrawErrorMessage(ERROR_GPSLOADING));
            }
        }