/// <summary> /// Shows a message that the user will need to have different Module permissions for the editing of data /// in *this* screen. Call this Method if the screen is read-only and the user has admin rights for the /// Module in which the screen is listed in the Main Menu. /// The user can choose to not get that message shown again (handled inside this called Method) - this /// choice is stored in a UserDefault. /// </summary> /// <param name="AParentForm">Reference to the calling Form.</param> /// <param name="AShownOnMenuForConvenience">The Module in which the screen is listed in the /// Main Menu.</param> /// <param name="AModuleThatDataIsAssociatedWith">Module that the data that this Form allows to edit /// is associated with.</param> /// <param name="AAdminModulePermission">The Module Permission required for editing data in the screen /// that differs from the Module Permission that is required for editing data of Setup screens in the /// respective Module.</param> /// <param name="AUserDefaultNameForNotShowingTheMessageBoxAgain">Name of the UserDefault. /// Gets prefixed with <see cref="TUserDefaults.NamedDefaults.SUPPRESS_MESSAGE_PREFIX"/>!</param> public static void MsgUserWillNeedToHaveDifferentAdminModulePermissionForEditing(Form AParentForm, string AShownOnMenuForConvenience, string AModuleThatDataIsAssociatedWith, string AAdminModulePermission, string AUserDefaultNameForNotShowingTheMessageBoxAgain) { TFrmExtendedMessageBox ExtendedMessageBox = new TFrmExtendedMessageBox(AParentForm); bool DoNotShowMessageBoxAgain; string FinalUserDefaultName = TUserDefaults.NamedDefaults.SUPPRESS_MESSAGE_PREFIX + AUserDefaultNameForNotShowingTheMessageBoxAgain; if (!TUserDefaults.GetBooleanDefault(FinalUserDefaultName, false)) { ExtendedMessageBox.ShowDialog( String.Format(MCommonResourcestrings.StrDiffentPermissionRequiredForEditingData, AAdminModulePermission) + Environment.NewLine + String.Format( MCommonResourcestrings.StrDiffentPermissionRequiredForEditingDataMenuHint, AShownOnMenuForConvenience, AModuleThatDataIsAssociatedWith), MCommonResourcestrings.StrReadOnlyInformationTitle, MCommonResourcestrings.StrDontShowThisMessageAgain, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); // We don't care about the return value because there is only an 'OK' Button shown... ExtendedMessageBox.GetResult(out DoNotShowMessageBoxAgain); if (DoNotShowMessageBoxAgain) { TUserDefaults.SetDefault(FinalUserDefaultName, DoNotShowMessageBoxAgain); } } }
/// <summary> /// The main method to run a reference check on a single item of data /// </summary> /// <param name="APetraUtilsObject">The calling forms PetraUtils Object</param> /// <param name="AVerificationResults">The results collection to check</param> /// <param name="ALimitedCount">Will be true if the reference count call was a limited check</param> /// <returns>A message box result. Yes implies doing a new unlimited count, Undefined implies there are no references so deletion can proceed. /// Any other value implies that references exist</returns> public TFrmExtendedMessageBox.TResult HandleReferences(TFrmPetraEditUtils APetraUtilsObject, TVerificationResultCollection AVerificationResults, bool ALimitedCount) { Form MyForm = APetraUtilsObject.GetForm(); // There were reference(s) TRowReferenceInfo info = (TRowReferenceInfo)AVerificationResults[0].ResultContext; bool bIncomplete = info.CascadingCountEndedEarly; // Build up a message string string msgContent = Messages.BuildMessageFromVerificationResult( MCommonResourcestrings.StrRecordCannotBeDeleted + Environment.NewLine + Catalog.GetPluralString(MCommonResourcestrings.StrReasonColon, MCommonResourcestrings.StrReasonsColon, AVerificationResults.Count), AVerificationResults); TFrmExtendedMessageBox.TButtons buttons = TFrmExtendedMessageBox.TButtons.embbOK; TFrmExtendedMessageBox.TDefaultButton defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton1; if (bIncomplete && ALimitedCount) { msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly1, Environment.NewLine, APetraUtilsObject.MaxReferenceCountOnDelete); msgContent += MCommonResourcestrings.StrCountTerminatedEarly2; msgContent += MCommonResourcestrings.StrCountTerminatedEarly3; msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly4, Environment.NewLine, MyForm.Text); buttons = TFrmExtendedMessageBox.TButtons.embbYesNo; defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton2; } else { if (bIncomplete) { // We should never get an incomplete count on an unlimited check } msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarlyOK, Environment.NewLine); } // Show an Extended Message Box and return the value TFrmExtendedMessageBox extendedMsgBox = new TFrmExtendedMessageBox(MyForm); return(extendedMsgBox.ShowDialog( msgContent, MCommonResourcestrings.StrRecordDeletionTitle, String.Empty, buttons, defButton, TFrmExtendedMessageBox.TIcon.embiInformation)); }
/// <summary> /// Opens an extended message box screen. /// </summary> /// <param name="AParentForm">The owner of the screen</param> /// <param name="AMessage">The message</param> /// <param name="ACaption">The box Title</param> /// <param name="AChkOptionText">Text to display with the checkbox. If empty no box is displayed.</param> /// <param name="AButtons">Integer value for the buttons to display corresponding to the TButtons enumeration. /// 0=embbYesYesToAllNoCancel, 1=embbYesYesToAllNoNoToAllCancel, 2=embbYesYesToAllNoNoToAll, 3=embbYesNo, 4=embbYesNoCancel, /// 5=embbOK, 6=embbOKCancel</param> /// <param name="ADefaultButton">Integer value for the default button corresponding to the TDefaultBtton enumeration. /// 0 indicates no default, 1 is button 1 and so on.</param> /// <param name="AIcon">Integer value for the icon corresponding to the TIcon enumeration.</param> /// <param name="AOptionEntrySelected">Set to true if the checkbox is to be initially selected.</param> /// <param name="AOptionExitSelected">Returns true if the option was selected on exit. False otherwise.</param> /// <returns>0=Yes, 1=YesToAll, 2=No, 3=NoToAll, 4=OK, 5=Cancel, 6=Undefined</returns> public static int Create(Form AParentForm, String AMessage, String ACaption, String AChkOptionText, int AButtons, int ADefaultButton, int AIcon, bool AOptionEntrySelected, out bool AOptionExitSelected) { TFrmExtendedMessageBox dlg = new TFrmExtendedMessageBox(AParentForm); dlg.ShowDialog(AMessage, ACaption, AChkOptionText, (TFrmExtendedMessageBox.TButtons)AButtons, (TFrmExtendedMessageBox.TDefaultButton)ADefaultButton, (TFrmExtendedMessageBox.TIcon)AIcon, AOptionEntrySelected); return((int)dlg.GetResult(out AOptionExitSelected)); }
private void Import(System.Object sender, EventArgs e) { if (ValidateAllData(true, TErrorProcessingMode.Epm_All)) { TVerificationResultCollection results = FPetraUtilsObject.VerificationResultCollection; int nRowsImported = TImportExchangeRates.ImportCurrencyExRates(FMainDS.ADailyExchangeRate, "Daily", results); if (results.Count > 0) { string formatter; if (nRowsImported == 0) { formatter = MCommonResourcestrings.StrExchRateImportNoRows; } else if (nRowsImported == 1) { formatter = MCommonResourcestrings.StrExchRateImportOneRow; } else { formatter = MCommonResourcestrings.StrExchRateImportMultiRow; } formatter += "{0}{0}{1}{0}{0}{3}{0}{0}{4}"; TFrmExtendedMessageBox messageBox = new TFrmExtendedMessageBox(this); messageBox.ShowDialog(String.Format( formatter, Environment.NewLine, results[0].ResultText, nRowsImported, results[0].ResultSeverity == TResultSeverity.Resv_Critical ? MCommonResourcestrings.StrExchRateImportTryAgain : String.Empty, results[0].ResultCode), MCommonResourcestrings.StrExchRateImportTitle, String.Empty, TFrmExtendedMessageBox.TButtons.embbOK, results[0].ResultSeverity == TResultSeverity.Resv_Critical ? TFrmExtendedMessageBox.TIcon.embiError : TFrmExtendedMessageBox.TIcon.embiInformation); results.Clear(); } else if (nRowsImported == 0) { MessageBox.Show(MCommonResourcestrings.StrExchRateImportNoRows, MCommonResourcestrings.StrExchRateImportTitle); } else if (nRowsImported == 1) { MessageBox.Show(MCommonResourcestrings.StrExchRateImportOneRowSuccess, MCommonResourcestrings.StrExchRateImportTitle); } else { MessageBox.Show(String.Format(MCommonResourcestrings.StrExchRateImportMultiRowSuccess, nRowsImported), MCommonResourcestrings.StrExchRateImportTitle); } if (nRowsImported > 0) { FPetraUtilsObject.SetChangedFlag(); } } }
/// <summary> /// The main method to run a reference check on a single item of data /// </summary> /// <param name="APetraUtilsObject">The calling forms PetraUtils Object</param> /// <param name="AVerificationResults">The results collection to check</param> /// <param name="ALimitedCount">Will be true if the reference count call was a limited check</param> /// <returns>A message box result. Yes implies doing a new unlimited count, Undefined implies there are no references so deletion can proceed. /// Any other value implies that references exist</returns> public TFrmExtendedMessageBox.TResult HandleReferences(TFrmPetraEditUtils APetraUtilsObject, TVerificationResultCollection AVerificationResults, bool ALimitedCount) { Form MyForm = APetraUtilsObject.GetForm(); // There were reference(s) TRowReferenceInfo info = (TRowReferenceInfo)AVerificationResults[0].ResultContext; bool bIncomplete = info.CascadingCountEndedEarly; // Build up a message string string msgContent = Messages.BuildMessageFromVerificationResult( MCommonResourcestrings.StrRecordCannotBeDeleted + Environment.NewLine + Catalog.GetPluralString(MCommonResourcestrings.StrReasonColon, MCommonResourcestrings.StrReasonsColon, AVerificationResults.Count), AVerificationResults); TFrmExtendedMessageBox.TButtons buttons = TFrmExtendedMessageBox.TButtons.embbOK; TFrmExtendedMessageBox.TDefaultButton defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton1; if (bIncomplete && ALimitedCount) { msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly1, Environment.NewLine, APetraUtilsObject.MaxReferenceCountOnDelete); msgContent += MCommonResourcestrings.StrCountTerminatedEarly2; msgContent += MCommonResourcestrings.StrCountTerminatedEarly3; msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly4, Environment.NewLine, MyForm.Text); buttons = TFrmExtendedMessageBox.TButtons.embbYesNo; defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton2; } else { if (bIncomplete) { // We should never get an incomplete count on an unlimited check } msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarlyOK, Environment.NewLine); } // Show an Extended Message Box and return the value TFrmExtendedMessageBox extendedMsgBox = new TFrmExtendedMessageBox(MyForm); return extendedMsgBox.ShowDialog( msgContent, MCommonResourcestrings.StrRecordDeletionTitle, String.Empty, buttons, defButton, TFrmExtendedMessageBox.TIcon.embiInformation); }
/// <summary> /// Delete subscription for Partners in selected Extract /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void DeleteSubscription(System.Object sender, EventArgs e) { String PublicationCode; Boolean DeleteAllSubscriptions = false; Boolean DeleteThisSubscription = false; Boolean AllDeletionsSucceeded = true; int CountDeleted = 0; if (!WarnIfNotSingleSelection(Catalog.GetString("Delete Subscription")) && (GetSelectedDetailRow() != null)) { TFrmUpdateExtractDeleteSubscriptionDialog dialog = new TFrmUpdateExtractDeleteSubscriptionDialog(this.FindForm()); dialog.SetExtractName(GetSelectedDetailRow().ExtractName); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { dialog.GetReturnedParameters(out PublicationCode); ExtractTDSMExtractTable ExtractTable; // retrieve all partners of extract from server ExtractTable = TRemote.MPartner.Partner.WebConnectors.GetExtractRowsWithPartnerData(GetSelectedDetailRow().ExtractId); foreach (ExtractTDSMExtractRow Row in ExtractTable.Rows) { if (TRemote.MPartner.Partner.WebConnectors.SubscriptionExists (Row.PartnerKey, PublicationCode)) { DeleteThisSubscription = false; if (!DeleteAllSubscriptions) { TFrmExtendedMessageBox.TResult Result; TFrmExtendedMessageBox ExtMsgBox = new TFrmExtendedMessageBox(this.FindForm()); Result = ExtMsgBox.ShowDialog(Catalog.GetString("You have chosen to delete the subscription of ") + PublicationCode + "\r\n" + Catalog.GetString("for Partner ") + Row.PartnerShortName + " (" + Row.PartnerKey + ")\r\n\r\n" + Catalog.GetString("Do you really want to delete it?"), Catalog.GetString("Delete Subscription"), "", TFrmExtendedMessageBox.TButtons.embbYesYesToAllNoCancel, TFrmExtendedMessageBox.TIcon.embiQuestion); switch (Result) { case TFrmExtendedMessageBox.TResult.embrYesToAll: DeleteAllSubscriptions = true; break; case TFrmExtendedMessageBox.TResult.embrYes: DeleteThisSubscription = true; break; case TFrmExtendedMessageBox.TResult.embrNo: DeleteThisSubscription = false; break; case TFrmExtendedMessageBox.TResult.embrCancel: MessageBox.Show(Catalog.GetString("Further deletion of Subscriptions cancelled"), Catalog.GetString("Delete Subscription"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; default: break; } } if (DeleteAllSubscriptions || DeleteThisSubscription) { if (!TRemote.MPartner.Partner.WebConnectors.DeleteSubscription (GetSelectedDetailRow().ExtractId, Row.PartnerKey, PublicationCode)) { MessageBox.Show(Catalog.GetString("Error while deleting Subscription ") + PublicationCode + Catalog.GetString(" for Partner ") + Row.PartnerShortName + " (" + Row.PartnerKey + ")", Catalog.GetString("Delete Subscription"), MessageBoxButtons.OK, MessageBoxIcon.Error); AllDeletionsSucceeded = false; } else { CountDeleted++; } } } } if (AllDeletionsSucceeded) { MessageBox.Show(String.Format(Catalog.GetString("Subscription {0} successfully deleted for {1} Partners in Extract {2}"), PublicationCode, CountDeleted, GetSelectedDetailRow().ExtractName), Catalog.GetString("Delete Subscription"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(String.Format(Catalog.GetString( "Error while deleting Subscription {0} for some Partners in Extract {1}. Subscription deleted for {2} Partners."), PublicationCode, GetSelectedDetailRow().ExtractName, CountDeleted), Catalog.GetString("Delete Subscription"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// Verify and if necessary update partner data in an extract /// </summary> public static void VerifyAndUpdateExtract(System.Windows.Forms.Form AForm, ref ExtractTDSMExtractTable AExtractTable, out bool AChangesMade) { bool AddressExists; bool AddressNeitherCurrentNorMailing; bool ReplaceAddress; bool ReplaceAddressYesToAll = false; bool ReplaceAddressNoToAll = false; string CountryName; string EmailAddress; PLocationTable LocationTable; PLocationRow LocationRow; PPartnerLocationTable PartnerLocationTable; TFrmExtendedMessageBox MsgBox = new TFrmExtendedMessageBox(AForm); TFrmExtendedMessageBox.TResult MsgBoxResult; bool DontShowPartnerRemovePartnerKeyNonExistent = false; bool DontShowReplaceAddress = false; bool DontShowPartnerRemoveNoAddress = false; // initialize output parameter AChangesMade = false; // build a collection of objects to be deleted before actually deleting them (as otherwise // indexes may not be valid any longer) List <ExtractTDSMExtractRow>RowsToDelete = new List <ExtractTDSMExtractRow>(); // prepare mouse cursor so user knows something is happening AForm.Cursor = Cursors.WaitCursor; // look at every single extract row foreach (ExtractTDSMExtractRow Row in AExtractTable.Rows) { // initialize for this row ReplaceAddress = false; // check if the partner record still exists, otherwise remove from extract if (!TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartner(Row.PartnerKey)) { if (!DontShowPartnerRemovePartnerKeyNonExistent) { MsgBox.ShowDialog(String.Format(Catalog.GetString("The following partner record does not exist any longer and " + "will therefore be removed from this extract: \n\r\n\r" + "{0} ({1})"), Row.PartnerShortName, Row.PartnerKey), Catalog.GetString("Verify and Update Extract"), Catalog.GetString("Don't show this message again"), TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemovePartnerKeyNonExistent); } RowsToDelete.Add(Row); } else { AddressExists = TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartnerAtLocation (Row.PartnerKey, new TLocationPK(Row.SiteKey, Row.LocationKey), out AddressNeitherCurrentNorMailing); if (!AddressExists) { if (!DontShowReplaceAddress) { MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract no longer exists and " + "will therefore be replaced with a current address"), Row.PartnerShortName, Row.PartnerKey), Catalog.GetString("Verify and Update Extract"), Catalog.GetString("Don't show this message again"), TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); MsgBoxResult = MsgBox.GetResult(out DontShowReplaceAddress); } ReplaceAddress = true; } else if (AddressNeitherCurrentNorMailing) { if (!ReplaceAddressYesToAll && !ReplaceAddressNoToAll) { MsgBoxResult = MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract is not current. " + "Do you want to update it with a current address if there is one?"), Row.PartnerShortName, Row.PartnerKey), Catalog.GetString("Verify and Update Extract"), "", TFrmExtendedMessageBox.TButtons.embbYesYesToAllNoNoToAll, TFrmExtendedMessageBox.TIcon.embiQuestion); if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYesToAll) { ReplaceAddressYesToAll = true; } else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYes) { ReplaceAddress = true; } else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrNoToAll) { ReplaceAddressNoToAll = true; } } // need to set the flag each time we come through here. if (ReplaceAddressYesToAll) { ReplaceAddress = true; } } if (ReplaceAddress) { if (!TRemote.MPartner.Mailing.WebConnectors.GetBestAddress(Row.PartnerKey, out LocationTable, out PartnerLocationTable, out CountryName, out EmailAddress)) { // in this case there is no address at all for this partner (should not really happen) if (!DontShowPartnerRemoveNoAddress) { MsgBox.ShowDialog(String.Format(Catalog.GetString("No address could be found for {0} ({1}). " + "Therefore the partner record will be removed from this extract"), Row.PartnerShortName, Row.PartnerKey), Catalog.GetString("Verify and Update Extract"), Catalog.GetString("Don't show this message again"), TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemoveNoAddress); } RowsToDelete.Add(Row); } else { if (LocationTable.Rows.Count > 0) { LocationRow = (PLocationRow)LocationTable.Rows[0]; /* it could be that GetBestAddress still returns a non-current address if * there is no better one */ if ((Row.SiteKey != LocationRow.SiteKey) || (Row.LocationKey != LocationRow.LocationKey)) { AChangesMade = true; Row.SiteKey = LocationRow.SiteKey; Row.LocationKey = LocationRow.LocationKey; } } } } } } // now delete the actual rows foreach (ExtractTDSMExtractRow Row in RowsToDelete) { AChangesMade = true; Row.Delete(); } // prepare mouse cursor so user knows something is happening AForm.Cursor = Cursors.Default; }
/// <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 ImportBatches(TGiftImportDataSourceEnum AImportSource) { bool ok = false; String importString; String impOptions; OpenFileDialog dialog = null; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString("Please save before calling this function!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FdlgSeparator = new TDlgSelectCSVSeparator(false); if (AImportSource == TGiftImportDataSourceEnum.FromClipboard) { importString = Clipboard.GetText(TextDataFormat.UnicodeText); if ((importString == null) || (importString.Length == 0)) { MessageBox.Show(Catalog.GetString("Please first copy data from your spreadsheet application!"), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.SelectedSeparator = "\t"; FdlgSeparator.CSVData = importString; FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } } else if (AImportSource == TGiftImportDataSourceEnum.FromFile) { dialog = new OpenFileDialog(); dialog.FileName = TUserDefaults.GetStringDefault("Imp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "import.csv"); dialog.Title = Catalog.GetString("Import Batches from CSV File"); dialog.Filter = Catalog.GetString("Gift Batches files (*.csv)|*.csv"); impOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN); if (dialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(dialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } importString = File.ReadAllText(dialog.FileName); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } FdlgSeparator.SelectedSeparator = impOptions.Substring(0, 1); } else { return; } } else { // unknown source!! The following need a value... impOptions = String.Empty; importString = String.Empty; } if (FdlgSeparator.ShowDialog() == DialogResult.OK) { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", FdlgSeparator.SelectedSeparator); requestParams.Add("DateFormatString", FdlgSeparator.DateFormat); requestParams.Add("NumberFormat", FdlgSeparator.NumberFormat); requestParams.Add("NewLine", Environment.NewLine); bool Repeat = true; while (Repeat) { Repeat = false; TVerificationResultCollection AMessages = new TVerificationResultCollection(); GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber = new GiftBatchTDSAGiftDetailTable(); Thread ImportThread = new Thread(() => ImportGiftBatches( requestParams, importString, out AMessages, out ok, out NeedRecipientLedgerNumber)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } // If NeedRecipientLedgerNumber contains data then AMessages will only ever contain // one message alerting the user that no data has been imported. // We do not want to show this as we will be displaying another more detailed message. if (NeedRecipientLedgerNumber.Rows.Count == 0) { ShowMessages(AMessages); } // if the import contains gifts with Motivation Group 'GIFT' and that have a Family recipient with no Gift Destination // then the import will have failed and we need to alert the user if (NeedRecipientLedgerNumber.Rows.Count > 0) { bool OfferToRunImportAgain = true; bool DoNotShowMessageBoxEverytime = false; TFrmExtendedMessageBox.TResult Result = TFrmExtendedMessageBox.TResult.embrUndefined; int count = 1; // for each gift in which the recipient needs a Git Destination foreach (GiftBatchTDSAGiftDetailRow Row in NeedRecipientLedgerNumber.Rows) { if (!DoNotShowMessageBoxEverytime) { string CheckboxText = string.Empty; // only show checkbox if there is at least one more occurance of this error if (NeedRecipientLedgerNumber.Rows.Count - count > 0) { CheckboxText = string.Format( Catalog.GetString("Do this for all further occurances ({0})?"), NeedRecipientLedgerNumber.Rows.Count - count); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm()); extendedMessageBox.ShowDialog(string.Format( Catalog.GetString( "Gift Import has been cancelled as the recipient '{0}' ({1}) has no Gift Destination assigned."), Row.RecipientDescription, Row.RecipientKey) + "\n\r\n\r\n\r" + Catalog.GetString("Do you want to assign a Gift Destination to this partner now?"), Catalog.GetString("Import Errors"), CheckboxText, TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiWarning); Result = extendedMessageBox.GetResult(out DoNotShowMessageBoxEverytime); } if (Result == TFrmExtendedMessageBox.TResult.embrYes) { // allow the user to assign a Gift Destingation TFrmGiftDestination GiftDestinationForm = new TFrmGiftDestination(FPetraUtilsObject.GetForm(), Row.RecipientKey); GiftDestinationForm.ShowDialog(); } else { OfferToRunImportAgain = false; if (DoNotShowMessageBoxEverytime) { break; } } count++; } // if the user has clicked yes to assigning Gift Destinations then offer to restart the import if (OfferToRunImportAgain && (MessageBox.Show(Catalog.GetString("Would you like to import this Gift Batch again?"), Catalog.GetString("Gift Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)) { Repeat = true; } } } } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); SaveUserDefaults(dialog, impOptions); FMyUserControl.LoadBatchesForCurrentYear(); FPetraUtilsObject.DisableSaveButton(); } }
private void ShowMessages(TVerificationResultCollection AMessages) { StringBuilder ErrorMessages = new StringBuilder(); if (AMessages.Count > 0) { foreach (TVerificationResult message in AMessages) { ErrorMessages.AppendFormat("[{0}] {1}: {2}{3}", message.ResultContext, message.ResultTextCaption, message.ResultText.Replace(Environment.NewLine, " "), Environment.NewLine); } } if (ErrorMessages.Length > 0) { TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm()); extendedMessageBox.ShowDialog(ErrorMessages.ToString(), Catalog.GetString("Import Errors"), String.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiError); } }
private void UpdateTaxDeductiblePct() { decimal OriginalPct = 100; decimal NewPct = 100; DateTime OriginalValidFrom = DateTime.MinValue; DateTime NewValidFrom = DateTime.MinValue; // if a datarow already exists if (FMainDS.PPartnerTaxDeductiblePct.Rows[0].HasVersion(DataRowVersion.Original)) { OriginalPct = Convert.ToDecimal( FMainDS.PPartnerTaxDeductiblePct.Rows[0][PPartnerTaxDeductiblePctTable.GetPercentageTaxDeductibleDBName(), DataRowVersion.Original]); OriginalValidFrom = Convert.ToDateTime( FMainDS.PPartnerTaxDeductiblePct.Rows[0][PPartnerTaxDeductiblePctTable.GetDateValidFromDBName(), DataRowVersion.Original]); } int i = 0; // there will be either 0 or 1 rows that are not marked as deleted while (FMainDS.PPartnerTaxDeductiblePct.Rows[i].RowState == DataRowState.Deleted && i < (FMainDS.PPartnerTaxDeductiblePct.Rows.Count - 1)) { i++; } // if Tax Deductible Pct has not just been removed if (FMainDS.PPartnerTaxDeductiblePct.Rows[i].HasVersion(DataRowVersion.Current)) { NewPct = Convert.ToDecimal( FMainDS.PPartnerTaxDeductiblePct.Rows[i][PPartnerTaxDeductiblePctTable.GetPercentageTaxDeductibleDBName(), DataRowVersion.Current]); NewValidFrom = Convert.ToDateTime( FMainDS.PPartnerTaxDeductiblePct.Rows[i][PPartnerTaxDeductiblePctTable.GetDateValidFromDBName(), DataRowVersion.Current]); } // if either pct or date has changed if ((NewPct != OriginalPct) || (OriginalValidFrom != NewValidFrom)) { DataTable GiftTotals; // find gifts that could be affected by this change if (TRemote.MFinance.Gift.WebConnectors.IsPartnerARecipient(FPartnerKey, out GiftTotals, NewPct, NewValidFrom)) { string StartMsg = string.Empty; string PermissionGifts = string.Empty; string NoPermissionGifts = string.Empty; bool UnpostedGifts = false; bool UnpostedGiftInLedgerWithNoPermission = false; bool PostedGifts = false; bool PostedGiftInLedgerWithNoPermission = false; // check what gifts we have - posted/unposted - ledger permission/no ledger permission foreach (DataRow Row in GiftTotals.Rows) { if (Convert.ToInt32(Row["Unposted"]) > 0) { if (UserInfo.GUserInfo.IsInLedger(Convert.ToInt32(Row["LedgerNumber"]))) { UnpostedGifts = true; } else { UnpostedGiftInLedgerWithNoPermission = true; } } if (Convert.ToInt32(Row["Posted"]) > 0) { if (UserInfo.GUserInfo.IsInLedger(Convert.ToInt32(Row["LedgerNumber"]))) { PostedGifts = true; } else { PostedGiftInLedgerWithNoPermission = true; } } } // if pct (and date) has changed if (NewPct != OriginalPct) { StartMsg = string.Format(Catalog.GetString("This partner's Tax Deductible Percentage has been changed from {0}% to {1}%."), OriginalPct.ToString("0.##"), NewPct.ToString("0.##")); } // if only date has changed else { StartMsg = string.Format(Catalog.GetString( "This partner's Tax Deductible Percentage has been changed to {0}% for all gifts from {1}."), NewPct.ToString("0.##"), NewValidFrom.Date.ToString("dd-MMM-yyyy")); } /* Unposted gifts */ if (UnpostedGifts || UnpostedGiftInLedgerWithNoPermission) { if (UnpostedGifts) { PermissionGifts = "\n\n" + Catalog.GetString("Do you want to update all unposted gifts with this new percentage?") + "\n"; } if (UnpostedGiftInLedgerWithNoPermission) { NoPermissionGifts = "\n\n" + Catalog.GetString( "Some unposted gifts cannot be auto updated with this new percentage as you do not have permission to access the ledger which they belong to." ) + "\n"; } // add info on how many gifts belonging to which ledger foreach (DataRow Row in GiftTotals.Rows) { if ((Convert.ToInt32(Row["Unposted"]) > 0) && UserInfo.GUserInfo.IsInLedger(Convert.ToInt32(Row["LedgerNumber"]))) { if (Convert.ToInt32(Row["Unposted"]) == 1) { PermissionGifts += "\n" + "- " + string.Format(Catalog.GetString("1 unposted gift from Ledger {0}"), Convert.ToInt32(Row["LedgerNumber"])); } else { PermissionGifts += "\n" + "- " + string.Format(Catalog.GetString("{0} unposted gifts from Ledger {1}"), Convert.ToInt32(Row["Unposted"]), Convert.ToInt32(Row["LedgerNumber"])); } } else if (Convert.ToInt32(Row["Unposted"]) > 0) { if (Convert.ToInt32(Row["Unposted"]) == 1) { NoPermissionGifts += "\n" + "- " + string.Format(Catalog.GetString("1 unposted gift from Ledger {0}"), Convert.ToInt32(Row["LedgerNumber"])); } else { NoPermissionGifts += "\n" + "- " + string.Format(Catalog.GetString("{0} unposted gifts from Ledger {1}"), Convert.ToInt32(Row["Unposted"]), Convert.ToInt32(Row["LedgerNumber"])); } } } // display a message box if (UnpostedGifts) { if (!string.IsNullOrEmpty(NoPermissionGifts)) { NoPermissionGifts = "(" + NoPermissionGifts + ")"; } if (MessageBox.Show(StartMsg + PermissionGifts + NoPermissionGifts, Catalog.GetString("Tax Deductible Percentage Changed"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { // update unposted gifts TRemote.MFinance.Gift.WebConnectors.UpdateUnpostedGiftsTaxDeductiblePct(FPartnerKey, NewPct, NewValidFrom); } } else { MessageBox.Show(StartMsg + NoPermissionGifts, Catalog.GetString("Tax Deductible Percentage Changed"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } /* Posted gifts */ if (PostedGifts || PostedGiftInLedgerWithNoPermission) { if (PostedGifts) { PermissionGifts = Environment.NewLine + Environment.NewLine + string.Format(Catalog.GetString( "Do you want to update all posted gifts from {0} with this new percentage?"), NewValidFrom.Date.ToString("dd-MMM-yyyy")) + Environment.NewLine; } if (PostedGiftInLedgerWithNoPermission) { NoPermissionGifts = Environment.NewLine + Environment.NewLine + Catalog.GetString( "Some posted gifts cannot be auto updated with this new percentage as you do not have permission to access the ledger which they belong to." ) + Environment.NewLine; } // add info on how many gifts belonging to which ledger foreach (DataRow Row in GiftTotals.Rows) { if ((Convert.ToInt32(Row["Posted"]) > 0) && UserInfo.GUserInfo.IsInLedger(Convert.ToInt32(Row["LedgerNumber"]))) { if (Convert.ToInt32(Row["Posted"]) == 1) { PermissionGifts += Environment.NewLine + "- " + string.Format(Catalog.GetString("1 posted gift from Ledger {0}"), Convert.ToInt32(Row["LedgerNumber"])); } else { PermissionGifts += Environment.NewLine + "- " + string.Format(Catalog.GetString("{0} posted gifts from Ledger {1}"), Convert.ToInt32(Row["Posted"]), Convert.ToInt32(Row["LedgerNumber"])); } } else if (Convert.ToInt32(Row["Posted"]) > 0) { if (Convert.ToInt32(Row["Posted"]) == 1) { NoPermissionGifts += Environment.NewLine + "- " + string.Format(Catalog.GetString("1 posted gift from Ledger {0}"), Convert.ToInt32(Row["LedgerNumber"])); } else { NoPermissionGifts += Environment.NewLine + "- " + string.Format(Catalog.GetString("{0} posted gifts from Ledger {1}"), Convert.ToInt32(Row["Posted"]), Convert.ToInt32(Row["LedgerNumber"])); } } } // display a message box if (PostedGifts) { if (!string.IsNullOrEmpty(NoPermissionGifts)) { NoPermissionGifts = "(" + NoPermissionGifts + ")"; } TFrmExtendedMessageBox ExtendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm()); if (ExtendedMessageBox.ShowDialog(StartMsg + PermissionGifts + NoPermissionGifts, Catalog.GetString("Tax Deductible Percentage Changed"), Catalog.GetString("Do not print the adjusting gift transactions on periodic receipts"), TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiQuestion) == TFrmExtendedMessageBox.TResult.embrYes) { bool NoLabel; ExtendedMessageBox.GetResult(out NoLabel); // update posted gifts TCommonScreensForwarding.TaxDeductiblePctAdjust.Invoke(FPartnerKey, NewPct, NewValidFrom, NoLabel, FPetraUtilsObject.GetForm()); } } else { MessageBox.Show(StartMsg + NoPermissionGifts, Catalog.GetString("Tax Deductible Percentage Changed"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } }
private void ShowMessages(TVerificationResultCollection AMessages, int ANumBudgetsToImport, int ANumRecsUpdated, int ANumRowsFailed) { StringBuilder ErrorMessages = new StringBuilder(); if (ANumBudgetsToImport != 0) { // if there were budgets to import if (ANumBudgetsToImport > 0) { ErrorMessages.AppendFormat (Catalog.GetPluralString("{0} budget row was found in the file ", "{0} budget rows were found in the file ", ANumBudgetsToImport, true), ANumBudgetsToImport); ErrorMessages.AppendFormat (Catalog.GetPluralString("and {0} was successfully imported!", "and {0} were successfully imported!", ANumBudgetsToImport - ANumRowsFailed, true), (ANumBudgetsToImport - ANumRowsFailed)); if (ANumRecsUpdated > 0) { ErrorMessages.AppendFormat(Catalog.GetPluralString("{0}({1} of which updated an existing budget row.)", "{0}({1} of which updated existing budget rows.)", ANumRecsUpdated), Environment.NewLine, ANumRecsUpdated); } ErrorMessages.Append(Environment.NewLine + Environment.NewLine); } //Check for import errors if (AMessages.Count > 0) { ErrorMessages.AppendFormat( Catalog.GetPluralString("{0} row failed to import:{1}", "{0} rows failed to import:{1}", ANumRowsFailed, true), ANumRowsFailed, Environment.NewLine); foreach (TVerificationResult message in AMessages) { ErrorMessages.AppendFormat("{0}[{1}] {2}: {3}", Environment.NewLine, message.ResultContext, message.ResultTextCaption, message.ResultText); } } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FParentForm); if ((ANumRowsFailed > 0) || (ANumBudgetsToImport == -1)) { extendedMessageBox.ShowDialog(ErrorMessages.ToString(), Catalog.GetString("Budget Import"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiError); } else { extendedMessageBox.ShowDialog(ErrorMessages.ToString(), Catalog.GetString("Budget Import"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); } } else //0 { MessageBox.Show(Catalog.GetString("No records found to import"), Catalog.GetString( "Budget Import"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Opens an extended message box screen. /// </summary> /// <param name="AParentForm">The owner of the screen</param> /// <param name="AMessage">The message</param> /// <param name="ACaption">The box Title</param> /// <param name="AChkOptionText">Text to display with the checkbox. If empty no box is displayed.</param> /// <param name="AButtons">Integer value for the buttons to display corresponding to the TButtons enumeration. /// 0=embbYesYesToAllNoCancel, 1=embbYesYesToAllNoNoToAllCancel, 2=embbYesYesToAllNoNoToAll, 3=embbYesNo, 4=embbYesNoCancel, /// 5=embbOK, 6=embbOKCancel</param> /// <param name="ADefaultButton">Integer value for the default button corresponding to the TDefaultBtton enumeration. /// 0 indicates no default, 1 is button 1 and so on.</param> /// <param name="AIcon">Integer value for the icon corresponding to the TIcon enumeration.</param> /// <param name="AOptionEntrySelected">Set to true if the checkbox is to be initially selected.</param> /// <param name="AOptionExitSelected">Returns true if the option was selected on exit. False otherwise.</param> /// <returns>0=Yes, 1=YesToAll, 2=No, 3=NoToAll, 4=OK, 5=Cancel, 6=Undefined</returns> public static int Create(Form AParentForm, String AMessage, String ACaption, String AChkOptionText, int AButtons, int ADefaultButton, int AIcon, bool AOptionEntrySelected, out bool AOptionExitSelected) { TFrmExtendedMessageBox dlg = new TFrmExtendedMessageBox(AParentForm); dlg.ShowDialog(AMessage, ACaption, AChkOptionText, (TFrmExtendedMessageBox.TButtons)AButtons, (TFrmExtendedMessageBox.TDefaultButton)ADefaultButton, (TFrmExtendedMessageBox.TIcon)AIcon, AOptionEntrySelected); return (int)dlg.GetResult(out AOptionExitSelected); }
// The Preview button has been clicked private void PreviewLayout(Object sender, EventArgs e) { // perform standard validation to make sure the layout text has no errors if (ValidateAllData(true, TErrorProcessingMode.Epm_IgnoreNonCritical)) { this.Cursor = Cursors.WaitCursor; TFrmExtendedMessageBox msgBox = new TFrmExtendedMessageBox(this); string s = Catalog.GetString("This is how your address layout will look when printed :"); s += Environment.NewLine + Environment.NewLine; // Get the layout from the server using the same method used by Templater s += TRemote.MPartner.Partner.WebConnectors.PreviewAddressBlock(txtDetailAddressBlockText.Text); this.Cursor = Cursors.Default; msgBox.ShowDialog(s, Catalog.GetString("Layout Printing Example"), String.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiInformation); } }