/// <summary>
        /// an event to show the add line window
        /// </summary>

        public void AddBus_Click(object sender, RoutedEventArgs e)
        {
            AddBus addBus = new AddBus(true);

            if (addBus.ShowDialog() == true)
            {
                addBus.MyBus.Status(1);
                listBuses.Add(addBus.MyBus);
                bl.AddBus(addBus.MyBus);
            }
        }
 /// <summary>
 /// Add the bus to the data
 /// </summary>
 /// <param name="sender">sender of the event</param>
 /// <param name="e">e of the argument</param>
 private void AddBus(object sender, RoutedEventArgs e)
 {
     try
     {
         int    lic;
         double trip;
         if (date.SelectedDate == null || !int.TryParse(licTB.Text, out lic) || !double.TryParse(kmTB.Text, out trip)) // when some data is missing / Invalid  jumping massage to the user and asking it
         {
             string message = "";
             if (!int.TryParse(licTB.Text, out lic))
             {
                 message += "Please enter valid license!\n";
             }
             if (!double.TryParse(kmTB.Text, out trip))
             {
                 message += "Please enter valid distance!\n";
             }
             if (date.SelectedDate == null)
             {
                 message += "Please select a date!";
             }
             MessageBox.Show(message, "Invalid input", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         else
         {
             if (lic.ToString().Length < 7) // check the input license
             {
                 MessageBox.Show("License is too short!", "Input Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else if (lic.ToString().Length == 7 && bus.FromDate.Year >= 2018 || lic.ToString().Length == 8 && bus.FromDate.Year < 2018)
             {
                 MessageBox.Show("License is not align with the bus's year!", "Input Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else
             {
                 bus.LicenseNum = lic;
                 bus.TotalTrip  = trip;
                 bl.AddBus(bus);
                 this.Close();
             }
         }
     }
     catch (BO.BusExists ex) // the bus already exists
     {
         MessageBox.Show(ex.Message + string.Format("\nChoose different license than {0}", ex.License), "Invalid new object", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 3
0
 private void pbAddBus_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bl.AddBus(newBus);
         buses.Add(newBus); //if bl failed this wont execute
         this.Close();
     }
     catch (InvalidOperationException ex)
     {
         MessageBox.Show("You tried to add a bus that already exists!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show("You tried to add a bus that is invalid!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 4
0
 public Bus AddBus(AddBus newBus)
 {
     return(BL.AddBus(newBus));
 }