public void AddResultTableColumn(MDModel_Table _mtable, MDModel_Table_Column _mColumn) { MDQuery_ResultTable _rtable = null; string _tname = _mtable.TableName; if (this.queryRequest.MainResultTable != null && this.queryRequest.MainResultTable.TableName == _tname) { _rtable = this.queryRequest.MainResultTable; } else { var _rts = from _c in this.queryRequest.ChildResultTables where _c.TableName == _tname select _c; if (_rts != null && _rts.Count() > 0) { _rtable = _rts.First(); } } if (_rtable.Columns == null) { _rtable.Columns = new List <MDQuery_TableColumn>(); } string _cname = _mColumn.ColumnName; var _find = from _t in _rtable.Columns where _t.ColumnName == _cname select _t; if (_find == null || _find.Count() < 1) { MDQuery_TableColumn _column = new MDQuery_TableColumn(_mColumn); _rtable.Columns.Add(_column); } }
/// <summary> /// 构建主表的查询结果字段语句 /// </summary> /// <param name="_qv"></param> /// <param name="_ResultTable"></param> /// <returns></returns> public static string CreateDisplayString(MDModel_QueryModel _qv, MDQuery_ResultTable _ResultTable, List <MD_SecretFieldItem> _secretFields) { StringBuilder _sql = new StringBuilder(); _sql.Append(string.Format("{0}.{1} MAINID", _qv.MainTable.TableName, _qv.MainTable.TableDefine.Table.MainKey)); foreach (MDQuery_TableColumn _rc in _ResultTable.Columns) { _sql.Append(MySqlResultItemBuilder.BuildItem(_rc, _qv)); if (_rc.SecretLevel > 0) { // 字符串类型才进行解密 switch (_rc.ColumnDataType.ToUpper()) { case "CHAR": case "VARCHAR": case "NVARCHAR": case "NVARCHAR2": case "VARCHAR2": _secretFields.Add(new MD_SecretFieldItem() { TableName = _rc.TableName, FieldName = _rc.ColumnAlias }); break; } } } return(_sql.ToString()); }
public void AddResultTable(MDModel_Table _mtable) { string _tname = _mtable.TableName; if (this.queryRequest.MainResultTable != null && this.queryRequest.MainResultTable.TableName == _tname) { return; } if (this.queryRequest.ChildResultTables == null) { this.queryRequest.ChildResultTables = new List <MDQuery_ResultTable>(); } var find = from _t in this.queryRequest.ChildResultTables where _t.TableName == _tname select _t; if (find != null && find.Count() > 0) { return; } MDQuery_ResultTable _table = new MDQuery_ResultTable(); _table.TableName = _mtable.TableName; _table.DisplayTitle = _mtable.TableDefine.DisplayTitle; if (_mtable.TableDefine.ViewTableType == MDType_ViewTable.MainTable) { this.queryRequest.MainResultTable = _table; } else { _table.Columns = new List <MDQuery_TableColumn>(); this.queryRequest.ChildResultTables.Add(_table); } }
private static string CreateChildTableResult(MDModel_QueryModel _qv, MDQuery_ResultTable _rt, string _conditionStr, string _filterStr, List <string> _QueryUsedTableList) { List <string> _usedTables = new List <string>(); foreach (string _s in _QueryUsedTableList) { _usedTables.Add(_s); } if (!_usedTables.Contains(_rt.TableName)) { _usedTables.Add(_rt.TableName); } string _displayStr = CreateDisplayString(_qv, _rt); string _tableStr = CreateTableString(_qv, _usedTables); string _tableRelationStr = CreateTableRelationString(_qv, _usedTables); string _condistr = _conditionStr; if (_tableRelationStr.Trim().Length > 0) { _condistr = string.Format(" {0} ({1}) ", _tableRelationStr, _condistr); } if (_filterStr.Trim().Length > 0) { _condistr = string.Format(" {0} ({1}) ", _filterStr, _condistr); } return(string.Format("select {0} from {1} where {2} ", _displayStr, _tableStr, _condistr)); }
public void ShowQueryResult(MDCompare_Request _request, MDModel_QueryModel _qv, DataTable _excelResultData) { //QueryResultData = new DataSet(); QueryRequest = _request; QueryModel = _qv; this.bandedGridView1.Columns.Clear(); this.bandedGridView1.Bands.Clear(); FieldsDictionary.Clear(); MDQuery_ResultTable _mtable = QueryRequest.MainResultTable; CreateBandColumn(_mtable, DefaultBoolean.True); foreach (MDQuery_ResultTable _ctable in QueryRequest.ChildResultTables) { if (_ctable.TableName != "") { CreateBandColumn(_ctable, DefaultBoolean.False); } } CreateExcelBandColumn(_excelResultData); }
public void AddResultTable(MDModel_Table _mtable) { string _tname = _mtable.TableName; if (this.queryRequest.MainResultTable != null && this.queryRequest.MainResultTable.TableName == _tname) { return; } if (this.queryRequest.ChildResultTables.ContainsKey(_tname)) { return; } MDQuery_ResultTable _table = new MDQuery_ResultTable(); _table.TableName = _mtable.TableName; _table.DisplayTitle = _mtable.TableDefine.DisplayTitle; if (_mtable.TableDefine.ViewTableType == MDType_ViewTable.MainTable) { this.queryRequest.MainResultTable = _table; } else { this.queryRequest.ChildResultTables.Add(_tname, _table); } }
private void RefreshTableSelected(MDQuery_ResultTable _mtable) { TreeListNode _mtableNode = FindTableNode(_mtable.TableName); MDModel_Table _tb = _mtableNode.GetValue("Data") as MDModel_Table; if (_mtableNode != null) { foreach (TreeListNode _cnode in _mtableNode.Nodes) { MDModel_Table_Column _mColumn = _cnode.GetValue("Data") as MDModel_Table_Column; var _find = from _c in _mtable.Columns where _c.ColumnName == _mColumn.ColumnName select _c; if (_find != null && _find.Count() > 0) { _cnode.SetValue("State", 2); SetTableState(_cnode, 2); } } foreach (MDQuery_TableColumn _rtc in _mtable.Columns) { if (_rtc.ColumnType == QueryColumnType.CalculationColumn) { AddCalculationField(_rtc.ColumnTitle, _rtc.ColumnAlgorithm, this.queryModel.FullQueryModelName, _tb, _rtc.ColumnDataType); } if (_rtc.ColumnType == QueryColumnType.StatisticsColumn) { AddStaticsticsField(_rtc.ColumnTitle, _rtc.ColumnAlgorithm, _rtc.ColumnDataType, _tb); } } } }
/// <summary> /// 通过字段别名从查询请求中取一个表中的字段定义 /// </summary> /// <param name="_qr"></param> /// <param name="_tName"></param> /// <param name="_aliasName"></param> /// <returns></returns> public static MDQuery_ResultTableColumn GetColumnDefineByAlias(MDQuery_Request _qr, string _tName, string _aliasName) { MDQuery_ResultTable _table = GetResultTableDefine(_qr, _tName); if (_table == null) { return(null); } return(_table.AliasDict[_aliasName]); }
private static string CreateDisplayString(MDModel_QueryModel _qv, MDQuery_ResultTable _ResultTable, SinoRequestUser RequestUser) { StringBuilder _sql = new StringBuilder(); _sql.Append(string.Format("{0}.{1} MAINID", _qv.MainTable.TableName, _qv.MainTable.MainKey)); foreach (MDQuery_TableColumn _rc in _ResultTable.Columns) { _sql.Append(OraResultItemBuilder.BuildItem(_rc, _qv, RequestUser)); } return(_sql.ToString()); }
/// <summary> /// 建立主表的查询结果语句 /// </summary> /// <param name="_qv"></param> /// <param name="mDQuery_ResultTable"></param> /// <returns></returns> private static string CreateMainTableResult(MDModel_QueryModel _qv, MDQuery_ResultTable _ResultTable, List <MD_SecretFieldItem> _secretFields, string _tempTableName) { List <string> _usedTables = new List <string>(); _usedTables.Add(_ResultTable.TableName); string _displayStr = CreateDisplayString(_qv, _ResultTable, _secretFields); string _conditionRes = CreateConditionStringByMainID(_qv, _tempTableName); string _tableStr = CreateTableString(_qv, _usedTables); return(string.Format("select {0} from {1} where ( {2}) ", _displayStr, _tableStr, _conditionRes)); }
private static string CreateMainTableResult(MDModel_QueryModel _qv, MDQuery_ResultTable _ResultTable, SinoRequestUser RequestUser) { List <string> _usedTables = new List <string>(); _usedTables.Add(_ResultTable.TableName); string _displayStr = CreateDisplayString(_qv, _ResultTable, RequestUser); string _conditionRes = CreateConditionStringByMainID(_qv); string _tableStr = CreateTableString(_qv, _usedTables); return(string.Format("select {0} from {1} where ( {2}) ", _displayStr, _tableStr, _conditionRes)); }
/// <summary> /// 通过查询模型及查询请求建立字段 /// </summary> /// <param name="_request"></param> /// <param name="_qv"></param> public void ShowQueryResult(MDQuery_Request _request, MDModel_QueryModel _qv) { QueryRequest = _request; //QueryModel = _qv; MDQuery_ResultTable _mtable = QueryRequest.MainResultTable; foreach (MDQuery_TableColumn _rc in _mtable.Columns) { GridColumn _gc = AddColumn(_rc.ColumnTitle, _rc.ColumnAlias, _rc.ColumnDataType, _rc.DisplayFormat, _rc.DisplayLength); _gc.Tag = _rc; } }
private static void CreateComboTableColumn(MDModel_QueryModel QueryModel, MDQuery_ResultTable _resultTable, DataTable _ret) { MDModel_Table _tableDefine = MC_QueryModel.GetTableDefine(QueryModel, _resultTable.TableName); foreach (MDQuery_TableColumn _rc in _resultTable.Columns) { string FieldName = _rc.TableName + "_" + _rc.ColumnName; DataColumn _dc = new DataColumn(FieldName); _dc.Caption = _rc.ColumnTitle; bool _isRefTable = (_rc.RefDMB == null || _rc.RefDMB == "") ? false : true; _dc.DataType = CreateTypeByMeta(_rc.ColumnDataType, _isRefTable); _ret.Columns.Add(_dc); } }
private static string GetQueryStrByMainID(MDModel_QueryModel _qv, MDQuery_ResultTable _qrc) { List <string> _usedTables = new List <string>(); _usedTables.Add(_qv.MainTable.TableName); _usedTables.Add(_qrc.TableName); string _displayStr = OraQueryBuilder.CreateDisplayString(_qv, _qrc); string _conditionRes = CreateConditionStringByMainID(_qv); string _tableStr = OraQueryBuilder.CreateTableString(_qv, _usedTables); string _tableRelationStr = OraQueryBuilder.CreateTableRelationString(_qv, _usedTables); return(string.Format("select {0} from {1} where ( {2} ({3})) ", _displayStr, _tableStr, _tableRelationStr, _conditionRes)); }
/// <summary> /// 建立平铺数据表字段 /// </summary> /// <param name="QueryRequest"></param> /// <param name="QueryModel"></param> /// <param name="_ret"></param> private static void CreateFullComboTableColumn(MDQuery_Request QueryRequest, MDModel_QueryModel QueryModel, DataTable _ret) { _ret.Columns.Clear(); MDQuery_ResultTable _mtable = QueryRequest.MainResultTable; //通过表定义建字段 CreateComboTableColumn(QueryModel, _mtable, _ret); _ret.Columns.Add(new DataColumn("ROW_MAINID", typeof(string))); _ret.Columns.Add(new DataColumn("IS_ODD_ROW", typeof(bool))); foreach (MDQuery_ResultTable _ctable in QueryRequest.ChildResultTables) { CreateComboTableColumn(QueryModel, _ctable, _ret); } }
public static MDQuery_Request RuleToQueryRequest(MD_CheckRule _rule, MDModel_QueryModel _queryModel, MDQuery_Request filter_Request) { MDQuery_Request _ret = new MDQuery_Request(); _ret.ChildResultTables = new List <MDQuery_ResultTable>(); _ret.QueryModelName = _rule.QueryModelName; _ret.ConditionExpressions = StrUtils.GetMetaByName("C_BDS", _rule.MethodDefine); MDQuery_ResultTable _restable = new MDQuery_ResultTable(); _restable.TableName = _queryModel.MainTable.TableName; _restable.DisplayTitle = _queryModel.DisplayName; _restable.Columns = new List <MDQuery_TableColumn>(); _ret.MainResultTable = _restable; if (_ret.ConditionItems == null) { _ret.ConditionItems = new List <MDQuery_ConditionItem>(); } foreach (string _field in StrUtils.GetMetasByName("C_FIELD", _rule.MethodDefine)) { string _index = StrUtils.GetMetaByName("MII_INDEX", _field); MDQuery_ConditionItem _citem = new MDQuery_ConditionItem(); _citem.Operator = StrUtils.GetMetaByName("MII_OPER", _field).TrimStart().TrimEnd(); MDModel_Table_Column _columnDefine = GetColumn(StrUtils.GetMetaByName("MII_FIELD", _field), _queryModel); _citem.Column = new MDQuery_TableColumn(_columnDefine); _ret.ConditionItems.Add(_citem); _citem.Values = GetValues(StrUtils.GetMetaByName("MII_VALUE", _field), (_columnDefine.ColumnRefDMB != "")); _citem.ColumnIndex = _index; } if (filter_Request != null && filter_Request.ConditionItems.Count > 0) { int _oldcount = _ret.ConditionItems.Count; _ret.ConditionExpressions = string.Format("({0})", _ret.ConditionExpressions); foreach (MDQuery_ConditionItem _fci in filter_Request.ConditionItems) { MDQuery_ConditionItem _citem = new MDQuery_ConditionItem(); _citem.Operator = _fci.Operator; _citem.Column = _fci.Column; _citem.Values = _fci.Values; _citem.CaseSensitive = _fci.CaseSensitive; _citem.ColumnIndex = (int.Parse(_fci.ColumnIndex) + _oldcount).ToString(); _ret.ConditionItems.Add(_citem); _ret.ConditionExpressions += string.Format("*{0}", _citem.ColumnIndex); } } return(_ret); }
private static string CreateMainTableResult(MDModel_QueryModel _qv, MDQuery_ResultTable _ResultTable, string _condi, List <string> _QueryUsedTableList) { List <string> _usedTables = new List <string>(); foreach (string _s in _QueryUsedTableList) { _usedTables.Add(_s); } if (!_usedTables.Contains(_ResultTable.TableName)) { _usedTables.Add(_ResultTable.TableName); } string _displayStr = CreateDisplayString(_qv, _ResultTable); string _tableStr = CreateTableString(_qv, _usedTables); return(string.Format("select {0} from {1} where {2} ", _displayStr, _tableStr, _condi)); }
public void ShowBlankQueryResult(MDQuery_Request _request) { QueryRequest = _request; MDQuery_ResultTable _mtable = QueryRequest.MainResultTable; foreach (MDQuery_TableColumn _rc in _mtable.Columns) { GridColumn _gc = AddColumn(_rc.ColumnTitle, _rc.ColumnAlias, _rc.ColumnDataType, _rc.DisplayFormat, _rc.DisplayLength); _gc.Tag = _rc; } DataSet _tempDataSet = new DataSet(); //加主表 DataTable _mtb = new DataTable(); _tempDataSet.Tables.Add(_mtb); _mtb.Columns.Add("TEMP_MAINID", typeof(string)); DataRow _newrow = _mtb.NewRow(); _newrow["TEMP_MAINID"] = "1"; _mtb.Rows.Add(_newrow); //加子表 foreach (MDQuery_ResultTable _childTD in QueryRequest.ChildResultTables) { DataTable _ctb = new DataTable(); _ctb.Columns.Add("MAINID", typeof(string)); foreach (MDQuery_TableColumn _rc in _childTD.Columns) { _ctb.Columns.Add(_rc.ColumnTitle); } DataRow _cnrow = _ctb.NewRow(); _cnrow["MAINID"] = "1"; _ctb.Rows.Add(_cnrow); _tempDataSet.Tables.Add(_ctb); _tempDataSet.Relations.Add(_childTD.DisplayTitle, _mtb.Columns["TEMP_MAINID"], _ctb.Columns["MAINID"]); } this.gridControl1.DataSource = _mtb; this.gridView1.ExpandMasterRow(0); }
/// <summary> /// 通过元数据添加Band /// </summary> /// <param name="_mtable"></param> private void CreateBandColumn(MDQuery_ResultTable _resultTable, DefaultBoolean _canSort) { Font UseFont = null; GridBand _band = null; try { _band = this.bandedGridView1.Bands.Add(); UseFont = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold); _band.AppearanceHeader.Font = UseFont; MDModel_Table _tableDefine = MC_QueryModel.GetTableDefine(QueryModel, _resultTable.TableName); _band.Caption = _tableDefine.TableDefine.DisplayTitle; int i = 1; foreach (MDQuery_TableColumn _rc in _resultTable.Columns) { BandedGridColumn _col = this.bandedGridView1.Columns.Add(); _col.OptionsColumn.ReadOnly = this.ReadOnly; _col.OptionsColumn.AllowSort = _canSort; _col.Caption = _rc.ColumnTitle; _col.FieldName = _rc.TableName + "_" + _rc.ColumnName; _col.Visible = true; _col.VisibleIndex = i++; _col.Width = 150; FieldsDictionary.Add(_col.FieldName, new RealColumnDefine(_rc.TableName, _rc.ColumnAlias)); this.bandedGridView1.Columns.Add(_col); _band.Columns.Add(_col); } _band = null; UseFont = null; } finally { if (_band != null) { _band.Dispose(); } if (UseFont != null) { UseFont.Dispose(); } } }
/// <summary> /// 通过查询模型及查询请求建立字段 /// </summary> /// <param name="_request"></param> /// <param name="_qv"></param> public void ShowQueryResult(MDQuery_Request _request, MDModel_QueryModel _qv, DataSet _data) { QueryResultData = _data; QueryRequest = _request; QueryModel = _qv; this.bandedGridView1.Columns.Clear(); this.bandedGridView1.Bands.Clear(); FieldsDictionary.Clear(); MDQuery_ResultTable _mtable = QueryRequest.MainResultTable; CreateBandColumn(_mtable, DefaultBoolean.True); foreach (MDQuery_ResultTable _ctable in QueryRequest.ChildResultTables) { CreateBandColumn(_ctable, DefaultBoolean.False); } }
/// <summary> /// 通过字段别名从查询请求中取一个表中的字段定义 /// </summary> /// <param name="_qr"></param> /// <param name="_tName"></param> /// <param name="_aliasName"></param> /// <returns></returns> public static MDQuery_TableColumn GetColumnDefineByAlias(MDQuery_Request _qr, string _tName, string _aliasName) { MDQuery_ResultTable _table = GetResultTableDefine(_qr, _tName); if (_table == null) { return(null); } var _find = from _c in _table.Columns where _c.ColumnAlias == _aliasName select _c; if (_find != null && _find.Count() > 0) { return(_find.First()); } else { return(null); } }
/// <summary> /// 用保存的查询请求更新此控件 /// </summary> /// <param name="_request"></param> public void RefreshBySaveRequest(MDQuery_Request _request) { //清除选择 foreach (TreeListNode _node in this.treeList1.Nodes) { _node.SetValue("State", 0); foreach (TreeListNode _cnode in _node.Nodes) { _cnode.SetValue("State", 0); } } //选择 MDQuery_ResultTable _mtable = _request.MainResultTable; RefreshTableSelected(_mtable); foreach (MDQuery_ResultTable _ctable in _request.ChildResultTables) { RefreshTableSelected(_ctable); } }
public static SinoSZ_TableRelationCompose Compse(MDQuery_Request _srcRequest, MDModel_QueryModel _srcModel, DataTable _srcChildTable) { SinoSZ_TableRelationCompose _ret = new SinoSZ_TableRelationCompose(); #region 处理查询结果字段 _ret.QueryRequest = new MDQuery_Request(); _ret.ResultData = new DataTable(); _ret.ResultData.Columns.Add(new DataColumn("MAINID", typeof(String))); MDQuery_ResultTable _qrDefine = new MDQuery_ResultTable(); _qrDefine.TableName = _srcRequest.MainResultTable.TableName; _qrDefine.TableName = _srcRequest.MainResultTable.DisplayTitle; _qrDefine.Columns = new List <MDQuery_TableColumn>(); //添加所有主表字段 Dictionary <string, string> _aliasLib = new Dictionary <string, string>(); int _index = 0; DataTable _mainTable = _srcChildTable.DataSet.Tables[_srcRequest.MainResultTable.TableName]; foreach (MDQuery_TableColumn _col in _srcRequest.MainResultTable.Columns) { MDQuery_TableColumn _newcol = CopyResultTableColumn(_col); _newcol.ColumnAlias = string.Format("F{0}", _index++); _aliasLib.Add(string.Format("{0}.{1}", _col.TableName, _col.ColumnAlias), _newcol.ColumnAlias); _qrDefine.Columns.Add(_newcol); DataColumn _dc = _mainTable.Columns[_col.ColumnAlias]; DataColumn _newdc = new DataColumn(_newcol.ColumnAlias, _dc.DataType); _newdc.Caption = _dc.Caption; _ret.ResultData.Columns.Add(_newdc); } //添加所有子表字段 var _find = from _t in _srcRequest.ChildResultTables where _t.TableName == _srcChildTable.TableName select _t; if (_find != null && _find.Count() > 0) { MDQuery_ResultTable _CResultTable = _find.First(); foreach (MDQuery_TableColumn _col in _CResultTable.Columns) { MDQuery_TableColumn _newcol = CopyResultTableColumn(_col); _newcol.ColumnAlias = string.Format("F{0}", _index++); _aliasLib.Add(string.Format("{0}.{1}", _col.TableName, _col.ColumnAlias), _newcol.ColumnAlias); _qrDefine.Columns.Add(_newcol); DataColumn _dc = _srcChildTable.Columns[_col.ColumnAlias]; DataColumn _newdc = new DataColumn(_newcol.ColumnAlias, _dc.DataType); _newdc.Caption = _dc.Caption; _ret.ResultData.Columns.Add(_newdc); } } else { foreach (DataColumn _dc in _srcChildTable.Columns) { if (_dc.ColumnName != "MAINID") { MDQuery_TableColumn _newcol = new MDQuery_TableColumn(); _newcol.ColumnAlias = _dc.ColumnName; _newcol.ColumnTitle = "EXCEL_" + _dc.ColumnName; _aliasLib.Add(string.Format("{0}.{1}", _srcChildTable.TableName, _dc.ColumnName), _dc.ColumnName); _qrDefine.Columns.Add(_newcol); DataColumn _newdc = new DataColumn(_dc.ColumnName, _dc.DataType); _newdc.Caption = _dc.Caption; _ret.ResultData.Columns.Add(_newdc); } } } _ret.QueryRequest.MainResultTable = _qrDefine; #endregion #region 处理元数据定义字段 #endregion #region 处理数据表 //添加数据 foreach (DataRow _dr in _srcChildTable.Rows) { DataRow _newrow = _ret.ResultData.NewRow(); foreach (DataColumn _dc in _srcChildTable.Columns) { if (_dc.ColumnName != "MAINID") { string _newFieldName = _aliasLib[string.Format("{0}.{1}", _dc.Table.TableName, _dc.ColumnName)]; _newrow[_newFieldName] = _dr[_dc.ColumnName]; } } DataRow _fatherRow = _dr.GetParentRow(_srcChildTable.ParentRelations[0].RelationName); foreach (DataColumn _dc in _fatherRow.Table.Columns) { if (_dc.ColumnName == "MAINID") { _newrow["MAINID"] = _fatherRow[_dc.ColumnName]; } else { string _newFieldName = _aliasLib[string.Format("{0}.{1}", _dc.Table.TableName, _dc.ColumnName)]; _newrow[_newFieldName] = _fatherRow[_dc.ColumnName]; } } _ret.ResultData.Rows.Add(_newrow); } #endregion return(_ret); }
public static DataTable CreateFullComboData(MDCompare_Request QueryRequest, MDModel_QueryModel QueryModel, DataSet QueryResultData) { DataTable _ret = new DataTable(); //建TableColumn CreateFullComboTableColumn(QueryRequest as MDQuery_Request, QueryModel, _ret); foreach (DataColumn _dc in QueryResultData.Tables["EXCELRESULTDATA"].Columns) { if (_dc.ColumnName != "MAINID") { string FieldName = "EXCEL_" + _dc.ColumnName; DataColumn _newdc = new DataColumn(FieldName); _newdc.Caption = _dc.ColumnName; _ret.Columns.Add(_newdc); } } //填充数据 DataTable _mtableData = QueryResultData.Tables[QueryRequest.MainResultTable.TableName]; bool _isOddRow = false; foreach (DataRow _mainRow in _mtableData.Rows) { _isOddRow = !_isOddRow; int _intRows = 1; int ChildTableCount = _mtableData.ChildRelations.Count; for (int i = 0; i < ChildTableCount; i++) { string _rname = _mtableData.ChildRelations[i].RelationName; int _ChildCount = _mainRow.GetChildRows(_rname).Length; _intRows = (_ChildCount > _intRows) ? _ChildCount : _intRows; } for (int _line = 0; _line < _intRows; _line++) { DataRow _newRow = _ret.NewRow(); _newRow["ROW_MAINID"] = _mainRow["MAINID"].ToString(); _newRow["IS_ODD_ROW"] = _isOddRow; #region 将主表的记录数据加入新行 foreach (MDQuery_TableColumn _rc in QueryRequest.MainResultTable.Columns) { string FieldName = _rc.TableName + "_" + _rc.ColumnName; _newRow[FieldName] = _mainRow[_rc.ColumnAlias]; } #endregion #region 依次将子表的数据加入新行 for (int i = 0; i < ChildTableCount; i++) { string _rname = _mtableData.ChildRelations[i].RelationName; DataRow[] ChildRows = _mainRow.GetChildRows(_rname); int _ChildCount = ChildRows.Length; if (_ChildCount > 0) { int _CurrentLine = 0; if (_line < _ChildCount) { _CurrentLine = _line; } else { _CurrentLine = _ChildCount - 1; } DataRow _CRow = ChildRows[_CurrentLine]; if (_rname != "比对的EXCEL文件") { var _find = from _t in QueryRequest.ChildResultTables where _t.TableName == _mtableData.ChildRelations[i].ChildTable.TableName select _t; MDQuery_ResultTable _resultChildTable = _find.First(); foreach (MDQuery_TableColumn _crc in _resultChildTable.Columns) { string cFieldName = _crc.TableName + "_" + _crc.ColumnName; _newRow[cFieldName] = _CRow[_crc.ColumnAlias]; } } else { foreach (DataColumn _dc in QueryResultData.Tables["EXCELRESULTDATA"].Columns) { if (_dc.ColumnName != "MAINID") { string cFieldName = "EXCEL_" + _dc.ColumnName; _newRow[cFieldName] = _CRow[_dc.ColumnName]; } } } } } #endregion _ret.Rows.Add(_newRow); } } return(_ret); }
/// <summary> /// 从查询结果中建立全部展示数据 /// </summary> /// <param name="QueryRequest"></param> /// <param name="QueryModel"></param> /// <param name="QueryResultData"></param> /// <returns></returns> public static DataTable CreateFullComboData(MDQuery_Request QueryRequest, MDModel_QueryModel QueryModel, DataSet QueryResultData) { DataTable _ret = new DataTable(); //建TableColumn CreateFullComboTableColumn(QueryRequest, QueryModel, _ret); //填充数据 DataTable _mtableData = QueryResultData.Tables[QueryRequest.MainResultTable.TableName]; bool _isOddRow = false; foreach (DataRow _mainRow in _mtableData.Rows) { _isOddRow = !_isOddRow; int _intRows = 1; int ChildTableCount = _mtableData.ChildRelations.Count; for (int i = 0; i < ChildTableCount; i++) { string _rname = _mtableData.ChildRelations[i].RelationName; int _ChildCount = _mainRow.GetChildRows(_rname).Length; _intRows = (_ChildCount > _intRows) ? _ChildCount : _intRows; } for (int _line = 0; _line < _intRows; _line++) { DataRow _newRow = _ret.NewRow(); _newRow["ROW_MAINID"] = _mainRow["MAINID"].ToString(); _newRow["IS_ODD_ROW"] = _isOddRow; #region 将主表的记录数据加入新行 foreach (MDQuery_ResultTableColumn _rc in QueryRequest.MainResultTable.ColumnsDict.Values) { string FieldName = _rc.TableName + "_" + _rc.ColumnName; _newRow[FieldName] = _mainRow[_rc.ColumnAlias]; } #endregion #region 依次将子表的数据加入新行 for (int i = 0; i < ChildTableCount; i++) { string _rname = _mtableData.ChildRelations[i].RelationName; DataRow[] ChildRows = _mainRow.GetChildRows(_rname); int _ChildCount = ChildRows.Length; if (_ChildCount > 0) { int _CurrentLine = 0; if (_line < _ChildCount) { _CurrentLine = _line; } else { _CurrentLine = _ChildCount - 1; } DataRow _CRow = ChildRows[_CurrentLine]; MDQuery_ResultTable _resultChildTable = QueryRequest.ChildResultTables[_mtableData.ChildRelations[i].ChildTable.TableName]; foreach (MDQuery_ResultTableColumn _crc in _resultChildTable.ColumnsDict.Values) { string cFieldName = _crc.TableName + "_" + _crc.ColumnName; _newRow[cFieldName] = _CRow[_crc.ColumnAlias]; } } } #endregion _ret.Rows.Add(_newRow); } } return(_ret); }