Пример #1
0
        /// <summary>
        /// Validates the ReallocationJournal Dialog.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AAmountEnabled">True if txtDetailAmount is enabled (rather than txtDetailPercentage).</param>
        /// <param name="ATotalAmount">The total amount for the allocation.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="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>
        /// <returns>True if the validation found no data validation errors, otherwise false.</returns>
        public static bool ValidateReallocationJournalDialog(object AContext,
                                                             GLBatchTDSATransactionRow ARow,
                                                             bool AAmountEnabled,
                                                             decimal?ATotalAmount,
                                                             ref TVerificationResultCollection AVerificationResultCollection,
                                                             TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData   ValidationControlsData;
            TScreenVerificationResult VerificationResult = null;
            int VerifResultCollAddedCount = 0;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return(true);
            }

            ValidationColumn = ARow.Table.Columns[GLBatchTDSATransactionTable.ColumnTransactionAmountId];

            // an individual amount cannot be great than total amount
            if (AAmountEnabled && (ARow.TransactionAmount > ATotalAmount))
            {
                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    VerificationResult = new TScreenVerificationResult(
                        new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(
                                                    PetraErrorCodes.ERR_AMOUNT_TOO_LARGE, new string[] { ARow.TransactionAmount.ToString() })),
                        ValidationColumn, ValidationControlsData.ValidationControl);
                }
            }

            // Handle addition to/removal from TVerificationResultCollection
            if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn))
            {
                VerifResultCollAddedCount++;
            }

            VerificationResult = null;
            ValidationColumn   = ARow.Table.Columns[GLBatchTDSATransactionTable.ColumnPercentageId];

            // a percentage cannot be greater than 100%
            if (!AAmountEnabled && (ARow.Percentage > 100))
            {
                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    VerificationResult = new TScreenVerificationResult(
                        new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_PERCENTAGE_TOO_LARGE)),
                        ValidationColumn, ValidationControlsData.ValidationControl);
                }
            }

            // Handle addition to/removal from TVerificationResultCollection
            if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn))
            {
                VerifResultCollAddedCount++;
            }

            return(VerifResultCollAddedCount == 0);
        }
Пример #2
0
        /// <summary>
        /// Checks whether two strings are in correct order (lexical comparison).  Null values are accepted.
        /// </summary>
        /// <param name="ATxt1">The first string; it is supposed to be lesser or equal than ATxt2.</param>
        /// <param name="ATxt2">The second string; it is supposed to be greater or equal than ATxt1.</param>
        /// <param name="AFirstDescription">Description what the value is about (for the
        /// error message).</param>
        /// <param name="ASecondDescription">Description what the value is about (for the
        /// error message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param>
        /// <returns>Null if <paramref name="ATxt1" /> is lesser or equal than
        /// <paramref name="ATxt2" />, otherwise a <see cref="TVerificationResult" /> is returned that
        /// contains details about the problem, with a message that uses <paramref name="AFirstDescription" />
        /// and <paramref name="ASecondDescription" />.</returns>
        public static TVerificationResult FirstLesserOrEqualThanSecondString(String ATxt1, String ATxt2,
                                                                             String AFirstDescription, String ASecondDescription,
                                                                             object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue;

            string FirstDescription  = THelper.NiceValueDescription(AFirstDescription);
            string SecondDescription = THelper.NiceValueDescription(ASecondDescription);

            // Check
            if (System.String.Compare(ATxt1, ATxt2, false) <= 0)
            {
                // Lexical comparision results in: ATxt1 <= ATxt2
                ReturnValue = null;
            }
            else
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INCONGRUOUSSTRINGS,
                                                                              StrInvalidStringOrder, new string[] { FirstDescription, SecondDescription }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
                }
            }

            return(ReturnValue);
        }
Пример #3
0
        /// <summary>
        /// Checks whether the date is today or in the past. Null values are accepted.
        /// </summary>
        /// <param name="ADate">The date to check.</param>
        /// <param name="ADescription">The name of the date value.</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if the date <paramref name="ADate" /> is today or in the past,
        /// otherwise a verification result with a message that uses <paramref name="ADescription" />.
        /// </returns>
        public static TVerificationResult IsCurrentOrPastDate(DateTime?ADate, String ADescription,
                                                              object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue;
            String Description = THelper.NiceValueDescription(ADescription);

            if (!ADate.HasValue)
            {
                return(null);
            }

            // Check
            if (ADate <= DateTime.Today)
            {
                //MessageBox.Show('Date <= Today');
                ReturnValue = null;
            }
            else
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOFUTUREDATE, CommonResourcestrings.StrInvalidDateEntered +
                                                                              Environment.NewLine + StrDateMustNotBeFutureDate, new string[] { Description }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                }
            }

            return(ReturnValue);
        }
