Пример #1
0
        public void AddLineStation(DO.LineStation lineStation)
        {
            var lineStationList = XmlTools.LoadListFromXMLSerializer <DO.LineStation>(lineStationsPath);
            var ls = lineStationList.FirstOrDefault(s =>
                                                    s.Station == lineStation.Station && s.LineId == lineStation.LineId);

            if (ls != null && !ls.IsDeleted)
            {
                throw new DO.BadLineStationException(lineStation.Station, lineStation.LineId,
                                                     "Duplicate line station");
            }

            var line = GetLine(lineStation.LineId);

            foreach (var s in lineStationList)
            {
                if (s.LineId == line.Id)
                {
                    if (lineStation.PrevStation == s.Station)
                    {
                        lineStation.LineStationIndex = s.LineStationIndex + 1;
                        continue;
                    }
                    if (lineStation.LineStationIndex != -1)
                    {
                        s.LineStationIndex += 1;
                        UpdateLineStation(s);
                    }
                }
            }

            lineStationList.Add(lineStation);
            XmlTools.SaveListToXMLSerializer(lineStationList, lineStationsPath);
        }
Пример #2
0
        public void AddUser(DO.User newUser)
        {
            var userList = XmlTools.LoadListFromXMLSerializer <DO.User>(usersPath);
            var user     = userList.FirstOrDefault(u => u.UserName == newUser.UserName);

            if (user != null && !newUser.IsDeleted)
            {
                throw new DO.BadUsernameException(newUser.UserName, "Duplicate user username");
            }

            userList.Add(newUser);
            XmlTools.SaveListToXMLSerializer(userList, usersPath);
        }
Пример #3
0
        public void AddStation(DO.Station station)
        {
            var stationList = XmlTools.LoadListFromXMLSerializer <DO.Station>(stationPath);
            var st          = stationList.Find(s => s.Code == station.Code);

            if (st != null && !station.IsDeleted)
            {
                throw new DO.BadStationException(station.Code, "Duplicate Station");
            }

            stationList.Add(station);
            XmlTools.SaveListToXMLSerializer(stationList, stationPath);
        }
Пример #4
0
        public void RemoveLineStationOnRemoveline(DO.LineStation lineStation)
        {
            var lineStationList = XmlTools.LoadListFromXMLSerializer <DO.LineStation>(lineStationsPath);
            var ls = lineStationList.Find(s => s.Station == lineStation.Station &&
                                          s.LineId == lineStation.LineId);

            if (ls != null && !ls.IsDeleted)
            {
                lineStationList.Remove(ls);
                ls.IsDeleted = true;
                lineStationList.Add(ls);
                XmlTools.SaveListToXMLSerializer(lineStationList, lineStationsPath);
            }
        }
Пример #5
0
        public void UpdateUser(DO.User user)
        {
            var userList = XmlTools.LoadListFromXMLSerializer <DO.User>(usersPath);
            var findUser = userList.Find(u => u.UserName == user.UserName);

            if (findUser != null && !findUser.IsDeleted)
            {
                userList.Remove(findUser);
                userList.Add(user);
                XmlTools.SaveListToXMLSerializer(userList, usersPath);
            }
            else
            {
                throw new DO.BadUsernameException(user.UserName, $"User not found {user.UserName}");
            }
        }
Пример #6
0
        public void UpdateStation(DO.Station station)
        {
            var stationList = XmlTools.LoadListFromXMLSerializer <DO.Station>(stationPath);
            var stationToUp = stationList.Find(s => s.Code == station.Code);

            if (stationToUp != null && !stationToUp.IsDeleted)
            {
                stationList.Remove(stationToUp);
                stationList.Add(station);
                XmlTools.SaveListToXMLSerializer(stationList, stationPath);
            }
            else
            {
                throw new DO.BadStationException(station.Code, "Station not found");
            }
        }
