Example #1
0
        public void DeleteLine(int b)
        {
            int         templine, linecount;
            XmlDocument XmlStation = new XmlDocument();

            XmlStation.Load(StationXml);
            XmlNode     StationRoot = XmlStation.SelectSingleNode("All_Stations");
            XmlNodeList StationList = StationRoot.ChildNodes;
            XmlDocument XmlLine     = new XmlDocument();

            XmlLine.Load(LineXml);
            XmlNode     LineRoot = XmlLine.SelectSingleNode("All_Lines");
            XmlNodeList LineList = LineRoot.ChildNodes;

            foreach (int station in LinesArray[b].Stations)
            {
                if (StationsArray[station] == null)
                {
                    ChangeStationCount--; continue;
                }
                linecount = StationsArray[station].Lines.Count;
                if (linecount == 1)
                {
                    foreach (XmlNode stationnode in StationList)
                    {
                        XmlElement stationele = (XmlElement)stationnode;
                        if (stationele.GetAttribute("Station_ID") == station.ToString())
                        {
                            StationRoot.RemoveChild(stationnode);
                            break;
                        }
                    }
                    StationCount--;
                    StationsArray[station] = null;
                    FreeStationNum.Add(station);
                }
                else if (linecount == 2)
                {
                    while (StationsArray[station].Lines.Contains(b))
                    {
                        StationsArray[station].Lines.Remove(b);
                    }
                    ChangeStationCount--;
                    foreach (XmlNode stationnode in StationList)
                    {
                        XmlElement stationele = (XmlElement)stationnode;
                        if (stationele.GetAttribute("Station_ID") == station.ToString())
                        {
                            XmlNodeList nodelist = stationele.ChildNodes;
                            foreach (XmlNode nodenode in nodelist)
                            {
                                XmlElement nodeele = (XmlElement)nodenode;
                                if (nodeele.Name == "Station_Lines")
                                {
                                    nodeele.InnerText = StationsArray[station].LinesToString();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    templine = StationsArray[station].Lines[0];
                    while (LinesArray[templine].ChangeStations.Contains(station))
                    {
                        LinesArray[templine].ChangeStations.Remove(station);
                    }
                    foreach (XmlNode linenode in LineList)
                    {
                        XmlElement lineele = (XmlElement)linenode;
                        if (lineele.GetAttribute("Line_ID") == templine.ToString())
                        {
                            XmlNodeList nodelist = lineele.ChildNodes;
                            foreach (XmlNode nodenode in nodelist)
                            {
                                XmlElement nodeele = (XmlElement)nodenode;
                                if (nodeele.Name == "Line_ChangeStations")
                                {
                                    nodeele.InnerText = LinesArray[templine].ChangeStationsToString();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    while (StationsArray[station].Lines.Contains(b))
                    {
                        StationsArray[station].Lines.Remove(b);
                    }
                    foreach (XmlNode stationnode in StationList)
                    {
                        XmlElement stationele = (XmlElement)stationnode;
                        if (stationele.GetAttribute("Station_ID") == station.ToString())
                        {
                            XmlNodeList nodelist = stationele.ChildNodes;
                            foreach (XmlNode nodenode in nodelist)
                            {
                                XmlElement nodeele = (XmlElement)nodenode;
                                if (nodeele.Name == "Station_Lines")
                                {
                                    nodeele.InnerText = StationsArray[station].LinesToString();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            XmlStation.Save(StationXml);
            foreach (XmlNode linenode in LineList)
            {
                XmlElement lineele = (XmlElement)linenode;
                if (lineele.GetAttribute("Line_ID") == b.ToString())
                {
                    LineRoot.RemoveChild(linenode);
                    break;
                }
            }
            XmlLine.Save(LineXml);
            LinesArray[b] = null;
            LineCount--;
            FreeLineNum.Add(b);
            FreeLineNum.Sort();
        }
Example #2
0
        public void DeleteStation(int a)
        {
            int         templine, i, linecount;
            XmlDocument XmlLine = new XmlDocument();

            XmlLine.Load(LineXml);
            XmlNode     LineRoot = XmlLine.SelectSingleNode("All_Lines");
            XmlNodeList LineList = LineRoot.ChildNodes;

            linecount = StationsArray[a].Lines.Count;
            if (linecount == 1)
            {
                templine = StationsArray[a].Lines[0];
                if (a == LinesArray[templine].Extral)
                {
                    while (LinesArray[templine].ChangeStations.Contains(a))
                    {
                        LinesArray[templine].ChangeStations.Remove(a);
                    }
                    ChangeStationCount--;
                }
                while (LinesArray[templine].Stations.Contains(a))
                {
                    LinesArray[templine].Stations.Remove(a);
                }
                foreach (XmlNode linenode in LineList)
                {
                    XmlElement lineele = (XmlElement)linenode;
                    if (lineele.GetAttribute("Line_ID") == templine.ToString())
                    {
                        XmlNodeList nodelist = lineele.ChildNodes;
                        foreach (XmlNode nodenode in nodelist)
                        {
                            XmlElement nodeele = (XmlElement)nodenode;
                            if (nodeele.Name == "Line_Stations")
                            {
                                nodeele.InnerText = LinesArray[templine].StationsToString();
                                continue;
                            }
                            if (nodeele.Name == "Line_ChangeStations")
                            {
                                nodeele.InnerText = LinesArray[templine].ChangeStationsToString();
                                continue;
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                for (i = 0; i < linecount; i++)
                {
                    templine = StationsArray[a].Lines[i];
                    while (LinesArray[templine].ChangeStations.Contains(a))
                    {
                        LinesArray[templine].ChangeStations.Remove(a);
                    }
                    while (LinesArray[templine].Stations.Contains(a))
                    {
                        LinesArray[templine].Stations.Remove(a);
                    }
                    foreach (XmlNode linenode in LineList)
                    {
                        XmlElement lineele = (XmlElement)linenode;
                        if (lineele.GetAttribute("Line_ID") == templine.ToString())
                        {
                            XmlNodeList nodelist = lineele.ChildNodes;
                            foreach (XmlNode nodenode in nodelist)
                            {
                                XmlElement nodeele = (XmlElement)nodenode;
                                if (nodeele.Name == "Line_Stations")
                                {
                                    nodeele.InnerText = LinesArray[templine].StationsToString();
                                    continue;
                                }
                                if (nodeele.Name == "Line_ChangeStations")
                                {
                                    nodeele.InnerText = LinesArray[templine].ChangeStationsToString();
                                    continue;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            XmlLine.Save(LineXml);
            XmlDocument XmlStation = new XmlDocument();

            XmlStation.Load(StationXml);
            XmlNode     StationRoot = XmlStation.SelectSingleNode("All_Stations");
            XmlNodeList StationList = StationRoot.ChildNodes;

            foreach (XmlNode stationnode in StationList)
            {
                XmlElement stationele = (XmlElement)stationnode;
                if (stationele.GetAttribute("Station_ID") == a.ToString())
                {
                    StationRoot.RemoveChild(stationnode);
                    break;
                }
            }
            XmlStation.Save(StationXml);
            StationCount--;
            StationsArray[a] = null;
            FreeStationNum.Add(a);
        }