Пример #4
0
        /// <summary>
        /// Checks whether an integer time is in the range 0..86399
        /// </summary>
        /// <param name="AValue">Integer number.</param>
        /// <param name="ADescription">Description what the integer number is about (for the error
        /// message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if <paramref name="AValue" /> contains a valid integer number or is null,
        /// otherwise a <see cref="TVerificationResult" /> is returned that contains details about the problem,
        /// with a message that uses <paramref name="ADescription" />.</returns>
        public static TVerificationResult IsValidIntegerTime(Int64?AValue, String ADescription,
                                                             object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue = null;
            String Description = THelper.NiceValueDescription(ADescription);

            if (!AValue.HasValue)
            {
                return(null);
            }

            // Check
            if ((AValue.Value < 0) || (AValue.Value >= 86400))
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDINTEGERTIME, CommonResourcestrings.StrInvalidStringEntered +
                                                                              Environment.NewLine +
                                                                              StrMustBeTime, new string[] { Description }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                }
            }

            return(ReturnValue);
        }
        public void TestDowngradeScreenVerificationResults()
        {
            TScreenVerificationResult     res0, res1;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            DataColumn col = new DataColumn("test", typeof(int));

            res0 = new TScreenVerificationResult(null, col, "test0", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res0);

            DataColumn          col2     = new DataColumn("test2", typeof(int));
            TextBox             txtField = new TextBox();
            TVerificationResult resVR    = new TVerificationResult(null, "test", TResultSeverity.Resv_Critical);

            res1 = new TScreenVerificationResult(resVR, col2, txtField);
            coll.Add(res1);

            Assert.AreEqual(2, coll.Count, "there should be two results");

            foreach (object o in coll)
            {
                Assert.IsInstanceOf(typeof(TScreenVerificationResult), o, "should be TScreenVerificationResult");
            }

            TVerificationResultCollection.DowngradeScreenVerificationResults(coll);

            Assert.AreEqual(2, coll.Count, "there should be two results after downgrade");

            foreach (object o in coll)
            {
                Assert.IsInstanceOf(typeof(TVerificationResult), o, "should be TVerificationResult");
                Assert.IsNotInstanceOf(typeof(TScreenVerificationResult), o, "should not be TScreenVerificationResult");
            }
        }
Пример #6
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>
        public static void ValidateAccountDetailManual(object AContext, GLSetupTDSAAccountRow ARow,
                                                       ref TVerificationResultCollection AVerificationResultCollection)
        {
            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

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

                    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),
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
                }

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

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

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

                    TScreenVerificationResult VerificationResult = new TScreenVerificationResult(
                        AContext,
                        ValidationColumn,
                        Catalog.GetString("Currency Code must be specified for foreign accounts."),
                        TResultSeverity.Resv_Critical);
                    // Handle addition/removal to/from TVerificationResultCollection
                    AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
                }
            }
            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]);
            }
        }
        /// <summary>
        /// Validates the MConference Standard Cost Setup screen data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="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>
        /// <param name="AGridData">A <see cref="TValidationControlsDict" />Contains all rows that are included in the grid</param>
        public static void ValidateConferenceStandardCost(object AContext, PcConferenceCostRow ARow,
                                                          ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict,
                                                          DataRowCollection AGridData)
        {
            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            // Check the row being validated is consistent with the rest of the data in the table
            PcConferenceCostRow ARowCompare = null;
            Boolean             StandardCostInconsistency = false;

            string[] InconsistentRows = new string[2];  // used for the error message
            int      i = 0;

            while (i < AGridData.Count)
            {
                ARowCompare = (PcConferenceCostRow)AGridData[i];

                if ((ARowCompare.RowState != DataRowState.Deleted) && (ARowCompare.OptionDays > ARow.OptionDays) && (ARowCompare.Charge < ARow.Charge))
                {
                    StandardCostInconsistency = true;
                    InconsistentRows[0]       = ARow.OptionDays.ToString();
                    InconsistentRows[1]       = ARowCompare.OptionDays.ToString();
                    break;
                }
                else if ((ARowCompare.RowState != DataRowState.Deleted) && (ARowCompare.OptionDays < ARow.OptionDays) &&
                         (ARowCompare.Charge > ARow.Charge))
                {
                    StandardCostInconsistency = true;
                    InconsistentRows[0]       = ARowCompare.OptionDays.ToString();
                    InconsistentRows[1]       = ARow.OptionDays.ToString();
                    break;
                }

                i++;
            }

            // if an inconsistency is found
            if (StandardCostInconsistency == true)
            {
                TValidationControlsData   ValidationControlsData;
                TScreenVerificationResult VerificationResult = null;
                DataColumn ValidationColumn = ARow.Table.Columns[PcConferenceCostTable.ColumnChargeId];

                // displays a warning message (non-critical error)
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(
                                                                                               PetraErrorCodes.ERR_STANDARD_COST_INCONSISTENCY, InconsistentRows)),
                                                                   ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }
