/// <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> public void ExportBatches(bool AWithInteractionOnSuccess = true) { if (File.Exists(txtFilename.Text)) { if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"), Catalog.GetString("Export Gifts"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No) { return; } } StreamWriter sw1 = null; try { sw1 = new StreamWriter(txtFilename.Text, false, Encoding.GetEncoding(TAppSettingsManager.GetInt32("ExportGiftBatchEncoding", 1252))); } catch (Exception ex) { MessageBox.Show(ex.Message, Catalog.GetString("Failed to open file"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (rbtBatchNumberSelection.Checked) { if (!txtBatchNumberStart.NumberValueInt.HasValue) { txtBatchNumberStart.NumberValueInt = 0; } if (!txtBatchNumberEnd.NumberValueInt.HasValue) { txtBatchNumberEnd.NumberValueInt = 999999; } } else { if ((dtpDateFrom.Text == "") || (dtpDateTo.Text == "")) { MessageBox.Show(Catalog.GetString("Start and end dates must be provided."), Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate())) // If ValidDate fails, it displays a helpful message. { return; } } 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; } Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", delimiter); requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString()); requestParams.Add("Summary", rbtSummary.Checked); requestParams.Add("IncludeUnposted", chkIncludeUnposted.Checked); requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked); requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked); requestParams.Add("RecipientNumber", Convert.ToInt64(txtDetailRecipientKey.Text)); requestParams.Add("FieldNumber", Convert.ToInt64(txtDetailFieldKey.Text)); requestParams.Add("DateForSummary", dtpDateSummary.Date); requestParams.Add("NumberFormat", numberFormat); requestParams.Add("ExtraColumns", chkExtraColumns.Checked); if (rbtBatchNumberSelection.Checked) { requestParams.Add("BatchNumberStart", txtBatchNumberStart.NumberValueInt); requestParams.Add("BatchNumberEnd", txtBatchNumberEnd.NumberValueInt); } else { requestParams.Add("BatchDateFrom", dtpDateFrom.Date); requestParams.Add("BatchDateTo", dtpDateTo.Date); } TVerificationResultCollection AMessages = new TVerificationResultCollection(); String exportString = null; Int32 BatchCount = 0; Thread ExportThread = new Thread(() => ExportAllGiftBatchData( requestParams, out exportString, out AMessages, out BatchCount)); using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread)) { ExportDialog.ShowDialog(); } if ((AMessages != null) && (AMessages.Count > 0)) { if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages)) { MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (BatchCount == 0) { MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"), Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } sw1.Write(exportString); sw1.Close(); SaveUserDefaults(); if (AWithInteractionOnSuccess) { MessageBox.Show(Catalog.GetString("Gift Batches Exported successfully."), Catalog.GetString("Gift Batch Export"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { TLogging.Log("GiftBatchExport.ManualCode: " + ex.ToString()); MessageBox.Show(ex.Message, Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sw1.Close(); } }
/// <summary> /// Checks that a <see cref="TVerificationResultCollection" /> is either null or that it doesn't contain /// any <see cref="TVerificationResult" /> items . If it isn't null and it contains items an Assert.Fail call /// is issued by this Method! /// </summary> /// <remarks> /// Can be used for 'Guard Asserts' to check that the <see cref="TVerificationResultCollection" /> /// that is returned from server calls is null or empty. /// </remarks> /// <param name="AVerificationResult"><see cref="TVerificationResultCollection" /> reference (can be null!).</param> /// <param name="AMessage">String to append before the Assert message that this Method produces (optional).</param> public static void EnsureNullOrEmptyVerificationResult(TVerificationResultCollection AVerificationResult, string AMessage = "") { if ((AVerificationResult != null) && (AVerificationResult.Count > 0)) { Assert.Fail(AMessage + "*** VerificationResult is NOT EMPTY *** : " + AVerificationResult.BuildVerificationResultString()); } }
/// <summary> /// Checks that a <see cref="TVerificationResultCollection" /> is either null or that it doesn't contain /// any <see cref="TVerificationResult" /> items that are CriticalErrors. If it isn't null and it contains such items, an Assert.Fail /// call is issued by this Method! /// </summary> /// <remarks> /// Can be used for 'Guard Asserts' to check that the <see cref="TVerificationResultCollection" /> /// that is returned from server calls is null or holds only non-critical <see cref="TVerificationResult" /> items. /// </remarks> /// <param name="AVerificationResult"><see cref="TVerificationResultCollection" /> reference (can be null!).</param> /// <param name="AMessage">String to append before the Assert message that this Method produces (optional).</param> public static void EnsureNullOrOnlyNonCriticalVerificationResults(TVerificationResultCollection AVerificationResult, string AMessage = "") { string VerificationResultStr; if ((AMessage != String.Empty) && (!AMessage.EndsWith(" "))) { AMessage = AMessage + " "; } if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult)) { VerificationResultStr = AVerificationResult.BuildVerificationResultString(); TLogging.Log(VerificationResultStr); Assert.Fail(AMessage + "*** TVerificationResult HAS CRITICAL ERRORS *** : " + VerificationResultStr); } }
/// <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> /// <returns>True if the Export succeeded and a file was created, false otherwise</returns> public bool ExportBatches(bool AWithInteractionOnSuccess = true) { 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 Gifts"), 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 Gift 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.Text == "") || (dtpDateTo.Text == "")) { MessageBox.Show(Catalog.GetString("Start and end dates must be provided."), Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate())) // If ValidDate fails, it displays a helpful message. { 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; } try { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", delimiter); requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString()); requestParams.Add("Summary", rbtSummary.Checked); requestParams.Add("IncludeUnposted", chkIncludeUnposted.Checked); requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked); requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked); requestParams.Add("RecipientNumber", Convert.ToInt64(txtDetailRecipientKey.Text)); requestParams.Add("FieldNumber", Convert.ToInt64(txtDetailFieldKey.Text)); requestParams.Add("DateForSummary", dtpDateSummary.Date); requestParams.Add("NumberFormat", numberFormat); requestParams.Add("ExtraColumns", chkExtraColumns.Checked); if (rbtBatchNumberSelection.Checked) { requestParams.Add("BatchNumberStart", txtBatchNumberStart.NumberValueInt); requestParams.Add("BatchNumberEnd", txtBatchNumberEnd.NumberValueInt); } else { requestParams.Add("BatchDateFrom", dtpDateFrom.Date); requestParams.Add("BatchDateTo", dtpDateTo.Date); } TVerificationResultCollection AMessages = new TVerificationResultCollection(); String exportString = null; Int32 BatchCount = 0; Thread ExportThread = new Thread(() => ExportAllGiftBatchData( requestParams, out exportString, out AMessages, out BatchCount)); using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread)) { ExportDialog.ShowDialog(); } if ((AMessages != null) && (AMessages.Count > 0)) { if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages)) { MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else { MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } SaveUserDefaults(); //Process BatchCount value if (BatchCount == 0) { MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"), Catalog.GetString("Export"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } else if (BatchCount == -1) { MessageBox.Show(Catalog.GetString("Gift batch export cancelled"), Catalog.GetString("Export"), MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } else if (BatchCount == -2) { MessageBox.Show(Catalog.GetString("Gift batch export failed"), Catalog.GetString("Export"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } StreamWriter sw1 = new StreamWriter(txtFilename.Text, false, Encoding.GetEncoding(TAppSettingsManager.GetInt32("ExportGiftBatchEncoding", 1252))); sw1.Write(exportString); sw1.Close(); } catch (Exception ex) { TLogging.Log("GiftBatchExport.ManualCode: " + ex.ToString()); MessageBox.Show(ex.Message, Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } if (AWithInteractionOnSuccess) { if (MessageBox.Show(Catalog.GetString( "Gift Batches Exported successfully. Would you like to open the file in your default application?"), Catalog.GetString("Gift 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; }