/// <summary> /// constractor of SUPER_BUS_LIST /// </summary> public SUPER_BUS_LIST() { m_BusCollection = (BusCollection)this; m_BusCollection.m_busList = new List <Bus>(); Program_6077_5711_02.initializeBusRoute(ref m_BusCollection, ref myUniqueStops); Random r = new Random(); foreach (BusRoute bus in m_BusCollection) { int i = 0; SUPER_BUS newMbus = new SUPER_BUS(0, 0, 0, new DateTime(), bus.m_Stations, bus.m_direction, bus.m_Area, bus.m_BusLine); comprehensiveCollection.Add(new SUPER_BUS(0, 0, 0, new DateTime(), bus.m_Stations, bus.m_direction, bus.m_Area, bus.m_BusLine) { m_fuel = r.Next(1200), m_licenseNum = r.Next(100000000), m_sum_Tr = ((float)r.NextDouble() + r.Next(1200)), m_yearStart = r.Next(1950, 2020), m_sum_Tr_Treat = r.Next(20000) }); } foreach (SUPER_BUS bus in comprehensiveCollection) { int a = r.Next(2020, 2024); int b = r.Next(11) + 1; int c = r.Next(29) + 1; bus.m_time_Treat = new DateTime(a, b, c); bus.m_fuel = r.Next(1200); m_BusCollection.m_busList.Add(bus); } SpecialInit(); }
/// <summary> /// busline input /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_6(object sender, RoutedEventArgs e) { TextRange textRange = new TextRange(MyTextBox6.Document.ContentStart, MyTextBox6.Document.ContentEnd); float result = 0; if (float.TryParse(textRange.Text, out result) && result > 0) { if (!input_6) { input_6 = true; amount++; inputBus.m_BusLine = (int)result; if (amount != 6) { MessageBox.Show("input submited " + result + " to exit click X", "input", MessageBoxButton.OK, MessageBoxImage.Information); } } } else { throw new SuperBusException("wrong input!!!!"); } List <BusStop> myUniqueStops = new List <BusStop>(); Program_6077_5711_02.initializeBus((BusRoute)inputBus, MainWindow.M_SUPER_BUS_LIST, myUniqueStops); inputBus.m_BusLine = (int)result; inputBus.m_direction = "A"; MainWindow.M_SUPER_BUS_LIST.comprehensiveCollection.Add(inputBus); MessageBox.Show(inputBus.m_BusLine + "A" + " is added!"); inputBus = new SUPER_BUS(); valid_Bus_List.temp = 0; }
/// <summary> /// event that responsible about a listBox called "SelectionChanged" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void busList_SelectionChanged(object sender, SelectionChangedEventArgs e) { string str = busList.SelectedItem?.ToString(); if (str != null) { currentDisplayBusLine = MainWindow.M_SUPER_BUS_LIST.FinDSuperBusByFullName(str); lbBusLineStations.DataContext = currentDisplayBusLine.Stations; areaTextChange.DataContext = currentDisplayBusLine.m_Area; areaTextChange.Text = currentDisplayBusLine.m_Area; if (currentDisplayBusLine.m_fuel < 1200 && currentDisplayBusLine.m_time_Treat >= DateTime.Now && currentDisplayBusLine.m_sum_Tr_Treat < 20000) { currentDisplayBusLine.m_ReadyForDrive = true; } if (currentDisplayBusLine.refuling == null) { valid_Bus_List.currentDisplayBusLine.refuling = new BackgroundWorker(); } if (currentDisplayBusLine.treating == null) { valid_Bus_List.currentDisplayBusLine.treating = new BackgroundWorker(); } //currentDisplayBusLine.refuling.RunWorkerAsync(12); } }
/// <summary> /// manage the treatment of a SUPER_BUS /// </summary> /// <param name="sbus"></param> /// <returns></returns> public string checkupT(SUPER_BUS sbus) { string messeg = ""; sbus.m_time_Treat = DateTime.Now; messeg = "success"; return(messeg); }
/// <summary> /// manage the fueling of a SUPER_BUS /// </summary> /// <param name="sbus"></param> /// <returns></returns> public string checkupF(SUPER_BUS sbus) { string messeg = ""; sbus.m_fuel = 0; messeg = "success"; return(messeg); }
/// <summary> /// Function to initialize the properties of project 1 randomly and add 4 unique busses /// </summary> /// <param name="myBusCollection"></param> //private void project1Init(ref BusCollection myBusCollection) //{ // Random r = new Random(); // foreach (BusRoute bus in myBusCollection) // { // SUPER_BUS newMbus = new SUPER_BUS(0,0,0,new DateTime(), bus.m_Stations,bus.m_direction,bus.m_Area,bus.m_BusLine); // comprehensiveCollection.Add(new SUPER_BUS(0, 0, 0, new DateTime(), bus.m_Stations, bus.m_direction, bus.m_Area, bus.m_BusLine) { m_fuel = r.Next(1200)}); // } //} /// <summary> /// remove a SUPER_BUS from SUPER_BUS_LIST /// </summary> /// <param name="sbus"></param> /// <returns></returns> public string remove(SUPER_BUS sbus) { string messeg = ""; int i = 0; for (; i < comprehensiveCollection.Count; i++) { if (sbus.m_licenseNum == comprehensiveCollection[i].m_licenseNum) { break; } } comprehensiveCollection.RemoveAt(i); return(messeg); }
/// manage the travel of a SUPER_BUS public string travel(int numKm, SUPER_BUS sbus) { string messeg = ""; if ((sbus.m_sum_Tr_Treat + numKm) > 20000 || (sbus.m_fuel + numKm) > 1200) { messeg = "can't do this travel - passed your limit!"; } else { messeg = "can't do this travel - passed your limit!"; sbus.m_sum_Tr_Treat += numKm; sbus.m_fuel += numKm; //update total travel sbus.m_sum_Tr += numKm; } return(messeg); }