Пример #8
0
        /// <summary>
        /// TODO: Replace this with the Data Validation Framework - once it supports user interaction as needed
        /// in this case (=asking the user to make a decision).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnUnitDataColumnChanging(System.Object sender, DataColumnChangeEventArgs e)
        {
            TVerificationResult       VerificationResultReturned;
            TScreenVerificationResult VerificationResultEntry;
            Control BoundControl;

            // MessageBox.Show('Column ''' + e.Column.ToString + ''' is changing...');
            try
            {
                if (TPartnerVerification.VerifyUnitData(e, FMainDS, out VerificationResultReturned) == false)
                {
                    if (VerificationResultReturned.ResultCode != PetraErrorCodes.ERR_UNITNAMECHANGEUNDONE)
                    {
                        TMessages.MsgVerificationError(VerificationResultReturned, this.GetType());

                        BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column);

                        // MessageBox.Show('Bound control: ' + BoundControl.ToString);
// TODO                        BoundControl.Focus();
                        VerificationResultEntry = new TScreenVerificationResult(this,
                                                                                e.Column,
                                                                                VerificationResultReturned.ResultText,
                                                                                VerificationResultReturned.ResultTextCaption,
                                                                                VerificationResultReturned.ResultCode,
                                                                                BoundControl,
                                                                                VerificationResultReturned.ResultSeverity);
                        FPetraUtilsObject.VerificationResultCollection.Add(VerificationResultEntry);

                        // MessageBox.Show('After setting the error: ' + e.ProposedValue.ToString);
                    }
                    else
                    {
                        // undo the change in the DataColumn
                        e.ProposedValue = e.Row[e.Column.ColumnName, DataRowVersion.Original];

                        // need to assign this to make the change actually visible...
                        txtUnitName.Text = e.ProposedValue.ToString();
// TODO                        BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column);

                        // MessageBox.Show('Bound control: ' + BoundControl.ToString);
// TODO                        BoundControl.Focus();
                    }
                }
                else
                {
                    if (FPetraUtilsObject.VerificationResultCollection.Contains(e.Column))
                    {
                        FPetraUtilsObject.VerificationResultCollection.Remove(e.Column);
                    }
                }
            }
            catch (Exception Exp)
            {
                MessageBox.Show(Exp.ToString());
            }
        }
        public void TestRemove()
        {
            TVerificationResult           res0, res1, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Noncritical);
            coll.Add(res1);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Assert.AreEqual(6, coll.Count, "should be 6 elements at the start of the test");

            // Remove(DataColumn)
            coll.Remove(col);
            Assert.AreEqual(5, coll.Count, "only one element should be removed, even if there are 2 results with column col");
            Assert.AreEqual(2, coll.IndexOf(res5), "res4 was removed");
            coll.Insert(2, res4);
            coll.Remove(new DataColumn("test"));
            Assert.AreEqual(6, coll.Count, "nothing happens when trying to remove unknown column");

            // Remove(IResultInterface value)
            coll.Remove(res1);
            Assert.AreEqual(5, coll.Count, "res1 should have been removed");
            coll.Insert(1, res1);
            Assert.Throws(typeof(ArgumentException),
                          delegate { coll.Remove(new TVerificationResult(null, "test3", TResultSeverity.Resv_Info)); },
                          "trying to remove unknown verification result throws ArgumentException");

            // Remove(String AResultColumnName)
            coll.Remove("nonexisting");
            Assert.AreEqual(6, coll.Count, "nothing happens when trying to remove unknown resultcolumnname");
            coll.Remove(col.ColumnName);
            Assert.AreEqual(5, coll.Count, "should have removed res4");
            Assert.AreEqual(res6, coll.FindBy(col), "first result with col should be res6");
            coll.Insert(4, res4);
        }
        private void ValidateDataManual(PcConferenceRow ARow)
        {
            PcDiscountTable DiscountTable = FMainDS.PcDiscount;

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;
            TValidationControlsData       ValidationControlsData;
            TScreenVerificationResult     VerificationResult = null;
            DataColumn ValidationColumn;

            List <string> CriteriaCodesUsed = new List <string>();

            foreach (PcDiscountRow Row in DiscountTable.Rows)
            {
                if ((Row.RowState != DataRowState.Deleted) && (Row.DiscountCriteriaCode != "CHILD"))
                {
                    if (Row.Discount > 100)
                    {
                        ValidationColumn = Row.Table.Columns[PcDiscountTable.ColumnDiscountId];

                        // displays a warning message
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                                       PetraErrorCodes.ERR_DISCOUNT_PERCENTAGE_GREATER_THAN_100)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);

                        // Handle addition to/removal from TVerificationResultCollection
                        VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                    }

                    if (!CriteriaCodesUsed.Exists(element => element == Row.DiscountCriteriaCode))
                    {
                        CriteriaCodesUsed.Add(Row.DiscountCriteriaCode);
                    }
                }
            }

            string[] CriteriaCodesUsedArray = CriteriaCodesUsed.ToArray();

            if (!TRemote.MConference.Conference.WebConnectors.CheckDiscountCriteriaCodeExists(CriteriaCodesUsedArray))
            {
                ValidationColumn = DiscountTable.Columns[PcDiscountTable.ColumnDiscountCriteriaCodeId];

                // displays a warning message
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                               PetraErrorCodes.ERR_DISCOUNT_CRITERIA_CODE_DOES_NOT_EXIST)),
                                                                   ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
            }
        }
