/// <summary>
        /// Export data to a range of different file formats;
        /// ask the user for filename and file format
        ///
        /// NOTE this has been replaced by the two-part scheme above:
        ///   first get the filename, then the caller loads the data
        ///   from the server, then it calls ExportToFile.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="ADialogTitle"></param>
        /// <param name="ADefaultExtension"></param>
        /// <returns></returns>
        public static bool ExportWithDialog(XmlDocument doc, string ADialogTitle, string ADefaultExtension = "yml")
        {
            // TODO: openoffice
            // See also http://sourceforge.net/apps/mediawiki/openpetraorg/index.php?title=Data_liberation
            SaveFileDialog DialogSave = new SaveFileDialog();

            DialogSave.Filter = Catalog.GetString(
                "Text file (*.yml)|*.yml|XML file (*.xml)|*.xml|Excel file (*.xlsx)|*.xlsx|Spreadsheet file (*.csv)|*.csv");
            DialogSave.DefaultExt = ADefaultExtension;
            string[] filterLines = DialogSave.Filter.Split(new char[] { '|' });

            for (int count = 0; count < filterLines.Length; count++)
            {
                if (count % 2 == 1 && filterLines[count] == "*." + ADefaultExtension)
                {
                    DialogSave.FilterIndex = count / 2 + 1;
                }
            }

            DialogSave.AddExtension     = true;
            DialogSave.RestoreDirectory = true;
            DialogSave.Title            = ADialogTitle;

            if (DialogSave.ShowDialog() == DialogResult.OK)
            {
                if (DialogSave.FileName.ToLower().EndsWith("xml"))
                {
                    doc.Save(DialogSave.FileName);
                    return(true);
                }
                else if (DialogSave.FileName.ToLower().EndsWith("csv"))
                {
                    return(TCsv2Xml.Xml2Csv(doc, DialogSave.FileName));
                }
                else if (DialogSave.FileName.ToLower().EndsWith("yml"))
                {
                    return(TYml2Xml.Xml2Yml(doc, DialogSave.FileName));
                }
                else if (DialogSave.FileName.ToLower().EndsWith("xlsx"))
                {
                    using (FileStream fs = new FileStream(DialogSave.FileName, FileMode.Create))
                    {
                        if (TCsv2Xml.Xml2ExcelStream(doc, fs, false))
                        {
                            fs.Close();
                            return(true);
                        }
                    }

                    return(false);
                }
            }

            return(false);
        }
        /// <summary>
        /// convert from all sorts of formats into xml document;
        /// shows a dialog to the user to select the file to import
        /// </summary>
        /// <returns></returns>
        public static XmlDocument ImportWithDialog(string ADialogTitle, out string AFilename)
        {
            // TODO support import from Excel and OpenOffice files
            // See also http://sourceforge.net/apps/mediawiki/openpetraorg/index.php?title=Data_liberation
            OpenFileDialog DialogOpen = new OpenFileDialog();

            AFilename = "";

            DialogOpen.Filter = Catalog.GetString(
                "Text file (*.yml)|*.yml|XML file (*.xml)|*.xml|Spreadsheet file (*.csv)|All supported file formats (*.yml, *.xml, *.csv)|*.csv;*.yml;*.xml|");
            DialogOpen.FilterIndex      = 4;
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title            = ADialogTitle;

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                AFilename = DialogOpen.FileName;

                if (DialogOpen.FileName.ToLower().EndsWith("csv"))
                {
                    // select separator, make sure there is a header line with the column captions/names
                    TDlgSelectCSVSeparator dlgSeparator = new TDlgSelectCSVSeparator(true);
                    Boolean fileCanOpen = dlgSeparator.OpenCsvFile(DialogOpen.FileName);

                    if (!fileCanOpen)
                    {
                        throw new Exception(String.Format(Catalog.GetString("File {0} Cannot be opened."), DialogOpen.FileName));
                    }

                    dlgSeparator.SelectedSeparator = StringHelper.GetCSVSeparator(dlgSeparator.FileContent);

                    if (dlgSeparator.ShowDialog() == DialogResult.OK)
                    {
                        XmlDocument doc = TCsv2Xml.ParseCSVContent2Xml(dlgSeparator.FileContent, dlgSeparator.SelectedSeparator);
                        return(doc);
                    }
                }
                else if (DialogOpen.FileName.ToLower().EndsWith("xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(DialogOpen.FileName);
                    return(doc);
                }
                else if (DialogOpen.FileName.ToLower().EndsWith("yml"))
                {
                    TYml2Xml yml = new TYml2Xml(DialogOpen.FileName);
                    return(yml.ParseYML2XML());
                }
            }

            return(null);
        }
        /// <summary>
        /// Put this (XML formatted) data on a local file
        /// </summary>
        /// <param name="doc">XML data to be exported</param>
        /// <param name="FileName">Filename from GetExportFilename, above</param>
        /// <returns>true if successful</returns>
        public static bool ExportTofile(XmlDocument doc, string FileName)
        {
            if (FileName.EndsWith("xml"))
            {
                doc.Save(FileName);
                return(true);
            }
            else if (FileName.EndsWith("csv"))
            {
                return(TCsv2Xml.Xml2Csv(doc, FileName));
            }
            else if (FileName.EndsWith("yml"))
            {
                return(TYml2Xml.Xml2Yml(doc, FileName));
            }

            return(false);
        }
        /// <summary>
        /// Export data to a range of different file formats;
        /// ask the user for filename and file format
        ///
        /// NOTE this has been replaced by the two-part scheme above:
        ///   first get the filename, then the caller loads the data
        ///   from the server, then it calls ExportToFile.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="ADialogTitle"></param>
        /// <returns></returns>
        public static bool ExportWithDialog(XmlDocument doc, string ADialogTitle)
        {
            // TODO: TExcel excel = new TExcel();
            // TODO: openoffice
            // See also http://sourceforge.net/apps/mediawiki/openpetraorg/index.php?title=Data_liberation
            SaveFileDialog DialogSave = new SaveFileDialog();

            DialogSave.DefaultExt = "yml";
            DialogSave.Filter     = Catalog.GetString(
                "Text file (*.yml)|*.yml|XML file (*.xml)|*.xml|Petra export (*.ext)|*.ext|Spreadsheet file (*.csv)|*.csv");
            DialogSave.AddExtension     = true;
            DialogSave.RestoreDirectory = true;
            DialogSave.Title            = ADialogTitle;

            if (DialogSave.ShowDialog() == DialogResult.OK)
            {
                if (DialogSave.FileName.ToLower().EndsWith("xml"))
                {
                    doc.Save(DialogSave.FileName);
                    return(true);
                }
                else if (DialogSave.FileName.ToLower().EndsWith("ext"))
                {
                    return(false);
                }
                else if (DialogSave.FileName.ToLower().EndsWith("csv"))
                {
                    return(TCsv2Xml.Xml2Csv(doc, DialogSave.FileName));
                }
                else if (DialogSave.FileName.ToLower().EndsWith("yml"))
                {
                    return(TYml2Xml.Xml2Yml(doc, DialogSave.FileName));
                }
            }

            return(false);
        }