public void UpdateBusStatus(int status, long licenseNumber)
        {
            //***************************CONVERT INT TO STATUS!!!!!!!!!!!!!************
            status update;

            switch (status)
            {
            case 0:
                update = DO.status.TRAVELING;
                break;

            case 1:
                update = DO.status.READY_FOR_DRIVE;
                break;

            case 2:
                update = DO.status.TREATING;
                break;

            case 3:
                update = DO.status.REFULING;
                break;

            default:
                throw new Exception("wrong status!!");
            }

            List <Bus> BusesList = XMLTools.LoadListFromXMLSerializer <Bus>(busesPath);

            GetBus(licenseNumber); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusesList.Find(p => p.LicenseNumber == licenseNumber).Status = update;
            XMLTools.SaveListToXMLSerializer(BusesList, busesPath);
        }
        public void CreateBus(Bus bus)
        {
            List <Bus> BusesList = XMLTools.LoadListFromXMLSerializer <Bus>(busesPath);

            bus.Valid = true;
            Bus a = new Bus();

            try
            {
                a = GetBus(bus.LicenseNumber);
            }
            catch (DOBadBusIdException ex)                                             //try "BusException" and check if it work.
            {
                if (ex.Message == "no bus with such license number!!")
                {
                    BusesList.Add(bus);
                }
                else if (ex.Message == "bus is not valid!!")
                {
                    BusesList.Find(bus1 => bus1.LicenseNumber == bus.LicenseNumber).Valid = true;
                }
                XMLTools.SaveListToXMLSerializer(BusesList, busesPath);
                return;
            }
            throw new DOBadBusIdException(bus.LicenseNumber, "bus already exists!!!");
        }
        /// <summary>
        ///add new line to database
        /// </summary>
        /// <param name="line"></param>
        public void CreateLine(Line line)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            //line.Id = Configuration.LineCounter + 10;//בקובץ אקסממל יש כבר
            line.Id = LineList.Count() + 11;
            try
            {
                GetLineByNumber(line.Number);
            }
            catch (DOBadLineIdException ex)
            {
                if (ex.Message == "line doesn't  exist!!")
                {
                    LineList.Add(line);
                }

                else if (ex.Message == "line is not valid!!")
                {
                    LineList.Find(line1 => line1.Number == line.Number).Valid = true;
                }
                XMLTools.SaveListToXMLSerializer(LineList, linesPath);
                return;
            }
            throw new DOBadLineIdException(line.Id, "line already exists!!!");
        }
Beispiel #4
0
        /// <summary>
        /// add new userTravel to database
        /// </summary>
        /// <param name="userTravel"></param>
        public void CreateUserTravel(UserTravel userTravel)
        {
            List <UserTravel> UserTravelList = XMLTools.LoadListFromXMLSerializer <UserTravel>(userTravelPath);

            userTravel.Valid = true;

            try
            {
                GetUserTravel(userTravel.IdTravel);
            }
            catch (Exception ex)
            {
                if (ex.Message == "no user with such license number!!")
                {
                    UserTravelList.Add(userTravel);
                }
                else if (ex.Message == "bus is not valid!!")
                {
                    UserTravelList.Find(ut => ut.IdTravel == userTravel.IdTravel).Valid = true;
                }
                XMLTools.SaveListToXMLSerializer(UserTravelList, userTravelPath);
                return;
            }

            throw new Exception("user already exists!!!");
        }
