示例#1
0
        /// <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 ExportBudget(object sender, EventArgs e)
        {
            FExportFileName = txtFilename.Text;
            String fileContents = string.Empty;
            Int32  budgetCount  = 0;

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

                FExportFileName = string.Empty;
                return;
            }

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

            Hashtable requestParams = new Hashtable();

            requestParams.Add("ALedgerNumber", FLedgerNumber);
            requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
            requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString());
            requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));

            TVerificationResultCollection AMessages;

            string[] delims = new string[1];
            delims[0] = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                budgetCount = TRemote.MFinance.Budget.WebConnectors.ExportBudgets(FLedgerNumber,
                                                                                  FExportFileName,
                                                                                  delims,
                                                                                  ref fileContents,
                                                                                  ref FBudgetDS,
                                                                                  out AMessages);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            if ((AMessages != null) && (AMessages.Count > 0))
            {
                if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages))
                {
                    MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    FExportFileName = string.Empty;
                    return;
                }
                else
                {
                    MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }

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

                FExportFileName = string.Empty;
                return;
            }

            StreamWriter sw1 = null;

            try
            {
                sw1 = new StreamWriter(FExportFileName);
                sw1.Write(fileContents);
            }
            finally
            {
                if (sw1 != null)
                {
                    sw1.Close();
                }
            }

            MessageBox.Show(Catalog.GetString(String.Format("Exported successfully! {0} Budget rows exported as file:{1}{1}{2}",
                                                            budgetCount.ToString(),
                                                            Environment.NewLine,
                                                            FExportFileName.ToUpper())),
                            Catalog.GetString("Budget Export"),
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            SaveUserDefaults();
        }
        /// <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 BtnOK_Click(object sender, EventArgs e)
        {
            FExportFileName = txtFilename.Text;
            String fileContents = string.Empty;
            Int32  budgetCount  = 0;

            if (FExportFileName == String.Empty)
            {
                MessageBox.Show(Catalog.GetString("Please choose a location for the Export File."),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            else if (!FExportFileName.EndsWith(".csv",
                                               StringComparison.CurrentCultureIgnoreCase) && !FExportFileName.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
            {
                FExportFileName += ".csv";
                txtFilename.Text = FExportFileName;
            }

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

                FExportFileName = string.Empty;
                return;
            }

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

                try
                {
                    File.Delete(FExportFileName);
                }
                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 Budget"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }

            //Hashtable requestParams = new Hashtable();

            //requestParams.Add("ALedgerNumber", FLedgerNumber);
            //requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
            //requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString());
            //requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));

            TVerificationResultCollection AMessages;

            string[] delims = new string[1];
            delims[0] = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            TFrmStatusDialog dlgStatus = null;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm());

                dlgStatus.Show();
                dlgStatus.Heading       = Catalog.GetString("Exporting Budgets");
                dlgStatus.CurrentStatus = Catalog.GetString("Exporting budget data for this year and next...");

                budgetCount = TRemote.MFinance.Budget.WebConnectors.ExportBudgets(FLedgerNumber,
                                                                                  FExportFileName,
                                                                                  delims,
                                                                                  ref fileContents,
                                                                                  ref FBudgetDS,
                                                                                  out AMessages);

                dlgStatus.Close();
                dlgStatus = null;

                this.Cursor = Cursors.Default;

                if ((AMessages != null) && (AMessages.Count > 0))
                {
                    if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages))
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);

                        FExportFileName = string.Empty;
                        return;
                    }
                    else
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }

                SaveUserDefaults();

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

                    FExportFileName = string.Empty;
                    return;
                }

                StreamWriter sw1 = new StreamWriter(FExportFileName);
                sw1.Write(fileContents);
                sw1.Close();
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
            finally
            {
                this.Cursor = Cursors.Default;

                if (dlgStatus != null)
                {
                    dlgStatus.Close();
                    dlgStatus = null;
                }
            }

            bool ShowExportedFileInExplorer = false;

            // Offer the client the chance to open the file in Excel or whatever
            if (MessageBox.Show(String.Format(Catalog.GetString(
                                                  "{0} Budget rows were exported successfully! Would you like to open the file in your default application?"),
                                              budgetCount.ToString()),
                                Catalog.GetString("Budget Export"),
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    ProcessStartInfo si = new ProcessStartInfo(FExportFileName);
                    si.UseShellExecute = true;
                    si.Verb            = "open";

                    Process p = new Process();
                    p.StartInfo = si;
                    p.Start();
                }
                catch
                {
                    MessageBox.Show(Catalog.GetString(
                                        "Unable to launch the default application to open: '") + FExportFileName + "'!", Catalog.GetString(
                                        "Budget Export"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    ShowExportedFileInExplorer = true;
                }
            }
            else
            {
                ShowExportedFileInExplorer = true;
            }

            if (ShowExportedFileInExplorer)
            {
                //If windows start Windows File Explorer
                TExecutingOSEnum osVersion = Utilities.DetermineExecutingOS();

                if ((osVersion >= TExecutingOSEnum.eosWinXP) &&
                    (osVersion < TExecutingOSEnum.oesUnsupportedPlatform))
                {
                    try
                    {
                        Process.Start("explorer.exe", string.Format("/select,\"{0}\"", FExportFileName));
                    }
                    catch
                    {
                        MessageBox.Show(Catalog.GetString(
                                            "Unable to launch Windows File Explorer to open: '") + FExportFileName + "'!", Catalog.GetString(
                                            "Budget Export"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }

            Close();
        }
        /// <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 BtnOK_Click(object sender, EventArgs e)
        {
            FExportFileName = txtFilename.Text;
            String fileContents = string.Empty;
            Int32  budgetCount  = 0;

            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;
            }

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

                FExportFileName = string.Empty;
                return;
            }

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

                try
                {
                    File.Delete(FExportFileName);
                }
                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 Budget"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }

            //Hashtable requestParams = new Hashtable();

            //requestParams.Add("ALedgerNumber", FLedgerNumber);
            //requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
            //requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString());
            //requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));

            TVerificationResultCollection AMessages;

            string[] delims = new string[1];
            delims[0] = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            try
            {
                this.Cursor = Cursors.WaitCursor;

                budgetCount = TRemote.MFinance.Budget.WebConnectors.ExportBudgets(FLedgerNumber,
                                                                                  FExportFileName,
                                                                                  delims,
                                                                                  ref fileContents,
                                                                                  ref FBudgetDS,
                                                                                  out AMessages);

                this.Cursor = Cursors.Default;

                if ((AMessages != null) && (AMessages.Count > 0))
                {
                    if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages))
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);

                        FExportFileName = string.Empty;
                        return;
                    }
                    else
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }

                SaveUserDefaults();

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

                    FExportFileName = string.Empty;
                    return;
                }

                StreamWriter sw1 = new StreamWriter(FExportFileName);
                sw1.Write(fileContents);
                sw1.Close();
            }
            catch (Exception ex)
            {
                TLogging.Log("ExportBudget.ManualCode: " + ex.ToString());
                MessageBox.Show(ex.Message,
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            // Offer the client the chance to open the file in Excel or whatever
            if (MessageBox.Show(String.Format(Catalog.GetString(
                                                  "{0} Budget rows were exported successfully! Would you like to open the file in your default application?"),
                                              budgetCount.ToString()),
                                Catalog.GetString("Budget 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();
            }

            Close();
        }