예제 #1
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog {
                Filter = "AnimalExport files (*.txt)|*.txt"
            };

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    administration.Export(saveFile.FileName);
                }
                catch (PathTooLongException ex)
                {
                    ExceptionOccuredForm.Show(this, "The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.", ex.Message);
                }
                catch (DirectoryNotFoundException ex)//Note: exception has misleading name, directory should be path
                {
                    ExceptionOccuredForm.Show(this, "The specified path is invalid, such as being on an unmapped drive.", ex.Message);
                }
                catch (IOException ex)
                {
                    ExceptionOccuredForm.Show(this, "I/O error, path already exists and cannot overwrite path, or another IO error occured", ex.Message);
                }
                catch (SecurityException ex)
                {
                    ExceptionOccuredForm.Show(this, "This application does not have the security permission to access the path.", ex.Message);
                }
                catch (UnauthorizedAccessException ex)
                {
                    ExceptionOccuredForm.Show(this, "Access is denied to path", ex.Message);
                }
                catch (ArgumentException ex)
                {
                    ExceptionOccuredForm.Show(this, "path refers to a non-file device, such as \"con:\", \"com1:\", \"lpt1:\", etc.", ex.Message);
                }
                catch (NotSupportedException ex)
                {
                    ExceptionOccuredForm.Show(this, "The animals cannot be written to the underlying file stream because a buffer overrun occured in the writer, the export is incomplete and/or corrupt.", ex.Message);
                }
            }
        }
예제 #2
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog {
                Filter = "AnimalDB files (*.adb)|*.adb"
            };

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    administration.Save(saveFile.FileName);
                }
                catch (PathTooLongException ex)
                {
                    ExceptionOccuredForm.Show(this, "The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.", ex.Message);
                }
                catch (DirectoryNotFoundException ex)//Note: exception has misleading name, directory should be path
                {
                    ExceptionOccuredForm.Show(this, "The specified path is invalid, such as being on an unmapped drive.", ex.Message);
                }
                catch (IOException ex)
                {
                    ExceptionOccuredForm.Show(this, "I/O error, path already exists and cannot overwrite path", ex.Message);
                }
                catch (SecurityException ex)
                {
                    ExceptionOccuredForm.Show(this, "This application does not have the security permission to access the path.", ex.Message);
                }
                catch (NotSupportedException ex)
                {
                    ExceptionOccuredForm.Show(this, "path is empty, contains only white space, or contains one or more invalid characters -or- refers to a non-file device, such as \"con:\", \"com1:\", \"lpt1:\", etc.", ex.Message);
                }
                catch (ArgumentException ex)
                {
                    ExceptionOccuredForm.Show(this, "path refers to a non-file device, such as \"con:\", \"com1:\", \"lpt1:\", etc.", ex.Message);
                }
                catch (SerializationException ex)
                {
                    ExceptionOccuredForm.Show(this, "One or more animal objects use classes that are not marked as serializable", ex.Message);
                }
            }
        }
예제 #3
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog {
                Filter = "AnimalDB files(*.adb) | *.adb"
            };

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    administration.Load(openFile.FileName);
                }
                catch (PathTooLongException ex)
                {
                    ExceptionOccuredForm.Show(this, "The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.", ex.Message);
                    return;
                }
                catch (DirectoryNotFoundException ex)//Note: exception has misleading name, directory should be path
                {
                    ExceptionOccuredForm.Show(this, "The specified path is invalid, such as being on an unmapped drive.", ex.Message);
                    return;
                }
                catch (IOException ex)
                {
                    ExceptionOccuredForm.Show(this, "I/O error, path already exists and cannot overwrite path", ex.Message);
                    return;
                }
                catch (SecurityException ex)
                {
                    ExceptionOccuredForm.Show(this, "This application does not have the security permission to access the path.", ex.Message);
                    return;
                }
                catch (NotSupportedException ex)
                {
                    ExceptionOccuredForm.Show(this, "path is empty, contains only white space, or contains one or more invalid characters -or- refers to a non-file device, such as \"con:\", \"com1:\", \"lpt1:\", etc.", ex.Message);
                    return;
                }
                catch (ArgumentException ex)
                {
                    ExceptionOccuredForm.Show(this, "path refers to a non-file device, such as \"con:\", \"com1:\", \"lpt1:\", etc.", ex.Message);
                    return;
                }
                catch (SerializationException ex)
                {
                    ExceptionOccuredForm.Show(this, "Deserialisation has failed, input file corrupt and/or invalid?", ex.Message);
                    return;
                }
            }

            listboxNotReserved.Items.Clear();
            listboxReserved.Items.Clear();

            foreach (Animal a in administration.Animals)
            {
                if (a.IsReserved)
                {
                    listboxReserved.Items.Add(a);
                }
                else if (!a.IsReserved)
                {
                    listboxNotReserved.Items.Add(a);
                }
            }
        }