Example #1
0
        private void lineShow_Click(object sender, EventArgs e)
        {
            BusCommandText.Clear();
            int    linehandle = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);
            string LineSearch;

            LineSearch = LineName.Text;
            #region 文字信息
            string           sqlLine   = "select BSName,BLNote from buslines where BLName  = '" + LineSearch + "'";
            MySqlDataAdapter adapter   = new MySqlDataAdapter(sqlLine, connection_);
            DataTable        dataTable = new DataTable();
            adapter.Fill(dataTable);
            //dataGridView1.DataSource = dataTable;
            //查询到表
            int rowNum = dataTable.Rows.Count;
            for (int i = 0; i <= rowNum - 1; i++)
            {
                if (i == 0)
                {
                    BusCommandText.Text = "正方向:";
                }
                BusCommandText.Text = BusCommandText.Text + dataTable.Rows[i][0].ToString() + "-";
                if (i != rowNum - 1)
                {
                    int nextrow = 0;
                    int thisrow = 0;
                    nextrow = Int16.Parse(dataTable.Rows[i + 1][1].ToString());
                    thisrow = Int16.Parse(dataTable.Rows[i][1].ToString());
                    if (thisrow != nextrow)
                    {
                        BusCommandText.Text = BusCommandText.Text + "\n" + "逆方向:";
                    }
                }
            }
            #endregion
            #region 地图信息
            //获取数据库内容
            string           sqlLineShow = "select N,E,Note,Num from buslinesshow where BLName  = '" + LineSearch + "'";
            MySqlDataAdapter adapter2    = new MySqlDataAdapter(sqlLineShow, connection_);
            DataTable        dataTable2  = new DataTable();
            adapter2.Fill(dataTable2);

            double[] N;
            double[] E;
            N = new double[300];
            E = new double[300];
            int rowNum2 = 0;
            rowNum2 = dataTable2.Rows.Count;
            for (int i = 0; i <= rowNum2 - 1; i++)
            {
                N[i] = double.Parse(dataTable2.Rows[i][0].ToString());
                E[i] = double.Parse(dataTable2.Rows[i][1].ToString());
            }

            //画点

            int jungleStop = 0;
            for (int i = 0; i < rowNum2 - 1; i++)
            {
                jungleStop = Int16.Parse(dataTable2.Rows[i][3].ToString());//判断是否为站点
                if (jungleStop == 1)
                {
                    axMap1.DrawPointEx(linehandle, E[i], N[i], 10, 1);
                }
            }
            //画线
            for (int n = 0; n <= rowNum2 - 1; n++)
            {
                int nextrow2 = 0;
                int thisrow2 = 0;
                nextrow2 = Int16.Parse(dataTable2.Rows[n + 1][2].ToString());
                thisrow2 = Int16.Parse(dataTable2.Rows[n][2].ToString());
                if (nextrow2 != thisrow2)
                {
                    for (int i = 0; i < n; i++)
                    {
                        axMap1.DrawLineEx(linehandle, E[i], N[i], E[i + 1], N[i + 1], 3, 1);
                    }
                    for (int i = n; i < rowNum2 - 1; i++)
                    {
                        axMap1.DrawLineEx(linehandle, E[i], N[i], E[i + 1], N[i + 1], 3, 200);
                    }
                    break;
                }
            }



            #endregion
        }
