示例#1
0
        private void frmAdmin_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult r;

            // Allow the user to save the updated data
            if (!dataModified)
            {
                return;
            }
            r = MessageBox.Show("Save changes before closing?", "Save",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (r == DialogResult.No)
            {
                return;
            }
            // Save the data in a file.
            if (dlgSaveFile.ShowDialog() != DialogResult.OK)
            {
                e.Cancel = true;
                return;
            }
            try
            {
                LibraryApp.WriteBooks(dlgSaveFile.FileName,
                                      lstBooks.Items);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }
        }
示例#2
0
 private void mnuSave_Click(object sender, EventArgs e)
 {
     if (dlgSaveFile.ShowDialog() == DialogResult.OK)
     {
         LibraryApp.WriteBooks(dlgSaveFile.FileName, lstBooks.Items);
         dataModified = false;
     }
 }