//Reset goal when user reaches his goal. private void ResetGoal() { SaveGoal goal = new SaveGoal(0.0, "Please edit your new goal", 0, "none"); }
//Save data. private void SaveData() { string correctPrice = txtPrice.Text; //Search for comma in String. if (correctPrice.IndexOf(',') >= 0) { int place = correctPrice.IndexOf(','); correctPrice = correctPrice.Replace(',', '.'); } //Check if correct price is given. if (!CheckCorrectPrice(correctPrice)) { MessageBox.Show("Please enter a correct price.", "Error", MessageBoxButton.OK); txtPrice.Text = ""; } else { int roundedProgress = 0; //Update progress with new price. if (Convert.ToDouble(correctPrice) > 0) { double currentProgressMoney = (Price / 100) * Progress; double newProgress = (currentProgressMoney / Convert.ToDouble(txtPrice.Text)) * 100; roundedProgress = Convert.ToInt32(Math.Round(newProgress, 0)); } this.Price = Convert.ToDouble(correctPrice); this.GoalName = txtGoalName.Text; this.Progress = roundedProgress; SaveGoal goal = new SaveGoal(Price, GoalName, Progress, ImagePath); //Show messagebox with success message. ShowSuccess(); } }
//Update goal progress when user stops tracking. private void UpdateProgress() { GetGoal goal = new GetGoal(); double currentProgress = goal.Progress; double goalPrice = goal.Price; double currentProgressMoney = (goalPrice / 100) * currentProgress; int roundedProgress = 0; if (goalPrice != 0) { double newProgressMoney = currentProgressMoney + Convert.ToDouble(txbMoney2.Text); double newProgress = (newProgressMoney / goalPrice) * 100; roundedProgress = Convert.ToInt32(Math.Round(newProgress, 0)); } txbProgress.Text = Convert.ToString(roundedProgress) + "%"; SaveGoal goalSaver = new SaveGoal(goal.Price, goal.GoalName, roundedProgress, goal.ImagePath); }