private static RecordTable CreateDataSource(GridColumnInfo info, IDbAccess dataAccess) { SqlQuery query = new SqlQuery(); StringBuilder text = query.Text; text.Append("SELECT "); text.Append(info.ParentValueField); text.Append(','); text.Append(info.ParentTextField); text.Append(" FROM "); text.Append(info.ParentTable); if (!String.IsNullOrEmpty(info.FilterExpression)) { text.Append(" WHERE "); text.Append(info.FilterExpression); } if (!String.IsNullOrEmpty(info.SortExpression)) { text.Append(" ORDER BY "); text.Append(info.SortExpression); } RecordTable table = new RecordTable(info.ParentTable); using(IDataReader dr = dataAccess.CreateDataReader(query, CommandBehavior.Default)) { table.Load(dr, false, new UISchemaTableReader(info.ParentValueField)); } return table; }
public void DataBind() { if (this.IsAutoDataBindingEnabled) { if (!String.IsNullOrEmpty(this.columnInfoList.TableName) && !String.IsNullOrEmpty(this.columnInfoList.KeyName)) { SqlQuery query = new SqlQuery(); StringBuilder text = query.Text; text.Append("SELECT "); text.Append(this.columnInfoList.KeyName); text.Append(','); foreach(GridColumnInfo info in this.columnInfoList) { text.Append(info.PropertyName); text.Append(','); } text.Remove(text.Length - 1, 1); text.Append(" FROM "); text.Append(this.columnInfoList.TableName); if (!String.IsNullOrEmpty(this.columnInfoList.FilterExpression)) { text.Append(" WHERE "); text.Append(this.columnInfoList.FilterExpression); } if (!String.IsNullOrEmpty(this.columnInfoList.SortExpression)) { text.Append(" ORDER BY "); text.Append(this.columnInfoList.SortExpression); } RecordTable table = new RecordTable(this.columnInfoList.TableName); using(IDataReader dr = this.Factory.DataAccess.CreateDataReader(query, CommandBehavior.Default)) { table.Load(dr, true, new UISchemaTableReader(this.columnInfoList.KeyName)); } base.ItemsSource = table; } } }