private static void DoFieldRelation(DataSet dataSource, DataTable table, List <FieldRelation> list, string joinTableName, int fieldIndex, int relSourceIndex, int relFieldIndex, bool isLeftJoin) { RelativeSource relSource = null; if (table.Columns[fieldIndex].ExtendedProperties.ContainsKey(FieldProperty.RelativeSource)) { relSource = ((RelativeSourceCollection)table.Columns[fieldIndex].ExtendedProperties[FieldProperty.RelativeSource])[relSourceIndex]; } string tempJoin = relSource.IsCheckSource && !isLeftJoin ? "Inner Join" : "Left Join"; List <FieldOwn> tempJoinFields = new List <FieldOwn>(); if (!string.IsNullOrEmpty(relSource.RelPK)) { string[] relPks = relSource.RelPK.Split(';'); if (relPks == null) { tempJoinFields.Add(ReturnFieldOwn(relSource.RelPK, dataSource)); } else { int length = relPks.Length; for (int i = 0; i < length; i++) { tempJoinFields.Add(ReturnFieldOwn(relPks[i], dataSource)); } } } tempJoinFields.Add(new FieldOwn(table.TableName, table.Columns[fieldIndex].ColumnName)); DataSet relDataSource = LibSqlModelCache.Default.GetSqlModel(relSource.RelSource); list.AddRange(GetFieldRelation(relDataSource, relSource.TableIndex, relSource.RelFields[relFieldIndex].Name, relSource.GroupCondation, tempJoin, joinTableName, tempJoinFields)); }
public static string[] GetFieldBelongTo(this DataSet dataSource, int tableIndex, string fieldName) { DataTable table = dataSource.Tables[tableIndex]; FieldAddr addr = ((Dictionary <string, FieldAddr>)table.ExtendedProperties[TableProperty.FieldAddrDic])[fieldName]; if (addr.RelSourceIndex == -1) { return(new string[] { table.TableName, table.Columns[addr.FieldIndex].ColumnName }); } else { //为关联字段 RelativeSource relSource = null; if (table.Columns[addr.FieldIndex].ExtendedProperties.ContainsKey(FieldProperty.RelativeSource)) { relSource = ((RelativeSourceCollection)table.Columns[addr.FieldIndex].ExtendedProperties[FieldProperty.RelativeSource])[addr.RelSourceIndex]; } DataSet relDataSource = LibSqlModelCache.Default.GetSqlModel(relSource.RelSource); return(GetFieldBelongTo(relDataSource, relSource.TableIndex, relSource.RelFields[addr.RelFieldIndex].Name)); } }