Пример #11
0
        /// <summary>
        /// Checks whether the date is not undefined. DateTime.MinValue is seen as undefined by this Method.
        /// Null values are accepted. They are treated as valid, unless <paramref name="ATreatNullAsInvalid" /> is
        /// set to true.
        /// </summary>
        /// <param name="ADate">The date to check.</param>
        /// <param name="ADescription">The name of the date value.</param>
        /// <param name="ATreatNullAsInvalid">Set this to true to treated null value in <paramref name="ADate" /> as invalid.</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param>
        /// <remarks>Usage in the Data Validation Framework: rather than using this Method, use Method
        /// 'TSharedValidationControlHelper.IsNotInvalidDate' for checking the validity of dates as the latter can deal not only with
        /// empty dates, but dates that are invalid in other respects (e.g. exceeding a valid date range)!!!</remarks>
        /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is
        /// returned that contains details about the problem.</returns>
        public static TVerificationResult IsNotUndefinedDateTime(DateTime?ADate, String ADescription,
                                                                 bool ATreatNullAsInvalid = false, object AResultContext = null, System.Data.DataColumn AResultColumn = null,
                                                                 System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue;
            DateTime            TheDate = TSaveConvert.ObjectToDate(ADate);
            String Description          = THelper.NiceValueDescription(ADescription);

            if (!ADate.HasValue)
            {
                if (!ATreatNullAsInvalid)
                {
                    return(null);
                }
                else
                {
                    ReturnValue = new TVerificationResult(AResultContext,
                                                          ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE,
                                                                                  CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                                  StrDateMustNotBeEmpty, new string[] { Description }));

                    if (AResultColumn != null)
                    {
                        ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
                    }
                }
            }

            // Check
            if (TheDate != DateTime.MinValue)
            {
                //MessageBox.Show('Date <> DateTime.MinValue');
                ReturnValue = null;
            }
            else
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE,
                                                                              CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                              StrDateMustNotBeEmpty, new string[] { Description }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
                }
            }

            return(ReturnValue);
        }
Пример #12
0
        /// <summary>
        /// Checks whether the date is not undefined. DateTime.MinValue is seen as undefined by this Method.
        /// Null values are accepted.
        /// </summary>
        /// <param name="ADate">The date to check.</param>
        /// <param name="ADescription">The name of the date value.</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <param name="AAlternativeFirstDayOfPeriod"></param>
        /// <remarks>Usage in the Data Validation Framework: rather than using this Method, use Method
        /// 'TValidationControlHelper.IsNotInvalidDate' for checking the validity of dates as the latter can deal not only with
        /// empty dates, but dates that are invalid in other respects (e.g. exceeding a valid date range)!!!</remarks>
        /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is
        /// returned that contains details about the problem.</returns>
        public static TVerificationResult IsNotCorporateDateTime(DateTime?ADate, String ADescription,
                                                                 object AResultContext            = null, System.Data.DataColumn AResultColumn = null,
                                                                 int AAlternativeFirstDayOfPeriod = 1)
        {
            TVerificationResult ReturnValue;
            DateTime            TheDate = TSaveConvert.ObjectToDate(ADate);
            DateTime            FirstOfMonth;
            DateTime            FirstOfMonthAlternative;
            String Description = THelper.NiceValueDescription(ADescription);

            if (!ADate.HasValue)
            {
                return(null);
            }

            FirstOfMonth            = new DateTime(TheDate.Year, TheDate.Month, 1);
            FirstOfMonthAlternative = new DateTime(TheDate.Year, TheDate.Month, AAlternativeFirstDayOfPeriod);

            // Checks
            if ((TheDate == FirstOfMonth) || (TheDate == FirstOfMonthAlternative))
            {
                //MessageBox.Show('Date <> DateTime.MinValue');
                ReturnValue = null;
            }
            else
            {
                if (AAlternativeFirstDayOfPeriod == 1)
                {
                    ReturnValue = new TVerificationResult(AResultContext,
                                                          ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE,
                                                                                  CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                                  StrDateMustNotBeLaterThanFirstDayOfMonth, new string[] { Description }));
                }
                else
                {
                    ReturnValue = new TVerificationResult(AResultContext,
                                                          ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE,
                                                                                  CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                                  String.Format(Catalog.GetString("The first day of the period should be either 1 or {0}."), AAlternativeFirstDayOfPeriod)));
                }

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                }
            }

            return(ReturnValue);
        }
