private void Add_Click(object sender, EventArgs e) { try { trainList.Add(textBox1.Text, Convert.ToInt32(textBox2.Text), TimeSpan.Parse(textBox3.Text)); TrainSortAndFind trainSort = new TrainSortAndFind("Ost", trainList); trainList = trainSort.Sort(); update(); } catch (Exception) { MessageBox.Show("Неверные данные", "Error", MessageBoxButtons.OK); } }
private void LoadBoard(int players) { if (_imageBoard !.PrivateList.Count == 0) { throw new BasicBlankException("Sorry; there are no items on the private list. Run FirstLoad first before loading the board"); } if (TrainList.Count > 0) { throw new BasicBlankException("There are already items on the train list"); } if (Self > 7) { throw new BasicBlankException("The self player has to be between 1 and 7"); } CustomBasicList <int> newList; if (players == 2) { newList = new CustomBasicList <int>() { 1, 3, 6 }; } else if (players == 3) { newList = new CustomBasicList <int>() { 1, 3, 6, 8 }; } else if (players == 4) { newList = new CustomBasicList <int>() { 1, 2, 3, 6, 8 }; } else if (players == 5) { newList = new CustomBasicList <int>(); for (var x = 1; x <= 5; x++) { newList.Add(x); } newList.Add(8); } else if (players == 6) { newList = new CustomBasicList <int>(); for (var x = 1; x <= 6; x++) { newList.Add(x); } newList.Add(8); } else if (players == 7) { newList = GetIntegerList(1, 8); } else { throw new BasicBlankException("Sorry; the new list does not match. Find out what happened"); } for (var x = 1; x <= players + 1; x++) { TrainInfo thisTrain = new TrainInfo(); thisTrain.Index = newList[x - 1]; if (x == players + 1) { thisTrain.TrainUp = true; thisTrain.IsPublic = true; } TrainList.Add(thisTrain); } RepaintBoard(); }
public void refreshTrains() { lock (this) { if (!String.IsNullOrEmpty(id_)) { JArray tok = commander_.exec <JArray>("TrainInterface", "getTrains", true, id_); if (tok != null) { JEnumerable <JToken> children = tok.Children(); HashSet <string> seen = new HashSet <string>(); foreach (JToken child in children) { if (child is JObject) { string id = child["ID"].ToString(); seen.Add(id); Train train = null; if (trains_.Any(t => t.Id == id)) { train = trains_.First(t => t.Id == id); train.refresh(child); } else { train = new Train(commander_, child); trains_.Add(train); } } else { Debug.Print("Unexpected data in get all trains responce:\n{0}", child.ToString()); } } IEnumerable <Train> deleted = trains_.Where(t => !seen.Contains(t.Id)); //Debug.Print("Removed trains count {0}", deleted.Count()); foreach (Train old in deleted) { trains_.Remove(old); } Dictionary <string, int> routes = new Dictionary <string, int>(); foreach (Train train in trains_) { string loadSummary = train.Load.ToString(); if (routes.ContainsKey(loadSummary)) { routes[loadSummary] += 1; } else { routes.Add(loadSummary, 1); } } StringBuilder summary = new StringBuilder(); foreach (KeyValuePair <string, int> rt in routes) { if (summary.Length > 0) { summary.Append("\n"); } summary.Append(String.Format("{0} - {1}", rt.Key, rt.Value)); } RouteSummary = summary.ToString(); OnPropertyChanged("TrainList"); OnPropertyChanged("AvgReliability"); refreshWaggons(); } } } }
internal void AddTrain(Train add) { TrainList.Add(add); }