예제 #1
0
        public DO.AdjacentStations GetAdjacentStations(int station1, int station2)
        {
            var adjacentStationsList = XmlTools.LoadListFromXMLSerializer <DO.AdjacentStations>(adjacentStationsPath);
            var adst = adjacentStationsList.Find(s =>
                                                 s.Station1 == station1 && s.Station2 == station2);

            if (adst != null && !adst.IsDeleted)
            {
                return(adst);
            }
            throw new DO.BadAdjacentStationsException(station1, station2,
                                                      "Adjacent stations not found");
        }
예제 #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 DO.Line GetLine(int lineId)
        {
            var lineList = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);
            var line     = lineList.Find(l => l.Id == lineId);

            if (line != null && !line.IsDeleted)
            {
                return(line);
            }
            else
            {
                throw new DO.BadLineException(lineId, "Line not found");
            }
        }
예제 #5
0
        public DO.LineTrip GetLineTrip(int id)
        {
            var lineTripList = XmlTools.LoadListFromXMLSerializer <DO.LineTrip>(linesTripPath);
            var lineTrip     = lineTripList.Find(b => b.Id == id);

            if (lineTrip != null)
            {
                return(lineTrip);
            }
            else
            {
                throw new DO.BadLineTripException(id, "line trip not found");
            }
        }
예제 #6
0
        public DO.User GetUser(string userName)
        {
            var userList = XmlTools.LoadListFromXMLSerializer <DO.User>(usersPath);
            var user     = userList.Find(u => u.UserName == userName);

            if (user != null && !user.IsDeleted)
            {
                return(user);
            }
            else
            {
                throw new DO.BadUsernameException(userName, $"User not found {userName}");
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
        public DO.Station GetStation(int code)
        {
            var stationList = XmlTools.LoadListFromXMLSerializer <DO.Station>(stationPath);

            var station = stationList.Find(s => s.Code == code);

            if (station != null && !station.IsDeleted)
            {
                return(station);
            }
            else
            {
                throw new DO.BadStationException(code, "Station not found");
            }
        }
예제 #9
0
        public DO.LineStation GetLineStation(int stationCode, int lineId)
        {
            var lineStationList = XmlTools.LoadListFromXMLSerializer <DO.LineStation>(lineStationsPath);
            var lineStation     =
                lineStationList.Find(s => s.Station == stationCode && s.LineId == lineId);

            if (lineStation != null && !lineStation.IsDeleted)
            {
                return(lineStation);
            }
            else
            {
                throw new DO.BadLineStationException(stationCode, lineId, "Station Line not found");
            }
        }
예제 #10
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");
            }
        }
예제 #11
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");
            }
        }
예제 #12
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}");
            }
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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");
            }
        }
예제 #16
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);
        }
예제 #17
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");
            }
        }
예제 #18
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");
            }
        }
예제 #19
0
        public IEnumerable <DO.Bus> GetAllBuss()
        {
            var bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);
            var list         = from b in bussRootElem.Elements()
                               where !bool.Parse(b.Element("IsDeleted").Value)
                               select new DO.Bus()
            {
                LicenseNum               = int.Parse(b.Element("LicenseNum").Value),
                FromDate                 = DateTime.Parse(b.Element("FromDate").Value),
                FuelRemain               = double.Parse(b.Element("FuelRemain").Value),
                IsDeleted                = bool.Parse(b.Element("IsDeleted").Value),
                KilometersAfterFueling   = double.Parse(b.Element("KilometersAfterFueling").Value),
                KilometersAfterTreatment = double.Parse(b.Element("KilometersAfterTreatment").Value),
                LastTreatment            = DateTime.Parse(b.Element("LastTreatment").Value),
                Status    = (DO.BusStatus)Enum.Parse(typeof(DO.BusStatus), b.Element("Status").Value),
                TotalTrip = double.Parse(b.Element("TotalTrip").Value)
            };

            return(list);
        }
예제 #20
0
        public void UpdateBus(DO.Bus bus)
        {
            XElement bussRootElem = XmlTools.LoadListFromXMLElement(bussPath);

            var busNode = (from b in bussRootElem.Elements()
                           where b.Element("LicenseNum").Value == bus.LicenseNum.ToString()
                           select b).FirstOrDefault();

            if (busNode == null)
            {
                throw new DO.BadBusException(0, "bus not found");
            }
            if (busNode.Element("IsDeleted").Value == true.ToString())
            {
                throw new DO.BadBusException(bus.LicenseNum, "bus not found");
            }

            busNode.UpdateElement(bus);
            XmlTools.SaveListToXMLElement(bussRootElem, bussPath);
        }
예제 #21
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");
            }
        }