private void prepareListViewListOfStations() { // load throughStation's cache List <TrainStation> listStations = TrainStationCache.getInstance().getCacheContent(); // starting update list, protected before method Draw listViewListOfStations.BeginUpdate(); // clearStableLines previous list's items listViewListOfStations.Items.Clear(); // and prepare new list view accordind throughStation's cache foreach (TrainStation station in listStations) { ListViewItem lvi = new ListViewItem(); // fill item with throughStation's information lvi.Text = station.Id.ToString(); lvi.Tag = station.Id.ToString(); lvi.SubItems.Add(station.Name); lvi.SubItems.Add(station.TownCategory.ToString()); lvi.SubItems.Add(station.Inhabitation.ToString()); lvi.SubItems.Add(station.Town); // addConstraint item into the list listViewListOfStations.Items.Add(lvi); } // release list view listViewListOfStations.EndUpdate(); }
/// <summary> /// Updates the field town category for stations from file. /// </summary> /// <param name="fileName">Name of the file.</param> public static void updateStationDetailsFromFile(String fileName) { List <StationDetail> stationDetails = IOUtil.readTrainStationFromFile(fileName); foreach (StationDetail stationDetail in stationDetails) { // if station exits in train station cache if (TrainStationCache.getInstance().doesStationExist(stationDetail.StationName)) { // find station in cache TrainStation s = TrainStationCache.getInstance() .getCacheContentOnName(stationDetail.StationName); // copy inhabitation s.Inhabitation = stationDetail.Inhabitation; // update town category according inhabitation s.updateTownCategory(); if (stationDetail.MinimalTransferTime != Time.EmptyValue) { s.MinimalTransferTime = stationDetail.MinimalTransferTime; } if (stationDetail.Town != "") { s.Town = stationDetail.Town; } } } }
private void detailsStationOpen() { // if nothing selected if (listViewListOfStations.SelectedItems.Count.Equals(0)) { MessageBox.Show("Please, select the station.", "No station selected"); // if selected } else { Form formDetailsOfStation = new FormDetailsOfStation( TrainStationCache.getInstance().getCacheContentOnSelect( Convert.ToInt32( listViewListOfStations .SelectedItems[0] .Text ) ) ); // before calling subform - remember listView focus int selectedIndex = listViewListOfStations.SelectedIndices[0]; DialogResult dr = formDetailsOfStation.ShowDialog(); // if the subform closed by OK something may changed if (dr.Equals(DialogResult.OK)) { // then update list view comboBoxSelectLineChanged(); // refresh selection and focus on selected item FormUtil.listView_SelecdAndFocus(listViewListOfStations, selectedIndex); } } }
public Edge(int from_, int to_, Time time_, int distance_, int line_) { from = from_; fromStation = TrainStationCache.getInstance().getCacheContentOnSelect(from_); to = to_; toStation = TrainStationCache.getInstance().getCacheContentOnSelect(to_); time = time_; distance = distance_; line = line_; }
//-------------------------------------------- // create TrainLines //-------------------------------------------- private void createTrainLinesFromFiles() { // clearStableLines variableLines off previous run TrainLineCache.getInstance().clearContent(); // clearStableLines station off previous run TrainStationCache.getInstance().clearContent(); TrainLineCache lineCache = TrainLineCache.getInstance(); foreach (ListViewItem lvi in listViewLoadFiles.Items) { TrainLine line = IOUtil.readTrainLineFromFile(lvi.Tag.ToString()); // test if already exists if (TrainLineCache.getInstance().doesLineExist(line.LineNumber)) { } else { lineCache.addTrainLine(line); } } }
/// <summary> /// Creates the train stops. /// </summary> /// <param name="data">The data.</param> /// <param name="line">The line.</param> /// <returns>The train stops.</returns> private static List <TrainStop> createTrainStops(List <String[]> data, TrainLine line, out Time originalDepartureTime) { List <TrainStop> trainStops = new List <TrainStop>(); TrainStationCache stationCache = TrainStationCache.getInstance(); Int16 orderInLine = 0; String nameStation; Time departure; Time arrival; int kmFromStart; Time timeStart = Time.ToTime(data[0][2]);//Time.MinValue; // set original departure time originalDepartureTime = new Time(timeStart); Time timePrev = Time.MinValue; int kmPrev = 0; // foreach string[] createConstraintSet specific trainStop foreach (String[] str in data) { // if not correct number of stop details, take next stop if (str.Length != NUMBER_OF_STOP_DETAILS) { continue; } // createConstraintSet new stop TrainStop stop = new TrainStop(); // extract information about stop nameStation = str[0]; arrival = Time.ToTime(str[1]); departure = Time.ToTime(str[2]); kmFromStart = Convert.ToInt32(str[3]); // try toStation find out if throughStation already exists, if not, createConstraintSet appropriate throughStation if (!stationCache.doesStationExist(nameStation)) { // calculate new ID for new throughStation int id = stationCache.getCacheContent().Count; stationCache.addTrainStation(new TrainStation(id, nameStation)); // download new throughStation //stationCache = } // find appropriate throughStation TrainStation trainStation = stationCache.getCacheContentOnName(nameStation); // addConstraint linked line_ toStation throughStation trainStation.addTrainLine(line); stop.KmFromPreviousStop = kmFromStart - kmPrev; stop.KmFromStart = kmFromStart; stop.OrderInTrainLine = orderInLine; stop.TrainStation = trainStation; stop.TimeArrival = arrival - timeStart; stop.TimeDeparture = departure - timeStart; // if no arrival time_, count with departure if (arrival.Equals(Time.MinValue)) { stop.TimeFromPreviousStop = stop.TimeDeparture - timePrev; } //if arrival time_, use it else { stop.TimeFromPreviousStop = stop.TimeArrival - timePrev; } // set time_ and km for next stop timePrev = stop.TimeDeparture; kmPrev = stop.KmFromStart; orderInLine++; // addConstraint into final stops trainStops.Add(stop); } return(trainStops); }
/// <summary> /// Sets the default values for fields. /// </summary> private void setDefaultValues() { this.Timetables = new List <Timetable>(); this.TrainLines = TrainLineCache.getInstance().getCacheContent(); this.TrainStations = TrainStationCache.getInstance().getCacheContent(); }