/// <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) { var tuple = e.NavigationParameter as Tuple<IDataSource, RestaurantBill, Order>; this.DataRepository = tuple.Item1; this.bill = tuple.Item2; this.orderItem = tuple.Item3; this.DefaultViewModel[BillKey] = bill; this.DefaultViewModel[OrderKey] = orderItem; }
protected void old__DeserializeJson(string jsonText) { if (string.IsNullOrWhiteSpace(jsonText)) { return; } JsonObject jsonObject = JsonObject.Parse(jsonText); JsonArray jsonArray = jsonObject["Bills"].GetArray(); try { foreach (JsonValue RestaurantBillValue in jsonArray) { JsonObject RestaurantBillObject = RestaurantBillValue.GetObject(); DateTime date = DateTime.Now; if (RestaurantBillObject.ContainsKey("Date")) { // "Date": "/Date(2008-06-15T21:15:07)/", // http://regexlib.com/(X(1)A(plohCQBrb3JPpHX7KcH8auVKuRp8DdGM8wp_WQvQnRkqt078aQ_FHNpu-E3Q15qMcj_h5r_e1sDU99su-W3jeSa4Rg1YPf-sQ2t6j3wMh1hddZDrF4vczWP07PVccTC83u9Xx3nZSy-1p7Y2br4Fi6q9t_ZFiu_CyGmjBW-cH0xS1ybSZ5-oc4Nut3_tlJ_30))/REDetails.aspx?regexp_id=93 var r = new Regex(@"(?<grdate>20\d{2}(-|\/)((0[1-9])|(1[0-2]))(-|\/)((0[1-9])|([1-2][0-9])|(3[0-1]))(T|\s)(([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9]))"); var strDate = r.Match(RestaurantBillObject["Date"].GetString()).Groups["grdate"].Value; if (!string.IsNullOrEmpty(strDate)) { date = DateTime.Parse(strDate); } } Location location = null; if (RestaurantBillObject.ContainsKey("Location")) { JsonObject loc = RestaurantBillObject["Location"].GetObject(); location = new Location(loc["Longitude"].GetString(), loc["Latitude"].GetString()); } RestaurantBill bill = new RestaurantBill( RestaurantBillObject["UniqueId"].GetString(), RestaurantBillObject["Title"].GetString(), RestaurantBillObject["Subtitle"].GetString(), RestaurantBillObject["ImagePath"].GetString(), RestaurantBillObject["Description"].GetString(), date, location ); foreach (JsonValue GuestValue in RestaurantBillObject["Guests"].GetArray()) { bill.AddGuest(GuestValue.GetString()); } foreach (JsonValue OrderValue in RestaurantBillObject["Orders"].GetArray()) { JsonObject OrderObject = OrderValue.GetObject(); decimal price = 0; price = decimal.Parse( OrderObject.ContainsKey("Price") ? (OrderObject["Price"].GetString()) : "0", NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); var order = new Order( OrderObject["UniqueId"].GetString(), OrderObject["Title"].GetString(), OrderObject["Subtitle"].GetString(), OrderObject["ImagePath"].GetString(), OrderObject["Description"].GetString(), OrderObject["Content"].GetString(), price ); bill.Orders.Add(order); if (OrderObject.Keys.Contains("Shares")) { foreach (JsonValue OrderShareValue in OrderObject["Shares"].GetArray()) { JsonObject OrderShareObject = OrderShareValue.GetObject(); decimal sharePrice = 0; sharePrice = decimal.Parse( OrderShareObject.ContainsKey("Price") ? (OrderShareObject["Price"].GetString()) : "0", NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); order.Shares.Add( new OrderShare( //bill.Guests.First( guest => guest.Name == OrderShareObject["Guest"].GetString() ), //bill.Guests.First(guest => guest.Name == OrderShareObject["Guest"].GetObject()["Name"].GetString()), OrderShareObject["Guest"].GetString(), sharePrice ) ); } } } this.Bills.Add(bill); } } catch (Exception ex) { Debug.WriteLine("Exception in GetDataAsync : " + ex.Message); throw new Exception(ex.Message); } }
/// <summary> /// Adds an item to the list when the app bar button is clicked. /// </summary> private void BarButtonAdd_Click(object sender, RoutedEventArgs e) { var nextOrderId = bill.Orders.Count + 1; var newOrder = new Order( string.Format(CultureInfo.InvariantCulture, "Group-{0}-Item-{1}", this.pivot.SelectedIndex + 1, nextOrderId), string.Format(CultureInfo.CurrentCulture, this.resourceLoader.GetString("NewItemTitle"), nextOrderId), string.Empty, string.Empty, this.resourceLoader.GetString("NewItemDescription"), string.Empty, 0); bill.Orders.Add(newOrder); if (!Frame.Navigate(typeof(ItemPage), new Tuple<IDataSource, RestaurantBill, Order>(DataRepository, bill, newOrder))) { throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage")); } }