public void readTableLayoutFile(String tableLayoutFilePath, ref TableList tablesList) { int countTable = 0; int countColumn = 0; foreach (String s in FileUtil.openFile(tableLayoutFilePath)) { if (countTable == 0 && !s.Contains("Table1")) return; if (!s.Equals("==")) { List<String> values = s.Split(';').ToList(); if (values[0].Split(':')[0].Equals(tablesList.Tables[countTable].OriginalTableName)) { if (values[0].Split(':')[1] != null && !values[0].Split(':')[1].Equals("")) { tablesList.Tables[countTable].TableName = values[1]; } } else if (values[0].Split(':')[0].Equals(tablesList.Tables[countTable].Columns[countColumn].OriginalColumnName)) { if (values[0].Split(':')[1] != null && !values[0].Split(':')[1].Equals("")) tablesList.Tables[countTable].Columns[countColumn].ColumnName = values[1]; if (values[1].Split(':')[0] != null && values[1].Split(':')[0].Equals("PK")) if (values[1].Split(':')[1] != null) tablesList.Tables[countTable].Columns[countColumn].IsPK = Boolean.Parse(values[1].Split(':')[1]); if (values[2].Split(':')[0] != null && values[1].Split(':')[0].Equals("FK")) { if (values[2].Split(':')[1] != null) tablesList.Tables[countTable].Columns[countColumn].IsPK = Boolean.Parse(values[2].Split(':')[1]); if (tablesList.Tables[countTable].Columns[countColumn].IsPK) { KeyValue reference = new KeyValue(); if (values[3].Split(':')[0].Equals("ReferenceDB") && values[3].Split(':')[1] != null) reference.Key = values[3].Split(':')[1]; if (values[4].Split(':')[0].Equals("ReferenceTableColumn") && values[4].Split(':')[1] != null) reference.Value = values[4].Split(':')[1]; } else { tablesList.Tables[countTable].Columns[countColumn].Reference = null; } countColumn++; } } } else { countTable++; } } }
private Boolean isExcludedValue(List<Column> excludedColumns, KeyValue kv){ if(excludedColumns != null) { foreach (Column c in excludedColumns) { if (kv.Key.Equals(c.OriginalColumnName) || kv.Key.Equals(c.ColumnName)) { return true; } } } return false; }
public Column(String ColumnName, Boolean IsPK, Boolean IsFK, Boolean IsIDGenerated, KeyValue Reference) { this.ColumnName = ColumnName; this.OriginalColumnName = ColumnName; this.IsPK = IsPK; this.IsFK = IsFK; this.IsIDGenerated = IsIDGenerated; this.defaulValue = "def"; if (this.IsFK) if (Reference == null || "".Equals(Reference)) throw new Exception("NO REFERENCE ON FK"); else this.Reference = Reference; }
public static List<Table> getTablesFromXMLFile(String filePath) { XElement xml = XElement.Load(getXMLReader(filePath)); Console.Out.Write(xml.Name); Table table = null; Row row = null; List<Table> tables = new List<Table>(); int count = 0; foreach(XElement x in xml.Elements()) { // if (count >= 4) //break; KeyValue value = null; row = null; if (x.Elements().Count() > 0) { foreach (XElement att in x.Elements()) { value = new KeyValue(); value.Key = att.Name.ToString(); value.Value = (String)att.Value.ToString(); row = classUtil.initializeIfNull(row); row.Values = classUtil.initializeIfNull(row.Values); row.Values.Add(value); Column column = new Column(value.Key); table = classUtil.initializeIfNull(table); table.Columns = classUtil.initializeIfNull(table.Columns); Boolean columnFound = false; for (int i = 0; i < table.Columns.Count; i++) { if (table.Columns[i].ColumnName.Equals(column.ColumnName)) columnFound = true; } if(!columnFound) table.Columns.Add(column); } } else { //value = new KeyValue(); //value.Key = x.Name.ToString(); //value.Value = (String)x.Value.ToString(); //row = classUtil.initializeIfNull(row); //row.Values = classUtil.initializeIfNull(row.Values); //row.Values.Add(value); } if (row != null) { table = classUtil.initializeIfNull(table); table.Rows = classUtil.initializeIfNull(table.Rows); table.Rows.Add(row); count++; } } if (table != null) { tables.Add(table); } return tables; }
public static void addNodeToTables(XElement element, ref List<Table> tables) { int index = getElementIndexInTables(element, tables); if (index < 0) //if table do not yet exist { tables.Add(new Table(element.Name.ToString())); index = tables.Count - 1; tables[index].Columns = new List<Column>(); String columnIDName = element.Name.ToString() + "ID"; Column columnID = new Column(columnIDName, true, false, true,null); tables[index].Columns.Add(columnID); if (index > 0)//if not root node and is a child node to the root with children nodes of its own && (element.Parent.Parent == null && !element.HasElements) { String parentName = element.Parent.Name.ToString(); String columnParentIDName = parentName + "ID"; KeyValue reference = new KeyValue(parentName, columnParentIDName); Column columnParentID = new Column(columnParentIDName, false, true, true,reference); tables[index].Columns.Add(columnParentID); } } foreach (XElement x in element.Elements()) { if(x.HasElements) addNodeToTables(x, ref tables); else addNodeToRootTable(x, ref tables, index); } }
public static void getTableRows(XElement element, ref List<Table> tables, int maxRows) { int index = getElementIndexInTables(element, tables); if (index >= 0) //if table exists { Table table = tables[index]; table.Rows = new List<Row>(); Row row = new Row(); row.Values = new List<KeyValue>(); foreach (Column c in table.Columns) { if (c.IsIDGenerated) { if (c.IsFK) { // KeyValue value = new KeyValue(c.ColumnName, ); //row.Values.Add(value); } if (c.IsPK) { KeyValue value = new KeyValue(c.ColumnName, element.Element(c.ColumnName)); row.Values.Add(value); } } } foreach (XElement x in element.Elements()) { if (x.HasElements) { } else { } } } }