protected override async void OnAppearing() { // Create page if user doesnt exist or has logged out if (User.CurrentUserInstance.Name == null) { Label loginLbl = new Label { Text = "Login to access your settings", FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = 20, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; Button loginButton = new Button { Text = "Login", TextColor = Color.White, BackgroundColor = Color.Green, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.Fill, }; loginButton.Clicked += (sender, e) => { MenuPage.ChangePage(MenuPage.pages[3], 3); }; Content = new StackLayout { Children = { loginLbl, loginButton } }; } else { Content = initialContent; } }
public HomePage() { InitializeComponent(); BackgroundImage = "m1.jpg"; MenuBtn.Clicked += (sender, e) => { MenuPage.ChangePage(MenuPage.pages[1], 1); }; }
public void CreateLinkableCells(List <Food> FoodDB) { // Creating page header Label header = new Label { Text = "Reccomended based on location", TextColor = Color.Purple, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; // Adding all food items to imagecells List <ImageCell> foodDBLinks = new List <ImageCell>(); foreach (Food item in FoodDB) { ImageCell cellItem = new ImageCell { // Some differences with loading images in initial release. ImageSource = item.Photo, Text = $"{item.Name} - ${item.Price}", Detail = $"{item.Description}", }; cellItem.Tapped += (sender, args) => MenuPage.ChangePage( // Generate new page for item GenerateItemPage(item) ); foodDBLinks.Add(cellItem); } TableView tableView = new TableView { Intent = TableIntent.Form, Root = new TableRoot { new TableSection { foodDBLinks } } }; // Build the page. Content = new StackLayout { Children = { header, tableView } }; }
private void CreateLinkableCells(List <Food> FoodDB) { // Creating page header Label header = new Label { Text = "Your Cart:", FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; // Adding all food items to imagecells List <ImageCell> foodDBLinks = new List <ImageCell>(); foreach (Food item in FoodDB) { ImageCell cellItem = new ImageCell { // Some differences with loading images in initial release. ImageSource = item.Photo, Text = $"{item.Name} - ${item.Price}", Detail = $"{item.Description}", }; cellItem.Tapped += async(sender, args) => { var answer = await DisplayAlert($"{item.Name}", "Would you like to remove item from cart?", "Yes", "No"); if (answer) { Food.CartInstance.Remove(item); if (Food.CartInstance.Count == 0) { MenuPage.ChangePage(new NavigationPage(new OrderPage())); // FIX THIS } else { OnAppearing(); } } }; foodDBLinks.Add(cellItem); } TableView tableView = new TableView { Intent = TableIntent.Form, Root = new TableRoot { new TableSection { foodDBLinks } } }; double total = FoodDB.Sum(s => s.Price); Button orderButton = new Button { Text = $"Place Order - [ ${total} ]", BackgroundColor = Color.Green, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.Fill, }; ActivityIndicator AI = new ActivityIndicator(); AI.IsRunning = false; string foodNames = ""; foreach (string str in FoodDB.Select(s => s.Name)) { foodNames += str + " "; } string totPrice = FoodDB.Select(s => s.Price).Sum().ToString(); orderButton.Clicked += async(sender, e) => { AI.IsRunning = true; orderButton.IsEnabled = false; Order newOrder = new Order() { FoodNames = foodNames, Email = User.CurrentUserInstance.Email, TotalPrice = totPrice, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.PlaceOrder(newOrder); await DisplayAlert("Success", "Your order has been successfully placed", "OK"); // Generate page // foreach (var f in Food.CartInstance) Food.CartInstance.Remove(f); Food.CartInstance.Clear(); orderButton.IsEnabled = true; AI.IsRunning = false; MenuPage.ChangePage(new NavigationPage(new TabbedPage { Children = { new OrderPage(), new PlacedOrdersPage() } })); // FIX THIS }; // Build the page. Content = new StackLayout { Children = { header, tableView, AI, orderButton } }; }
private void ToMenu(object sender, EventArgs e) { MenuPage.ChangePage(MenuPage.pages[1], 1); }
private void GenerateOrdersPage(List <Order> orders) { // Generating page of orders Label header = new Label { Text = "Your Cart:", FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; ActivityIndicator AI = new ActivityIndicator(); AI.IsRunning = false; // Adding all food items to imagecells List <ImageCell> orderDBLinks = new List <ImageCell>(); foreach (Order order in orders) { ImageCell cellItem = new ImageCell { // Some differences with loading images in initial release. ImageSource = new Uri("http://www.lexingtoncolony.com/wp-content/uploads/2014/07/dinner-thumbnail.png"), Text = $"Your Order [ {order.Date} ] - Total: ${order.TotalPrice}", Detail = $"Food Items: {order.FoodNames}" }; cellItem.Tapped += async(sender, args) => { var answer = await DisplayAlert($"Cancel Order", "Would you like to cancel this order?", "Yes", "No"); if (answer) { // Remove it from database await AzureManager.AzureManagerInstance.CancelOrder(order); orders.Remove(order); await DisplayAlert("SUCCESS", "Successfuly cancelled your order", "OK"); if (orders.Count == 0) { MenuPage.ChangePage(new NavigationPage(new TabbedPage { Children = { new OrderPage(), new PlacedOrdersPage() } })); // FIX THIS } else { OnAppearing(); } } }; orderDBLinks.Add(cellItem); } TableView tableView = new TableView { Intent = TableIntent.Form, Root = new TableRoot { new TableSection { orderDBLinks } } }; // Build the page. Content = new StackLayout { Children = { header, tableView, AI } }; }
private Page GenerateItemPage(Food item) { Label category = new Label { Text = $"{item.Category.ToUpper()}", TextColor = Color.Blue, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalTextAlignment = TextAlignment.Center }; Image image = new Image { Source = item.Photo, Aspect = Aspect.AspectFit }; Label name = new Label { Text = $"{item.Name}", TextColor = Color.Blue, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalTextAlignment = TextAlignment.Center }; Label description = new Label { Text = $"{item.Description}", FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalTextAlignment = TextAlignment.Center }; Label price = new Label { Text = $"Cost: ${ item.Price}", TextColor = Color.Red, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = 20, HorizontalTextAlignment = TextAlignment.End }; Button addToCart = new Button { Text = "ADD TO CART", BackgroundColor = Color.Green, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.Fill, }; addToCart.Clicked += async(sender, e) => { if (User.CurrentUserInstance.Name != null) { Food.CartInstance.Add(item); await DisplayAlert("Success", $"Successfully added {item.Name} to cart", "OK"); } else { var res = await DisplayAlert("Failed", "Please login to place an order", "Login", "Cancel"); if (res) { MenuPage.ChangePage(MenuPage.pages[3], 3); } } }; Button toCartBtn = new Button { Text = "View Cart", TextColor = Color.White, BackgroundColor = Color.Blue, Font = Font.SystemFontOfSize(NamedSize.Small), BorderWidth = 1, HorizontalOptions = LayoutOptions.Fill, }; toCartBtn.Clicked += (sender, e) => { MenuPage.ChangePage(MenuPage.pages[2], 2); }; Button backToMenu = new Button { Text = "BACK", BackgroundColor = Color.Red, Font = Font.SystemFontOfSize(NamedSize.Small), BorderWidth = 1, HorizontalOptions = LayoutOptions.End, }; backToMenu.Clicked += (sender, e) => { MenuPage.ChangePage(MenuPage.pages[1]); }; return(new NavigationPage(new ContentPage { Content = new StackLayout { Children = { category, image, name, description, price, addToCart, toCartBtn, backToMenu } } })); }
private void Change(object sender, EventArgs e) { Label passLbl = new Label { Text = "Enter curent password:"******"Password*", IsPassword = true }; Entry pass2 = new Entry { Placeholder = "Current Password*", IsPassword = true }; Button confirm = new Button { Text = "Confirm", TextColor = Color.White, BackgroundColor = Color.Green, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.StartAndExpand, }; confirm.Clicked += async(sender2, e2) => { if (pass1.Text == null || pass2.Text == null || pass1.Text.Length < 1 || pass2.Text.Length < 1) { await DisplayAlert("Incomplete Information", "Please complete the password fields", "OK"); } else if (pass1.Text != pass2.Text) { await DisplayAlert("Password mismatch error", "Please enter identical passwords in the displayed fields", "OK"); } else if (pass1.Text != User.CurrentUserInstance.Password) { await DisplayAlert("Password Incorrect", "Please enter correct current password", "OK"); } else { // CHECK IF USER WITH SAME EMAIL EXISTS TO PREVENT CLASHES/DUPLICATES User changedUser = new User() { ID = User.CurrentUserInstance.ID, Name = usernameEntry.Text ?? User.CurrentUserInstance.Name, Email = (emailEntry.Text == null || emailEntry.Text.Length < 1) ? User.CurrentUserInstance.Email : emailEntry.Text, Password = (passwordEntry.Text == null || passwordEntry.Text.Length < 1) ? User.CurrentUserInstance.Password : passwordEntry.Text, Photo = User.CurrentUserInstance.Photo, Phone = phoneEntry.Text ?? User.CurrentUserInstance.Phone, Address = addressEntry.Text ?? User.CurrentUserInstance.Address, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.UpdateUser(changedUser); await DisplayAlert("SUCCESS", "Successfuly changed your details", "OK"); MenuPage.GoHomeAfterLogin(changedUser); } }; Button goBack = new Button { Text = "Back", TextColor = Color.White, BackgroundColor = Color.Red, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.EndAndExpand, }; goBack.Clicked += (sender2, e2) => { MenuPage.ChangePage(MenuPage.pages[5]); }; MenuPage.ChangePage(new NavigationPage(new ContentPage { Content = new StackLayout { Children = { passLbl, pass1, pass2, new Grid { Children = { confirm,goBack } } } } })); }