Пример #13
0
        /// <summary>
        /// Validates the GL Batch Date dialog.
        /// </summary>
        /// <param name="ABatchDate">The Data being validated</param>
        /// <param name="ADescription">Description of control</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AStartDateCurrentPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param>
        /// <param name="AEndDateLastForwardingPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param>
        /// <param name="AControl"></param>
        /// <returns>True if the validation found no data validation errors, otherwise false.</returns>
        public static bool ValidateGLBatchDateManual(DateTime?ABatchDate, string ADescription,
                                                     ref TVerificationResultCollection AVerificationResultCollection,
                                                     DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod, Control AControl)
        {
            TScreenVerificationResult VerificationResult = null;
            int VerifResultCollAddedCount = 0;

            // 'Reversal Date' must be a valid date
            TVerificationResult Result = TSharedValidationControlHelper.IsNotInvalidDate(ABatchDate,
                                                                                         ADescription, AVerificationResultCollection, true,
                                                                                         AControl, null, AControl);

            if (Result != null)
            {
                VerificationResult = new TScreenVerificationResult(Result, null, AControl);
            }

            // Handle addition/removal to/from TVerificationResultCollection
            if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AControl, VerificationResult, null, true))
            {
                VerifResultCollAddedCount++;
            }
            else
            {
                // 'Reversal Date' must lie within the required date range
                Result = TDateChecks.IsDateBetweenDates(ABatchDate,
                                                        AStartDateCurrentPeriod,
                                                        AEndDateLastForwardingPeriod,
                                                        ADescription,
                                                        TDateBetweenDatesCheckType.dbdctUnspecific,
                                                        TDateBetweenDatesCheckType.dbdctUnspecific,
                                                        AControl,
                                                        null,
                                                        AControl);

                if (Result != null)
                {
                    VerificationResult = new TScreenVerificationResult(Result, null, AControl);
                }

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AControl, VerificationResult, null, true))
                {
                    VerifResultCollAddedCount++;
                }
            }

            return(VerifResultCollAddedCount == 0);
        }
        public void TestBuildVerificationResultString()
        {
            TVerificationResult           res0, res1, res2, res3, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            TextBox tb1 = new TextBox();

            res2 = new TVerificationResult(tb1, "test2", TResultSeverity.Resv_Critical);
            coll.Add(res2);
            res3 = new TVerificationResult(tb1, "test3", TResultSeverity.Resv_Noncritical);
            coll.Add(res3);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Console.WriteLine(coll.BuildVerificationResultString());
            Console.WriteLine(coll.BuildVerificationResultString().Replace("\n", "\\n").Replace("\r", "\\r"));

            const string expectedString =
                "\r\n    Problem: test0\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Status: test1\r\n\r\n\r\nSystem.Windows.Forms.TextBox, Text: " +
                "\r\n    Problem: test2\r\n    (Critical)\r\n\r\nSystem.Windows.Forms.TextBox, Text: " +
                "\r\n    Problem: test3\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Problem: test4\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Status: test5\r\n\r\n\r\n" +
                "\r\n    Problem: test6\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Problem: test7\r\n    (Non-critical)\r\n\r\n";

            Assert.AreEqual(expectedString, coll.BuildVerificationResultString(), "comparing the string");
        }
Пример #15
0
        private void ValidateDataDetailsManual(AMotivationDetailRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult     VerificationResult;
            Boolean KeyMinistryActive;

            // Partner Key must be for a Key Ministry and Key Ministry must not be deactivated
            if (Convert.ToInt64(txtDetailRecipientKey.Text) != 0)
            {
                ValidationColumn = FMainDS.AMotivationDetail[0].Table.Columns[AMotivationDetailTable.ColumnRecipientKeyId];

                if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    if (TRemote.MFinance.Gift.WebConnectors.KeyMinistryExists(Convert.ToInt64(txtDetailRecipientKey.Text), out KeyMinistryActive))
                    {
                        if (!KeyMinistryActive)
                        {
                            // Key Ministry is deactivated and therefore can't be used here
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                       ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_KEY_MINISTRY_DEACTIVATED)),
                                                                               ValidationColumn, ValidationControlsData.ValidationControl);

                            // Handle addition to/removal from TVerificationResultCollection.
                            VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                        }
                    }
                    else
                    {
                        // Partner Key does not refer to Key Ministry
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                   ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_NOT_A_KEY_MINISTRY)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);

                        // Handle addition to/removal from TVerificationResultCollection.
                        VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                    }
                }
            }

            TSharedFinanceValidation_Gift.ValidateGiftMotivationSetupManual(this,
                                                                            ARow, FTaxDeductiblePercentageEnabled,
                                                                            ref VerificationResultCollection,
                                                                            FPetraUtilsObject.ValidationControlsDict);
        }
Пример #16
0
        /// <summary>
        /// Checks wheter a given DateTime is an invalid date. A check whether it is an undefined DateTime is always performed.
        /// If Delegate <see cref="SharedGetDateVerificationResultDelegate" /> is set up and Argument
        /// <paramref name="AResultControl" /> isn't null, the 'DateVerificationResult' of the TtxtPetraDate Control is
        /// returned by this Method through this Method if it isn't null. That way the Data Validation Framework can
        /// use the detailed Data Verification error that is held by the Control.
        /// </summary>
        /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is
        /// returned that contains details about the problem.</returns>
        public static TVerificationResult IsNotInvalidDate(DateTime?ADate, String ADescription,
                                                           TVerificationResultCollection AVerificationResultCollection, bool ATreatNullAsInvalid = false,
                                                           object AResultContext  = null, System.Data.DataColumn AResultColumn = null,
                                                           Control AResultControl = null)
        {
            TVerificationResult VerificationResult;

            if (FDelegateSharedGetDateVerificationResult != null)
            {
                if ((AResultControl != null))
                {
                    VerificationResult = FDelegateSharedGetDateVerificationResult(AResultControl);

                    if (VerificationResult == null)
                    {
                        VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate,
                                                                                ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn, AResultControl);
                    }
                    else
                    {
                        VerificationResult.OverrideResultContext(AResultContext);
                        VerificationResult = new TScreenVerificationResult(VerificationResult, AResultColumn, AResultControl);
                    }
                }
                else
                {
                    VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate,
                                                                            ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn, AResultControl);
                }

                // Remove Verification Result that would have been recorded earlier for the same DataColumn
                TVerificationResult OtherRecordedVerificationResult = AVerificationResultCollection.FindBy(AResultColumn);

                if (OtherRecordedVerificationResult != null)
                {
                    AVerificationResultCollection.Remove(OtherRecordedVerificationResult);
                }
            }
            else
            {
                VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate,
                                                                        ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn, AResultControl);
            }

            return(VerificationResult);
        }
        private void ValidateDataDetailsManual(PcDiscountRow ARow)
        {
            if (txtDetailDiscount.Text == "")
            {
                ARow.Discount = 0;
            }

            // check that default data exists in database
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TValidationControlsData   ValidationControlsData;
            TScreenVerificationResult VerificationResult = null;
            DataColumn ValidationColumn;

            if (ARow.RowState != DataRowState.Deleted)
            {
                if (!TRemote.MConference.Conference.WebConnectors.CheckDiscountCriteriaCodeExists(new string[] { ARow.DiscountCriteriaCode }))
                {
                    ValidationColumn = ARow.Table.Columns[PcDiscountTable.ColumnDiscountCriteriaCodeId];

                    // displays a warning message
                    VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                                   PetraErrorCodes.ERR_DISCOUNT_CRITERIA_CODE_DOES_NOT_EXIST)),
                                                                       ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition to/removal from TVerificationResultCollection
                    VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                }

                if (!TRemote.MConference.Conference.WebConnectors.CheckCostTypeExists(ARow.CostTypeCode))
                {
                    ValidationColumn = ARow.Table.Columns[PcDiscountTable.ColumnCostTypeCodeId];

                    // displays a warning message
                    VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                                   PetraErrorCodes.ERR_COST_TYPE_CODE_DOES_NOT_EXIST)),
                                                                       ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition to/removal from TVerificationResultCollection
                    VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                }
            }

            EnableOrDisableCmb(ARow);
        }
