Ejemplo n.º 1
0
		/// <summary>
		/// Populates the page with content passed during navigation. Any saved state is also
		/// provided when recreating a page from a prior session.
		/// </summary>
		/// <param name="sender">
		/// The source of the event; typically <see cref="NavigationHelper"/>.
		/// </param>
		/// <param name="e">Event data that provides both the navigation parameter passed to
		/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
		/// a dictionary of state preserved by this page during an earlier
		/// session.  The state will be null the first time a page is visited.</param>
		private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
		{
			Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
			// TODO: Create an appropriate data model for your problem domain to replace the sample data.
			try
			{
				item = e.NavigationParameter as BusItem;

				if (item == null)
				{
					item = new BusItem();
				}

				this.DefaultViewModel["Bus"] = item;

				if (string.IsNullOrEmpty(item.OperationsTime))
				{
					thoigianhoatdong_text.Text = "Chưa có dữ liệu";
				}
				if (string.IsNullOrEmpty(item.Frequency))
				{
					giancach_text.Text = "Chưa có dữ liệu";
				}
				if (string.IsNullOrEmpty(item.Cost))
				{
					giave_text.Text = "Chưa có dữ liệu";
				}
				if (string.IsNullOrEmpty(item.RouteGo))
				{
					luotdi_text.Text = "Chưa có dữ liệu";
				}
				if (string.IsNullOrEmpty(item.RouteReturn))
				{
					luotve_text.Text = "Chưa có dữ liệu";
				}
			}
			catch (Exception exc)
			{
				string errMsg = exc.Message;
			}
		}
Ejemplo n.º 2
0
		private async Task GetSampleDataAsync()
		{
			if (this._buses.Count != 0)
				return;

			ObservableCollection<BusItem> obi = new ObservableCollection<BusItem>();
			ObservableCollection<BusStop> obs = new ObservableCollection<BusStop>();

			for (int i = 1; i <= 74; i++)
			{
				List<Geopoint> RouteGoGeo = new List<Geopoint>();
				List<BusStop> RouteGoStations = new List<BusStop>();
				List<Geopoint> RouteReturnGeo = new List<Geopoint>();
				List<BusStop> RouteReturnStations = new List<BusStop>();
				List<BusNode> goNode = new List<BusNode>();
				List<BusNode> returnNode = new List<BusNode>();

				Uri dataUri = new Uri("ms-appx:///DataModel/" + i.ToString() + ".txt");
				StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
				string jsonText = await FileIO.ReadTextAsync(file);
				JsonObject jsonObject = JsonObject.Parse(jsonText)["dt"].GetObject();

				// Get Go
				JsonObject goObject = jsonObject["Go"].GetObject();
				JsonArray goGeoArray = goObject["Geo"].GetArray();
				foreach (JsonValue value in goGeoArray)
				{
					JsonObject goGeoObject = value.GetObject();

					double lng = goGeoObject["Lng"].GetNumber();
					double lat = goGeoObject["Lat"].GetNumber();
					RouteGoGeo.Add(new Geopoint(new BasicGeoposition { Latitude = lat, Longitude = lng }));
				}

				JsonArray goStationArray = goObject["Station"].GetArray();
				foreach (JsonValue value in goStationArray)
				{
					JsonObject goStationObject = value.GetObject();

					double lng = goStationObject["Geo"].GetObject()["Lng"].GetNumber();
					double lat = goStationObject["Geo"].GetObject()["Lat"].GetNumber();

					string code = "";
					try
					{
						code = goStationObject["ObjectID"].GetNumber().ToString();
						//code = goStationObject["Code"].GetString();
					}
					catch (Exception exc)
					{
						string errMsg = exc.Message;
					}

					BusStop bs = new BusStop(code,
												goStationObject["Name"].GetString(),
												goStationObject["FleetOver"].GetString(),
												new Geopoint(new BasicGeoposition { Latitude = lat, Longitude = lng }));
					RouteGoStations.Add(bs);

					BusNode bn = new BusNode(jsonObject["Code"].GetString(), code, null);
					goNode.Add(bn);	

					if (!obs.Any(a => a.Code == code))
					{
						bs.arrayNode.Add(bn);
						obs.Add(bs);
					}
					else
					{
						obs.Where(x => x.Code == code).FirstOrDefault().arrayNode.Add(bn);
					}
				
				}



				// Get Return
				JsonObject reObject = jsonObject["Re"].GetObject();
				JsonArray reGeoArray = reObject["Geo"].GetArray();
				foreach (JsonValue value in reGeoArray)
				{
					JsonObject reGeoObject = value.GetObject();

					double lng = reGeoObject["Lng"].GetNumber();
					double lat = reGeoObject["Lat"].GetNumber();
					RouteReturnGeo.Add(new Geopoint(new BasicGeoposition { Latitude = lat, Longitude = lng }));
				}

				JsonArray reStationArray = reObject["Station"].GetArray();
				foreach (JsonValue value in reStationArray)
				{
					JsonObject reStationObject = value.GetObject();

					double lng = reStationObject["Geo"].GetObject()["Lng"].GetNumber();
					double lat = reStationObject["Geo"].GetObject()["Lat"].GetNumber();

					string code = "";
					try
					{
						code = reStationObject["ObjectID"].GetNumber().ToString();
					}
					catch (Exception exc)
					{
						string errMsg = exc.Message;
					}

					BusStop bs = new BusStop(code,
												reStationObject["Name"].GetString(),
												reStationObject["FleetOver"].GetString(),
												new Geopoint(new BasicGeoposition { Latitude = lat, Longitude = lng }));
					RouteReturnStations.Add(bs);
					
					BusNode bn = new BusNode(jsonObject["Code"].GetString(), code, null);
					returnNode.Add(bn);

					if (!obs.Any(a => a.Code == code))
					{
						bs.arrayNode.Add(bn);
						obs.Add(bs);
					}
					else
					{
						obs.Where(x => x.Code == code).First().arrayNode.Add(bn);
					}
				}

				BusItem bus = new BusItem(jsonObject["FleetID"].GetNumber().ToString(),
											jsonObject["Code"].GetString(),
											jsonObject["Name"].GetString(),
											jsonObject["OperationsTime"].GetString(),
											jsonObject["Frequency"].GetString(),
											jsonObject["Cost"].GetString(),
											goObject["Route"].GetString(),
											RouteGoGeo,
											RouteGoStations,
											reObject["Route"].GetString(),
											RouteReturnGeo,
											RouteReturnStations);
				bus.goNode = goNode;
				bus.returnNode = returnNode;
				obi.Add(bus);
			}

			BusGroup bg = new BusGroup(obi, obs);
			this.Buses.Add(bg);

			foreach (BusItem bi in bg.Items)
			{
				for (int i = 0; i < bi.goNode.Count(); i++)
				{
					if (i < bi.goNode.Count()-1)
						bi.goNode[i].nextNode = bi.goNode[i + 1];
				}
				for (int i = 0; i < bi.returnNode.Count(); i++)
				{
					if (i < bi.returnNode.Count()-1)
						bi.returnNode[i].nextNode = bi.returnNode[i + 1];
				}
			}
		}