Beispiel #1
0
        private void initDataList() //数据还原,太懒了,简单点吧
        {
            int i;

            listNode.Clear();
            listPath.Clear();
            listPathDFS.Clear();


            for (i = 0; i < dSet.Tables["NODE"].Rows.Count; i++)
            {
                cNode cnode = new cNode();
                cnode.iROOMID    = int.Parse(dSet.Tables["NODE"].Rows[i][0].ToString());
                cnode.sROOMName  = dSet.Tables["NODE"].Rows[i][1].ToString();
                cnode.iROOMCLASS = int.Parse(dSet.Tables["NODE"].Rows[i][2].ToString());
                //cnode.sROOMName = dSet.Tables["NODE"].Rows[i][3].ToString();
                listNode.Add(cnode);
            }

            for (i = 0; i < dSet.Tables["PATH"].Rows.Count; i++)
            {
                cNodePath cnodepath = new cNodePath();

                //找到起始节点
                var qNodes = from cnode in listNode
                             where cnode.iROOMID == int.Parse(dSet.Tables["PATH"].Rows[i][0].ToString())
                             select cnode;
                if (qNodes.Count() < 1)
                {
                    continue;
                }
                foreach (cNode cnode1 in qNodes)
                {
                    cnodepath.nFromROOM = cnode1;
                    break;
                }

                //找到终点
                var qNodes1 = from cnode in listNode
                              where cnode.iROOMID == int.Parse(dSet.Tables["PATH"].Rows[i][2].ToString())
                              select cnode;
                if (qNodes1.Count() < 1)
                {
                    continue;
                }
                foreach (cNode cnode1 in qNodes1)
                {
                    cnodepath.nToROOM = cnode1;
                    break;
                }
                cnodepath.iValue    = int.Parse(dSet.Tables["PATH"].Rows[i][4].ToString());
                cnodepath.sDoorID   = dSet.Tables["PATH"].Rows[i][5].ToString();
                cnodepath.sDoorName = dSet.Tables["PATH"].Rows[i][6].ToString();


                listPath.Add(cnodepath);
            }


            for (i = 0; i < dSet.Tables["DFS"].Rows.Count; i++)
            {
                cNodePathRecord cnodepathr = new cNodePathRecord();

                //找到节点
                cnodepathr.iPathNO    = int.Parse(dSet.Tables["DFS"].Rows[i][0].ToString());
                cnodepathr.iNodeNO    = int.Parse(dSet.Tables["DFS"].Rows[i][1].ToString());
                cnodepathr.iROOMID    = int.Parse(dSet.Tables["DFS"].Rows[i][2].ToString());
                cnodepathr.sROOMName  = dSet.Tables["DFS"].Rows[i][3].ToString();
                cnodepathr.iROOMCLASS = int.Parse(dSet.Tables["DFS"].Rows[i][7].ToString());
                listPathDFS.Add(cnodepathr);
            }

            var pathMax = (from s in listPathDFS
                           select s.iPathNO)
                          .Max();

            iPathNo = pathMax;
            //MessageBox.Show(iPathNo.ToString());
        }
Beispiel #2
0
        //路径描述
        private void dataGridViewDFS_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridViewDFS.RowCount < 1)
            {
                return;
            }

            dtPaths.Rows.Clear();

            if (dataGridViewDFS.SelectedRows.Count < 1)
            {
                dtPaths.Rows.Clear();
                return;
            }

            var qPathDFS = from cPathDFS in listPathDFS
                           where cPathDFS.iPathNO == int.Parse(dataGridViewDFS.SelectedRows[0].Cells[0].Value.ToString())
                           orderby cPathDFS.iPathNO, cPathDFS.iPathNO ascending
            select cPathDFS;

            if (qPathDFS.Count() < 1) //没有路径,中止
            {
                dtPaths.Rows.Clear();
                return;
            }


            int             j        = 0;
            cNodePathRecord cnodeprF = null;

            object[] oT = new object[3];
            foreach (cNodePathRecord cnodepr in qPathDFS)
            {
                if (j == 0) //第一点
                {
                    cnodeprF = cnodepr;
                    oT[0]    = "空间";
                    oT[1]    = cnodepr.sROOMName;
                    oT[2]    = cnodepr.iROOMID.ToString() + ":" + cnodepr.iROOMCLASS;

                    dtPaths.Rows.Add(oT);
                    j++;
                }
                else //中间点,取路径
                {
                    var qPaths = from cPaths in listPath
                                 where cPaths.nToROOM.iROOMID == cnodeprF.iROOMID && cPaths.nFromROOM.iROOMID == cnodepr.iROOMID
                                 select cPaths;

                    if (qPaths.Count() < 1)
                    {
                        cnodeprF = cnodepr;
                        continue;
                    }

                    foreach (cNodePath cpath in qPaths)
                    {
                        cnodeprF = cnodepr;

                        oT[0] = "门";
                        oT[1] = cpath.sDoorName;
                        oT[2] = cpath.sDoorID;
                        dtPaths.Rows.Add(oT);

                        oT[0] = "空间";
                        oT[1] = cnodepr.sROOMName;
                        oT[2] = cnodepr.iROOMID.ToString() + ":" + cnodepr.iROOMCLASS;;
                        dtPaths.Rows.Add(oT);
                        //textBoxPaths.Text += "\r\n->[" + cpath.sDoorName+"]->\r\n" + cnodepr.sROOMName + "}";

                        j++;
                    }
                }
            }

            //textBoxPaths.Text += "\r\n\r\n经:\r\n" + dataGridViewDFS.SelectedRows[0].Cells[3].Value.ToString() + "个空间\r\n" + dataGridViewDFS.SelectedRows[0].Cells[4].Value.ToString() + "扇门";
            toolStripStatusLabelS.Text = "共有" + dataGridViewDFS.RowCount.ToString() + "条路径,所选路径经:" + dataGridViewDFS.SelectedRows[0].Cells[3].Value.ToString() + "个空间、" + dataGridViewDFS.SelectedRows[0].Cells[4].Value.ToString() + "扇门";
        }