Пример #18
0
        private void ValidateFeeCode(string AFeeCode, TVerificationResultCollection AVerificationResultCollection)
        {
            TScreenVerificationResult result = null;
            string context = "ReceivableCrossCodeCheck";

            if (FExtraDS.AFeesPayable.DefaultView.Find(new object[] { LedgerNumber, AFeeCode }) >= 0)
            {
                // oops - we have this code in the other data set
                result = new TScreenVerificationResult(context,
                                                       FMainDS.AFeesReceivable.ColumnFeeCode,
                                                       Catalog.GetString("The Fee Code has already been used as a Fee Code in the 'Payable Administration Grants' screen"),
                                                       CommonErrorCodes.ERR_DUPLICATE_RECORD,
                                                       txtDetailFeeCode,
                                                       TResultSeverity.Resv_Critical);
            }

            AVerificationResultCollection.Auto_Add_Or_AddOrRemove(context, result, FMainDS.AFeesReceivable.ColumnFeeCode);
        }
        public void TestBuildScreenVerificationResultList()
        {
            TVerificationResult           res0, res1, res4, res5, res6, res7, res8;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);
            res8 = new TScreenVerificationResult("test8", col3, "test8", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res8);

            String ErrorMessages;
            Object testObject;

            coll.BuildScreenVerificationResultList(out ErrorMessages, out testObject, null, true);

            coll.BuildScreenVerificationResultList("test8", out ErrorMessages);

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            String expectedErrorMessages =
                "test8" + Environment.NewLine + Environment.NewLine;

            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "only show errors of resultcontext test1 and of TVerificationScreenResult");
        }
        public void TestContains()
        {
            TVerificationResult           res1;
            TScreenVerificationResult     res2;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            // Contains(IResultInterface)
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Noncritical);
            Assert.IsFalse(coll.Contains(res1), "should not contain res1");
            coll.Add(res1);
            Assert.IsTrue(coll.Contains(res1), "should contain res1");

            // Contains(string AResultContext)
            res1 = new TVerificationResult("testcontext", "testresulttext", "testcaption", "testresultcode", TResultSeverity.Resv_Noncritical);
            Assert.IsFalse(coll.Contains("testcontext"), "should not contain testcontext");
            coll.Add(res1);
            Assert.IsTrue(coll.Contains("testcontext"), "should contain testcontext (by string)");

            // Contains(object AResultContext) with a control
            TextBox txtTest1 = new TextBox();

            res2 = new TScreenVerificationResult(txtTest1, null, "test1", "t1", txtTest1, TResultSeverity.Resv_Noncritical);
            Assert.IsFalse(coll.Contains(txtTest1), "should not contain txtTest1 box");
            coll.Add(res2);
            Assert.IsTrue(coll.Contains(txtTest1), "should contain txtTest1 box");

            // Contains(DataColumn)
            DataColumn col = new DataColumn("test", typeof(int));

            Assert.IsFalse(coll.Contains(col), "should not contain col");
            res2 = new TScreenVerificationResult(null, col, "test1", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res2);
            Assert.IsTrue(coll.Contains(col), "should contain col");

            // Contains(DataTable)
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            Assert.IsFalse(coll.Contains(tab), "should not contain tab");
            res2 = new TScreenVerificationResult(null, col2, "test1", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res2);
            Assert.IsTrue(coll.Contains(tab), "should contain tab");
        }
