public override object GetModel(string moduleId, NameValueCollection args) { if (moduleId == null) { return(null); } int si = moduleId.IndexOf(":"); string libId = moduleId.Substring(4, si - 4); DataAccessType type = ModuleManager.GetDBType(libId); string connStr = ModuleManager.GetDBConn(libId); if (connStr == null) { return(null); } string sqlstr = HandleArgs(moduleId.Substring(si + 1), args); StatisticControl ctrl = new StatisticControl(); ctrl.DataAccessType = type; ctrl.ConnectionString = connStr; ctrl.SQL = sqlstr; ctrl.UploadFileVirtualPath = ModuleManager.UploadFileVirtualPath; DynamicTable dt = ctrl.GetWebDynamicTable(); HandleArgs(dt, args); dt = ctrl.GetWebDynamicTable(); HandleArgs(dt, args); return(ctrl); }
public static StatisticControl NewStatisticControl(string sqlstr, string libId) { StatisticControl stat = new StatisticControl(); stat.DataAccessType = GetDBType(libId); stat.ConnectionString = GetDBConn(libId); stat.SQL = sqlstr; return(stat); }
void ButtonClick(object sender, ImageClickEventArgs e) { ImageButton ib = (ImageButton)sender; if (ib.CommandName == "Ok") { StatisticControl.OnBuildCondition(dynaTable); string where = null; string having = null; string[] sorts = dynaTable.GetQuerySql(out where, out having); string[] groups = dynaTable.GetGroupInfo(StatisticControl); StatisticControl.WhereCondition = where; StatisticControl.HavingCondition = having; if (sorts.Length > 0) { StatisticControl.Sorts = sorts; } else { StatisticControl.Sorts = null; } if (groups.Length > 0) { StatisticControl.Groups = groups; } else { StatisticControl.Groups = null; } StatisticControl.ChangeState("show"); } else if (ib.CommandName == "Return") { StatisticControl.ChangeState("show"); } }
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> " ); }
protected override void Handle() { Table t = new Table(); TableRow tr = new TableRow(); TableCell tc = new TableCell(); tr.Cells.Add(tc); t.Rows.Add(tr); dynaTable = StatisticControl.GetWebDynamicTable(); dynaTable.CssUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.CssUrl); dynaTable.ScriptUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.ScriptUrl); dynaTable.MaxFieldWidth = StatisticControl.MaxFieldWidth; dynaTable.UseGroups = true; if (StatisticControl.Groups != null && StatisticControl.Groups.Length > 0) { foreach (string g in StatisticControl.Groups) { dynaTable.SetFieldGroup(g, true); } } if (StatisticControl.Sorts != null && StatisticControl.Sorts.Length > 0) { for (int i = 1; i <= StatisticControl.Sorts.Length; i++) { int sort = i; string field = StatisticControl.Sorts[i - 1].Trim(); if (field.ToUpper().EndsWith("DESC")) { sort = -sort; field = field.Substring(0, field.Length - 4).Trim(); } dynaTable.SetFieldSort(field, sort); } } foreach (string s in dynaTable.KeyFields) { dynaTable[s].StatMethod = StatisticControl.GetStatisticFieldType(s); } foreach (string s in dynaTable.NormalFields) { dynaTable[s].StatMethod = StatisticControl.GetStatisticFieldType(s); } dynaTable.UI = WebDynamicTableUI.QUERY; StatisticControl.OnShowSearch(dynaTable); LiteralControl lc = new LiteralControl(dynaTable.GenerateHtml()); dynaTable.RegisterCss(StatisticControl.Page); dynaTable.RegisterScript(StatisticControl.Page); tc.Controls.Add(lc); tr = new TableRow(); tc = new TableCell(); tr.Cells.Add(tc); t.Rows.Add(tr); ImageButton okBtn = new ImageButton(); okBtn.ID = "OK"; okBtn.ImageUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.SearchIcon); okBtn.ToolTip = "开始搜索符合条件的数据"; okBtn.CommandName = "Ok"; okBtn.Click += new ImageClickEventHandler(this.ButtonClick); tc.Controls.Add(okBtn); ImageButton returnBtn = new ImageButton(); returnBtn.ID = "Return"; returnBtn.ImageUrl = ControlStateUrl.BuildResourceRequestUrl(StatisticControl.ReturnIcon); returnBtn.ToolTip = "返回数据表"; returnBtn.CommandName = "Return"; returnBtn.Click += new ImageClickEventHandler(this.ButtonClick); tc.Controls.Add(returnBtn); tc.HorizontalAlign = HorizontalAlign.Center; StatisticControl.Controls.Add(t); }