Beispiel #5
0
        public void CreateBusTravel(BusTravel busTravel)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);

            busTravel.Valid = true;
            // busTravel.Id = Configuration.Bus_TravelCounter + 20; //בקובץ אקסממל יש כבר 20 "אוטובוסים בנסיעה
            try
            {
                //  GetBusTravel(busTravel.Id);
                var id = RequestBusTravel(bt => bt.FormalDepartureTime == busTravel.FormalDepartureTime && bt.LineId == busTravel.LineId).Id;
            }
            catch (Exception ex)
            {
                if (ex.Message == "no busTravel with such Id!!")
                {
                    busTravel.Id = Configuration.Bus_TravelCounter;
                    BusTravelList.Add(busTravel);
                }
                else if (ex.Message == "busTravel is not valid!!")
                {
                    BusTravelList.Find(busTravelInput => busTravelInput.Id == busTravel.Id).Valid = true;
                }
                XMLTools.SaveListToXMLSerializer(BusTravelList, busTravelsPath);
                return;
            }
            throw new Exception("busTravel already exists!!!");
        }
        /// <summary>
        /// update name in database
        /// </summary>
        /// <param name="name"></param>
        /// <param name="licenseNumber"></param>
        public void UpdateStopName(string name, long code)
        {
            List <Stop> StopList = XMLTools.LoadListFromXMLSerializer <Stop>(stopsPath);

            try
            {
                Stop temp = RequestStop(myStop => myStop.StopName == name);
            }
            catch (DOStopException exc)
            {
                if (exc.Message == "no stop that meets these conditions!")
                {
                    try
                    {
                        StopList.Find(stopInput => stopInput.StopCode == code).StopName = name;
                        XMLTools.SaveListToXMLSerializer(StopList, stopsPath);
                        return;
                    }
                    catch (DOStopException ex)
                    {
                        throw new DOBadStopIdException(code, ex.Message);
                    }
                }
            }
        }
        public User GetUser(string nameId)
        {
            XElement userRootElem = XMLTools.LoadListFromXMLElement(usersPath);

            User myUser = (from temUser in userRootElem.Elements()
                           where temUser.Element("UserName").Value == nameId
                           select new User()
            {
                Valid = bool.Parse(temUser.Element("Valid").Value),
                UserName = temUser.Element("UserName").Value,
                Password = temUser.Element("Password").Value,
                Permission = (DO.authority)authority.Parse(typeof(authority), temUser.Element("Permission").Value)
            }
                           ).FirstOrDefault();

            if (myUser == null)
            {
                throw new DO.DOBadUserIdException("", "no user with such UserName!!");
            }
            if (!myUser.Valid)
            {
                throw new Exception("user is not valid!!");
            }
            return(myUser);
        }
        /// <summary>
        /// add new line departure to database
        /// </summary>
        /// <param name="lineDeparture"></param>
        public void CreateLineDeparture(LineDeparture lineDeparture)
        {
            List <LineDeparture> LineDepartureList = XMLTools.LoadListFromXMLSerializer <LineDeparture>(lineDeparturesPath);

            LineDepartureList.Add(lineDeparture);
            XMLTools.SaveListToXMLSerializer(LineDepartureList, lineDeparturesPath);
        }
        /// <summary>
        /// add new lineStation to database
        /// </summary>
        /// <param name="lineStation"></param>
        public void CreateLineStation(LineStation lineStation)
        {
            List <LineStation> LineStationList = XMLTools.LoadListFromXMLSerializer <LineStation>(lineStationsPath);

            LineStationList.Add(lineStation);
            XMLTools.SaveListToXMLSerializer(LineStationList, lineStationsPath);
        }
        /// <summary>
        /// update time_End in database
        /// </summary>
        /// <param name="id"></param>
        /// <param name="time_Start"></param>
        /// <param name="time_End"></param>
        public void UpdateLineDepartureTime_End(long id, DateTime time_Start, DateTime time_End)
        {
            List <LineDeparture> LineDepartureList = XMLTools.LoadListFromXMLSerializer <LineDeparture>(lineDeparturesPath);

            GetLineDeparture(id, time_Start); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות
            LineDepartureList.Find(p => (p.Id == id) && (p.TimeStart == time_Start)).TimeEnd = time_End;
            XMLTools.SaveListToXMLSerializer(LineDepartureList, lineDeparturesPath);
        }
        /// <summary>
        /// update numberInLine in database
        /// </summary>
        /// <param name="numberInLine"></param>
        /// <param name="code"></param>
        /// <param name="lineId"></param>
        public void UpdateLineStationNumberInLine(long numberInLine, long code, long lineId) //?
        {
            List <LineStation> LineStationList = XMLTools.LoadListFromXMLSerializer <LineStation>(lineStationsPath);

            GetLineStation(code, lineId, numberInLine);
            LineStationList.Find(p => (p.Code == code) && (p.LineId == lineId)).NumberInLine = numberInLine;
            XMLTools.SaveListToXMLSerializer(LineStationList, lineStationsPath);
        }
        public void DeleteBus(long licenseNumber)
        {
            List <Bus> BusesList = XMLTools.LoadListFromXMLSerializer <Bus>(busesPath);

            GetBus(licenseNumber); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusesList.Find(p => p.LicenseNumber == licenseNumber).Valid = false;
            XMLTools.SaveListToXMLSerializer(BusesList, busesPath);
        }
