Beispiel #1
0
        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sfd_SaveXmlFile.InitialDirectory             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data");
            sfd_SaveXmlFile.CreatePrompt                 = true;
            sfd_SaveXmlFile.OverwritePrompt              = true;
            sfd_SaveXmlFile.RestoreDirectory             = true;
            sfd_SaveXmlFile.Filter                       = "XML (*.Xml)|*.Xml|" + "All files (*.*)|*.*";
            sfd_SaveXmlFile.SupportMultiDottedExtensions = true;
            sfd_SaveXmlFile.Title = "My Data file Browser";

            //TBD refactor
            if (tc_Info.SelectedTab == tabPage_Book)
            {
                List <Book> parse = FileOPs.ParseBookXmlToList(bookFileName);

                if (sfd_SaveXmlFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        bookFileName = sfd_SaveXmlFile.FileName;
                        FileOPs.SaveXmlFile(parse, bookFileName);
                    }
                    catch (SecurityException ex)
                    {
                        // The user lacks appropriate permissions to read files, discover paths, etc.
                        MessageBox.Show("Security error. Please contact your administrator for details.\n\n" +
                                        "Error message: " + ex.Message + "\n\n" +
                                        "Details (send to Support):\n\n" + ex.StackTrace
                                        );
                    }
                    catch (Exception ex)
                    {
                        // Could not load the image - probably related to Windows file system permissions.
                        MessageBox.Show("Cannot open file: " + sfd_SaveXmlFile.FileName.Substring(sfd_SaveXmlFile.FileName.LastIndexOf('\\'))
                                        + ". You may not have permission to read the file, or " +
                                        "it may be corrupt.\n\nReported error: " + ex.Message);
                    }
                }
            }

            if (tc_Info.SelectedTab == tabPage_Film)
            {
                List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName);

                if (sfd_SaveXmlFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        filmFileName = sfd_SaveXmlFile.FileName;
                        FileOPs.SaveXmlFile(parse, filmFileName);
                    }
                    catch (SecurityException ex)
                    {
                        // The user lacks appropriate permissions to read files, discover paths, etc.
                        MessageBox.Show("Security error. Please contact your administrator for details.\n\n" +
                                        "Error message: " + ex.Message + "\n\n" +
                                        "Details (send to Support):\n\n" + ex.StackTrace
                                        );
                    }
                    catch (Exception ex)
                    {
                        // Could not load the image - probably related to Windows file system permissions.
                        MessageBox.Show("Cannot open file: " + sfd_SaveXmlFile.FileName.Substring(sfd_SaveXmlFile.FileName.LastIndexOf('\\'))
                                        + ". You may not have permission to read the file, or " +
                                        "it may be corrupt.\n\nReported error: " + ex.Message);
                    }
                }
            }
        }