public DetailHistory(ItemHistory item) { InitializeComponent(); itemName.Text = item.name; itemQuantity.Text = item.quantity.ToString(); itemPurchased.Text = item.PurchasedDate.ToString(); int totalAm = item.quantity * item.price; totalAmount.Text = totalAm.ToString(); }
void Buy(System.Object sender, System.EventArgs e) { //update: there is an anotherway: save the index and insert to position //testing, not work Item newItem = temp_item; if (string.IsNullOrEmpty(number.Text) || mylist.SelectedItem == null) { DisplayAlert("Error ", "You have to select an Item and provide a new quantity", "OK"); } else { int result = newItem.quantity - (Convert.ToInt32(number.Text)); //* case *// if (result < 0) { DisplayAlert("Error", "Item is out of stock, please update the quantity and try again", "Continue"); //type.Text = "Total"; number.Text = ""; //total.Text = ""; } else { //list_items.Insert(list_items.IndexOf(temp_item), newItem); newItem.quantity = result; //update list_items.Remove(temp_item); //list_items.Remove(temp_item); list_items.Add(newItem); mylist.ItemsSource = list_items.Reverse(); // work //mylist.ItemsSource = list_items; //temp_item.quantity = 999; //list_items.Add(temp_item); //add to history ItemHistory tempHistory = new ItemHistory(temp_item.name, temp_item.price, temp_item.quantity, DateTime.Now); history.Add(tempHistory); //reset type.Text = "Total"; number.Text = ""; total.Text = ""; DisplayAlert("Success", "The quantity is updated", "Close"); } } //(e.SelectedItem as Item).price -= ; }
void mylist_ItemSelected(System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) { temp_item = e.SelectedItem as ItemHistory; Navigation.PushModalAsync(new DetailHistory(temp_item)); }