Beispiel #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)
 {
     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;
 }
        /// <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>;
            DataRepository = tuple.Item1;
            bill = tuple.Item2;
            this.DefaultViewModel[CurrentBill] = bill;

            ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("Resources");
            PriceStringFormatConverter.PriceStrFormat = resourceLoader.GetString("PriceStrFormat");
        }
Beispiel #3
0
        public async Task<RestaurantBill> AddBillAsync(string title, List<string> guests)
        {
            await GetDataAsync();

            Location location = null;
            var geoloc = await GetLocation();
            if (geoloc != null)
            {
                //Debug.WriteLine("location pos acc: " + geoloc.Coordinate?.Accuracy.ToString() ?? "undefined");
                //Debug.WriteLine("location pos long: " + geoloc.Coordinate?.Point.Position.Longitude.ToString() ?? "undefined");
                //Debug.WriteLine("location pos lat: " + geoloc.Coordinate?.Point.Position.Latitude.ToString() ?? "undefined");
                location = new Location(geoloc.Coordinate.Point.Position.Longitude, geoloc.Coordinate.Point.Position.Latitude);
            }

            var newUniqueId = Guid.NewGuid().ToString();
            var now = DateTime.Now;
            var bill = new RestaurantBill(newUniqueId, title, "", "", "", now, location);
            foreach (var guest in guests)
            {
                bill.AddGuest(guest);
            }
            Bills.Add(bill);
            return bill;
        }
Beispiel #4
0
        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);
            }
        }
        private async void BarButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            // Create the message dialog and set its content
            var messageDialog = new MessageDialog(this.resourceLoader.GetString("DialogTitleDeleteThisBill"));    // "Supprimer cette note de restaurant?"
            
            // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
            messageDialog.Commands.Add(new UICommand(
                this.resourceLoader.GetString("BtnDelete"),  // "Supprimer"
                new UICommandInvokedHandler(this.CommandInvokedHandler),
                1));
            messageDialog.Commands.Add(new UICommand(
                this.resourceLoader.GetString("BtnCancel"),  // "Annuler"
                new UICommandInvokedHandler(this.CommandInvokedHandler),
                0));

            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = 1;

            // Set the command to be invoked when escape is pressed
            messageDialog.CancelCommandIndex = 1;

            // Show the message dialog
            var result = await messageDialog.ShowAsync();
            if ((int)result.Id == 1)
            {
                // delete this bill and navigate to main page
                var oldBill = bill;
                this.DefaultViewModel[CurrentBill] = null;
                bill = null;
                await DataRepository.DeleteBillAsync(oldBill.UniqueId);

                this.navigationHelper.GoBack();
            }
        }
 public DialogEditResto(RestaurantBill bill)
 {
     _bill = bill;
     _title = _bill.Title;
     this.InitializeComponent();
 }
 public DialogEditResto(string defaultTitle)
 {
     _title = defaultTitle;
     _bill = null;
     this.InitializeComponent();
 }