protected override void OnAppearing() { base.OnAppearing(); GunTypeList.Children.Clear(); _gunTypeDatabase = new GunTypeDatabase(); var gunTypes = _gunTypeDatabase.GetGunTypes(); foreach (var item in gunTypes) { Button newButton = new Button(); newButton.Text = item.GunTypeName; newButton.ClassId = item.ID.ToString(); newButton.BackgroundColor = Color.Red; newButton.TextColor = Color.Black; newButton.Margin = 4; newButton.Clicked += GunTypeClicked; GunTypeList.Children.Add(newButton); } }
public async void RemoveGunTypeClicked(object sender, EventArgs e) { var answer = await DisplayAlert("Remove Gun type", "Deleting the gun type will delete all guns with this type, this action can not be undone?", "Remove", "Cancel"); if (answer) { _gunTypeDatabase = new GunTypeDatabase(); _gunDatabase = new GunDatabase(); try { _gunTypeDatabase.DeleteGunType(GunType.CurrentGunTypeId); _gunDatabase.DeleteGunsWithType(); } catch (Exception ex) { Debug.WriteLine(@" GunStock.GunListPage.RemoveGunTypeClicked ERROR {0}", ex.Message); } Navigation.RemovePage(this); } }
public async void AddGunType(object o, EventArgs e) { _gunType = new GunType(); _gunTypeDatabase = new GunTypeDatabase(); try { if (!string.IsNullOrEmpty(gunType.Text)) { _gunType.GunTypeName = gunType.Text; _gunTypeDatabase.AddGunType(_gunType); Navigation.RemovePage(this); } else { await DisplayAlert("Field Error", "Type is required", "OK"); } } catch (Exception ex) { Debug.WriteLine(@" GunStock.GunTypeEntryPage.AddGunType ERROR {0}", ex.Message); } }