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");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes validation warnings by showing a Yes/No message box to the client.  The client can choose to ignore
        /// the warnings and proceed with, for example, saving the data - or to cancel saving and adjust the entered data.
        /// The method should only be used when it has been established that there are no validation errors but there is at
        /// least one warning. Returns true in case the user answers Yes to the question, false otherwise.
        /// </summary>
        /// <param name="AVerificationResultCollection">A <see cref="TVerificationResultCollection" /> to inspect for
        /// data verification errors.</param>
        /// <param name="AQuestion">A Yes/No question to the client that is appended to the warning list.</param>
        /// <param name="ATypeWhichRaisesError">Instance of the calling WinForm.</param>
        /// <returns>True (success) in case the user answers Yes, otherwise false.</returns>
        public static bool ProcessAnyDataValidationWarnings(TVerificationResultCollection AVerificationResultCollection,
                                                            String AQuestion, Type ATypeWhichRaisesError)
        {
            bool ReturnValue = true;

            if (AVerificationResultCollection.HasCriticalOrNonCriticalErrors && AVerificationResultCollection.HasOnlyNonCriticalErrors)
            {
                ReturnValue = false;

                string  errorMessages;
                Control firstControl;
                object  context;
                AVerificationResultCollection.BuildScreenVerificationResultList(out errorMessages, out firstControl, out context);

                if (TMessages.MsgFormSaveVerificationWarning(errorMessages, AVerificationResultCollection[0].ResultCode,
                                                             ATypeWhichRaisesError, AQuestion, false) == System.Windows.Forms.DialogResult.Yes)
                {
                    ReturnValue = true;
                }
            }

            return(ReturnValue);
        }
        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");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks for data verification errors and displays appropriate error messages. Returns true in case there
        /// were no data verification errors, otherwise false.
        /// </summary>
        /// <param name="ARecordChangeVerification">Set this to true if this Method is called in the context of a record change
        /// in a Grid, otherwise set it to false.</param>
        /// <param name="AVerificationResultCollection">A <see cref="TVerificationResultCollection" /> to inspect for
        /// data verification errors.</param>
        /// <param name="ATypeWhichRaisesError">Instance of the calling WinForm.</param>
        /// <param name="ARestrictToTypeWhichRaisesError">Restricts the <see cref="TVerificationResult" />s that
        /// are considered by this Method to those whose <see cref="TVerificationResult.ResultContext" /> matches
        /// <paramref name="ARestrictToTypeWhichRaisesError"></paramref> (defaults to null).</param>
        /// <param name="AIgnoreWarnings">Set to true if Warnings are to be ignored (defaults to false).</param>
        /// <returns>True in case there were no data verification errors, otherwise false.</returns>
        public static bool ProcessAnyDataValidationErrors(bool ARecordChangeVerification,
                                                          TVerificationResultCollection AVerificationResultCollection,
                                                          Type ATypeWhichRaisesError, Type ARestrictToTypeWhichRaisesError = null, bool AIgnoreWarnings = false)
        {
            bool    ReturnValue = false;
            string  ErrorMessages;
            Control FirstErrorControl;
            object  FirstErrorContext;
            bool    RecordDeletionErrorsBecauseOfReference = false;

            // In case there were only warnings, we return true and record change/saving of data can go ahead,
            // otherwise false is returned to prevent record change/saving of data.
            if (TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResultCollection))
            {
                ReturnValue = true;
            }

            if (AVerificationResultCollection.HasCriticalOrNonCriticalErrors)
            {
                // Determine data validation message, and more
                AVerificationResultCollection.BuildScreenVerificationResultList(out ErrorMessages,
                                                                                out FirstErrorControl, out FirstErrorContext, true, ARestrictToTypeWhichRaisesError, AIgnoreWarnings);

                // Tell user that there are data validation errors if there are any
                if (ErrorMessages != String.Empty)
                {
                    if (ARecordChangeVerification)
                    {
                        TMessages.MsgRecordChangeVerificationError(ErrorMessages, ReturnValue, ATypeWhichRaisesError);
                    }
                    else
                    {
                        for (int Counter = 0; Counter < AVerificationResultCollection.Count; Counter++)
                        {
                            if (AVerificationResultCollection[Counter].ResultCode == CommonErrorCodes.ERR_RECORD_DELETION_NOT_POSSIBLE_REFERENCED)
                            {
                                RecordDeletionErrorsBecauseOfReference = true;
                                break;
                            }
                        }

                        if (!RecordDeletionErrorsBecauseOfReference)
                        {
                            TMessages.MsgFormSaveVerificationError(ErrorMessages, ReturnValue, ATypeWhichRaisesError);
                        }
                        else
                        {
                            TMessages.MsgFormSaveVerificationError(ErrorMessages,
                                                                   CommonErrorCodes.ERR_RECORD_DELETION_NOT_POSSIBLE_REFERENCED,
                                                                   ReturnValue, ATypeWhichRaisesError,
                                                                   true);
                        }
                    }

                    // Put Focus on first Control that an error was recorded for
                    if (FirstErrorControl != null)
                    {
                        FirstErrorControl.Focus();
                    }
                }
                else
                {
                    ReturnValue = true;
                }
            }
            else
            {
                ReturnValue = true;
            }

            return(ReturnValue);
        }