private void BtnSaveSettings_Clicked(object sender, EventArgs e) { var settings = new CoffeeSettings { CoffeeName = txtCoffeeName.Text, HasSugar = swHasSugar.On, MilkAmount = (int)sldMilkAmount.Value, BrewTime = tpBrewTime.Time }; //object to json string string jsonText = JsonConvert.SerializeObject(settings); //get appdata dir using Xamaring Essentials string folder = FileSystem.AppDataDirectory; //standard,simple save operation string fullPath = Path.Combine(folder, Constants.CoffeeSettingsFileName); File.WriteAllText(fullPath, jsonText); }
//Write Values in DB private void _okButton_Click(object sender, EventArgs e) { //Test for Correctness if (_editCoffeeQuantity.Text == string.Empty) { Toast.MakeText(Activity, GetString(Resource.String.StatCoffeeQuantity) + " " + GetString(Resource.String.MissingValue), ToastLength.Short).Show(); return; } if (_editMilkQuantity.Text == string.Empty) { Toast.MakeText(Activity, GetString(Resource.String.StatMilkQuantity) + " " + GetString(Resource.String.MissingValue), ToastLength.Short).Show(); return; } if (_editCoffeeStregth.Text == string.Empty) { Toast.MakeText(Activity, GetString(Resource.String.StatCoffeeStregth) + " " + GetString(Resource.String.MissingValue), ToastLength.Short).Show(); return; } if (int.Parse(_editCoffeeQuantity.Text) > 120) { Toast.MakeText(Activity, GetString(Resource.String.StatCoffeeQuantity) + " " + GetString(Resource.String.ValueTooHigh), ToastLength.Short).Show(); _editCoffeeQuantity.Text = "120"; return; } if (int.Parse(_editMilkQuantity.Text) > 120) { Toast.MakeText(Activity, GetString(Resource.String.StatMilkQuantity) + " " + GetString(Resource.String.ValueTooHigh), ToastLength.Short).Show(); _editMilkQuantity.Text = "120"; return; } if (int.Parse(_editCoffeeStregth.Text) > 5) { Toast.MakeText(Activity, GetString(Resource.String.StregthTooHigh), ToastLength.Short).Show(); _editCoffeeStregth.Text = "5"; return; } if (int.Parse(_editCoffeeStregth.Text) < 1) { Toast.MakeText(Activity, GetString(Resource.String.StregthTooLow), ToastLength.Short).Show(); _editCoffeeStregth.Text = "1"; return; } //Object to Update CoffeeSettings coffeeSettings = new CoffeeSettings() { CoffeeName = _coffeeName, CoffeeQuantity = int.Parse(_editCoffeeQuantity.Text), MilkQuantity = int.Parse(_editMilkQuantity.Text), CoffeeStregth = int.Parse(_editCoffeeStregth.Text) }; _dataBase.UpdateTableCoffeeSettings(coffeeSettings); //Event For Change Complete // ReSharper disable once PossibleNullReferenceException CoffeeValueDialogComplete.Invoke(this, EventArgs.Empty); //Close Dialog Activity.OnBackPressed(); Dismiss(); }