Beispiel #13
0
        /// <summary>
        /// sets user travel valid to false
        /// </summary>
        /// <param name="userTravel"></param>
        public void DeleteUserTravel(long id)
        {
            List <UserTravel> UserTravelList = XMLTools.LoadListFromXMLSerializer <UserTravel>(userTravelPath);

            GetUserTravel(id); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            UserTravelList.Find(p => p.IdTravel == id).Valid = false;
            XMLTools.SaveListToXMLSerializer(UserTravelList, userTravelPath);
        }
        public void UpdateBusFuel(float fuel, long licenseNumber)
        {
            List <Bus> BusesList = XMLTools.LoadListFromXMLSerializer <Bus>(busesPath);

            GetBus(licenseNumber); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusesList.Find(p => p.LicenseNumber == licenseNumber).Fuel = fuel;
            XMLTools.SaveListToXMLSerializer(BusesList, busesPath);
        }
        public void CreateOppositeDirectionLine(Line line)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            line.Valid = true;
            line.Id    = Configuration.LineCounter + 10;
            LineList.Add(line);
            XMLTools.SaveListToXMLSerializer(LineList, linesPath);
        }
Beispiel #16
0
        public void UpdateRealDepartureTime(DateTime realDepartureTime, long id)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);

            GetBusTravel(id); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusTravelList.Find(p => p.Id == id).RealDepartureTime = realDepartureTime;
            XMLTools.SaveListToXMLSerializer(BusTravelList, busTravelsPath);
        }
        /// <summary>
        /// update lastStop in database
        /// </summary>
        /// <param name="lastStop"></param>
        /// <param name="id"></param>
        public void UpdateLineLastStop(long lastStop, long id)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            GetLine(id);
            LineList.Find(p => p.Id == id).LastStop = lastStop;

            XMLTools.SaveListToXMLSerializer(LineList, linesPath);
        }
        /// <summary>
        /// deletes a line
        /// </summary>
        /// <param name="id"></param>
        public void DeleteLine(long id)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            GetLine(id);
            LineList.Find(p => p.Id == id).Valid = false;

            XMLTools.SaveListToXMLSerializer(LineList, linesPath);
        }
        /// <summary>
        /// update in database
        /// </summary>
        /// <param name="number"></param>
        /// <param name="id"></param>
        public void UpdateLineNumber(long number, long id)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            GetLine(id);
            LineList.Find(p => p.Id == id).Number = number;

            XMLTools.SaveListToXMLSerializer(LineList, linesPath);
        }
        public void UpdateLineArea(string area, long id)
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            GetLine(id);
            LineList.Find(p => p.Id == id).Area = area;

            XMLTools.SaveListToXMLSerializer(LineList, linesPath);
        }
Beispiel #21
0
        public void DeleteBusTravel(long id)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);

            GetBusTravel(id); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusTravelList.Find(p => p.Id == id).Valid = false;
            XMLTools.SaveListToXMLSerializer(BusTravelList, busTravelsPath);
        }
Beispiel #22
0
        public void UpdateDriverId(string driverId, long id)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);

            GetBusTravel(id); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusTravelList.Find(p => p.Id == id).DriverId = driverId;
            XMLTools.SaveListToXMLSerializer(BusTravelList, busTravelsPath);
        }
