Exemplo n.º 1
0
 public void Save(XmlElement xml)
 {
     SaveBase(xml);
     this.SavePropertiesCore(xml);
     XmlTool.SaveParameters(xml, SpecificData);
     if (ObjectName != null)
     {
         ObjectName.SaveToXml(xml);
     }
     if (RelatedTable != null)
     {
         RelatedTable.SaveToXml(xml, "relschema", "reltable");
     }
     //XmlTool.SaveNameWithSchema(xml, RelatedTable, "relschema", "reltable");
     if (DependsOn != null)
     {
         XmlElement deps = xml.AddChild("DependsOn");
         foreach (var item in DependsOn)
         {
             var        repr = SpecificRepresentationAddonType.Instance.FindRepresentation(item.ObjectType);
             XmlElement it   = deps.AddChild(repr.XmlElementName);
             if (item.Name != null)
             {
                 item.Name.SaveToXml(it);
             }
         }
     }
 }
Exemplo n.º 2
0
        internal override bool IsConstraintViolated()
        {
            if (Table.DataSet == null || RelatedTable.DataSet == null)
            {
                return(false);
            }

            bool hasErrors = false;

            foreach (DataRow row in Table.Rows)
            {
                if (row.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                // we check if all values in _childColumns place are nulls.
                // if yes we return.
                if (row.IsNullColumns(_childColumns))
                {
                    continue;
                }

                // check whenever there is (at least one) parent row  in RelatedTable
                if (!RelatedTable.RowsExist(_parentColumns, _childColumns, row))
                {
                    // if no parent row exists - constraint is violated
                    hasErrors = true;
                    string[] values = new string[_childColumns.Length];
                    for (int i = 0; i < _childColumns.Length; i++)
                    {
                        DataColumn col = _childColumns[i];
                        values[i] = row[col].ToString();
                    }

                    row.RowError = String.Format("ForeignKeyConstraint {0} requires the child key values ({1}) to exist in the parent table.",
                                                 ConstraintName, String.Join(",", values));
                }
            }

            if (hasErrors)
            {
                //throw new ConstraintException("Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.");
                return(true);
            }

            return(false);
        }
        internal override void AssertConstraint(DataRow row)
        {
            // first we check if all values in _childColumns place are nulls.
            // if yes we return.
            if (row.IsNullColumns(_childColumns))
            {
                return;
            }

            // check whenever there is (at least one) parent row  in RelatedTable
            if (!RelatedTable.RowsExist(_parentColumns, _childColumns, row))
            {
                // if no parent row exists - constraint is violated
                throw new InvalidConstraintException(GetErrorMessage(row));
            }
        }
Exemplo n.º 4
0
        private void BuildKeyDialog_Load(object sender, EventArgs e)
        {
            if (SelectedDataSource != null)
            {
                if (SelectedDataSource is IDbDriver)
                {
                    IDbDriver db = SelectedDataSource as IDbDriver;
                    //--EI-114
                    // relatedFields = db.GetTableColumnNames(RelatedTable);
                    if (RelatedTable.Contains(StringLiterals.SPACE))
                    {
                        string    pstr      = "Select TOP 2 * from [" + RelatedTable + "]";
                        DataTable relfields = DBReadExecute.GetDataTable(db, pstr);
                        foreach (DataColumn dc in relfields.Columns)
                        {
                            relatedFields.Add(dc.ColumnName);
                        }
                    }
                    else
                    {
                        relatedFields = db.GetTableColumnNames(RelatedTable);
                    }
                    //---
                }
                else if (SelectedDataSource is Project)
                {
                    Project project = SelectedDataSource as Project;

                    if (project.Views.Exists(relatedTable))
                    {
                        foreach (Epi.Fields.IField field in project.Views[RelatedTable].Fields)
                        {
                            if (!(field is Epi.Fields.LabelField) & !(field is Epi.Fields.CommandButtonField) & !(field is Epi.Fields.PhoneNumberField)//EI-705
                                & !(field is Epi.Fields.MultilineTextField) & !(field is Epi.Fields.GroupField) & !(field is Epi.Fields.CheckBoxField)
                                & !(field is Epi.Fields.ImageField) & !(field is Epi.Fields.OptionField) & !(field is Epi.Fields.GridField)
                                & !(field is Epi.Fields.MirrorField))
                            {
                                relatedFields.Add(field.Name);
                            }
                        }
                    }
                    else
                    {
                        relatedFields = project.GetTableColumnNames(RelatedTable);
                    }
                }
                if (this.EpiInterpreter.Context.DataSet != null)
                {
                    View CurrentView = null;
                    bool currentReadIdentifierIsView = false;

                    if (this.EpiInterpreter.Context.CurrentProject != null)
                    {
                        currentReadIdentifierIsView = this.EpiInterpreter.Context.CurrentProject.IsView(this.EpiInterpreter.Context.CurrentRead.Identifier);
                    }

                    if (currentReadIdentifierIsView)
                    {
                        CurrentView = this.EpiInterpreter.Context.CurrentProject.GetViewByName(this.EpiInterpreter.Context.CurrentRead.Identifier); //EI-705
                        foreach (DataColumn column in this.EpiInterpreter.Context.DataSet.Tables["Output"].Columns)
                        {
                            if ((CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.LabelField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.CommandButtonField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.PhoneNumberField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.MultilineTextField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.GroupField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.CheckBoxField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.ImageField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.OptionField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.GridField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.MirrorField)))
                            {
                                currentFields.Add(column.ColumnName);
                            }
                        }
                    }
                    else
                    {
                        foreach (DataColumn column in this.EpiInterpreter.Context.DataSet.Tables["Output"].Columns)
                        {
                            currentFields.Add(column.ColumnName);
                        }
                    }
                }
                currentFields.Sort();
            }
            //rdbCurrentTable.Checked = true;

            relatedFields.Sort();
            currentFields.Sort();

            //cmbAvailableVariables2.DataSource = relatedFields;
            lbxRelatedTableFields.DataSource = relatedFields;
            //cmbAvailableVariables.DataSource = currentFields;
            lbxCurrentTableFields.DataSource = currentFields;

            lbxCurrentTableFields.SelectedIndex = -1;
            lbxRelatedTableFields.SelectedIndex = -1;

            if (CallingDialog == "RELATE")
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_RELATE_INSTRUCTIONS;
            }
            else
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_MERGE_INSTRUCTIONS;
            }

            this.LoadIsFinished = true;
        }
