public static StatisticRow CreateTotalRow(Table output, int num, DynamicTable dynaTable, int maxWidth, int _baseColor, int _deltaColor, bool _forExport) { StatisticRow sr = CreateTotalRow(output, num, dynaTable, maxWidth, _baseColor, _deltaColor); sr.forExport = _forExport; return(sr); }
public void DisplayHead(StatisticRow totalRow, DataView dv) { int headRows = 1; for (int i = 0; i < Fields.Count; i++) { string colname = dv.Table.Columns[this[i].Index].ColumnName; if (headRows <= dynamicTable[colname].Indent) { headRows = dynamicTable[colname].Indent + 1; } } TableRow row = new TableRow(); row.BackColor = Color.FromArgb(baseColor); outputTable.Rows.Add(row); StatisticRow lastRow = totalRow.SubGroup; while (lastRow != null) { string colname = dv.Table.Columns[lastRow.GroupField].ColumnName; TableCell cell = new TableCell(); cell.CssClass = "LanStatHeadCell1"; if (headRows > 1) { cell.RowSpan = headRows; } row.Cells.Add(cell); cell.Text = dynamicTable[colname].ShowName; lastRow = lastRow.SubGroup; } for (int i = 1; i < headRows; i++) { TableRow trow = new TableRow(); trow.BackColor = Color.FromArgb(baseColor); outputTable.Rows.Add(trow); } for (int i = 0; i < Fields.Count;) { string colname = dv.Table.Columns[this[i].Index].ColumnName; if (dynamicTable[colname].ShowType == ShowType.HIDDEN) { continue; } BuildField(dv, headRows, false, dynamicTable[colname].Indent, ref i); } }
public StatisticRow CreateSubGroup(int field) { if (field < 0) { throw new Exception("分组列中有不存在的列名,可能指定了原始名而非别名?"); } StatisticRow subRow = new StatisticRow(); subRow.GroupField = field; subRow.groupNum = groupNum; subRow.outputTable = outputTable; subRow.dynamicTable = dynamicTable; subRow.maxFieldWidth = maxFieldWidth; subRow.baseColor = baseColor; subRow.deltaH = deltaH; subRow.deltaS = deltaS; subRow.deltaL = deltaL; SubGroup = subRow; return(subRow); }
public static StatisticRow CreateTotalRow(Table output, int num, DynamicTable dynaTable, int maxWidth, int _baseColor, int _deltaColor) { StatisticRow sr = new StatisticRow(); sr.GroupLevel = -1; sr.GroupField = -1; sr.groupNum = num; sr.outputTable = output; sr.dynamicTable = dynaTable; sr.maxFieldWidth = maxWidth; sr.baseColor = _baseColor; int dh = (int)(((uint)(_deltaColor & 0x00FF0000)) >> 16); int ds = (int)(((uint)(_deltaColor & 0x0000FF00)) >> 8); int dl = (int)(((uint)(_deltaColor & 0x000000FF))); dh = dh > 127 ? 127 - dh : dh; ds = ds > 127 ? 127 - ds : ds; dl = dl > 127 ? 127 - dl : dl; sr.deltaH = dh; sr.deltaS = ds; sr.deltaL = dl; return(sr); }
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; } } } }
private void ButtonClick(object sender, ImageClickEventArgs e) { ImageButton ib = (ImageButton)sender; if (ib.CommandName == "Export") { DataTable data = StatisticControl.Data; DataView dataView = new DataView(data); string[] sorts = StatisticControl.Sorts; if (sorts != null) { dataView.Sort = string.Join(",", sorts); } string[] groups = StatisticControl.Groups; int groupNum = 0; if (groups != null) { groupNum = groups.Length; } StringCollection sc = new StringCollection(); foreach (DataColumn dc in dataView.Table.Columns) { sc.Add(dc.ColumnName); } Table export = new Table(); export.Width = table.Width; export.Font.Size = FontUnit.Point(10); foreach (string key in table.Style.Keys) { export.Style.Add(key, table.Style[key]); } export.CssClass = table.CssClass; StatisticRow statRow = null, lastRow = null; if (statRow == null) { statRow = StatisticRow.CreateTotalRow(export, groupNum, dynamicTable, StatisticControl.MaxFieldWidth, StatisticControl.BaseColor, StatisticControl.DeltaColor, true); lastRow = statRow; } for (int i = 0; i < groupNum; i++) { string field = groups[i]; sc.Remove(field); lastRow = lastRow.CreateSubGroup(dataView.Table.Columns.IndexOf(field)); } foreach (string field in sc) { DataColumn dc = dataView.Table.Columns[field]; lastRow = statRow; while (lastRow != null) { lastRow.AddField(dc, StatisticControl.GetStatisticFieldType(field)); lastRow = lastRow.SubGroup; } } statRow.DisplayHead(statRow, dataView); for (int ii = 0; ii < dataView.Count; ii++) { DataRowView drv = dataView[ii]; statRow.ExecStatistic(drv, false); if (ii == dataView.Count - 1) { statRow.ExecStatistic(drv, true); //结束统计 } } if (StatisticControl.OnExportStatTable(export)) { System.IO.StringWriter tw = new System.IO.StringWriter(); export.RenderControl(new System.Web.UI.HtmlTextWriter(tw)); tw.Close(); HttpResponse res = HttpContext.Current.Response; res.Clear(); res.ContentType = StatisticControl.ExportContentType; res.ContentEncoding = System.Text.Encoding.GetEncoding(StatisticControl.ExportContentEncoding); res.AppendHeader("Content-Disposition", StatisticControl.ExportContentDisposition); res.Write(tw.ToString()); res.End(); } StatisticControl.ChangeState("show"); } else if (ib.CommandName == "Search") { StatisticControl.ChangeState("search"); } }
protected override void Handle() { dynamicTable = StatisticControl.GetWebDynamicTable(); StatisticControl.OnStatTableUseDynamicTable(dynamicTable); DataTable data = StatisticControl.Data; DataView dataView = new DataView(data); string[] sorts = StatisticControl.Sorts; if (sorts != null) { dataView.Sort = string.Join(",", sorts); } string[] groups = StatisticControl.Groups; int groupNum = 0; if (groups != null) { groupNum = groups.Length; } StringCollection sc = new StringCollection(); foreach (DataColumn dc in dataView.Table.Columns) { sc.Add(dc.ColumnName); } table = StatisticControl.GetStatTable(); StatisticRow statRow = null, lastRow = null; if (statRow == null) { statRow = StatisticRow.CreateTotalRow(table, groupNum, dynamicTable, StatisticControl.MaxFieldWidth, StatisticControl.BaseColor, StatisticControl.DeltaColor); lastRow = statRow; } for (int i = 0; i < groupNum; i++) { string field = groups[i]; sc.Remove(field); lastRow = lastRow.CreateSubGroup(dataView.Table.Columns.IndexOf(field)); } foreach (string field in sc) { DataColumn dc = dataView.Table.Columns[field]; lastRow = statRow; while (lastRow != null) { lastRow.AddField(dc, StatisticControl.GetStatisticFieldType(field)); lastRow = lastRow.SubGroup; } } statRow.DisplayHead(statRow, dataView); for (int ii = 0; ii < dataView.Count; ii++) { DataRowView drv = dataView[ii]; statRow.ExecStatistic(drv, false); if (ii == dataView.Count - 1) { statRow.ExecStatistic(drv, true); //结束统计 } } Table t = new Table(); t.Width = Unit.Percentage(100.0); TableRow tr = new TableRow(); TableCell tc = new TableCell(); tr.Cells.Add(tc); t.Rows.Add(tr); if ((StatisticControl.DisplayButtons & DisplayButtons.EXPORT) == DisplayButtons.EXPORT) { ImageButton exportBtn = new ImageButton(); exportBtn.ID = "ExportBtn"; exportBtn.ImageUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.ExportIcon); exportBtn.ToolTip = StatisticControl.ExportToolTip; exportBtn.CommandName = "Export"; exportBtn.Click += new ImageClickEventHandler(this.ButtonClick); tc.Controls.Add(exportBtn); } if ((StatisticControl.DisplayButtons & DisplayButtons.SEARCH) == DisplayButtons.SEARCH) { ImageButton searchBtn = new ImageButton(); searchBtn.ID = "SearchBtn"; searchBtn.ImageUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.SearchIcon); searchBtn.ToolTip = "搜索数据"; searchBtn.CommandName = "Search"; searchBtn.Click += new ImageClickEventHandler(this.ButtonClick); tc.Controls.Add(searchBtn); } tc.HorizontalAlign = HorizontalAlign.Right; tr = new TableRow(); tc = new TableCell(); tr.Cells.Add(tc); t.Rows.Add(tr); tc.Controls.Add(table); StatisticControl.Controls.Add(t); StatisticControl.OnShowStatTable(t, table); StatisticControl.Page.RegisterClientScriptBlock("InfoServiceCss", "<LINK href='" + StatisticControl.CssUrl + "' type='text/css' rel='stylesheet'>"); StatisticControl.Page.RegisterClientScriptBlock("ShowControlClientScript", @" <script language='javascript'> <!-- function openHtml(obj) { var pobj=obj.parentElement; if(pobj) { try { var w=window.open('about:blank','HTMLVIEW','resizable=yes,scrollbars=yes'); w.document.write(pobj.dreamanHtml); } catch(eee) { alert('您的浏览器好象禁止了弹出窗口,无法查看HTML内容!'); } event.returnValue=false; } } --> </script> " ); }