Exemple #1
0
        private void SetupExtraGridFunctionality()
        {
            //Prepare grid to highlight inactive accounts/cost centres
            // Create a cell view for special conditions
            SourceGrid.Cells.Views.Cell strikeoutCell = new SourceGrid.Cells.Views.Cell();
            strikeoutCell.Font = new System.Drawing.Font(grdDetails.Font, FontStyle.Strikeout);
            //strikeoutCell.ForeColor = Color.Crimson;

            // Create a condition, apply the view when true, and assign a delegate to handle it
            SourceGrid.Conditions.ConditionView conditionAccountCodeActive = new SourceGrid.Conditions.ConditionView(strikeoutCell);
            conditionAccountCodeActive.EvaluateFunction = delegate(SourceGrid.DataGridColumn column, int gridRow, object itemRow)
            {
                DataRowView row         = (DataRowView)itemRow;
                string      accountCode = row[ARecurringGiftBatchTable.ColumnBankAccountCodeId].ToString();
                return(!FAccountAndCostCentreLogicObject.AccountIsActive(accountCode));
            };

            SourceGrid.Conditions.ConditionView conditionCostCentreCodeActive = new SourceGrid.Conditions.ConditionView(strikeoutCell);
            conditionCostCentreCodeActive.EvaluateFunction = delegate(SourceGrid.DataGridColumn column, int gridRow, object itemRow)
            {
                DataRowView row            = (DataRowView)itemRow;
                string      costCentreCode = row[ARecurringGiftBatchTable.ColumnBankCostCentreId].ToString();
                return(!FAccountAndCostCentreLogicObject.CostCentreIsActive(costCentreCode));
            };

            //Add conditions to columns
            int indexOfCostCentreCodeDataColumn = 5;
            int indexOfAccountCodeDataColumn    = 6;

            grdDetails.Columns[indexOfCostCentreCodeDataColumn].Conditions.Add(conditionCostCentreCodeActive);
            grdDetails.Columns[indexOfAccountCodeDataColumn].Conditions.Add(conditionAccountCodeActive);
        }
Exemple #2
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);
        }