/// <summary>
        /// Check for ExWorkers before saving or cancelling
        /// </summary>
        /// <param name="AAction"></param>
        /// <param name="AGetOnlyTransDataFromControls"></param>
        /// <param name="ABatchLevelAction"></param>
        /// <returns>True if Save is successful</returns>
        public bool SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction AAction,
                                      bool AGetOnlyTransDataFromControls = false,
                                      bool ABatchLevelAction             = true)
        {
            if (AAction == TExtraGiftBatchChecks.GiftBatchAction.NONE)
            {
                AAction = TExtraGiftBatchChecks.GiftBatchAction.SAVING;
                FCurrentGiftBatchAction = AAction;
            }

            if ((AAction != TExtraGiftBatchChecks.GiftBatchAction.DELETING) &&
                (AAction != TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS))
            {
                GetDataFromControls();
            }
            else if (ABatchLevelAction && AGetOnlyTransDataFromControls) //Only applicable when cancelling current batch
            {
                //If in deletion but trans tab is showing data from an earlier viewed batch with changes
                // then still need to get data from controls on Transaction tab.
                ucoRecurringTransactions.GetDataFromControls();
            }

            //First alert the user to any recipients who are Ex-Workers
            // For deleted batches this data would already have been deleted and so will
            //  only affect other unsaved batches.
            if (TExtraGiftBatchChecks.CanContinueWithAnyExWorkers(AAction, FMainDS, FPetraUtilsObject))
            {
                return(SaveChanges());
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Check for ExWorkers before saving or cancelling
        /// </summary>
        /// <returns>True if Save is successful</returns>
        public bool SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction AAction)
        {
            GetDataFromControls();

            // first alert the user to any recipients who are Ex-Workers
            if (TExtraGiftBatchChecks.CanContinueWithAnyExWorkers(AAction, FMainDS, FPetraUtilsObject))
            {
                return(SaveChanges());
            }

            return(false);
        }
        private void FPetraUtilsObject_DataSavingValidated(object Sender, CancelEventArgs e)
        {
            if (FCurrentGiftBatchAction == TExtraGiftBatchChecks.GiftBatchAction.NONE)
            {
                FCurrentGiftBatchAction = TExtraGiftBatchChecks.GiftBatchAction.SAVING;
            }

            //Check if the user has made a Bank Cost Centre or Account Code inactive
            // on saving
            if (!ucoRecurringBatches.AllowInactiveFieldValues(FCurrentGiftBatchAction))
            {
                e.Cancel = true;
            }
        }
Example #4
0
        /// <summary>
        /// Check for inactive field values
        /// </summary>
        /// <param name="AAction"></param>
        /// <returns></returns>
        public bool AllowInactiveFieldValues(TExtraGiftBatchChecks.GiftBatchAction AAction)
        {
            TFrmRecurringGiftBatch MainForm = (TFrmRecurringGiftBatch)this.ParentForm;

            bool InSubmitting    = (AAction == TExtraGiftBatchChecks.GiftBatchAction.SUBMITTING);
            bool InDeleting      = (AAction == TExtraGiftBatchChecks.GiftBatchAction.DELETING);
            bool InDeletingTrans = (AAction == TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS);

            int CurrentBatch = FPreviouslySelectedDetailRow.BatchNumber;

            //Variables for building warning message
            string        WarningMessage = string.Empty;
            string        WarningHeader  = string.Empty;
            StringBuilder WarningList    = new StringBuilder();

            //Find batches that have changed
            List <ARecurringGiftBatchRow> BatchesToCheck = MainForm.GetUnsavedBatchRowsList(CurrentBatch);
            List <int> BatchesWithInactiveValues         = new List <int>();

            if (BatchesToCheck.Count > 0)
            {
                int    currentBatchListNo;
                string batchNoList = string.Empty;

                int    numInactiveFieldsPresent = 0;
                string bankCostCentre;
                string bankAccount;

                foreach (ARecurringGiftBatchRow gBR in BatchesToCheck)
                {
                    currentBatchListNo = gBR.BatchNumber;

                    bool checkingCurrentBatch = (currentBatchListNo == CurrentBatch);

                    bool batchVerified     = false;
                    bool batchExistsInDict = FRecurringBatchesVerifiedOnSavingDict.TryGetValue(currentBatchListNo, out batchVerified);

                    if (batchExistsInDict)
                    {
                        if (batchVerified && !(InSubmitting && checkingCurrentBatch && FWarnOfInactiveValuesOnSubmitting))
                        {
                            continue;
                        }
                    }
                    else if (!(InDeleting && checkingCurrentBatch))
                    {
                        FRecurringBatchesVerifiedOnSavingDict.Add(currentBatchListNo, false);
                    }

                    //If processing batch about to be submitted, only warn according to user preferences
                    if ((InSubmitting && checkingCurrentBatch && !FWarnOfInactiveValuesOnSubmitting) ||
                        (InDeleting && checkingCurrentBatch))
                    {
                        continue;
                    }

                    //Check for inactive Bank Cost Centre & Account
                    bankCostCentre = gBR.BankCostCentre;
                    bankAccount    = gBR.BankAccountCode;

                    if (!FAccountAndCostCentreLogicObject.CostCentreIsActive(bankCostCentre))
                    {
                        WarningList.AppendFormat("   Cost Centre '{0}' in batch: {1}{2}",
                                                 gBR.BankAccountCode,
                                                 gBR.BatchNumber,
                                                 Environment.NewLine);

                        numInactiveFieldsPresent++;
                        BatchesWithInactiveValues.Add(currentBatchListNo);
                    }

                    if (!FAccountAndCostCentreLogicObject.AccountIsActive(bankAccount))
                    {
                        WarningList.AppendFormat(" Bank Account '{0}' in batch: {1}{2}",
                                                 gBR.BankAccountCode,
                                                 gBR.BatchNumber,
                                                 Environment.NewLine);

                        numInactiveFieldsPresent++;

                        if (!BatchesWithInactiveValues.Contains(currentBatchListNo))
                        {
                            BatchesWithInactiveValues.Add(currentBatchListNo);
                        }
                    }
                }

                if (numInactiveFieldsPresent > 0)
                {
                    string batchList           = string.Empty;
                    string otherChangedBatches = string.Empty;

                    BatchesWithInactiveValues.Sort();

                    //Update the dictionary
                    foreach (int batch in BatchesWithInactiveValues)
                    {
                        if (batch == CurrentBatch)
                        {
                            if ((!InSubmitting && (FRecurringBatchesVerifiedOnSavingDict[batch] == false)) ||
                                (InSubmitting && FWarnOfInactiveValuesOnSubmitting))
                            {
                                FRecurringBatchesVerifiedOnSavingDict[batch] = true;
                                batchList += (string.IsNullOrEmpty(batchList) ? "" : ", ") + batch.ToString();
                            }
                        }
                        else if (FRecurringBatchesVerifiedOnSavingDict[batch] == false)
                        {
                            FRecurringBatchesVerifiedOnSavingDict[batch] = true;
                            batchList += (string.IsNullOrEmpty(batchList) ? "" : ", ") + batch.ToString();
                            //Build a list of all batches except current batch
                            otherChangedBatches += (string.IsNullOrEmpty(otherChangedBatches) ? "" : ", ") + batch.ToString();
                        }
                    }

                    //Create header message
                    WarningHeader  = "{0} inactive value(s) found in recurring batch{1}{4}{4}Do you still want to continue with ";
                    WarningHeader += (!InDeletingTrans ? AAction.ToString().ToLower() : "deleting gift detail(s) and saving changes to") +
                                     " batch: {2}";
                    WarningHeader += (otherChangedBatches.Length > 0 ? " and with saving: {3}" : "") + " ?{4}";

                    if (!InSubmitting || (otherChangedBatches.Length > 0))
                    {
                        WarningHeader += "{4}(You will only be warned once about inactive values when saving any batch!){4}";
                    }

                    //Handle plural
                    batchList = (otherChangedBatches.Length > 0 ? "es: " : ": ") + batchList;

                    WarningMessage = String.Format(Catalog.GetString(WarningHeader + "{4}Inactive values:{4}{5}{4}{6}{5}"),
                                                   numInactiveFieldsPresent,
                                                   batchList,
                                                   CurrentBatch,
                                                   otherChangedBatches,
                                                   Environment.NewLine,
                                                   new String('-', 44),
                                                   WarningList);

                    TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox((TFrmRecurringGiftBatch)ParentForm);

                    string header = string.Empty;

                    if (InSubmitting)
                    {
                        header = "Submit";
                    }
                    else if (InDeleting)
                    {
                        header = "Delete";
                    }
                    else if (InDeletingTrans)
                    {
                        header = "Delete Gift Detail From";
                    }
                    else
                    {
                        header = "Save";
                    }

                    return(extendedMessageBox.ShowDialog(WarningMessage,
                                                         Catalog.GetString(header + " Recurring Gift Batch"), string.Empty,
                                                         TFrmExtendedMessageBox.TButtons.embbYesNo,
                                                         TFrmExtendedMessageBox.TIcon.embiQuestion) == TFrmExtendedMessageBox.TResult.embrYes);
                }
            }

            return(true);
        }