Esempio n. 1
0
        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");
            }
        }
Esempio n. 2
0
        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");
            }
        }