コード例 #1
0
        /// <summary>
        /// This is the DoneButton event handler, done if undone and undone if done!
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         First of all a <c>goal</c> is retreived as the one that
        ///         has the same tag as the <c>sender</c> that raised the event,
        ///         using a <see cref="System.Linq"/> metohd compact expression.
        ///         <example>
        ///             <code>
        ///                 var myGoal = allgoals.FirstOrDefault(g => g.GoalTag == (sender as Button).Tag));
        ///             </code>
        ///         </example>
        ///     </para>
        ///     <para>
        ///         Then I check if that goal <c>!IsDone</c>, And if it is then call the
        ///         <see cref="GoalManipulation.MakeGoalDone(ObservableCollection{Goal}, User, ListView, object)"/>
        ///         method to make the goal done!
        ///     </para>
        ///     <para>
        ///         At the same level I check for the oposite, if the goal <c>IsDone</c>
        ///         if it is then undo the goal calling the <see cref="GoalManipulation.MakeGoalUnDone(ListView, Goal)"/>
        ///     </para>
        ///     <para>
        ///         And then I save the user!
        ///     </para>
        /// </remarks>
        /// <param name="sender">Holds the data about the <c>Button</c> that raised the event!</param>
        /// <param name="e">Event data about the event</param>
        private async void DoneButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            //Border goes green and change the content to an accept
            //to get the border with the tag!
            //https://stackoverflow.com/questions/15189715/how-to-access-a-control-inside-the-data-template-in-c-sharp-metro-ui-in-the-code

            //get the goal with the same tag as the (sender as Button)
            var goal = allGoals.FirstOrDefault(g => g.GoalTag == Convert.ToInt16((sender as Button).Tag));

            if (!goal.IsDone)
            {
                GoalManipulation.MakeGoalDone(allGoals, App.MyUser, GoalsListView, sender);

                if (App.AreSoundEffectsAreOn)
                {
                    //play the bell sound effect!
                    PlayMediaFilesFromPackageFolderService.PlayMedia("Assets", "smallbell.mp3");
                }
            }
            else
            {
                GoalManipulation.MakeGoalUnDone(GoalsListView, goal);
            }

            string userAsJsonString = Serializer.Serialize(App.MyUser);
            await Serializer.SaveUserAsync(userAsJsonString);
        }
コード例 #2
0
        /// <summary> Add new goal to the user's list Of Goals </summary>
        /// <remarks>
        /// This is where the new goal is added to the ObservableCollection allGoals,
        /// and the ListView is automatically updated,
        /// <see cref="GoalManipulation.AddGoal(ObservableCollection{Goal}, User, string)"/>
        /// then a cash register sound will be played
        /// <see cref="PlayMediaFilesFromPackageFolderService.PlayMedia(string, string)"/>
        /// And the App.MyUser is saved as a Json string in the stream,
        /// <see cref="Serializer"/></remarks>
        /// <param name="sender"> The data of the XAML control (<c>Button</c>) that raised the event</param>
        /// <param name="e">Event data of the event</param>
        private async void AddButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            //Add the goal
            GoalManipulation.AddGoal(allGoals, App.MyUser, String.IsNullOrEmpty(NewGoalDescriptionTextBox.Text) ? null : NewGoalDescriptionTextBox.Text);
            NewGoalDescriptionTextBox.Text = String.Empty;

            if (App.AreSoundEffectsAreOn)
            {
                //Play the cash register sound effect
                PlayMediaFilesFromPackageFolderService.PlayMedia("Assets", "cashregister.mp3");
            }

            //Save the user to the stream!
            string userAsJsonString = Serializer.Serialize(App.MyUser);
            await Serializer.SaveUserAsync(userAsJsonString);
        }