Пример #7
0
        public void UpdateLine(DO.Line line)
        {
            var lineList = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);
            var lineToUp = lineList.Find(l => l.Id == line.Id);

            if (lineToUp != null && !lineToUp.IsDeleted)
            {
                lineList.Remove(lineToUp);
                lineList.Add(line);
                XmlTools.SaveListToXMLSerializer(lineList, linesPath);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
Пример #8
0
        public int AddLineTrip(DO.LineTrip lineTrip)
        {
            var counters = XmlTools.LoadListFromXMLSerializer <int>(countersPath);

            DalApi.Counters.LineTripCounter = counters[1];

            lineTrip.Id = DalApi.Counters.LineTripCounter;

            counters[1] = lineTrip.Id;
            XmlTools.SaveListToXMLSerializer(counters, countersPath);

            var lineTripList = XmlTools.LoadListFromXMLSerializer <DO.LineTrip>(linesTripPath);

            lineTripList.Add(lineTrip);
            XmlTools.SaveListToXMLSerializer(lineTripList, linesTripPath);
            return(lineTrip.Id);
        }
Пример #9
0
        public void AddAdjacentStations(DO.AdjacentStations adjacentStations)
        {
            var adjacentStationsList = XmlTools.LoadListFromXMLSerializer <DO.AdjacentStations>(adjacentStationsPath);
            var adst = adjacentStationsList.Find(s =>
                                                 s.Station1 == adjacentStations.Station1 && s.Station2 == adjacentStations.Station2);

            if (adst != null)
            {
                if (!adst.IsDeleted)
                {
                    throw new DO.BadAdjacentStationsException(adjacentStations.Station1, adjacentStations.Station2,
                                                              "Duplicate adjacent stations");
                }
            }
            adjacentStationsList.Add(adjacentStations);
            XmlTools.SaveListToXMLSerializer(adjacentStationsList, adjacentStationsPath);
        }
Пример #10
0
        public void UpdateLineStation(DO.LineStation lineStation)
        {
            var lineStationList = XmlTools.LoadListFromXMLSerializer <DO.LineStation>(lineStationsPath);
            var ls = lineStationList.Find(s => s.Station == lineStation.Station &&
                                          s.LineId == lineStation.LineId);

            if (ls != null && !ls.IsDeleted)
            {
                lineStationList.Remove(ls);
                lineStationList.Add(lineStation);
                XmlTools.SaveListToXMLSerializer(lineStationList, lineStationsPath);
            }
            else
            {
                throw new DO.BadLineStationException(lineStation.Station,
                                                     lineStation.LineId, "Station line not found");
            }
        }
Пример #11
0
        public void RemoveLine(DO.Line line)
        {
            var lineList  = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);
            var lineToRem = lineList.Find(l => l.Id == line.Id);

            if (lineToRem != null && !lineToRem.IsDeleted)
            {
                GetAllLineStationBy(ls => ls.LineId == lineToRem.Id).ToList().ForEach(RemoveLineStationOnRemoveline);
                lineList.Remove(lineToRem);
                lineToRem.IsDeleted = true;
                lineList.Add(lineToRem);
                XmlTools.SaveListToXMLSerializer(lineList, linesPath);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
Пример #12
0
        public int AddLine(DO.Line line)
        {
            var counters = XmlTools.LoadListFromXMLSerializer <int>(countersPath);

            DalApi.Counters.LineCounter = counters[0];

            line.Id = DalApi.Counters.LineCounter;

            counters[0] = line.Id;
            XmlTools.SaveListToXMLSerializer(counters, countersPath);

            var lineList = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);

            lineList.Add(line);
            XmlTools.SaveListToXMLSerializer(lineList, linesPath);

            return(line.Id);
        }
Пример #13
0
        public void UpdateAdjacentStations(DO.AdjacentStations adjacentStations)
        {
            var adjacentStationsList = XmlTools.LoadListFromXMLSerializer <DO.AdjacentStations>(adjacentStationsPath);
            var adst =
                adjacentStationsList.Find(s => s.Station1 == adjacentStations.Station1 &&
                                          s.Station2 == adjacentStations.Station2);

            if (adst != null && !adst.IsDeleted)
            {
                adjacentStationsList.Remove(adst);
                adjacentStationsList.Add(adjacentStations);
                XmlTools.SaveListToXMLSerializer(adjacentStationsList, adjacentStationsPath);
            }
            else
            {
                throw new DO.BadAdjacentStationsException(adjacentStations.Station1, adjacentStations.Station2
                                                          , "Adjacent Stations not found");
            }
        }
Пример #14
0
        public void RemoveStation(DO.Station station)
        {
            var stationList  = XmlTools.LoadListFromXMLSerializer <DO.Station>(stationPath);
            var stationToRem = stationList.Find(s => s.Code == station.Code);

            if (stationToRem != null && !stationToRem.IsDeleted)
            {
                GetAllLineStationBy(s => s.Station == stationToRem.Code).ToList().ForEach(RemoveLineStation);
                GetAllAdjacentStationsBy(s => s.Station1 == stationToRem.Code ||
                                         s.Station2 == stationToRem.Code).ToList().ForEach(RemoveAdjacentStations);

                stationList.Remove(stationToRem);
                stationToRem.IsDeleted = true;
                stationList.Add(stationToRem);
                XmlTools.SaveListToXMLSerializer(stationList, stationPath);
            }
            else
            {
                throw new DO.BadStationException(station.Code, "Station not found");
            }
        }