Пример #21
0
        /// <summary>
        /// Checks if the specified record is a duplicate of an existing one
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation occurs.</param>
        /// <param name="AConstraintExceptionOccurred">Set to True if a constraint exception occurred when saving the data or False otherwise</param>
        /// <param name="AResultText">The text that will be displayed as help that explains the data entered that is a duplicate</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>
        /// <returns>TVerificationResult Nil if validation succeeded, otherwise it contains
        /// details about the problem.
        /// </returns>
        public static TVerificationResult ValidateNonDuplicateRecord(object AContext, bool AConstraintExceptionOccurred, string AResultText,
                                                                     System.Data.DataColumn APrimaryKeyColumn, System.Windows.Forms.Control APrimaryKeyControl)
        {
            TVerificationResult ReturnValue = null;

            if (AConstraintExceptionOccurred)
            {
                // create a new screen verification result
                ReturnValue = new TScreenVerificationResult(AContext,
                                                            APrimaryKeyColumn,
                                                            AResultText,
                                                            CommonErrorCodes.ERR_DUPLICATE_RECORD,
                                                            APrimaryKeyControl,
                                                            TResultSeverity.Resv_Critical);
                ReturnValue.OverrideResultTextCaption(Catalog.GetString("Duplicate record"));
            }

            return(ReturnValue);
        }
Пример #22
0
        /// <summary>
        /// Checks whether an International Postal Type is valid. Null values are accepted.
        /// </summary>
        /// <param name="AInternatPostalTypeCode">The International Postal Type to check.</param>
        /// <param name="ADescription">Description what the value is about (for the
        /// error message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if <paramref name="AInternatPostalTypeCode" /> is null,
        /// otherwise a <see cref="TVerificationResult" /> is returned that
        /// contains details about the problem, with a message that uses <paramref name="ADescription" />.</returns>
        public static TVerificationResult IsValidInternationalPostalCode(string AInternatPostalTypeCode,
                                                                         string ADescription = "", object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue = null;

            Ict.Common.Data.TTypedDataTable IntPostalDT;

            if (AInternatPostalTypeCode != null)
            {
                if (AInternatPostalTypeCode != String.Empty)
                {
                    TDBTransaction t = new TDBTransaction();
                    DBAccess.ReadTransaction(ref t,
                                             delegate {
                        IntPostalDT = PInternationalPostalTypeAccess.LoadAll(t);

                        if (IntPostalDT.Rows.Find(new object[] { AInternatPostalTypeCode }) == null)
                        {
                            ReturnValue = new TVerificationResult(AResultContext,
                                                                  ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALIDINTERNATIONALPOSTALCODE));

                            if (AResultColumn != null)
                            {
                                ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                            }
                        }
                    });
                }
                else
                {
                    ReturnValue = new TVerificationResult(AResultContext,
                                                          ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALIDINTERNATIONALPOSTALCODE));

                    if (AResultColumn != null)
                    {
                        ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                    }
                }
            }

            return(ReturnValue);
        }
Пример #23
0
        /// <summary>
        /// Used for checking if a particular lookup value relates to an inactive record
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ADataTable"></param>
        /// <param name="AKeyValue"></param>
        /// <param name="AActiveColumn"></param>
        /// <param name="AResultContext"></param>
        /// <param name="AResultColumn"></param>
        /// <param name="AResultControl"></param>
        /// <returns></returns>
        public static TVerificationResult ValidateValueIsActive(Int32 ALedgerNumber, DataTable ADataTable, String AKeyValue,
                                                                String AActiveColumn, object AResultContext = null, System.Data.DataColumn AResultColumn = null,
                                                                System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue;

            if (ADataTable != null)
            {
                DataRow foundRow = ADataTable.Rows.Find(new object[] { ALedgerNumber, AKeyValue });

                if (foundRow != null)
                {
                    bool isActive = (bool)foundRow[AActiveColumn];

                    if (!isActive)
                    {
                        ReturnValue = new TVerificationResult(AResultContext,
                                                              ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDVALUE,
                                                                                      StrStringInactiveValue, new string[] { AKeyValue }));

                        if (AResultColumn != null)
                        {
                            ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
                        }
                    }
                    else
                    {
                        ReturnValue = null;
                    }
                }
                else
                {
                    ReturnValue = null;
                }
            }
            else
            {
                ReturnValue = null;
            }

            return(ReturnValue);
        }
Пример #24
0
        /// <summary>
        /// Checks whether the string <paramref name="AString" /> contains a valid DateTime.
        /// </summary>
        /// <param name="AString">The date to check.</param>
        /// <param name="ADescription">The name of the date value.</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if <paramref name="AString" /> contains a valid DateTime, otherwise a
        /// <see cref="TVerificationResult" /> with a message which uses
        /// <paramref name="ADescription" /> is returned.</returns>
        public static TVerificationResult IsValidDateTime(String AString, String ADescription,
                                                          object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue = null;
            String Description = THelper.NiceValueDescription(ADescription);

            DateTime temp;

            if (!DateTime.TryParse(AString, out temp))
            {
                ReturnValue = GetInvalidDateVerificationResult(Description, AResultContext);

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                }
            }

            return(ReturnValue);
        }
Пример #25
0
        /// <summary>
        /// Checks whether an Object is null value or empty string.
        /// </summary>
        /// <param name="AValue">The Object to check.</param>
        /// <param name="ADescription">Description what the value is about (for the
        /// error message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if <paramref name="AValue" /> is not null,
        /// otherwise a <see cref="TVerificationResult" /> is returned that
        /// contains details about the problem, with a message that uses <paramref name="ADescription" />.</returns>
        public static TVerificationResult ValueMustNotBeNullOrEmptyString(object AValue, string ADescription,
                                                                          object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue = null;
            String Description = THelper.NiceValueDescription(ADescription);

            // Check
            if ((AValue == null) || (AValue.ToString() == String.Empty))
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NONULL, StrValueMustNotBeNullOrEmptyString, new string[] { Description }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                }
            }

            return(ReturnValue);
        }