Example #2
0
        private void Search_Click(object sender, EventArgs e)
        {
            BusCommandText.Clear();
            BusAllText.Clear();
            string startP            = comboBox1.Text;
            string endP              = comboBox2.Text;
            int    StartbuslineCount = 0;

            //结果参数(线路/方向/站数)
            string[] Rbusline   = new string[80];
            int[]    Rdirection = new int[80];
            int[]    Rstopsnum  = new int[80];
            int      R          = 0;

            string[] result = new string[80];
            int      MinR   = 0;

            //显示路线用参数
            int[]    BNStart     = new int[80];
            int[]    BNChange1   = new int[80];
            int[]    BNChange2   = new int[80];
            int[]    BNEnd       = new int[80];
            double[] N           = new double[300];
            double[] E           = new double[300];
            int      linehandle  = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);
            int      linehandle2 = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);



            string           SearchER = "select * from buslines where BSName like '%" + endP + "%'";
            MySqlDataAdapter endsql   = new MySqlDataAdapter(SearchER, connection_);
            DataTable        EndP     = new DataTable();

            endsql.Fill(EndP);

            string           SearchER3 = "select * from buslines where BSName like '%" + startP + "%'";
            MySqlDataAdapter startsql2 = new MySqlDataAdapter(SearchER3, connection_);
            DataTable        startp2   = new DataTable();

            startsql2.Fill(startp2);
            //获取终点的站点名和经过的路线
            string endPName   = EndP.Rows[0][2].ToString();
            string StartPName = startp2.Rows[0][2].ToString();

            BusCommandText.Text = "\n" + "起点:" + StartPName + "\n" + "终点:" + endPName + "\n";
            BusAllText.Text     = "\n" + "起点:" + StartPName + "\n" + "终点:" + endPName + "\n";


            #region 直达不需要换乘的情况下

            for (int i = 1; i < 3; i++)
            {
                //查询经过起点的路线
                string           SearchSR   = "select BLName,BNum,BSName from buslines where BSName like '%" + startP + "%'and BLNote=" + i;
                MySqlDataAdapter startsql   = new MySqlDataAdapter(SearchSR, connection_);
                DataTable        StartPLine = new DataTable();
                startsql.Fill(StartPLine);
                StartbuslineCount = StartPLine.Rows.Count;
                string StartSN = StartPLine.Rows[0][2].ToString();

                //循环各查询路线的站
                for (int a = 0; a < StartbuslineCount; a++)
                {
                    string           thisLine       = StartPLine.Rows[a][0].ToString();
                    int              thisStopIndex  = Int32.Parse(StartPLine.Rows[a][1].ToString());
                    string           LineStopSQL    = "select BLName,BSName,BNum from buslines where BLName ='" + thisLine + "' and BLNote=" + i;
                    MySqlDataAdapter LineStopSqad   = new MySqlDataAdapter(LineStopSQL, connection_);
                    DataTable        LineStopsTable = new DataTable();
                    LineStopSqad.Fill(LineStopsTable);
                    int thisDirCount = LineStopsTable.Rows.Count;

                    //这个方向下从起始站开始查找
                    for (int b = thisStopIndex; b < thisDirCount; b++)
                    {
                        string LineStopName = LineStopsTable.Rows[b][1].ToString();
                        //若可以直达不需要换乘
                        if (LineStopName == endPName)
                        {
                            int thisSNum = int.Parse(LineStopsTable.Rows[thisStopIndex][2].ToString());
                            int thisENum = int.Parse(LineStopsTable.Rows[b][2].ToString());
                            Rbusline[R]     = thisLine;
                            Rdirection[R]   = i;
                            Rstopsnum[R]    = b - thisStopIndex + 1;
                            BNStart[R]      = thisSNum;
                            BNEnd[R]        = thisENum;
                            result[R]       = "在【" + StartSN + "】乘坐【" + Rbusline[R] + "】路公交<" + Rstopsnum[R] + ">站直达【" + endPName + "】方向" + Rdirection[R];
                            BusAllText.Text = BusAllText.Text + result[R] + "\n";
                            R++;
                        }
                    }
                    LineStopsTable.Clear();
                }
                StartPLine.Clear();
            }
            //判断站数最少
            for (int n = 1; n < R; n++)
            {
                if (Rstopsnum[n] < Rstopsnum[MinR])
                {
                    MinR = n;
                }
            }
            BusCommandText.Text = BusCommandText.Text + result[MinR] + "\n";


            //*******************************************显示推荐路线**********************************************
            if (R != 0)
            {
                int startUse = BNStart[MinR];
                if (BNStart[MinR] != 1)
                {
                    startUse = BNStart[MinR] - 1;
                }
                string ShowDirSR = "select ID,N,E,Num,Note,BNum from buslinesshow where (BLName='" + Rbusline[MinR] + "') and (Note=" + Rdirection[MinR] + ") and (BNum in(" + startUse;
                //如果只有一站
                if (Rstopsnum[MinR] == 1)
                {
                    ShowDirSR = ShowDirSR + "))";
                }
                //多个站
                if (Rstopsnum[MinR] > 1)
                {
                    for (int q = startUse + 1; q < BNEnd[MinR]; q++)
                    {
                        ShowDirSR = ShowDirSR + "," + q;
                    }
                    ShowDirSR = ShowDirSR + "))";
                }
                MySqlDataAdapter show1      = new MySqlDataAdapter(ShowDirSR, connection_);
                DataTable        showTable1 = new DataTable();
                show1.Fill(showTable1);
                int showCount = showTable1.Rows.Count;
                for (int p = 0; p < showCount; p++)
                {
                    N[p] = double.Parse(showTable1.Rows[p][1].ToString());
                    E[p] = double.Parse(showTable1.Rows[p][2].ToString());
                }
                //画点
                int jungleStop = 0;
                for (int k = 0; k < showCount; k++)
                {
                    jungleStop = int.Parse(showTable1.Rows[k][3].ToString());
                    if (jungleStop == 1)
                    {
                        axMap1.DrawPointEx(linehandle, E[k], N[k], 10, 1);
                    }
                }
                axMap1.DrawPointEx(linehandle, E[showCount - 1], N[showCount - 1], 8, 1);
                //画线
                for (int n = 0; n < showCount - 1; n++)
                {
                    axMap1.DrawLineEx(linehandle, E[n], N[n], E[n + 1], N[n + 1], 2, 1);
                }
            }



            #endregion

            #region 需要换乘的情况下
            if (R == 0)
            {
                //存放换乘的各种信息参数
                string[] ChangeStopN = new string[80];
                string[] FirstLine   = new string[80];
                string[] SecondLine  = new string[80];
                int[]    FirstDir    = new int[80];
                int[]    SecondDir   = new int[80];
                int[]    FirstNum    = new int[80];
                int[]    SecondNum   = new int[80];
                int[]    SumStops    = new int[80];
                double[] N2          = new double[300];
                double[] E2          = new double[300];

                for (int i = 1; i < 3; i++)
                {
                    //查询经过起点的路线
                    string           SearchSR        = "select BLName,BNum,BSName from buslines where BSName like '%" + startP + "%'and BLNote=" + i;
                    MySqlDataAdapter startsql        = new MySqlDataAdapter(SearchSR, connection_);
                    DataTable        StartPLineTable = new DataTable();
                    startsql.Fill(StartPLineTable);
                    string StartPN = StartPLineTable.Rows[0][2].ToString();
                    StartbuslineCount = StartPLineTable.Rows.Count;

                    for (int a = 0; a < StartbuslineCount; a++)
                    {
                        //该方向下该线路会经过的站
                        string           thisLine       = StartPLineTable.Rows[a][0].ToString();
                        int              thisStopIndex  = Int32.Parse(StartPLineTable.Rows[a][1].ToString());
                        string           LineStopSQL    = "select BLName,BSName,BNum from buslines where BLName ='" + thisLine + "' and BLNote=" + i;
                        MySqlDataAdapter LineStopSqad   = new MySqlDataAdapter(LineStopSQL, connection_);
                        DataTable        LineStopsTable = new DataTable();
                        LineStopSqad.Fill(LineStopsTable);
                        int thisDirCount = LineStopsTable.Rows.Count;

                        for (int b = thisStopIndex; b < thisDirCount; b++)
                        {
                            //每个到达的的站如果作为中转站
                            string           ChangeStop     = LineStopsTable.Rows[b][1].ToString();
                            string           ChangeStartSql = "select * from buslines where BSName like '" + ChangeStop + "'";
                            MySqlDataAdapter ChangeAD       = new MySqlDataAdapter(ChangeStartSql, connection_);
                            DataTable        ChangeSTable   = new DataTable();
                            ChangeAD.Fill(ChangeSTable);
                            int ChangeTCount = ChangeSTable.Rows.Count;
                            //搜寻经过这个中转站的路线
                            for (int c = 0; c < ChangeTCount; c++)
                            {
                                string ChangeStartLine = ChangeSTable.Rows[c][1].ToString();
                                int    ChangeLineDir   = int.Parse(ChangeSTable.Rows[c][4].ToString());
                                //搜寻经过终点站的路线
                                for (int d = 0; d < EndP.Rows.Count; d++)
                                {
                                    string EndStopLine    = EndP.Rows[d][1].ToString();
                                    int    EndStopLineDir = int.Parse(EndP.Rows[d][4].ToString());
                                    if (EndStopLine == ChangeStartLine && ChangeLineDir == EndStopLineDir)
                                    {
                                        FirstNum[R] = int.Parse(LineStopsTable.Rows[b][2].ToString()) - int.Parse(LineStopsTable.Rows[thisStopIndex - 1][2].ToString());
                                        //确认该条换乘路线的有经过终点
                                        string           EndLineSQL   = "select * from buslines where BLName='" + EndStopLine + "' and BLNote = " + EndStopLineDir;
                                        MySqlDataAdapter EndLineAD    = new MySqlDataAdapter(EndLineSQL, connection_);
                                        DataTable        EndLineTable = new DataTable();
                                        EndLineAD.Fill(EndLineTable);
                                        for (int t = 0; t < EndLineTable.Rows.Count; t++)
                                        {
                                            string ResultEndLineStop = EndLineTable.Rows[t][2].ToString();
                                            if (ResultEndLineStop == ChangeStop)
                                            {
                                                for (int t2 = t; t2 < EndLineTable.Rows.Count; t2++)
                                                {
                                                    string thisStop = EndLineTable.Rows[t2][2].ToString();
                                                    if (thisStop == endPName)
                                                    {
                                                        int thisSNum  = int.Parse(LineStopsTable.Rows[thisStopIndex][2].ToString());
                                                        int thisCNum1 = int.Parse(LineStopsTable.Rows[b][2].ToString());
                                                        int thisCNum2 = int.Parse(EndLineTable.Rows[t][3].ToString());
                                                        int thisENum  = int.Parse(EndLineTable.Rows[t2][3].ToString());
                                                        SecondNum[R]    = int.Parse(EndLineTable.Rows[t2][3].ToString()) - int.Parse(EndLineTable.Rows[t][3].ToString());
                                                        FirstLine[R]    = thisLine;
                                                        ChangeStopN[R]  = ChangeStop;
                                                        SecondLine[R]   = EndStopLine;
                                                        FirstDir[R]     = i;
                                                        SecondDir[R]    = EndStopLineDir;
                                                        SumStops[R]     = FirstNum[R] + SecondNum[R];
                                                        BNStart[R]      = thisSNum;
                                                        BNChange1[R]    = thisCNum1;
                                                        BNChange2[R]    = thisCNum2;
                                                        BNEnd[R]        = thisENum;
                                                        BusAllText.Text = BusAllText.Text + "先" + FirstDir[R] + "方向上乘坐【" + FirstLine[R] + "】[" + FirstNum[R] + "]站到达【" + ChangeStopN[R] + "】后在" + SecondDir[R] + "方向上换乘【" + SecondLine[R] + "】[" + SecondNum[R] + "]站到达" + "\n";
                                                        R++;
                                                    }
                                                }
                                            }
                                        }
                                        EndLineTable.Clear();
                                    }
                                }
                            }
                            ChangeSTable.Clear();
                        }
                        LineStopsTable.Clear();
                    }
                }
                //判断哪条换乘线最适合
                for (int n = 1; n < R; n++)
                {
                    if (SumStops[n] < SumStops[MinR])
                    {
                        MinR = n;
                    }
                }
                BusCommandText.Text = BusCommandText.Text + "推荐换乘路线:" + "\n" + "先" + FirstDir[MinR] + "方向上乘坐【" + FirstLine[MinR] + "】[" + FirstNum[MinR] + "]站到达【" + ChangeStopN[MinR] + "】后在" + SecondDir[MinR] + "方向上换乘【" + SecondLine[MinR] + "】[" + SecondNum[MinR] + "]站到达";

                //**********************************************显示推荐线路************************************************
                //第一条
                if (R != 0)
                {
                    int startUse = BNStart[MinR];
                    if (BNStart[MinR] != 1)
                    {
                        startUse = BNStart[MinR] - 1;
                    }
                    string ShowDirSR = "select ID,N,E,Num,Note,BNum from buslinesshow where (BLName='" + FirstLine[MinR] + "') and (Note=" + FirstDir[MinR] + ") and (BNum in(" + startUse;
                    //如果只有一站
                    if (FirstNum[MinR] == 1)
                    {
                        ShowDirSR = ShowDirSR + "))";
                    }
                    //多个站
                    if (FirstNum[MinR] > 1)
                    {
                        for (int q = startUse + 1; q < BNChange1[MinR]; q++)
                        {
                            ShowDirSR = ShowDirSR + "," + q;
                        }
                        ShowDirSR = ShowDirSR + "))";
                    }
                    MySqlDataAdapter show1      = new MySqlDataAdapter(ShowDirSR, connection_);
                    DataTable        showTable1 = new DataTable();
                    show1.Fill(showTable1);
                    int showCount = showTable1.Rows.Count;
                    for (int p = 0; p < showCount; p++)
                    {
                        N[p] = double.Parse(showTable1.Rows[p][1].ToString());
                        E[p] = double.Parse(showTable1.Rows[p][2].ToString());
                    }
                    //画点
                    int jungleStop = 0;
                    for (int k = 0; k < showCount; k++)
                    {
                        jungleStop = int.Parse(showTable1.Rows[k][3].ToString());
                        if (jungleStop == 1)
                        {
                            axMap1.DrawPointEx(linehandle, E[k], N[k], 8, 1);
                        }
                    }
                    axMap1.DrawPointEx(linehandle, E[showCount - 1], N[showCount - 1], 8, 1);
                    //画线
                    for (int n = 0; n < showCount - 1; n++)
                    {
                        axMap1.DrawLineEx(linehandle, E[n], N[n], E[n + 1], N[n + 1], 2, 1);
                    }

                    //第二条
                    int startUse2 = BNChange2[MinR];
                    //if (BNStart[MinR] != 1 && SecondNum[MinR] != 1)
                    //{
                    //    startUse2 = BNChange2[MinR] - 2;
                    //}
                    string ShowDirSR2 = "select ID,N,E,Num,Note,BNum from buslinesshow where (BLName='" + SecondLine[MinR] + "') and (Note=" + SecondDir[MinR] + ") and (BNum in(" + startUse2;
                    //如果只有一站
                    if (SecondNum[MinR] == 1)
                    {
                        ShowDirSR2 = ShowDirSR2 + "))";
                    }
                    //多个站
                    if (SecondNum[MinR] > 1)
                    {
                        for (int q = startUse2 + 1; q < BNEnd[MinR]; q++)
                        {
                            ShowDirSR2 = ShowDirSR2 + "," + q;
                        }
                        ShowDirSR2 = ShowDirSR2 + "))";
                    }
                    MySqlDataAdapter show2      = new MySqlDataAdapter(ShowDirSR2, connection_);
                    DataTable        showTable2 = new DataTable();
                    show2.Fill(showTable2);
                    int showCount2 = showTable2.Rows.Count;
                    for (int p = 0; p < showCount2; p++)
                    {
                        N2[p] = double.Parse(showTable2.Rows[p][1].ToString());
                        E2[p] = double.Parse(showTable2.Rows[p][2].ToString());
                    }

                    //画点
                    int jungleStop2 = 0;
                    for (int k = 0; k < showCount2; k++)
                    {
                        jungleStop2 = int.Parse(showTable2.Rows[k][3].ToString());
                        if (jungleStop2 == 1)
                        {
                            axMap1.DrawPoint(E2[k], N2[k], 8, 200);
                        }
                    }
                    axMap1.DrawPointEx(linehandle, E2[showCount2 - 1], N2[showCount2 - 1], 8, 200);
                    //画线
                    for (int n = 0; n < showCount2 - 1; n++)
                    {
                        axMap1.DrawLineEx(linehandle, E2[n], N2[n], E2[n + 1], N2[n + 1], 2, 200);
                    }
                }

                if (R == 0)
                {
                    MessageBox.Show("路线超出大学城范围,建议转换其他方式或站点");
                }
            }
            #endregion
        }