private string GetRelateTextByValue(Rpt_DataSetParams param, string value) { if (param.RelationType == 1) { //关联字典表 return(DictionaryBLL.GetDicCollections(param.RelationTableName, false)[value].Name); } else if (param.RelationType == 2) { //关联实体表 return(TreeTableBLL.GetRelationTableDataValue(param.RelationTableName, param.RelationValueField, param.RelationTextField, value)); } else { return(value); } }
private string GetRelateTextByValue(UD_ModelFields field, string value) { if (field.RelationType == 1) { //关联字典表 return(DictionaryBLL.GetDicCollections(field.RelationTableName, false)[value].Name); } else if (field.RelationType == 2) { //关联实体表 return(TreeTableBLL.GetRelationTableDataValue(field.RelationTableName, field.RelationValueField, field.RelationTextField, value)); } else { return(value); } }
/// <summary> /// 用IList(IModel)数据源来绑定GridView /// </summary> /// <param name="m"></param> public void BindGrid <T>(IList <T> source) { this.DataSource = source; this.DataBind(); if (source.Count == 0) { return; } IList <UD_TableList> _tables = new UD_TableListBLL()._GetModelList("ModelName='" + ((IModel)source[0]).ModelName + "'"); if (_tables.Count == 0) { return; } UD_TableList table = _tables[0]; IList <UD_ModelFields> fields = new UD_TableListBLL(table.ID).GetModelFields(); for (int i = 0; i < Columns.Count; i++) { DataControlField column = Columns[i]; if (column.GetType().Name == "BoundField") { BoundField field = (BoundField)column; if (!column.Visible) { continue; } IList <UD_ModelFields> _models = UD_ModelFieldsBLL.GetModelList("TableID='" + table.ID.ToString() + "' AND FieldName='" + field.DataField + "'"); if (_models.Count == 0) { continue; } UD_ModelFields model = _models[0]; switch (model.RelationType) { case 1: //关联字典表 foreach (GridViewRow row in Rows) { Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections(model.RelationTableName, false); row.Cells[i].Text = dic.ContainsKey(row.Cells[i].Text) ? dic[row.Cells[i].Text].Name : ""; } break; case 2: //关联实体表 foreach (GridViewRow row in Rows) { row.Cells[i].Text = TreeTableBLL.GetRelationTableDataValue(model.RelationTableName, model.RelationValueField, model.RelationTextField, row.Cells[i].Text); } break; } if (model.DataType == 4) //日期型 { foreach (GridViewRow row in Rows) { if (row.Cells[i].Text.StartsWith("1900-01-01")) { row.Cells[i].Text = ""; } } } } } }