コード例 #1
0
        private void searchRoute()
        {
            if (subwayMap == null)
            {
                return;
            }

            string mode;

            if ((bool)radioButton_Shortest.IsChecked)
            {
                mode = "-b";
            }
            else
            {
                mode = "-c";
            }

            Cursor = Cursors.Wait;

            try
            {
                if (subwayMap.CurRoute != null)
                {
                    subwayMap.CurRoute.Clear();
                }
                displayRouteUnitList.Clear();
                subwayMap.SetStartStation(comboBox_StartStation.Text);
                subwayMap.SetEndStation(comboBox_EndStation.Text);
                subwayMap.CurRoute = subwayMap.GetDirections(mode);

                if (subwayMap.CurRoute.Count == 0)
                {
                    throw new Exception("起始/终点站点相同!");
                }

                displayRouteUnitList.Add(new DisplayRouteUnit(subwayMap.CurRoute[0].BeginStation.Name, subwayMap.CurRoute[0].LineName));
                foreach (Connection connection in (subwayMap.CurRoute))
                {
                    displayRouteUnitList.Add(new DisplayRouteUnit(connection.EndStation.Name, connection.LineName));
                }

                this.subwayGraph.ResetFlashIndex();
            }
            catch (Exception ex)
            {
                subwayMap.SetStartStation("");
                subwayMap.SetEndStation("");
                ErrorWindow errorWindow = new ErrorWindow();
                errorWindow.textBlock_Msg.Text = ex.Message;
                errorWindow.Show();
                return;
            }
            finally
            {
                Cursor = Cursors.Arrow;
                subwayGraph.InvalidateVisual();
            }
        }
コード例 #2
0
        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Station station = GetStationAt(e.MouseDevice.GetPosition(this));

            if (station != null)
            {
                if (subwayMap.StartStation == null)
                {
                    subwayMap.SetStartStation(station.Name);
                    ((MainWindow)((App)App.Current).MainWindow).comboBox_StartStation.Text = station.Name;
                }
                else
                {
                    subwayMap.SetEndStation(station.Name);
                    ((MainWindow)((App)App.Current).MainWindow).comboBox_EndStation.Text = station.Name;

                    //查找乘车线路
                    Cursor = Cursors.Wait;
                    string mode;

                    if (((App)App.Current).IsShortestPlaning)
                    {
                        mode = "-b";
                    }
                    else
                    {
                        mode = "-c";
                    }

                    try
                    {
                        if (subwayMap.CurRoute != null)
                        {
                            subwayMap.CurRoute.Clear();
                        }
                        displayRouteUnitList.Clear();
                        subwayMap.CurRoute = subwayMap.GetDirections(mode);

                        if (subwayMap.CurRoute.Count == 0)
                        {
                            throw new Exception("起始/终点站点相同!");
                        }

                        ResetFlashIndex();

                        displayRouteUnitList.Add(new DisplayRouteUnit(subwayMap.CurRoute[0].BeginStation.Name, subwayMap.CurRoute[0].LineName));
                        foreach (Connection connection in subwayMap.CurRoute)
                        {
                            displayRouteUnitList.Add(new DisplayRouteUnit(connection.EndStation.Name, connection.LineName));
                        }
                    }
                    catch (Exception ex)
                    {
                        subwayMap.SetStartStation("");
                        subwayMap.SetEndStation("");
                        ErrorWindow errorWindow = new ErrorWindow();
                        errorWindow.textBlock_Msg.Text = ex.Message;
                        errorWindow.Show();
                        return;
                    }
                    finally
                    {
                        Cursor = Cursors.Arrow;
                        InvalidateVisual();
                    }
                }
            }
            else if (Distance(e.MouseDevice.GetPosition(this), mouseDownPoint) < 1)//是否发生拖拽
            {
                subwayMap.SetStartStation("");
                subwayMap.SetEndStation("");
                ((MainWindow)((App)App.Current).MainWindow).comboBox_StartStation.Text = "";
                ((MainWindow)((App)App.Current).MainWindow).comboBox_EndStation.Text   = "";
                if (subwayMap.CurRoute != null)
                {
                    subwayMap.CurRoute.Clear();
                }
                displayRouteUnitList.Clear();
                flashStation = null;
            }

            InvalidateVisual();
        }