Ejemplo n.º 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AVerificationResultCollection"></param>
        /// <param name="AVerificationResult"></param>
        public static void VerifyDates(DataColumnChangeEventArgs e,
                                       TVerificationResultCollection AVerificationResultCollection,
                                       out TVerificationResult AVerificationResult)
        {
            AVerificationResult = null;
            DateTime DateGoodUntil = new DateTime();
            DateTime DateEffective = new DateTime();

            try
            {
                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    // MessageBox.Show('p_date_effective_d: ' + e.Row['p_date_effective_d', DataRowVersion.Current].ToString);
                    DateEffective = TSaveConvert.ObjectToDate(e.ProposedValue);
                    DateGoodUntil = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateGoodUntilDBName()]);
                }
                else if (e.Column.ColumnName == PPartnerLocationTable.GetDateGoodUntilDBName())
                {
                    DateEffective = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateEffectiveDBName()]);
                    DateGoodUntil = TSaveConvert.ObjectToDate(e.ProposedValue);
                }

                // MessageBox.Show('p_date_effective_d: ' + DateEffective.ToString + Environment.NewLine +
                // 'p_date_good_until_d: ' + DateGoodUntil.ToString);
                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateEffective, DateGoodUntil, "Valid From", "Valid To");
                }
                else
                {
                    AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateGoodUntil, DateEffective, "Valid To", "Valid From");
                }

                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    // delete any error that might have been there from a verification of the other column
                    AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateGoodUntilDBName());
                }
                else
                {
                    // delete any error that might have been there from a verification of the other column
                    AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateEffectiveDBName());
                }
            }
            catch (Exception Exp)
            {
                MessageBox.Show("Exception occured in TPartnerAddressVerification.VerifyDates: " + Exp.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks wheter a given DateTime is an invalid date. A check whether it is an undefined DateTime is always performed.
        /// </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)
        {
            TVerificationResult VerificationResult;

            if (FDelegateSharedGetDateVerificationResult != null)
            {
                VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate,
                                                                        ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn);

                // 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);
            }

            return(VerificationResult);
        }
        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);
        }
        public void TestBuildScreenVerificationResultList()
        {
            TVerificationResult           res0, res1, res2, res3, res4, res5, res6, res7, res8, res9, res10;
            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);
            res8 = new TScreenVerificationResult("test8", col3, "test8", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res8);

            string  ErrorMessages;
            Control FirstControl;

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

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

            string expectedErrorMessages =
                "test4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\n";

            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "only show errors of unspecified resultcontext and of TVerificationScreenResult");

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

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

            expectedErrorMessages =
                "test8\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "only show errors of resultcontext test1 and of TVerificationScreenResult");

            // test first control, but with updatefirstcontrol false
            TextBox tb2 = new TextBox();

            res9 = new TScreenVerificationResult(null, null, "test9", tb2, TResultSeverity.Resv_Critical);
            coll.Add(res9);
            TextBox tb3 = new TextBox();

            res10 = new TScreenVerificationResult(null, null, "test10", tb3, TResultSeverity.Resv_Critical);
            coll.Add(res10);
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, false);

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

            expectedErrorMessages =
                "test4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\ntest9\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "added test9 and test10");
            Assert.AreEqual(tb2, FirstControl, "expect to return tb2 as first control");
            Assert.AreEqual(null, coll.FirstErrorControl, "expect to not select tb2 as first control");

            // test updatefirstcontrol true
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, true);
            Assert.AreEqual(tb2, FirstControl, "expect to return tb2 as first control");
            Assert.AreEqual(tb2, coll.FirstErrorControl, "expect to select tb2 as first control");

            // remove res9, so that first control is tb3, but call with updatefirstcontrol false
            coll.Remove(res9);
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, false);
            Assert.AreEqual(tb3, FirstControl, "expect to return tb3 as first control");
            Assert.AreEqual(tb2, coll.FirstErrorControl, "expect tb2 to be still selected as first control");

            // test other overload of BuildScreenVerificationResult, ignorewarnings etc
            object FirstErrorContext;

            // test ignorewarnings true
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, true);

            Assert.AreEqual(null, FirstErrorContext, "FirstErrorContext is null");

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

            expectedErrorMessages = "test1\r\n\r\ntest2\r\n\r\ntest5\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "ignore warnings (ie. noncritical). Include TVerificationResults");

            // test ignorewarnings false
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, false);

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

            expectedErrorMessages =
                "test0\r\n\r\ntest1\r\n\r\ntest2\r\n\r\ntest3\r\n\r\ntest4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\ntest8\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "do not ignore warnings (ie. noncritical). Include TVerificationResults");

            // test ARestrictToTypeWhichRaisesError, restrict to string errorcontext
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, typeof(string), false);
            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages =
                "test8\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "restrict to string errorcontext");

            // test AUpdateFirstErrorControl
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, false);
            // it seems that res2/tb1 is ignored, because it is not a screenverificationresult
            Assert.AreEqual(tb3, FirstControl, "first control should be tb3");
            Assert.AreEqual(tb3, coll.FirstErrorControl, "first error control should be tb3");
            // now testing with res8/tb3 inserted before tb2, and not updating first error control
            coll.Insert(3, res9);
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, false, null, false);
            Assert.AreEqual(tb2, FirstControl, "first control should be tb2");
            Assert.AreEqual(tb3, coll.FirstErrorControl, "first error control should still be tb3");
        }
        private void ValidateDataManual(PSubscriptionRow ARow)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult     VerificationResult = null;
            bool NoClearingOfVerificationResult        = false;

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            if (!chkChangeReasonSubsGivenCode.Checked)
            {
                if (VerificationResultCollection.Contains(ARow.Table.Columns[PSubscriptionTable.ColumnReasonSubsGivenCodeId]))
                {
                    VerificationResultCollection.Remove(ARow.Table.Columns[PSubscriptionTable.ColumnReasonSubsGivenCodeId]);
                }
            }

            if (!chkChangeStartDate.Checked)
            {
                if (VerificationResultCollection.Contains(ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId]))
                {
                    VerificationResultCollection.Remove(ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId]);
                }
            }

            // if 'SubscriptionStatus' is CANCELLED or EXPIRED then 'Reason Ended' and 'End Date' must be set
            ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnSubscriptionStatusId];

            if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if ((!ARow.IsSubscriptionStatusNull()) &&
                    ((ARow.SubscriptionStatus == "CANCELLED") ||
                     (ARow.SubscriptionStatus == "EXPIRED")))
                {
                    if (ARow.IsReasonSubsCancelledCodeNull() ||
                        (ARow.ReasonSubsCancelledCode == String.Empty))
                    {
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                   ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDMANDATORY_WHEN_EXPIRED)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);
                    }
                    else if (ARow.IsDateCancelledNull())
                    {
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                   ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDMANDATORY_WHEN_EXPIRED)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);
                    }
                }
                else
                {
                    // if 'SubscriptionStatus' is not CANCELLED or EXPIRED then 'Reason Ended' and 'End Date' must NOT be set
                    if (chkChangeReasonSubsCancelledCode.Checked)
                    {
                        if ((ARow.IsReasonSubsCancelledCodeNull()) ||
                            (ARow.ReasonSubsCancelledCode == String.Empty))
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                       ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)),
                                                                               ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                    }
                    else if (!chkChangeReasonSubsCancelledCode.Checked)
                    {
                        if (ARow.SubscriptionStatus != String.Empty)
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                       ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)),
                                                                               ValidationColumn, ValidationControlsData.ValidationControl);

                            VerificationResult.OverrideResultText(Catalog.GetString(
                                                                      "Reason Ended must be cleared when a Subscription is made active."));

                            NoClearingOfVerificationResult = true;
                        }
                    }

                    if ((!ARow.IsReasonSubsCancelledCodeNull()) &&
                        (ARow.ReasonSubsCancelledCode != String.Empty))
                    {
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                   ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);
                    }
                    else if (!ARow.IsDateCancelledNull())
                    {
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                   ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDSET_WHEN_ACTIVE)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);
                    }
                    else if (!chkChangeDateCancelled.Checked)
                    {
                        if (ARow.SubscriptionStatus != String.Empty)
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(this,
                                                                                                       ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDSET_WHEN_ACTIVE)),
                                                                               ValidationColumn, ValidationControlsData.ValidationControl);

                            VerificationResult.OverrideResultText(Catalog.GetString("Date Ended must be cleared when a Subscription is made active."));
                        }
                    }
                    else
                    {
                        if (!NoClearingOfVerificationResult)
                        {
                            VerificationResult = null;
                        }
                    }
                }

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