Exemplo n.º 1
0
        private void AddLineButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string error = "";
                if (tbLineNumber.Text.Length == 0)
                {
                    error += "חייב למלא מספר קו\n";
                }

                if (cbArea.SelectedIndex == -1)
                {
                    error += "חייב לבחור אזור\n";
                }

                if (LineStationsListBox.Items.Count < 2)
                {
                    error += "אין מספיק תחנות בקו\n";
                }

                if (error != "")
                {
                    MessageBox.Show(error);
                    return;
                }

                busLine     = new BusLine();
                DataContext = busLine;

                busLine.AllStationsOfLine = from string item in LineStationsListBox.Items
                                            select int.Parse(item.Substring(6, 5));

                busLine.BusLineNumber   = int.Parse(tbLineNumber.Text);
                busLine.Area            = (BO.Areas)cbArea.SelectedItem;
                busLine.FirstStationKey = busLine.AllStationsOfLine.First();
                busLine.LastStationKey  = busLine.AllStationsOfLine.Last();

                bl.AddBusLine(busLine);
                LineStationsListBox.Items.Clear();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error thrown: " + ex);
            }
        }
        /// <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);
                }
            }
        }
Exemplo n.º 3
0
        private void AddLineButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                myLine.AllStationsOfLine = from string item in LineStationsListBox.Items
                                           select int.Parse(item.Substring(6, 5));

                myLine.FirstStationKey    = myLine.AllStationsOfLine.First();
                myLine.LastStationKey     = myLine.AllStationsOfLine.Last();
                myLine.AllLineTripsOfLine = listLineTrips;
                bl.AddBusLine(myLine);

                myLine = new BusLine();
                lineDetailsGrid.DataContext = myLine;
                listLineTrips.Clear();
                lineTripDataGrid.ItemsSource = listLineTrips;
                LineStationsListBox.Items.Clear();
            }
            catch (DuplicateLineException ex)
            {
                MessageBox.Show(ex.Message, "אירעה שגיאה", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            bl = BlFactory.GetBL();
            dl = DalFactory.GetDal();

            foreach (DO.BusStation item in dl.GetAllStationsBy(s => s.BusStationKey == 38831))
            {
                Console.WriteLine(item);
            }

            foreach (DO.LineStation item in dl.GetAllLineStationsBy(s => s.StationKey == 38831))
            {
                Console.WriteLine(item);
            }

            BusStation stationTest = bl.GetBusStation(38831);

            Console.WriteLine(stationTest);
            Console.ReadKey();
            foreach (BusStation item in bl.GetAllBusStations())
            {
                Console.WriteLine(item);
            }
            try
            {
                bl.AddStation(new BusStation {
                    Address = "testAdresse", BusStationKey = 12345, StationName = "testNom",
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            foreach (BusStation item in bl.GetAllBusStations())
            {
                Console.WriteLine(item);
            }
            bl.DeleteStation(12345);
            foreach (BusStation item in bl.GetAllBusStations())
            {
                Console.WriteLine(item);
            }
            //bl.UpdateBusStation(new BusStation { Address = "MonNewtestAdresse", BusStationKey = 12345, StationName = "2etestNom" });
            //bl.UpdateBusStation(12345, testVoid); Need to define function's body
            //void testVoid (BusStation myStation)
            //{
            //    myStation.BusStationKey = 45678;
            //}
            Console.WriteLine(bl.GetBusLine(30, DO.Areas.Jerusalem));
            List <int> test = (from item in dl.GetAllStationsBy(s => s.BusStationKey < 39020)
                               select bl.BusStationDoBoAdapter(item).BusStationKey).ToList();

            BO.BusLine lineToTest = new BusLine
            {
                Area              = BO.Areas.Center,
                BusLineNumber     = 52,
                FirstStationKey   = 38831,
                LastStationKey    = 39093,
                AllStationsOfLine = test
            };
            bl.AddBusLine(lineToTest);
            foreach (BusLine item in bl.GetAllBusLines())
            {
                Console.WriteLine(item);
            }
            bl.DeleteBusLine(lineToTest);
            foreach (BusLine item in bl.GetAllBusLines())
            {
                Console.WriteLine(item);
            }
            IEnumerable <LineStation> lineStatTest = bl.GetAllLineStationsBy(s => s.LineId == 52);

            foreach (LineStation item in bl.GetAllLineStationsBy(s => s.LineId == 52))
            {
                Console.WriteLine(item);
            }
            if (lineStatTest == null) //line stations doesn't exist but lineStatTest != null and not write "bravo"...!?
            {
                Console.WriteLine("bravo");
            }
            foreach (BusLine item in bl.GetAllBusLinesBy(l => l.BusLineNumber % 2 == 0))
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }