/// <summary> /// Returns the schema of a table. /// </summary> /// <param name="table">Table to retrieve.</param> /// <returns>An ArrayList of FieldUserSchemaInfo objects.</returns> public ArrayList GetTableSchema(string table) { ArrayList arrayFieldUser = new ArrayList(); ArrayList arraySchema = new ArrayList(); XmlNodeList fieldNodeList = _doc.SelectNodes("//table[@name='" + table + "']/field"); foreach (XmlNode fieldNode in fieldNodeList) { XmlElement fieldElement = (XmlElement)fieldNode; string name = fieldElement.GetAttribute("name"); bool visible = false; if (fieldElement.GetAttribute("visible") == "true") { visible = true; } int width = 0; if (fieldElement.GetAttribute("width") != "") { width = int.Parse(fieldElement.GetAttribute("width")); } string align = fieldElement.GetAttribute("align"); bool primaryKey = false; if (fieldElement.GetAttribute("primarykey") == "true") { primaryKey = true; } string relTable = fieldElement.GetAttribute("reltable"); string relField = fieldElement.GetAttribute("relfield"); string relShown = fieldElement.GetAttribute("relshown"); bool relTranslate = false; if (fieldElement.GetAttribute("reltranslate") == "true") { relTranslate = true; } bool bReadOnly = false; if (primaryKey) { string res = fieldElement.GetAttribute("readonly"); if (res == "true") { bReadOnly = true; } } FieldUserSchemaInfo fieldInfo = new FieldUserSchemaInfo(name, visible, width, align, primaryKey, relTable, relField, relShown, relTranslate, bReadOnly); // // XNA_08_10_2007 arrayFieldUser.Add(fieldInfo); // // XNA_08_10_2007 } // XNA_08_10_2007 string filter = null; XmlNode filterNode = _doc.SelectSingleNode("//table[@name='" + table + "']/filter"); if (filterNode != null) { XmlElement filterElement = (XmlElement)filterNode; filter = filterElement.GetAttribute("where"); } TableUserSchemaInfo tableInfo = new TableUserSchemaInfo(arrayFieldUser, filter); arraySchema.Add(tableInfo); // XNA_08_10_2007 return(arraySchema); }
public void LoadSchema(OPS.Components.Data.Database d) { standardOrderByField = _standardOrderByField; standardOrderByAsc = _standardOrderByAsc; standardTableName = _standardTableName; stValidDeleted.Clear(); standardFields.Clear(); standardPks.Clear(); standardRelationTables.Clear(); standardRelationFields.Clear(); standardRelationKeys.Clear(); standardRelationShowns.Clear(); standardRelationTranslate.Clear(); for (int aux = 0; aux < _stValidDeleted.Length; aux++) { stValidDeleted.Add(_stValidDeleted[aux]); } // When we have the table described in the UserSchema, we must load // its settings for the fields/columns of the table from there. if (d.UserSchema[standardTableName] != null) { ArrayList _array = (ArrayList)d.UserSchema[standardTableName]; string[] _newStandardFields = new string[_array.Count]; // Creates an enumerator and get all elements IEnumerator myEnumerator = _array.GetEnumerator(); while (myEnumerator.MoveNext()) { // XNA_08_10_2007 TableUserSchemaInfo currentTUSI = (TableUserSchemaInfo)myEnumerator.Current; standardWhere = currentTUSI.Where; IEnumerator enumTables = currentTUSI.TableFieldUserSchemaInfo.GetEnumerator(); while (enumTables.MoveNext()) { FieldUserSchemaInfo currentFUSI = (FieldUserSchemaInfo)enumTables.Current; if (currentFUSI.FieldVisible) { standardFields.Add(currentFUSI.FieldName); if (currentFUSI.FieldPrimaryKey) { standardPks.Add(currentFUSI.FieldName); standardFields.Remove(currentFUSI.FieldName); standardFields.Insert(0, currentFUSI.FieldName); } if (currentFUSI.FieldRelTable.Length > 0) { standardRelationTables.Add(TranslateTable2Component(currentFUSI.FieldRelTable)); standardRelationFields.Add(currentFUSI.FieldName); standardRelationKeys.Add(currentFUSI.FieldRelField); standardRelationShowns.Add(currentFUSI.FieldRelShown); standardRelationTranslate.Add(currentFUSI.FieldRelTranslate); } if (currentFUSI.FieldReadOnly) { m_bPKReadOnly = true; } else { m_bPKReadOnly = false; } } } // XNA_08_10_2007 } } // In case schema does not contain information about fields, We get standard. else { for (int aux = 0; aux < _standardFields.Length; aux++) { standardFields.Add(_standardFields[aux]); } for (int aux = 0; aux < _standardPks.Length; aux++) { standardPks.Add(_standardPks[aux]); } for (int aux = 0; aux < _standardRelationFileds.Length; aux++) { standardRelationFields.Add(_standardRelationFileds[aux]); } for (int aux = 0; aux < _standardRelationTables.Length; aux++) { standardRelationTables.Add(_standardRelationTables[aux]); } } IEnumerator mEnumerator = null; int contador = 0; mEnumerator = standardFields.GetEnumerator(); contador = 0; sstandardFields = new string[standardFields.Count]; while (mEnumerator.MoveNext()) { sstandardFields[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardPks.GetEnumerator(); contador = 0; sstandardPks = new string[standardPks.Count]; while (mEnumerator.MoveNext()) { sstandardPks[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardRelationTables.GetEnumerator(); contador = 0; sstandardRelationTables = new string[standardRelationTables.Count]; while (mEnumerator.MoveNext()) { sstandardRelationTables[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardRelationFields.GetEnumerator(); contador = 0; sstandardRelationFields = new string[standardRelationFields.Count]; while (mEnumerator.MoveNext()) { sstandardRelationFields[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardRelationKeys.GetEnumerator(); contador = 0; sstandardRelationKeys = new string[standardRelationKeys.Count]; while (mEnumerator.MoveNext()) { sstandardRelationKeys[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardRelationShowns.GetEnumerator(); contador = 0; sstandardRelationShowns = new string[standardRelationShowns.Count]; while (mEnumerator.MoveNext()) { sstandardRelationShowns[contador] = mEnumerator.Current.ToString(); contador++; } mEnumerator = standardRelationTranslate.GetEnumerator(); contador = 0; sstandardRelationTranslate = new bool[standardRelationTranslate.Count]; while (mEnumerator.MoveNext()) { sstandardRelationTranslate[contador] = bool.Parse(mEnumerator.Current.ToString()); contador++; } mEnumerator = stValidDeleted.GetEnumerator(); contador = 0; sstValidDeleted = new string[stValidDeleted.Count]; if (stValidDeleted.Count > 0) { while (mEnumerator.MoveNext()) { sstValidDeleted[contador] = mEnumerator.Current.ToString(); contador++; } } }