/// <summary>
        /// this supports the batch export files from Petra 2.x.
        /// Each line starts with a type specifier, B for batch, J for journal, T for transaction
        /// </summary>
        private void ExportBatches(object sender, EventArgs e)
        {
            if (rbtBatchNumberSelection.Checked)
            {
                if (!txtBatchNumberStart.NumberValueInt.HasValue)
                {
                    txtBatchNumberStart.NumberValueInt = 0;
                }

                if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                {
                    txtBatchNumberEnd.NumberValueInt = 999999;
                }
            }
            else
            {
                if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))
                {
                    return;
                }
            }

            if (File.Exists(txtFilename.Text))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                        Catalog.GetString("Export Batches"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            StreamWriter sw1 = null;
            try
            {
                sw1 = new StreamWriter(txtFilename.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                    Catalog.GetString("Failed to open file"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            String dateFormatString = cmbDateFormat.GetSelectedString();

            // might be called from the main navigation window (FMainDS is null), or from the GL Batch screen (reusing MainDS)
            if (FMainDS == null)
            {
                FMainDS = new Ict.Petra.Shared.MFinance.GL.Data.GLBatchTDS();
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatch(FLedgerNumber, -1, -1));
            }

            Int32 ALedgerNumber = 0;

            ArrayList batches = new ArrayList();

            foreach (ABatchRow batch in FMainDS.ABatch.Rows)
            {
                // check conditions for exporting this batch
                // Batch Status
                bool exportThisBatch = batch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED)
                                       || (chkIncludeUnposted.Checked && batch.BatchStatus.Equals(MFinanceConstants.BATCH_UNPOSTED));

                if (rbtBatchNumberSelection.Checked)
                {
                    exportThisBatch &= (batch.BatchNumber >= txtBatchNumberStart.NumberValueInt);
                    exportThisBatch &= (batch.BatchNumber <= txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    exportThisBatch &= (batch.DateEffective >= dtpDateFrom.Date);
                    exportThisBatch &= (batch.DateEffective <= dtpDateTo.Date);
                }

                if (exportThisBatch)
                {
                    batches.Add(batch.BatchNumber);
                }

                ALedgerNumber = batch.LedgerNumber;
            }

            if (batches.Count == 0)
            {
                MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            Hashtable requestParams = new Hashtable();
            requestParams.Add("ALedgerNumber", ALedgerNumber);
            requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
            requestParams.Add("DateFormatString", dateFormatString);
            requestParams.Add("Summary", rbtSummary.Checked);
            requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
            requestParams.Add("BaseCurrency", FMainDS.ALedger[0].BaseCurrency);
            requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
            requestParams.Add("bDontSummarize", chkDontSummarize.Checked);
            requestParams.Add("DontSummarizeAccount", cmbDontSummarizeAccount.GetSelectedString());
            requestParams.Add("DateForSummary", dtpDateSummary.Date);
            requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));

            String exportString = null;

            Thread ExportThread = new Thread(() => ExportAllGLBatchData(ref batches, requestParams, out exportString));
            using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
            {
                ExportDialog.ShowDialog();
            }

            sw1.Write(exportString);
            sw1.Close();

            MessageBox.Show(Catalog.GetString("Your data was exported successfully!"),
                Catalog.GetString("Success"),
                MessageBoxButtons.OK,
                MessageBoxIcon.Information);

            SaveUserDefaults();
        }
        /// <summary>
        /// Public method to export GL batches
        /// </summary>
        /// <returns>True if the Export succeeded and a file was created, false otherwise</returns>
        public bool ExportBatches()
        {
            if (txtFilename.Text == String.Empty)
            {
                MessageBox.Show(Catalog.GetString("Please choose a location for the Export File."),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            if (!Directory.Exists(Path.GetDirectoryName(txtFilename.Text)))
            {
                MessageBox.Show(Catalog.GetString("Please select an existing directory for this file!"),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                txtFilename.Text = string.Empty;
                return(false);
            }

            if (File.Exists(txtFilename.Text))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                                    Catalog.GetString("Export Batches"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return(false);
                }

                try
                {
                    File.Delete(txtFilename.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(
                                        Catalog.GetString(
                                            "Failed to delete the file. Maybe it is already open in another application?  The system message was:{0}{1}"),
                                        Environment.NewLine, ex.Message),
                                    Catalog.GetString("Export GL Batches"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }
            }

            if (rbtBatchNumberSelection.Checked)
            {
                if (!txtBatchNumberStart.NumberValueInt.HasValue)
                {
                    txtBatchNumberStart.NumberValueInt = 0;
                }

                if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                {
                    txtBatchNumberEnd.NumberValueInt = 999999;
                }
            }
            else
            {
                if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))
                {
                    return(false);
                }
            }

            String numberFormat = ConvertNumberFormat(cmbNumberFormat);
            String delimiter    = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            if (((numberFormat == "European") && (delimiter == ",")) || ((numberFormat == "American") && (delimiter == ".")))
            {
                MessageBox.Show(Catalog.GetString("Numeric Decimal cannot be the same as the delimiter."),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            // Save the defaults
            SaveUserDefaults();

            String dateFormatString = cmbDateFormat.GetSelectedString();

            // might be called from the main navigation window (FMainDS is null), or from the GL Batch screen (reusing MainDS)
            if (FMainDS == null)
            {
                FMainDS = new Ict.Petra.Shared.MFinance.GL.Data.GLBatchTDS();
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatch(FLedgerNumber, -1, -1));
            }

            Int32 ALedgerNumber = 0;

            ArrayList batches = new ArrayList();

            foreach (ABatchRow batch in FMainDS.ABatch.Rows)
            {
                // check conditions for exporting this batch
                // Batch Status
                bool exportThisBatch = batch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED) ||
                                       (chkIncludeUnposted.Checked && batch.BatchStatus.Equals(MFinanceConstants.BATCH_UNPOSTED));

                if (rbtBatchNumberSelection.Checked)
                {
                    exportThisBatch &= (batch.BatchNumber >= txtBatchNumberStart.NumberValueInt);
                    exportThisBatch &= (batch.BatchNumber <= txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    exportThisBatch &= (batch.DateEffective >= dtpDateFrom.Date);
                    exportThisBatch &= (batch.DateEffective <= dtpDateTo.Date);
                }

                if (exportThisBatch)
                {
                    batches.Add(batch.BatchNumber);
                }

                ALedgerNumber = batch.LedgerNumber;
            }

            if (batches.Count == 0)
            {
                MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            // Do the actual export work
            try
            {
                Hashtable requestParams = new Hashtable();
                requestParams.Add("ALedgerNumber", ALedgerNumber);
                requestParams.Add("Delimiter", delimiter);
                requestParams.Add("DateFormatString", dateFormatString);
                requestParams.Add("Summary", rbtSummary.Checked);
                requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
                requestParams.Add("BaseCurrency", FMainDS.ALedger[0].BaseCurrency);
                requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
                requestParams.Add("bDontSummarize", chkDontSummarize.Checked);
                requestParams.Add("DontSummarizeAccount", cmbDontSummarizeAccount.GetSelectedString());
                requestParams.Add("DateForSummary", dtpDateSummary.Date);
                requestParams.Add("NumberFormat", numberFormat);

                String exportString = null;
                Thread ExportThread = new Thread(() => ExportAllGLBatchData(batches, requestParams, out exportString));
                using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
                {
                    ExportDialog.ShowDialog();
                }

                // Now we have the string we can write it to the file
                StreamWriter sw1 = new StreamWriter(txtFilename.Text);
                sw1.Write(exportString);
                sw1.Close();
            }
            catch (Exception ex)
            {
                TLogging.Log("GLBatchExport.ManualCode: " + ex.ToString());
                MessageBox.Show(ex.Message,
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            // Offer the client the chance to open the file in Excel or whatever
            if (MessageBox.Show(Catalog.GetString("Your data was exported successfully! Would you like to open the file in your default application?"),
                                Catalog.GetString("GL Batch Export"),
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                ProcessStartInfo si = new ProcessStartInfo(txtFilename.Text);
                si.UseShellExecute = true;
                si.Verb            = "open";

                Process p = new Process();
                p.StartInfo = si;
                p.Start();
            }

            return(true);
        }
        /// <summary>
        /// Public method to export GL batches
        /// </summary>
        /// <returns>True if the Export succeeded and a file was created, false otherwise</returns>
        public bool ExportBatches()
        {
            if (txtFilename.Text == String.Empty)
            {
                MessageBox.Show(Catalog.GetString("Please choose a location for the Export File."),
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }

            if (!Directory.Exists(Path.GetDirectoryName(txtFilename.Text)))
            {
                MessageBox.Show(Catalog.GetString("Please select an existing directory for this file!"),
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                txtFilename.Text = string.Empty;
                return false;
            }

            if (File.Exists(txtFilename.Text))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                        Catalog.GetString("Export Batches"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return false;
                }

                try
                {
                    File.Delete(txtFilename.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(
                            Catalog.GetString(
                                "Failed to delete the file. Maybe it is already open in another application?  The system message was:{0}{1}"),
                            Environment.NewLine, ex.Message),
                        Catalog.GetString("Export GL Batches"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return false;
                }
            }

            if (rbtBatchNumberSelection.Checked)
            {
                if (!txtBatchNumberStart.NumberValueInt.HasValue)
                {
                    txtBatchNumberStart.NumberValueInt = 0;
                }

                if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                {
                    txtBatchNumberEnd.NumberValueInt = 999999;
                }
            }
            else
            {
                if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))
                {
                    return false;
                }
            }

            String numberFormat = ConvertNumberFormat(cmbNumberFormat);
            String delimiter = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            if (((numberFormat == "European") && (delimiter == ",")) || ((numberFormat == "American") && (delimiter == ".")))
            {
                MessageBox.Show(Catalog.GetString("Numeric Decimal cannot be the same as the delimiter."),
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }

            // Save the defaults
            SaveUserDefaults();

            String dateFormatString = cmbDateFormat.GetSelectedString();

            // might be called from the main navigation window (FMainDS is null), or from the GL Batch screen (reusing MainDS)
            if (FMainDS == null)
            {
                FMainDS = new Ict.Petra.Shared.MFinance.GL.Data.GLBatchTDS();
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatch(FLedgerNumber, -1, -1));
            }

            Int32 ALedgerNumber = 0;

            ArrayList batches = new ArrayList();

            foreach (ABatchRow batch in FMainDS.ABatch.Rows)
            {
                // check conditions for exporting this batch
                // Batch Status
                bool exportThisBatch = batch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED)
                                       || (chkIncludeUnposted.Checked && batch.BatchStatus.Equals(MFinanceConstants.BATCH_UNPOSTED));

                if (rbtBatchNumberSelection.Checked)
                {
                    exportThisBatch &= (batch.BatchNumber >= txtBatchNumberStart.NumberValueInt);
                    exportThisBatch &= (batch.BatchNumber <= txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    exportThisBatch &= (batch.DateEffective >= dtpDateFrom.Date);
                    exportThisBatch &= (batch.DateEffective <= dtpDateTo.Date);
                }

                if (exportThisBatch)
                {
                    batches.Add(batch.BatchNumber);
                }

                ALedgerNumber = batch.LedgerNumber;
            }

            if (batches.Count == 0)
            {
                MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }

            // Do the actual export work
            try
            {
                Hashtable requestParams = new Hashtable();
                requestParams.Add("ALedgerNumber", ALedgerNumber);
                requestParams.Add("Delimiter", delimiter);
                requestParams.Add("DateFormatString", dateFormatString);
                requestParams.Add("Summary", rbtSummary.Checked);
                requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
                requestParams.Add("BaseCurrency", FMainDS.ALedger[0].BaseCurrency);
                requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
                requestParams.Add("bDontSummarize", chkDontSummarize.Checked);
                requestParams.Add("DontSummarizeAccount", cmbDontSummarizeAccount.GetSelectedString());
                requestParams.Add("DateForSummary", dtpDateSummary.Date);
                requestParams.Add("NumberFormat", numberFormat);

                String exportString = null;
                Thread ExportThread = new Thread(() => ExportAllGLBatchData(batches, requestParams, out exportString));
                using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
                {
                    ExportDialog.ShowDialog();
                }

                // Now we have the string we can write it to the file
                StreamWriter sw1 = new StreamWriter(txtFilename.Text);
                sw1.Write(exportString);
                sw1.Close();
            }
            catch (Exception ex)
            {
                TLogging.Log("GLBatchExport.ManualCode: " + ex.ToString());
                MessageBox.Show(ex.Message,
                    Catalog.GetString("Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return false;
            }

            // Offer the client the chance to open the file in Excel or whatever
            if (MessageBox.Show(Catalog.GetString("Your data was exported successfully! Would you like to open the file in your default application?"),
                    Catalog.GetString("GL Batch Export"),
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                ProcessStartInfo si = new ProcessStartInfo(txtFilename.Text);
                si.UseShellExecute = true;
                si.Verb = "open";

                Process p = new Process();
                p.StartInfo = si;
                p.Start();
            }

            return true;
        }
        /// <summary>
        /// this supports the batch export files from Petra 2.x.
        /// Each line starts with a type specifier, B for batch, J for journal, T for transaction
        /// </summary>
        private void ExportBatches(object sender, EventArgs e)
        {
            if (rbtBatchNumberSelection.Checked)
            {
                if (!txtBatchNumberStart.NumberValueInt.HasValue)
                {
                    txtBatchNumberStart.NumberValueInt = 0;
                }

                if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                {
                    txtBatchNumberEnd.NumberValueInt = 999999;
                }
            }
            else
            {
                if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))
                {
                    return;
                }
            }

            if (File.Exists(txtFilename.Text))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                                    Catalog.GetString("Export Batches"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            StreamWriter sw1 = null;

            try
            {
                sw1 = new StreamWriter(txtFilename.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                Catalog.GetString("Failed to open file"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            String dateFormatString = cmbDateFormat.GetSelectedString();

            // might be called from the main navigation window (FMainDS is null), or from the GL Batch screen (reusing MainDS)
            if (FMainDS == null)
            {
                FMainDS = new Ict.Petra.Shared.MFinance.GL.Data.GLBatchTDS();
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatch(FLedgerNumber, -1, -1));
            }

            Int32 ALedgerNumber = 0;

            ArrayList batches = new ArrayList();

            foreach (ABatchRow batch in FMainDS.ABatch.Rows)
            {
                // check conditions for exporting this batch
                // Batch Status
                bool exportThisBatch = batch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED) ||
                                       (chkIncludeUnposted.Checked && batch.BatchStatus.Equals(MFinanceConstants.BATCH_UNPOSTED));

                if (rbtBatchNumberSelection.Checked)
                {
                    exportThisBatch &= (batch.BatchNumber >= txtBatchNumberStart.NumberValueInt);
                    exportThisBatch &= (batch.BatchNumber <= txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    exportThisBatch &= (batch.DateEffective >= dtpDateFrom.Date);
                    exportThisBatch &= (batch.DateEffective <= dtpDateTo.Date);
                }

                if (exportThisBatch)
                {
                    batches.Add(batch.BatchNumber);
                }

                ALedgerNumber = batch.LedgerNumber;
            }

            if (batches.Count == 0)
            {
                MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            Hashtable requestParams = new Hashtable();

            requestParams.Add("ALedgerNumber", ALedgerNumber);
            requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
            requestParams.Add("DateFormatString", dateFormatString);
            requestParams.Add("Summary", rbtSummary.Checked);
            requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
            requestParams.Add("BaseCurrency", FMainDS.ALedger[0].BaseCurrency);
            requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
            requestParams.Add("bDontSummarize", chkDontSummarize.Checked);
            requestParams.Add("DontSummarizeAccount", cmbDontSummarizeAccount.GetSelectedString());
            requestParams.Add("DateForSummary", dtpDateSummary.Date);
            requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));

            String exportString = null;

            Thread ExportThread = new Thread(() => ExportAllGLBatchData(ref batches, requestParams, out exportString));

            using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
            {
                ExportDialog.ShowDialog();
            }

            sw1.Write(exportString);
            sw1.Close();

            MessageBox.Show(Catalog.GetString("Your data was exported successfully!"),
                            Catalog.GetString("Success"),
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            SaveUserDefaults();
        }