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> " ); }