Пример #26
0
        /// <summary>
        /// Checks whether an Object is null.
        /// </summary>
        /// <param name="AValue">The Object to check.</param>
        /// <param name="ADescription">Description what the value is about (for the
        /// error message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param>
        /// <returns>Null if <paramref name="AValue" /> is not null,
        /// otherwise a <see cref="TVerificationResult" /> is returned that
        /// contains details about the problem, with a message that uses <paramref name="ADescription" />.</returns>
        public static TVerificationResult ValueMustNotBeNull(object AValue, string ADescription,
                                                             object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue = null;
            String Description = THelper.NiceValueDescription(ADescription);

            // Check
            if (AValue == null)
            {
                ReturnValue = new TVerificationResult(AResultContext,
                                                      ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NONULL, StrValueMustNotBeNull, new string[] { Description }));

                if (AResultColumn != null)
                {
                    ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
                }
            }

            return(ReturnValue);
        }
Пример #27
0
        /// <summary>
        /// A public validation method that can be called from the screen in ManualValidation.
        /// It checks that there were no errors in displaying the controls on the screen.
        /// </summary>
        /// <param name="ARowValue">The current value for the setting</param>
        /// <param name="ADataColum">The data column that holds the value</param>
        /// <param name="AContext">A validation context</param>
        /// <param name="AVerificationResults">The verification result collection to add any errors to</param>
        /// <returns>True if there are no errors, false otherwise</returns>
        public bool Validate(string ARowValue, DataColumn ADataColum, object AContext, TVerificationResultCollection AVerificationResults)
        {
            TVerificationResult verificationResult = null;

            if (ARowValue == TGuiControlsDataTable.CONTROL_DEFINITION_ERROR)
            {
                // This message should not occur in production because any control definition errors should have been discovered in testing.
                // They arise if the content of the s_system_defaults_gui_controls table is not correct or if
                //   the default value contains an array of values that does not match the array size of the controls in the controls table.
                string message = Catalog.GetString("There is an error in the database relating to the set-up of this row.  ");
                message += Catalog.GetString(
                    "In order to avoid saving badly constructed data to the System Settings table you must close the screen.  ");
                message += Catalog.GetString(
                    "You can re-open it and continue to change the settings in other rows, but do not select the current row until the problem is fixed.");
                verificationResult = new TScreenVerificationResult(AContext, ADataColum, message, null, TResultSeverity.Resv_Critical);
            }

            AVerificationResults.Auto_Add_Or_AddOrRemove(AContext, verificationResult, ADataColum);
            return(verificationResult == null);
        }
Пример #28
0
        /// <summary>
        /// Checks whether the first submitted date is later than the second submitted
        /// date. Null dates are accepted.
        /// </summary>
        /// <param name="ADate1">First date.</param>
        /// <param name="ADate2">Second date.</param>
        /// <param name="AFirstDateDescription">Description what the first date is about (for the
        /// error message).</param>
        /// <param name="ASecondDateDescription">Description what the second date is about (for
        /// the error message).</param>
        /// <param name="AResultContext">Context of verification (can be null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param>
        /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is
        /// returned that contains details about the problem, with a message that uses
        /// <paramref name="AFirstDateDescription" /> and <paramref name="ASecondDateDescription" />.</returns>
        public static TVerificationResult FirstGreaterThanSecondDate(DateTime?ADate1,
                                                                     DateTime?ADate2, string AFirstDateDescription, string ASecondDateDescription,
                                                                     object AResultContext = null, System.Data.DataColumn AResultColumn = null)
        {
            TVerificationResult ReturnValue;
            String FirstDateDescription  = THelper.NiceValueDescription(AFirstDateDescription);
            String SecondDateDescription = THelper.NiceValueDescription(ASecondDateDescription);

            if ((!ADate1.HasValue) || (!ADate2.HasValue))
            {
                return(null);
            }

            // Check
            if (ADate1 > ADate2)
            {
                //MessageBox.Show('ADate1 <= ADate2');
                ReturnValue = null;
            }
            else
            {
                if (ADate1 != new DateTime(0001, 1, 1))
                {
                    ReturnValue = new TVerificationResult(AResultContext,
                                                          ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                                                                                  StrDateCannotBeEarlierOrEqual, new string[] { FirstDateDescription, SecondDateDescription }));

                    if (AResultColumn != null)
                    {
                        ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn);
                    }
                }
                else
                {
                    ReturnValue = null;
                }
            }

            return(ReturnValue);
        }
Пример #29
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]);
            }
        }
        public void TestBuildVerificationResultString()
        {
            TVerificationResult           res0, res1, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Console.WriteLine(coll.BuildVerificationResultString());
            Console.WriteLine(coll.BuildVerificationResultString().Replace("\n", "\\n").Replace("\r", "\\r"));

            string expectedString =
                Environment.NewLine + "    Problem: test0" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Status: test1" + Environment.NewLine + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test4" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Status: test5" + Environment.NewLine + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test6" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test7" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine;

            Assert.AreEqual(expectedString, coll.BuildVerificationResultString(), "comparing the string");
        }