예제 #1
0
        //When the button to save and exit is pressed, the window's close function is
        //called, which then fires the event watchLater_Close

        public void watchLater_Close(object sender, CancelEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show(this, "Do you wish to save changes to the database" +
                                                      " before closing?", "Close Window", MessageBoxButton.YesNoCancel);

            //When the closing event fires, the following messageBox shows to allow for confirmation,
            //cancellation, and to save or not save any changes to the database, namely the deletion
            //of any items

            switch (result)
            {
            case MessageBoxResult.Yes:
                DataRoutines.saveDatabase(readData);
                closeEvents();
                break;

            case MessageBoxResult.No:
                closeEvents();
                break;

            case MessageBoxResult.Cancel:
                e.Cancel = true;
                break;
            }
            //The result from the messageBox is used in this switch-case statement to call the appropriate
            //functions. If the yes button is pressed the DataRoutines function saveDatabase is called.
            //closeEvents is called after this or when no is pressed to return to the main tickerWindow,
            //and cancelling sets the necssary event argument to commence cancellation
        }