Exemple #1
0
        /// <summary>
        /// Creates an Oid object with the list of values for its fields, passed as parameters.
        /// </summary>
        /// <param name="className">Name of the class of the new Oid.</param>
        /// <param name="oidFields">List of fields values.</param>
        /// <param name="alternatieKeyName">Indicates the name of the alternate key.</param>
        /// <param name="executeQuery">Indicates wheter a quey must be executed to retrieve the primary Oid.</param>
        /// <returns>An Oid object.</returns>
        public static Oid CreateOidFromOidFields(
            string className,
            List <object> oidFields,
            string alternateKeyName,
            bool executeQuery)
        {
            Oid lOid = null;

            // Null if some field is null.
            if (oidFields != null)
            {
                foreach (object lOidField in oidFields)
                {
                    if (lOidField == null)
                    {
                        return(null);
                    }
                }

                if (alternateKeyName != string.Empty)
                {
                    // Create the Oid to know its structure and be able to retrieve the alternate key.
                    lOid = Oid.Create(className);

                    // Fill the alternate key with the field values from the editors.
                    AlternateKey alternateKey = (AlternateKey)lOid.GetAlternateKey(alternateKeyName);
                    alternateKey.SetValues(oidFields);

                    if (executeQuery)
                    {
                        // Retrieve the suitable Oid.
                        lOid = GetOidFromAlternateKey(alternateKey, alternateKeyName);
                    }

                    // Null if number of alternate fields does not match.
                    if ((oidFields.Count != alternateKey.Fields.Count))
                    {
                        return(null);
                    }
                }
                else
                {
                    // Create the Oid and set its fields values from the editors.
                    lOid = Oid.Create(className, oidFields);

                    // Null if number of fields in oidField and Oid is not the same.
                    if ((oidFields.Count != lOid.Fields.Count))
                    {
                        return(null);
                    }
                }
            }
            return(lOid);
        }
        /// <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);
        }