예제 #1
0
        /// <summary>
        /// Check that Foreign Currency Accounts are using a valid currency
        /// </summary>
        /// <param name="AContext">Context that describes what I'm validating.</param>
        /// <param name="ARow">DataRow with the the data I'm validating</param>
        /// <param name="AVerificationResultCollection">Will be filled with TVerificationResult items if data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        public static void ValidateAccountDetailManual(object AContext, GLSetupTDSAAccountRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            TValidationControlsData ValidationControlsData;

            if (ARow.ForeignCurrencyFlag)
            {
                if ((ARow.AccountType != MFinanceConstants.ACCOUNT_TYPE_ASSET) && (ARow.AccountType != MFinanceConstants.ACCOUNT_TYPE_LIABILITY))
                {
                    DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnAccountTypeId];

                    Control targetControl = null;

                    if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                    {
                        targetControl = ValidationControlsData.ValidationControl;
                    }

                    TScreenVerificationResult VerificationResult = new TScreenVerificationResult(
                        AContext,
                        ValidationColumn,
                        string.Format(Catalog.GetString("A foreign currency account's Account Type must be either '{0}' or '{1}'."),
                            MFinanceConstants.ACCOUNT_TYPE_ASSET, MFinanceConstants.ACCOUNT_TYPE_LIABILITY),
                        targetControl,
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
                }

                if (!ARow.PostingStatus)
                {
                    DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnPostingStatusId];

                    Control targetControl = null;

                    if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                    {
                        targetControl = ValidationControlsData.ValidationControl;
                    }

                    TScreenVerificationResult VerificationResult = new TScreenVerificationResult(
                        AContext,
                        ValidationColumn,
                        Catalog.GetString("A foreign currency account must be a posting account; it cannot be a summary account."),
                        targetControl,
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
                }

                // If this account is foreign, its currency must be assigned!
                if (ARow.ForeignCurrencyCode == "")
                {
                    DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId];

                    Control targetControl = null;

                    if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                    {
                        targetControl = ValidationControlsData.ValidationControl;
                    }

                    TScreenVerificationResult VerificationResult = new TScreenVerificationResult(
                        AContext,
                        ValidationColumn,
                        Catalog.GetString("Currency Code must be specified for foreign accounts."),
                        targetControl,
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
                }
            }
            else // If the Account is not foreign, I have nothing at all to say about the contents of the currency field.
            {
                AVerificationResultCollection.AddOrRemove(null, ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]);
            }
        }
예제 #2
0
        /// <summary>
        /// Check that Foreign Currency Accounts are using a valid currency
        /// </summary>
        /// <param name="AContext">Context that describes what I'm validating.</param>
        /// <param name="ARow">DataRow with the the data I'm validating</param>
        /// <param name="AVerificationResultCollection">Will be filled with TVerificationResult items if data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        public static void ValidateAccountDetailManual(object AContext, GLSetupTDSAAccountRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            TValidationControlsData ValidationControlsData;

            // If this account is foreign, its currency must be assigned!
            if (ARow.ForeignCurrencyFlag)
            {
                if (ARow.ForeignCurrencyCode == "")
                {
                    DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId];

                    Control targetControl = null;

                    if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                    {
                        targetControl = ValidationControlsData.ValidationControl;
                    }

                    TScreenVerificationResult VerificationResult = new TScreenVerificationResult(
                        AContext,
                        ValidationColumn,
                        Catalog.GetString("Currency Code must be specified for foreign accounts."),
                        targetControl,
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
                }
            }
            else // If the Account is not foreign, I have nothing at all to say about the contents of the currency field.
            {
                AVerificationResultCollection.AddOrRemove(null, ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles validation of a duplicate or non-duplicate record entered in the GUI
        /// </summary>
        /// <param name="AHostContext">Context that describes where the data validation occurs (usually specified as 'this').</param>
        /// <param name="AConstraintExceptionOccurred">Set to True if a constraint exception occurred when saving the data or False otherwise</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="APrimaryKeyColumn">The data column that will be used to identify the error (usually the first of the primary key columns)</param>
        /// <param name="APrimaryKeyControl">The control corresponding to the Primary Key column</param>
        /// <param name="APrimaryKeys">The array of primary key data columns that define the unique constraint being validated</param>
        public static void ValidateNonDuplicateRecord(object AHostContext,
            bool AConstraintExceptionOccurred,
            TVerificationResultCollection AVerificationResultCollection,
            System.Data.DataColumn APrimaryKeyColumn,
            System.Windows.Forms.Control APrimaryKeyControl,
            System.Data.DataColumn[] APrimaryKeys)
        {
            TVerificationResult verificationResult = null;
            string resultText = String.Empty;

            if (AConstraintExceptionOccurred)
            {
                // Work out what the current user input values are for the primary keys
                ErrCodeInfo errInfo = ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_DUPLICATE_RECORD);
                resultText = errInfo.ErrorMessageText;

                string hintText = String.Empty;
                bool bFoundOne = false;

                foreach (System.Data.DataColumn column in APrimaryKeys)
                {
                    // Look at each primary key name and find its control.  It is quite common for one key (eg Ledger number) to not have a control.
                    System.Windows.Forms.Label label;
                    System.Windows.Forms.Control control;
                    string controlText = String.Empty;

                    if (GetControlsForPrimaryKey(column, (System.Windows.Forms.Control)AHostContext, out label, out control))
                    {
                        bFoundOne = true;
                        hintText += Environment.NewLine;
                        hintText += label.Text.Replace("&", String.Empty);
                        controlText = GetDisplayTextForControl(control);

                        if (controlText != String.Empty)
                        {
                            // Note from Alan:  I may not have implemented getting control text for all control types
                            // If you find a missing type, please add it to GetDisplayTextForControl()
                            // In the meantime we have to ignore empty text and just display the label text...
                            if (!hintText.EndsWith(":"))
                            {
                                hintText += ":";
                            }

                            hintText += " ";
                            hintText += controlText;
                        }
                    }
                }

                if (!bFoundOne)
                {
                    // See Alan's note above.  This will occur on a form that has no control type that has GetDisplayTextForControl()
                    hintText += Environment.NewLine;
                    hintText += Environment.NewLine;
                    hintText +=
                        String.Format(Catalog.GetString(
                                "No hint text is available for the following screen:{0}{1}.{0}Please inform the Open Petra team if you see this message."),
                            Environment.NewLine, AHostContext.ToString());
                }

                resultText += hintText;
            }

            verificationResult = TGuiChecks.ValidateNonDuplicateRecord(AHostContext,
                AConstraintExceptionOccurred,
                resultText,
                APrimaryKeyColumn,
                APrimaryKeyControl);

            // Add or remove the error from the collection
            AVerificationResultCollection.AddOrRemove(verificationResult, APrimaryKeyColumn);
        }