Beispiel #3
0
        private void InitDataGridViewDFS(string sFromFilter, string sToFilter)
        {
            int i, j;

            object[]        oTempDFS = new object[6];
            cNodePathRecord cnodeprF = null, cnodeprT;
            int             iMax;


            int ipaths = 0;

            i = 1;
            while (true)
            {
                //MessageBox.Show(ipaths.ToString());
                ipaths++;
                var qPathDFS = from cPathDFS in listPathDFS
                               where cPathDFS.iPathNO == ipaths
                               orderby cPathDFS.iPathNO, cPathDFS.iPathNO ascending
                select cPathDFS;

                if (qPathDFS.Count() < 1) //没有路径,中止
                {
                    break;
                }

                oTempDFS[0] = ipaths;

                //路径描述
                j = 0; iMax = 0; oTempDFS[5] = "";
                foreach (cNodePathRecord cnodepr in qPathDFS)
                {
                    if (j == 0) //第一点
                    {
                        cnodeprF    = cnodepr;
                        oTempDFS[5] = cnodepr.sROOMName + "{" + cnodepr.iROOMID + ":" + cnodepr.iROOMCLASS.ToString() + "}";
                        oTempDFS[1] = oTempDFS[5];
                        oTempDFS[2] = oTempDFS[1];
                        j++;
                    }
                    else //中间点,取路径
                    {
                        var qPaths = from cPaths in listPath
                                     where cPaths.nToROOM.iROOMID == cnodeprF.iROOMID && cPaths.nFromROOM.iROOMID == cnodepr.iROOMID
                                     select cPaths;

                        //MessageBox.Show(cnodeprF.iROOMID + "-" + qPaths.Count().ToString() + "-" + cnodepr.iROOMID.ToString());

                        if (qPaths.Count() < 1)
                        {
                            cnodeprF = cnodepr;
                            continue;
                        }

                        foreach (cNodePath cpath in qPaths)
                        {
                            iMax        += cpath.iValue;
                            cnodeprF     = cnodepr;
                            oTempDFS[5] += "->[" + cpath.sDoorID + "]->" + cnodepr.sROOMName + "{" + cnodepr.iROOMID + ":" + cnodepr.iROOMCLASS.ToString() + "}";
                            oTempDFS[2]  = cnodepr.sROOMName + "{" + cnodepr.iROOMID + ":" + cnodepr.iROOMCLASS.ToString() + "}";
                            j++;
                        }
                    }
                }

                oTempDFS[3] = j; oTempDFS[4] = iMax;

                if (sFromFilter == "" && sToFilter == "") //没有查询条件
                {
                    dtDFS.Rows.Add(oTempDFS);
                    i++;
                }
                else //有约束条件
                {
                    if (sFromFilter != "" && sToFilter != "") //均有约束
                    {
                        if (oTempDFS[1].ToString().Contains(sFromFilter) && oTempDFS[2].ToString().Contains(sToFilter))
                        {
                            dtDFS.Rows.Add(oTempDFS);
                            i++;
                        }
                    }
                    else //单一约束
                    {
                        if (sFromFilter != "")
                        {
                            if (oTempDFS[1].ToString().Contains(sFromFilter))
                            {
                                dtDFS.Rows.Add(oTempDFS);
                                i++;
                            }
                        }
                        else
                        {
                            if (oTempDFS[2].ToString().Contains(sToFilter))
                            {
                                dtDFS.Rows.Add(oTempDFS);
                                i++;
                            }
                        }
                    }
                }
            }

            toolStripStatusLabelS.Text = "共有" + dataGridViewDFS.RowCount.ToString() + "条路径";
            dtPaths.Rows.Clear();
        }