Beispiel #23
0
        public void UpdateLastPassedStop(long lastPassedStop, long id)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);

            GetBusTravel(id); // בודק אם קיים אוטובוס כזה אם לא זורק חריגות

            BusTravelList.Find(p => p.Id == id).LastPassedStop = lastPassedStop;
            XMLTools.SaveListToXMLSerializer(BusTravelList, busTravelsPath);
        }
        public IEnumerable <Bus> GetAllBusses()
        {
            List <Bus> BusesList = XMLTools.LoadListFromXMLSerializer <Bus>(busesPath);
            var        temList   = new List <Bus>();

            foreach (Bus bus in BusesList)
            {
                if (bus.Valid == true)
                {
                    temList.Add(bus);
                }
            }
            return(temList);
        }
Beispiel #25
0
        public IEnumerable <BusTravel> GetAllBusTravels(Predicate <BusTravel> pr = null)
        {
            List <BusTravel> BusTravelList = XMLTools.LoadListFromXMLSerializer <BusTravel>(busTravelsPath);
            var temList = new List <BusTravel>();

            foreach (BusTravel busTravel in BusTravelList)
            {
                if (busTravel.Valid == true)
                {
                    temList.Add(busTravel);
                }
            }
            return(temList);
        }
        /// <summary>
        /// gets all line stations
        /// </summary>
        /// <param name="pr"></param>
        /// <returns></returns>
        public IEnumerable <LineStation> GetAllLineStations(Predicate <LineStation> pr = null)
        {
            List <LineStation> LineStationList = XMLTools.LoadListFromXMLSerializer <LineStation>(lineStationsPath);
            var temList = new List <LineStation>();

            foreach (LineStation lineStation in LineStationList)
            {
                if (lineStation.Valid == true)
                {
                    temList.Add(lineStation);
                }
            }
            return(temList);
        }
Beispiel #27
0
        /// <summary>
        /// gets all user travels according to predicate
        /// </summary>
        /// <param name="pr"></param>
        /// <returns></returns>
        public IEnumerable <UserTravel> GetAllUserTravels()
        {
            List <UserTravel> UserTravelList = XMLTools.LoadListFromXMLSerializer <UserTravel>(userTravelPath);

            var temList = new List <UserTravel>();

            foreach (UserTravel busTravel in UserTravelList)
            {
                if (busTravel.Valid == true)
                {
                    temList.Add(busTravel);
                }
            }
            return(temList);
        }
        /// <summary>
        /// request a Stop according to a predicate
        /// </summary>
        /// <param name="pr"></param>
        /// <returns></returns>
        public Stop RequestStop(Predicate <Stop> pr = null)
        {
            List <Stop> StopList = XMLTools.LoadListFromXMLSerializer <Stop>(stopsPath);
            Stop        ret      = StopList.Find(stop => pr(stop));

            if (ret == null)
            {
                throw new DOStopException("no stop that meets these conditions!");
            }
            if (ret.Valid == false)
            {
                throw new DOStopException("stop that meets these conditions is not valid");
            }
            return(ret);
        }
        /// <summary>
        /// gets all stops
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Stop> GetAllStops()
        {
            List <Stop> StopList = XMLTools.LoadListFromXMLSerializer <Stop>(stopsPath);

            var myList = new List <Stop>();

            foreach (Stop stop in StopList)
            {
                if (stop.Valid == true)
                {
                    myList.Add(stop);
                }
            }
            return(myList);
        }
        /// <summary>
        /// gets all lines
        /// </summary>
        /// <returns></returns>

        public IEnumerable <Line> GetAllLines()
        {
            List <Line> LineList = XMLTools.LoadListFromXMLSerializer <Line>(linesPath);

            var temList = new List <Line>();

            foreach (Line line in LineList)
            {
                if (line.Valid == true)
                {
                    temList.Add(line);
                }
            }
            return(temList);
        }