예제 #1
0
 public void UpdateBusLine(int id, Action <DO.BusLine> action)
 {
     try
     {
         BO.BusLine line = GetBusLine(id);
         dl.UpdateLine(BusLineBoDoAdapter(line), action);
     }
     catch
     {
         throw new ArgumentException("This Line not exist " + id);
     }
 }
예제 #2
0
 public void DeleteBusLine(BO.BusLine lineBo)
 {
     try
     {
         dl.DeleteLine(BusLineBoDoAdapter(lineBo));
         dl.DeleteLineStation(s => s.LineId == lineBo.Id);
     }
     catch
     {
         throw new ArgumentException("This Line does not exist " + lineBo.BusLineNumber);
     }
 }
예제 #3
0
 public void UpdateBusLine(BO.BusLine line)
 {
     try
     {
         DeleteBusLine(line);
         AddBusLine(line);
         dl.UpdateLine(BusLineBoDoAdapter(line));
     }
     catch
     {
         throw new ArgumentException("This line does not exist " + line.BusLineNumber);
     }
 }
예제 #4
0
        public void AddBusLine(BO.BusLine newLine)
        {
            //1. Verify if all stations of list exists
            foreach (int item in newLine.AllStationsOfLine)
            {
                if (dl.GetStation(item) == null)
                {
                    throw new ArgumentException("Bus Station " + item + " doesn't exist. Please create station and then" +
                                                " add it to line");
                }
            }

            for (int i = 0; i < (newLine.AllStationsOfLine.Count() - 1); i++)
            {
                //2. Add FollowingStations if it's necessary
                DO.BusStation station1 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i));
                DO.BusStation station2 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i + 1));
                if (dl.GetFollowingStations(station1, station2) == null)
                {
                    dl.AddFollowingStations(station1, station2);
                }
            }

            dl.AddLine(BusLineBoDoAdapter(newLine));

            //3. Create corresponding line stations
            int lineId = dl.GetLine(newLine.BusLineNumber, AreasAdapter(newLine.Area)).Id;

            for (int i = 0; i < newLine.AllStationsOfLine.Count(); i++)
            {
                int stationKey = GetBusStation(newLine.AllStationsOfLine.ElementAt(i)).BusStationKey;
                if (GetLineStation(lineId, stationKey) == null)
                {
                    AddLineStation(new BO.LineStation
                    {
                        LineId     = lineId,
                        StationKey = stationKey,
                        RankInLine = i + 1
                    });
                }
            }
        }
예제 #5
0
        BO.BusLine BusLineDoBoAdapter(DO.BusLine lineDo)
        {
            BO.BusLine lineBo = new BO.BusLine();
            lineDo.CopyPropertiesTo(lineBo);

            DO.BusLine busLine = dl.GetLine(lineBo.BusLineNumber, AreasAdapter(lineBo.Area));
            List <int> request = (from station in dl.GetAllLineStationsBy(s => s.LineId == busLine.Id)
                                  orderby station.RankInLine
                                  select station.StationKey).ToList();

            lineBo.AllStationsOfLine = request;
            for (int i = 0; i < lineBo.AllStationsOfLine.Count() - 1; i++)
            {
                DO.BusStation station1 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i)));
                DO.BusStation station2 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i + 1)));

                lineBo.TotalDistance += dl.GetFollowingStations(station1, station2).Distance;
            }
            lineBo.TotalTime = lineBo.TotalDistance * 0.0012 * 0.5;
            return(lineBo);
        }
        /// <summary>
        /// Add the Line to the data
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">e of the argument</param>
        private void Add_Line(object sender, RoutedEventArgs e)
        {
            int    code;
            string message = "";

            if (!int.TryParse(LineCodeTB.Text, out code) || (newbusStationsList.Count < 2) || AreasCB.SelectedItem == null) // when some data is missing/invalid jumping massage to the user and asking it
            {
                if (!int.TryParse(LineCodeTB.Text, out code))
                {
                    message += "Please enter station's code!\n";
                }
                if (newbusStationsList.Count < 2)
                {
                    message += "Please choose 2 station at least!\n";
                }
                if (AreasCB.SelectedItem == null)
                {
                    message += "Please choose area!\n";
                }
                MessageBox.Show(message, "Invalid input", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                BO.BusLine line = new BO.BusLine();
                line.Area         = (BO.Areas)AreasCB.SelectedItem;
                line.LineNumber   = int.Parse(LineCodeTB.Text);
                line.LineStations = from station in newbusStationsList
                                    select bl.StationToLineStation(station);

                try
                {
                    bl.AddBusLine(line);
                    this.Close();
                }
                catch (BO.BusLineExists ex) // the BusLine already exists
                {
                    MessageBox.Show(ex.Message + string.Format(" Choose different line number than {0} or change it's route!", ex.LineNumber), "Object already exists", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #7
0
 public IEnumerable <BO.LineTrip> GetTripsForAStation(BO.BusLine line, BO.BusStation station)
 {
     return(from trip in dl.GetAllLineTrips()
            where trip.LineNumber == line.BusLineNumber && trip.StationKey == station.BusStationKey
            select LineTripDoBoAdapter(trip));
 }
예제 #8
0
 public IEnumerable <BO.LineTrip> GetTripsForABus(BO.BusLine line)
 {
     return(from trip in dl.GetAllLineTrips()
            where trip.LineNumber == line.BusLineNumber
            select LineTripDoBoAdapter(trip));
 }
예제 #9
0
 DO.BusLine BusLineBoDoAdapter(BO.BusLine lineBo)
 {
     DO.BusLine lineDo = new DO.BusLine();
     lineBo.CopyPropertiesTo(lineDo);
     return(lineDo);
 }