static void Main(string[] args) { var formatter = new StandardFormatter(); var buildings = new List <IBuilding>(); var apartment = new Apartment(); apartment.Description = "Nice apartment."; apartment.Rooms.Add("1/A", "Cozy little room"); apartment.Rooms.Add("2/C", "To be renovated"); buildings.Add(apartment); var house = new House(); house.Address = "New Street"; house.Description = "Large family home."; house.Owner = "Mr. Smith."; buildings.Add(house); var trainStation = new TrainStation(); trainStation.Director = "Mr. Kovacs"; trainStation.Location = "Budapest"; trainStation.NumberOfPassangers = 100000; trainStation.NumberOfTrains = 100; buildings.Add(trainStation); foreach (var building in buildings) { building.Print(formatter); } Console.ReadKey(); }
public async Task <ObjectResult> UpdateTrainStationAsync([FromBody] GeneralTrainStationRequest request, [FromRoute] int id) { TrainStation result = _trainStationServices.TrainStationRepository.Update(request.ToDTO(id)); await _trainStationServices.CommitChanges(); return(Ok(result)); }
static void CheckDriverByNumber(TrainStation trainObject) { bool looper = true; while (looper) { if (trainObject.GetNumberOfdrivers() == 0) { Console.WriteLine("To do this you need to first create a station!"); break; } int driverNumber = 0; Console.WriteLine("Which drivers name do you want to see?"); try { driverNumber = Convert.ToInt32(Console.ReadLine()); } catch (System.FormatException e) { Console.WriteLine(e.Message); continue; } Console.WriteLine(trainObject.DiversName(driverNumber - 1) + " Is this the correct dirvers name? Y/N"); if (Console.ReadLine().ToLower() == "y") { looper = false; } } }
public FormAddStageDialog(TrainStation fromStation, TrainStation toStation) { InitializeComponent(); setDefaultValues(); startStation = fromStation; finalStation = toStation; }
public FormAddStageDialog(Stage previousStage_, TrainStation toStation) { InitializeComponent(); setDefaultValues(); previousStage = previousStage_; finalStation = toStation; }
private void HandleStationsRecreate(IList <List <HtmlNode> > rows, Train train, TrainInstance trainInstance) { List <string> stationNames = new List <string>(); train.TrainStations.Clear(); trainInstance?.TrainInstanceStations.Clear(); foreach (IList <HtmlNode> row in rows) { string stationName = row[1].InnerText.Trim(); string normName = Station.NormalizeName(stationName); stationNames.Add(normName); var(arrival, actualArrival) = Parsing.GetCellTimes(row[2]); var(departure, actualDeparture) = Parsing.GetCellTimes(row[3]); var platform = row.Count == 5 ? row[4].InnerText.Trim() : null; var trainStation = new TrainStation { Train = train, Ordinal = train.TrainStations.Count, Station = new Station() { Name = stationName, NormName = normName }, Arrival = arrival, Departure = departure, Platform = string.IsNullOrEmpty(platform) ? null : platform }; train.TrainStations.Add(trainStation); if (trainInstance != null) { var trainInstanceStation = new TrainInstanceStation { TrainInstance = trainInstance, TrainStation = trainStation, ActualArrival = actualArrival, ActualDeparture = actualDeparture }; trainInstance.TrainInstanceStations.Add(trainInstanceStation); } } IDictionary <string, Station> stations = DbContext.Stations.Where(s => stationNames.Contains(s.NormName)).ToDictionary(s => s.NormName, s => s); foreach (TrainStation trainStation in train.TrainStations) { trainStation.Station = stations[trainStation.Station.NormName]; } var relativeDistances = GetRelativeDistances(train.TrainStations.Select(s => s.Station).ToList()); for (int i = 0; i < train.TrainStations.Count; i++) { train.TrainStations[i].RelativeDistance = relativeDistances[i]; } }
public async Task <IActionResult> Edit(int id, [Bind("Name,ID")] TrainStation trainStation) { if (id != trainStation.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(trainStation); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrainStationExists(trainStation.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(trainStation)); }
private void setDefaultValues() { newAddedStage = null; availableStages = new List <Stage>(); previousStage = null; startStation = null; finalStation = null; }
public ActionResult DeleteConfirmed(int id) { TrainStation trainStation = db.TrainStations.Find(id); db.TrainStations.Remove(trainStation); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ObjectResult> CreateTrainStationAsync([FromBody] GeneralTrainStationRequest request) { TrainStation result = await _trainStationServices.TrainStationRepository.CreateAsync(request.ToDTO()); await _trainStationServices.CommitChanges(); return(Ok(result)); }
// POST: api/TrainStations public IHttpActionResult PostTrainStation(JObject data) { dynamic jsonData = data; var idTrain = jsonData.IdTrain; var idStation = jsonData.IdStation; var ArrivalTime = jsonData.ArrivalTime; var index = jsonData.Index; if (idTrain == null || idStation == null || ArrivalTime == null) { return(BadRequest("Train or station can be null")); } int IdTrain = Convert.ToInt32(idTrain); int IdStation = Convert.ToInt32(idStation); int Index = index == null ? -1 : Convert.ToInt32(index); if (Index == -1) { Index = db.TrainStations.Where(e => e.IdTrain == IdTrain).Count(); } else { var trainStations = db.TrainStations.Where(e => e.IdTrain == IdTrain && e.IndexNumber >= Index).ToList(); trainStations.ForEach(e => e.IndexNumber = e.IndexNumber + 1); } Station preStation = ( from st in db.TrainStations join s in db.Stations on st.IdStation equals s.Id where st.IdTrain == IdTrain && st.IndexNumber == (Index - 1) select s ).FirstOrDefault(); Station currentStation = db.Stations.Find(IdStation); if (preStation == null || currentStation == null) { return(BadRequest()); } var distance = preStation.Location.Distance(currentStation.Location); TrainStation trainStation = new TrainStation { IdTrain = IdTrain, IdStation = IdStation, ArrivalTime = (long)ArrivalTime, IndexNumber = Index, DistancePreStation = Convert.ToInt32(distance) }; db.TrainStations.Add(trainStation); db.SaveChanges(); return(Ok(trainStation)); }
public async Task <ObjectResult> DeleteTrainStationAsync([FromRoute] int id) { TrainStation trainStation = await _trainStationServices.TrainStationRepository.GetByIdAsync(id); _trainStationServices.TrainStationRepository.Delete(trainStation); await _trainStationServices.CommitChanges(); return(Ok(trainStation)); }
public ActionResult Edit([Bind(Include = "Id,Suburb,Name,Latitude,Longitude")] TrainStation trainStation) { if (ModelState.IsValid) { db.Entry(trainStation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainStation)); }
public async Task <IActionResult> Create([Bind("Name,ID")] TrainStation trainStation) { if (ModelState.IsValid) { _context.Add(trainStation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trainStation)); }
public IHttpActionResult GetTrainStation(int id) { TrainStation trainStation = db.TrainStations.Find(id); if (trainStation == null) { return(NotFound()); } return(Ok(trainStation)); }
public ActionResult Create([Bind(Include = "Id,Suburb,Name,Latitude,Longitude")] TrainStation trainStation) { if (ModelState.IsValid) { db.TrainStations.Add(trainStation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainStation)); }
static TrainMap InitializeProgram() { #region InitializeProgram // inicializando o grafo com estações e rotas pré definidas var stationA = new TrainStation('A'); var stationB = new TrainStation('B'); var stationC = new TrainStation('C'); var stationD = new TrainStation('D'); var stationE = new TrainStation('E'); var edgeAB = new TrainConnection(5, stationA, stationB); var edgeBC = new TrainConnection(4, stationB, stationC); var edgeCD = new TrainConnection(8, stationC, stationD); var edgeDC = new TrainConnection(8, stationD, stationC); var edgeDE = new TrainConnection(6, stationD, stationE); var edgeAD = new TrainConnection(5, stationA, stationD); var edgeCE = new TrainConnection(2, stationC, stationE); var edgeEB = new TrainConnection(3, stationE, stationB); var edgeAE = new TrainConnection(7, stationA, stationE); stationA.AddConnections(new List <TrainConnection> { edgeAB, edgeAD, edgeAE }); stationB.AddConnection(edgeBC); stationC.AddConnections(new List <TrainConnection> { edgeCD, edgeCE }); stationD.AddConnections(new List <TrainConnection> { edgeDC, edgeDE }); stationE.AddConnection(edgeEB); var trainMap = new TrainMap(new List <TrainStation> { stationA, stationB, stationC, stationD, stationE }); trainMap.AddRoute("CDC".ToCharArray()); trainMap.AddRoute("CEBC".ToCharArray()); trainMap.AddRoute("ABCDC".ToCharArray()); trainMap.AddRoute("ADCDC".ToCharArray()); trainMap.AddRoute("ADEBC".ToCharArray()); trainMap.AddRoute("CEBCDC".ToCharArray()); trainMap.AddRoute("CDCEBC".ToCharArray()); trainMap.AddRoute("CDEBC".ToCharArray()); trainMap.AddRoute("CEBCEBC".ToCharArray()); trainMap.AddRoute("CEBCEBCEBC".ToCharArray()); return(trainMap); #endregion }
// GET: TrainStations/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TrainStation trainStation = db.TrainStations.Find(id); if (trainStation == null) { return(HttpNotFound()); } return(View(trainStation)); }
public IHttpActionResult DeleteTrainStation(int id) { TrainStation trainStation = db.TrainStations.Find(id); if (trainStation == null) { return(NotFound()); } db.TrainStations.Remove(trainStation); db.SaveChanges(); return(Ok(trainStation)); }
//-------------------------------------------------- // Station Timetable presentation //-------------------------------------------------- private void fillStationDetails(String stationName) { if (stationName == "") { return; } TrainStation station = TrainStationCache.getInstance().getCacheContentOnName(stationName); textBoxStationID.Text = station.Id.ToString(); textBoxStationName.Text = station.Name; textBoxStationCategory.Text = station.TownCategory.ToString(); textBoxStationInhabitation.Text = station.Inhabitation.ToString(); }
public void Pickup() { TrainStation station = Train.CurrentTrainStation; if (station.Pickups.Count > 0) { Train.Dropoffs.AddRange(station.Pickups); Messages.Add($"Picked up {station.Pickups.Count} passengers."); station.Pickups.Clear(); } else { Messages.Add("No passengers to pickup at this location."); } }
public void ShouldCalculateRoute() { var stationA = new TrainStation('A'); var stationB = new TrainStation('B'); Route route = new Route(); stationA.AddConnection(new TrainConnection(3, stationA, stationB)); route.AddNode(stationA); route.AddNode(stationB); int result = route.CalculateRouteDistance(); Assert.Equal(result, 3); }
public int GetTheRent(Property p, int dicesValue) { int rentValue = 0; if (p is Land) { Land l = (Land)p; if (CheckIfPlayerOwnAllLandInLandGroup(WhoOwnThisProperty(p), l.LandGroup)) { if (l.NbHouse == 0 && l.NbHotel == 0) { rentValue = 2 * l.GetRent(0); } else if (l.NbHouse <= Land.NB_MAX_HOUSES && l.NbHotel == 0) { rentValue = l.GetRent(l.NbHouse); } else if (l.NbHouse == 0 && l.NbHotel != 0) { rentValue = l.GetRent(Land.NB_MAX_HOUSES + l.NbHotel); } } else { rentValue = l.GetRent(l.NbHouse); } } else if (p is PublicService) { if (NumberOfPublicServiceOwned(p) == 1) { rentValue = 4 * dicesValue; } else if (NumberOfPublicServiceOwned(p) == CountTheNumberOfPublicSercices()) { rentValue = 10 * dicesValue; } } else if (p is TrainStation) { TrainStation t = (TrainStation)p; rentValue = t.TrainStationRent * NumberOfTrainStationOwned(p); } return(rentValue); }
public ActionResult Create(Train train, TrainStation trainStation) { try { // TODO: Add insert logic here _trainRepository.Add(train, trainStation); //_trainRepository.Add(collection["TrainSymbol"], Convert.ToInt32(collection["Speed"]), collection["stationAddress"], // collection["Description"]); return(View("DisplayTrains")); //return RedirectToAction("DisplayTrains"); } catch (Exception ex) { return(View(ex)); } }
private void Awake() { //Check if instance already exists if (instance == null) { //if not, set instance to this instance = this; } //If instance already exists and it's not this: else if (instance != this) { //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager. Destroy(gameObject); } }
public void Add(Train train, TrainStation trainStation) { using (var db = new TrainContext()) { if (!(db.Trains.Any(x => x.TrainSymbol == train.TrainSymbol) || db.TrainStations.Any(x => x.StationName == trainStation.StationName))) { db.Trains.Add(new Train { TrainSymbol = train.TrainSymbol, Speed = train.Speed, Description = train.Description }); db.TrainStations.Add(new TrainStation { StationName = trainStation.StationName, StationAddress = trainStation.StationAddress }); db.SaveChanges(); } } }
public async Task OnGetAsync(string id) { using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync("http://api.irail.be/stations/?format=json&lang=en")) { string apiResponse = await response.Content.ReadAsStringAsync(); StationApi stationApi = new StationApi(); stationApi = JsonConvert.DeserializeObject <StationApi>(apiResponse); IQueryable <TrainStation> stationApiQ = stationApi.Station.AsQueryable <TrainStation>(); Station = stationApiQ.FirstOrDefault(s => s.ID == id); } string StationId = Station.ID.Substring(Station.ID.Length - 9); UrlPictureStation = "https://github.com/iRail/stations/blob/master/Pictures/" + StationId + ".jpg?raw=true"; } }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); _id = Intent.GetStringExtra("id"); _station = _trainStations.Single(p => p.identifier == _id); // Set our view from the "main" layout resource SetContentView(Resource.Layout.All); try { var trains = await TrainStationService.GetTrainsForStation(_id); var listView = FindViewById <ListView>(Resource.Id.List); listView.Adapter = new TrainsAdapter(this, trains.ToArray()); } catch (Exception ex) { } }
// PUT: api/TrainStations/5 public IHttpActionResult PutTrainStation(int Id, int ToIndex) { TrainStation trainStation = db.TrainStations.Find(Id); if (trainStation == null) { return(BadRequest("Train station not found")); } trainStation.IndexNumber = ToIndex; db.Entry(trainStation).State = EntityState.Modified; var trainStations = db.TrainStations.Where(e => e.IdTrain == trainStation.IdTrain && e.IndexNumber >= ToIndex && e.Id != Id).ToList(); trainStations.ForEach(e => e.IndexNumber = e.IndexNumber + 1); db.SaveChanges(); return(Ok(HttpStatusCode.NoContent)); }
private static void HotelCrawler(OnCompletedEventArgs e) { var StationsInfos = e.WebDriver.FindElement(By.XPath("//*[@id='all_citybox']")); var stationList = StationsInfos.FindElements(By.XPath("li[@class='station-item']")); //var totalPage = Convert.ToInt32(comments.FindElement(By.XPath("div[@class='c_page_box']/div[@class='c_page']/div[contains(@class,'c_page_list')]/a[last()]")).Text); TrainStation temp; List <TrainStation> list = new List <TrainStation>(); foreach (var item in stationList) { temp = new TrainStation(); temp.text = item.GetAttribute("data-text"); temp.code = item.GetAttribute("data-code"); list.Add(temp); } Console.WriteLine(JsonConvert.SerializeObject(list)); Console.ReadKey(); }
public static void Init() { #region load cookies Cookies = new CookieContainer(); CookieStoragePath = AppDomain.CurrentDomain.BaseDirectory + "savedcookie.txt"; try { if (File.Exists(CookieStoragePath)) { using (TextReader tr = new StreamReader(CookieStoragePath, Encoding.UTF8)) { string line = null; int count = 0; while ((line = tr.ReadLine()) != null) { var cookie = JSON.decode<Cookie>(line); cookie.Expires = DateTime.Now.AddMonths(6); RunTimeData.Cookies.Add(cookie); count++; } IsCookieLoaded = count > 0; } } } catch { //FileNotFoundException } #endregion #region load stations var p0Array = Properties.Resources.StationNames.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries); Stations = new TrainStation[p0Array.Length]; int i = 0; foreach (var p0 in p0Array) { var p1 = p0.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); Stations[i++] = new TrainStation() { ShortCut = p1[0], Name = p1[1], Code = p1[2], Pinyin = p1[3], Sipinyin = p1[4], Id = int.Parse(p1[5]) }; } #endregion #region load seat type relation SeatTypeRelation = JSON.decode<SeatTypeRelation>(Properties.Resources.SeatTypeRelation); #endregion SeatTypeNames = new string[]{ "商务座", "特等座", "一等座", "二等座", "高级软卧", "软卧", "硬卧", "软座", "硬座", "无座", "其它" }; IDCardTypes = new KeyValuePair<string, string>[]{ new KeyValuePair<string, string>( "二代身份证", "1"), new KeyValuePair<string, string>( "一代身份证", "2"), new KeyValuePair<string, string>( "港澳通行证", "C"), new KeyValuePair<string, string>( "台湾通行证", "G"), new KeyValuePair<string, string>( "护照", "B") }; TicketTypes = new KeyValuePair<string, string>[]{ new KeyValuePair<string, string>( "成人票", "1"), new KeyValuePair<string, string>( "儿童票", "2"), new KeyValuePair<string, string>( "学生票", "3"), new KeyValuePair<string, string>( "残军票", "4") }; #region load MyAttentions MyAttentionsStoragePath = AppDomain.CurrentDomain.BaseDirectory + "MyAttentions.txt"; MyAttentions = new List<AttentionItem>(); QuickAttentions = new List<AttentionItem>(); if (File.Exists(MyAttentionsStoragePath)) { try { var items = JSON.decode<AttentionItem[]>(File.ReadAllText(MyAttentionsStoragePath, Encoding.UTF8)); MyAttentions.AddRange(items); } catch { } } #endregion SavedPassengersPath = AppDomain.CurrentDomain.BaseDirectory + "savedPassengers.txt"; }
private void btnSearchTrains_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cbxFrom.Text)) { MessageBox.Show(this, "请输入出发地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(cbxTo.Text)) { MessageBox.Show(this, "请输入目的地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _FromStation = Array.Find(RunTimeData.Stations, v => v.Name == cbxFrom.Text || v.ShortCut == cbxFrom.Text); if (_FromStation == null) { MessageBox.Show(this, "请输入正确的出发地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _ToStation = Array.Find(RunTimeData.Stations, v => v.Name == cbxTo.Text || v.ShortCut == cbxTo.Text); if (_ToStation == null) { MessageBox.Show(this, "请输入正确的目的地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbxFrom.Text != _FromStation.Name) { cbxFrom.Text = _FromStation.Name; } if (cbxTo.Text != _ToStation.Name) { cbxTo.Text = _ToStation.Name; } btnSearchTrains.Text = "正在查询……"; btnSearchTrains.Enabled = false; lstTrains.Items.Clear(); var query = new NameValueCollection(); query["date"] = dtpDate.Value.ToString("yyyy-MM-dd"); query["fromstation"] = _FromStation.Code; query["tostation"] = _ToStation.Code; query["starttime"] = "00:00--24:00"; HTTP.Request(new HttpRequest() { Method = "POST", OperationName = string.Format("查询车次信息_{0}_{1}_{2}", _FromStation.Name, _ToStation.Name, dtpDate.Value.ToString("yyyy_MM_dd")), Url = Properties.Settings.Default.QuerySingleActionUrl + "?method=queryststrainall", Referer = Properties.Settings.Default.QuerySingleActionUrl + "?method=init", Body = HTTP.ToString(query), MaxRetryCount = 0, OnReset = (req) => { DetermineCall(() => { btnSearchTrains.Text = "查询"; btnSearchTrains.Enabled = true; }); }, OnError = (req, error)=>{ return true; }, OnHtml = (req, uri, html) => { try { TrainItem[] trains = JSON.decode<TrainItem[]>(html); DetermineCall(() => { lstTrains.Items.AddRange(trains); btnAddAttention.Enabled = true; }); } catch { } } }); }