Ejemplo n.º 1
0
        private bool HasAlternateKeysToProcess(DataTable datatable, string alternateKeyName)
        {
            if (datatable != null && datatable.Rows.Count == 1)
            {
                // Get the Oid associated to the row and check if it has alternate key.
                Oid oid          = ServerConnection.GetOid(datatable, datatable.Rows[0], alternateKeyName);
                Oid alternateKey = (Oid)oid.GetAlternateKey(alternateKeyName);
                if (alternateKey != null)
                {
                    foreach (IOidField oidField in alternateKey.Fields)
                    {
                        if (datatable.Columns[oidField.Name] == null)
                        {
                            // If any field is null, it is considered that there is not alternate key.
                            return(false);
                        }
                    }
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 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);
        }