private void DisplayRow(DataRowView drv, bool includeThisGroup) { TableRow row = new TableRow(); outputTable.Rows.Add(row); int level = this.GroupLevel; if (!includeThisGroup) { level++; } for (int i = 0; i < level; i++) { TableCell cell = new TableCell(); cell.CssClass = "LanStatNormalCell1"; row.Cells.Add(cell); cell.Text = " "; } StatisticRow lastRow = this; if (!includeThisGroup) { lastRow = this.SubGroup; } while (lastRow != null) { string fieldName = drv.Row.Table.Columns[lastRow.GroupField].ColumnName; TableCell cell = new TableCell(); cell.CssClass = "LanStatNormalCell2"; row.Cells.Add(cell); object o = drv[lastRow.GroupField]; if (o == null || o == DBNull.Value) { cell.Text = " "; } else { string val = TableField.ValueToString(o, dynamicTable[fieldName].Format); if (!dynamicTable[fieldName].UseClassValue) { val = o.ToString().Trim(); if (dynamicTable[fieldName].ShowType == ShowType.COMBOBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); if (vals != null && vals[val] != null) { val = vals[val].Trim(); } } else if (dynamicTable[fieldName].ShowType == ShowType.CHECKBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); if (vals != null) { string[] keys = val.Split(','); for (int ii = 0; ii < keys.Length - 1; ii++) { string v = vals[keys[ii]]; if (v != null) { keys[ii] = v.Trim(); } } val = string.Join(",", keys, 0, keys.Length - 1); } } } if (!forExport) { if (dynamicTable[fieldName].ShowType == ShowType.HTML || dynamicTable[fieldName].ShowType == ShowType.HTMLEDIT || dynamicTable[fieldName].ShowType == ShowType.HTMLOUTEREDIT) { cell.Attributes.Add("dreamanHtml", val); cell.ToolTip = ""; cell.Text = "<a onclick='openHtml(this)' href='#' title='点此查看HTML字段的内容...'>查看内容</a>"; } else if (dynamicTable[fieldName].ShowType == ShowType.FILE || dynamicTable[fieldName].ShowType == ShowType.FILEUPLOAD) { cell.ToolTip = val; cell.Text = val; } else if (dynamicTable[fieldName].ShowType == ShowType.RAWVALUE) { cell.ToolTip = ""; cell.Text = val; } else if (val.Length > lastRow.maxFieldWidth + 1) { cell.ToolTip = val; cell.Text = val.Substring(0, lastRow.maxFieldWidth) + "..."; } else { cell.ToolTip = val; cell.Text = val; } } else { cell.ToolTip = ""; cell.Text = val; } } lastRow = lastRow.SubGroup; } for (int i = 0; i < Fields.Count; i++) { string fieldName = drv.Row.Table.Columns[this[i].Index].ColumnName; if (dynamicTable[fieldName].ShowType == ShowType.HIDDEN) { continue; } if (dynamicTable[fieldName].ShowType == ShowType.NOVALUE) { continue; //分组字段不产生新列 } TableCell cell = new TableCell(); cell.CssClass = "LanStatNormalCell3"; row.Cells.Add(cell); object o = drv[this[i].Index]; if (o == null || o == DBNull.Value) { cell.Text = " "; } else { string val = TableField.ValueToString(o, dynamicTable[fieldName].Format); if (!dynamicTable[fieldName].UseClassValue) { val = o.ToString().Trim(); if (dynamicTable[fieldName].ShowType == ShowType.COMBOBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); if (vals != null && vals[val] != null) { val = vals[val].Trim(); } } else if (dynamicTable[fieldName].ShowType == ShowType.CHECKBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); string[] keys = val.Split(','); for (int ii = 0; ii < keys.Length - 1; ii++) { string v = vals[keys[ii]]; if (v != null) { keys[ii] = v.Trim(); } } val = string.Join(",", keys, 0, keys.Length - 1); } } if (!forExport) { if (dynamicTable[fieldName].ShowType == ShowType.HTML || dynamicTable[fieldName].ShowType == ShowType.HTMLEDIT || dynamicTable[fieldName].ShowType == ShowType.HTMLOUTEREDIT) { cell.Attributes.Add("dreamanHtml", val); cell.ToolTip = ""; cell.Text = "<a onclick='openHtml(this)' href='#' title='点此查看HTML字段的内容...'>查看内容</a>"; } else if (dynamicTable[fieldName].ShowType == ShowType.FILE || dynamicTable[fieldName].ShowType == ShowType.FILEUPLOAD) { cell.ToolTip = val; cell.Text = val; } else if (dynamicTable[fieldName].ShowType == ShowType.RAWVALUE) { cell.ToolTip = ""; cell.Text = val; } else if (val.Length > maxFieldWidth + 1) { cell.ToolTip = val; cell.Text = val.Substring(0, maxFieldWidth) + "..."; } else { cell.ToolTip = val; cell.Text = val; } } else { cell.ToolTip = ""; cell.Text = val; } } } }
public void ExecStatistic(DataRowView drv, bool endGroup) { bool findEnd = false; if (!first) { if (GroupField >= 0 && !endGroup) //如果上级组没有发现组结束,则本组进行判断,否则按上级组的结论执行 { object o = drv[GroupField]; string tempVal = null; if (o != null && o != DBNull.Value) { tempVal = o.ToString().Trim(); } string tempVal0 = null; if (groupValue != null && groupValue != DBNull.Value) { tempVal0 = groupValue.ToString().Trim(); } if (tempVal0 != tempVal) { endGroup = true; findEnd = true; //当前组发现了新的分组。 } } } //让子组先更新 if (SubGroup != null) { SubGroup.ExecStatistic(drv, endGroup); } //输出本组当前结果 if (endGroup) { double[] hsl = ColorTransform.RGB2HSL((uint)baseColor); uint ccc = ColorTransform.HSL2RGB(hsl[0] + groupLevel * deltaH, hsl[1] + groupLevel * deltaS / 100.0, hsl[2] + groupLevel * deltaL / 100.0); Color color = Color.FromArgb((int)ccc); TableRow row = new TableRow(); outputTable.Rows.Add(row); for (int i = 0; i < groupNum; i++) { TableCell tcell = new TableCell(); row.Cells.Add(tcell); if (i >= GroupLevel) { tcell.CssClass = "LanStatGroupCell2"; tcell.BackColor = color; } else { tcell.CssClass = "LanStatGroupCell1"; } if (i != GroupLevel || groupValue == null || groupValue == DBNull.Value) { tcell.Text = " "; } else { string fieldName = drv.Row.Table.Columns[GroupField].ColumnName; string val = TableField.ValueToString(groupValue, dynamicTable[fieldName].Format); if (!dynamicTable[fieldName].UseClassValue) { val = groupValue.ToString().Trim(); if (dynamicTable[fieldName].ShowType == ShowType.COMBOBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); if (vals != null && vals[val] != null) { val = vals[val].Trim(); } } else if (dynamicTable[fieldName].ShowType == ShowType.CHECKBOX) { NameValueCollection vals = dynamicTable.GetClassVals(fieldName); if (vals != null) { string[] keys = val.Split(','); for (int ii = 0; ii < keys.Length - 1; ii++) { string v = vals[keys[ii]]; if (v != null) { keys[ii] = v.Trim(); } } val = string.Join(",", keys, 0, keys.Length - 1); } } } if (!forExport) { if (dynamicTable[fieldName].ShowType == ShowType.HTML || dynamicTable[fieldName].ShowType == ShowType.HTMLEDIT || dynamicTable[fieldName].ShowType == ShowType.HTMLOUTEREDIT) { tcell.Attributes.Add("dreamanHtml", val); tcell.ToolTip = ""; tcell.Text = "<a onclick='openHtml(this)' href='#' title='点此查看HTML字段的内容...'>查看内容</a>"; } else if (dynamicTable[fieldName].ShowType == ShowType.FILE || dynamicTable[fieldName].ShowType == ShowType.FILEUPLOAD) { tcell.ToolTip = val; tcell.Text = val; } else if (dynamicTable[fieldName].ShowType == ShowType.RAWVALUE) { tcell.ToolTip = ""; tcell.Text = val; } else if (val.Length > maxFieldWidth + 1) { tcell.ToolTip = val; tcell.Text = val.Substring(0, maxFieldWidth) + "..."; } else { tcell.ToolTip = val; tcell.Text = val; } } else { tcell.ToolTip = ""; tcell.Text = val; } } } foreach (StatisticField field in fields) { string fieldName = drv.Row.Table.Columns[field.Index].ColumnName; if (dynamicTable[fieldName].ShowType == ShowType.HIDDEN) { continue; } if (dynamicTable[fieldName].ShowType == ShowType.NOVALUE) { continue; //分组字段不产生新列 } TableCell tcell = new TableCell(); tcell.CssClass = "LanStatGroupCell3"; row.Cells.Add(tcell); tcell.BackColor = color; if (field.Type == StatisticFieldType.COUNT || field.Type == StatisticFieldType.DISTINCTCOUNT) { tcell.Text = "" + field.Type + ":" + field.Value.ToString("###,###,###,###"); } else { tcell.Text = "" + field.Type + ":" + TableField.ValueToString(field.Value, dynamicTable[fieldName].Format); } } //当前组结果输出完毕,清空统计值以开始新组统计 foreach (StatisticField field in fields) { field.Reset(); } } //计算统计值 if (GroupField >= 0) { object o = drv[GroupField]; if (o == null || o == DBNull.Value) { groupValue = null; } else { groupValue = o; } } foreach (StatisticField field in fields) { field.Calculate(drv[field.Index]); } //检查看是否要输出数据行 if (first) { //首先输出第一个分组的数据 if (GroupLevel < 0 && GroupField < 0) { DisplayRow(drv, false); } first = false; } else if (findEnd) //本组发现的新分组,则应由本组输出数据行 { DisplayRow(drv, true); } else if (!endGroup && SubGroup == null) //到达最低级分组时没有发现新分组,则由最低级分组输出数据行 { DisplayRow(drv, false); } }