protected override void PopulateAttributeValues() { int?_tableId = null; int?_fieldId = null; string qTableId = Request.QueryString["tableId"]; string qFieldId = Request.QueryString["fieldId"]; if (!string.IsNullOrEmpty(qTableId)) { _tableId = int.Parse(qTableId); if (!string.IsNullOrEmpty(qFieldId)) { _fieldId = int.Parse(qFieldId); } } if (!_tableId.HasValue) { return; } // populate table field attributes MetadataDa da = new MetadataDa(); DataTable dt = da.GetFieldMetadata(_tableId.Value, QueryDiseaseId); // build a list of unique metadata tables with there associated metadata var tableToAttributes = from row in dt.AsEnumerable() let fieldId = (int)row[MetadataField.FieldId] // restrict to single field (if applicable) where !_fieldId.HasValue || fieldId == _fieldId group row by fieldId into groupByField let filedName = groupByField.First()[MetadataField.FieldName].ToString() let fieldSort = groupByField.First()[MetadataField.FieldOrder].ToString() // sort by field sort order, with null to bottom let sort = !string.IsNullOrEmpty(fieldSort) ? int.Parse(fieldSort) : int.MaxValue orderby sort ascending, filedName ascending select new { TableId = _tableId, FieldId = groupByField.Key, FieldName = filedName, //FieldSuppress = groupByField.First()[MetadataField.FieldSuppress], //FieldOrder = groupByField.First()[MetadataField.FieldOrder], Data = groupByField, DiseaseAttributes = from record in groupByField where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }; MetadataGrid.DataSource = tableToAttributes; MetadataGrid.DataBind(); }
/// <summary> /// Builds a list of available MetadataTables /// </summary> protected override void PopulateAttributeValues() { if (tableId.HasValue) { // populate main table attributes PopulateTableAttributes(); // populate table field attributes MetadataDa da = new MetadataDa(); DataTable dt = da.GetFieldMetadata(tableId.Value, QueryDiseaseId); // build a list of unique metadata tables with there associated metadata var tableToAttributes = from row in dt.AsEnumerable() let fieldId = (int)row[MetadataField.FieldId] group row by fieldId into groupByField let filedName = groupByField.First()[MetadataField.FieldName].ToString() let fieldOrderMetadata = from record in groupByField let attributeName = record[MetadataFieldAttribute.AttributeName].ToString() let attributeValue = record[MetadataFieldAttributeValue.AttributeValue].ToString() // filter by FieldOrder attribute where attributeName.Equals(MetadataField.FieldOrder, StringComparison.OrdinalIgnoreCase) && PageUtil.IsInteger(attributeValue) // filter by disease (or defaul=NULL) where (!QueryDiseaseId.HasValue && record.IsNull(Disease.DiseaseId)) || (QueryDiseaseId.HasValue && !record.IsNull(Disease.DiseaseId)) let fieldOrder = int.Parse(attributeValue) select fieldOrder // sort by field sort order, with null to bottom let fieldOrder = fieldOrderMetadata.Count() > 0 ? fieldOrderMetadata.First() : int.MaxValue //let sort = !string.IsNullOrEmpty(fieldSort) ? int.Parse(fieldSort) : int.MaxValue orderby fieldOrder ascending, filedName ascending select new { TableId = tableId, FieldId = groupByField.Key, FieldName = filedName, FieldOrder = fieldOrder, //FieldSuppress = false, Data = groupByField, DiseaseAttributes = from record in groupByField where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }; MetadataGrid.DataSource = tableToAttributes; MetadataGrid.DataBind(); // build fields without metadata MetadataTable biz = new MetadataTable(); biz.Get(tableId.Value); MetadataNewDa MNDa = new MetadataNewDa(); DataTable cols = MNDa.GetTableColumns(tableId.Value, biz[MetadataTable.TableName_Field].ToString()); // build a list of actual fields not yet assigned metadata var nonMetadataFields = from row in cols.AsEnumerable() select new { COLUMN_NAME = row["COLUMN_NAME"].ToString(), DATA_TYPE = row["DATA_TYPE"].ToString(), CHAR_MAX_LEN = row["CHAR_MAX_LEN"].ToString(), IS_VIRTUAL = false }; // build blank rows for new virtual fields var blankVirtualFields = from i in Enumerable.Range(0, 1) select new { COLUMN_NAME = string.Empty, DATA_TYPE = string.Empty, CHAR_MAX_LEN = string.Empty, IS_VIRTUAL = true }; var dataSource = nonMetadataFields.Concat(blankVirtualFields); NonMetadataFields.DataSource = dataSource; NonMetadataFields.DataBind(); } }