Exemplo n.º 5
0
        private void BuildKeyDialog_Load(object sender, EventArgs e)
        {
            if (SelectedDataSource != null)
            {
                if (SelectedDataSource is IDbDriver)
                {
                    IDbDriver db = SelectedDataSource as IDbDriver;
                    //--EI-114
                    // relatedFields = db.GetTableColumnNames(RelatedTable);
                    if (RelatedTable.Contains(StringLiterals.SPACE))
                    {
                        string    pstr      = "Select TOP 2 * from [" + RelatedTable + "]";
                        DataTable relfields = DBReadExecute.GetDataTable(db, pstr);
                        foreach (DataColumn dc in relfields.Columns)
                        {
                            relatedFields.Add(dc.ColumnName);
                        }
                    }
                    else
                    {
                        relatedFields = db.GetTableColumnNames(RelatedTable);
                    }
                    //---
                }
                else if (SelectedDataSource is Project)
                {
                    Project project = SelectedDataSource as Project;

                    if (project.Views.Exists(relatedTable))
                    {
                        foreach (Epi.Fields.IField field in project.Views[RelatedTable].Fields)
                        {
                            if (!(field is Epi.Fields.LabelField) &
                                !(field is Epi.Fields.CommandButtonField) &
                                !(field is Epi.Fields.PhoneNumberField) &
                                !(field is Epi.Fields.MultilineTextField) &
                                !(field is Epi.Fields.GroupField) &
                                !(field is Epi.Fields.CheckBoxField) &
                                !(field is Epi.Fields.ImageField) &
                                !(field is Epi.Fields.OptionField) &
                                !(field is Epi.Fields.GridField) &
                                !(field is Epi.Fields.MirrorField))
                            {
                                relatedFields.Add(field.Name);
                            }
                        }
                    }
                    else
                    {
                        relatedFields = project.GetTableColumnNames(RelatedTable);
                    }
                }

                currentFields = GetCurrentFields();
            }

            relatedFields.Sort();
            currentFields.Sort();

            lbxRelatedTableFields.DataSource = relatedFields;
            lbxCurrentTableFields.DataSource = currentFields;

            lbxCurrentTableFields.SelectedIndex = -1;
            lbxRelatedTableFields.SelectedIndex = -1;

            if (CallingDialog == "RELATE")
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_RELATE_INSTRUCTIONS;
            }
            else
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_MERGE_INSTRUCTIONS;
            }

            this.LoadIsFinished = true;
        }