Пример #1
0
        /// <summary>
        /// Checks null values and format for the filter variables.
        /// </summary>
        /// <param name="filter">Filter to check.</param>
        /// <returns>If true, the cheking was OK, otherwise, return false.</returns>
        private bool CheckNullAndFormatFilterVariablesValues(IUFilterController filter)
        {
            bool lResult = true;

            object[] lArgs = new object[1];

            // Exit function if filter is null.
            if (filter == null)
            {
                return(false);
            }

            // Control the null - not null allowed for all the filter variables arguments.
            foreach (ArgumentController lFilterVariable in filter.InputFields)
            {
                // Argument data-valued validation.
                ArgumentDVController lFilterVariableDV = lFilterVariable as ArgumentDVController;
                if ((lFilterVariableDV != null) && (lFilterVariableDV.Editor != null))
                {
                    lArgs[0] = lFilterVariable.Alias;
                    lResult  = lResult & lFilterVariableDV.Editor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs));
                }
                // Argument object-valued validation.
                else
                {
                    ArgumentOVController lFilterVariableOV = lFilterVariable as ArgumentOVController;
                    if (lFilterVariableOV != null)
                    {
                        foreach (IEditorPresentation lEditor in lFilterVariableOV.Editors)
                        {
                            if (lEditor != null)
                            {
                                lArgs[0] = lFilterVariable.Alias;
                                // Shows the validation error only for the last editor field.
                                lResult = lResult & lEditor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs));
                            }
                        }
                    }
                }
            }

            return(lResult);
        }
Пример #2
0
        /// <summary>
        /// Validates the format and null allowed of the filter variables
        /// </summary>
        /// <returns></returns>
        protected bool CheckNullAndFormatFilterVariablesValues()
        {
            bool lResult = true;

            object[] lArgs = new object[1];

            // Control the null - not null allowed for all the filter variables arguments.
            foreach (ArgumentController lFilterVariable in InputFields)
            {
                // Argument data-valued validation.
                ArgumentDVController lFilterVariableDV = lFilterVariable as ArgumentDVController;
                if ((lFilterVariableDV != null) && (lFilterVariableDV.Editor != null))
                {
                    lArgs[0] = lFilterVariable.Alias;
                    lResult  = lResult & lFilterVariableDV.Editor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs));
                }
                // Argument object-valued validation.
                else
                {
                    ArgumentOVController lFilterVariableOV = lFilterVariable as ArgumentOVController;
                    if (lFilterVariableOV != null)
                    {
                        List <Object> lEditorFields = new List <object>();
                        foreach (IEditorPresentation lEditor in lFilterVariableOV.Editors)
                        {
                            if (lEditor != null)
                            {
                                lArgs[0] = lFilterVariable.Alias;
                                // Shows the validation error only for the last editor field.
                                lResult = lResult & lEditor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs));
                                if (lEditor.Value != null)
                                {
                                    // Fill the auxiliar list of values, in order to check if the Alternate Key is valid.
                                    lEditorFields.Add(lEditor.Value);
                                }
                            }
                        }

                        // If the OV filter variable has to work with an Alternate Key, check that the values specified
                        // in the editors are valid (It exist an instance that mach with this Alternate Key).
                        if (lFilterVariableOV.AlternateKeyName != string.Empty && lFilterVariableOV.Editors.Count == lEditorFields.Count)
                        {
                            Oid          lOid          = Oid.Create(lFilterVariableOV.Domain);
                            AlternateKey lAlternateKey = (AlternateKey)lOid.GetAlternateKey(lFilterVariableOV.AlternateKeyName);
                            lAlternateKey.SetValues(lEditorFields);

                            // Check if the Alternate Key is a valid one.
                            Oid lResultOid = Logic.GetOidFromAlternateKey(lAlternateKey, lFilterVariableOV.AlternateKeyName);
                            // If the Oid is not found, it is because the Alternate Key is not a valid one.
                            if (lResultOid == null)
                            {
                                ScenarioManager.LaunchErrorScenario(new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_NO_EXIST_INSTANCE, LanguageConstantValues.L_ERROR_NO_EXIST_INSTANCE)));
                                return(false);
                            }
                        }
                    }
                }
            }

            return(lResult);
        }