namespace DevControlpractice.myForm {
//数据统计分析示例
public partial class Frm_PicotGrid_Qry : XtraForm {
private DataTable _myDT;
private const string sSelectStr =
\其他业务数据分析时需要修改这里的查询语句;
private string sWhere = \ public Frm_PicotGrid_Qry() {
InitializeComponent(); }
//用来进行统计分析的基础业务数据集: public DataTable MyDT {
get { return _myDT; } set { _myDT = value; } }
///
///
///
private void btnOpenData_Click(object sender, EventArgs e) {
LoadData(); }
private void LoadData() {
_myDT = AccessHelper.ExecuteSqlQuery(\sSelectStr + sWhere, null);
bindingSource1.DataSource = _myDT;
string sSqlAnalyse = \项目名称,表名称,字段名称,描述,区域,排序,统计类别 from FieldArea where 项目名称='运输统计'\其他业务数据分析时需要修改这里的查询语句;
pivotGridControl1.DataSource = bindingSource1;
DataTable dtAnalyse = AccessHelper.ExecuteSqlQuery(\sSqlAnalyse, null);//加载统计分析字段设置数据集;
SetPivotUI(dtAnalyse); } //设置PivotGrid控件的字段。
private void SetPivotUI(DataTable DT) {
try {
pivotGridControl1.Fields.Clear();
for (int i = 0; i < DT.Rows.Count; i++) {
if (DT.Rows[i][\区域\ { //新建一个字段对象;
PivotGridField pZZ = new PivotGridField();
pZZ.FieldName = DT.Rows[i][\字段名称\设置字段的 FieldName 属性;
pZZ.Caption = DT.Rows[i][\描述\字段的显示文本属性;
switch (DT.Rows[i][\统计类别\ {
case \汇总和\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Sum;
pZZ.Caption += \统计类别\
break; }
case \汇总数量\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Count;
pZZ.Caption += \统计类别\
break; }
case \最大值\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Max;
pZZ.Caption += \统计类别\
break;
}
case \最小值\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Min;
pZZ.Caption += \统计类别\
break; }
case \平均值\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Average;
pZZ.Caption += \统计类别\
pZZ.CellFormat.FormatType DevExpress.Utils.FormatType.Numeric;
pZZ.CellFormat.FormatString \
break; }
case \标准差\
= =
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.StdDev;
pZZ.Caption += \统计类别\
pZZ.CellFormat.FormatType DevExpress.Utils.FormatType.Numeric;
pZZ.CellFormat.FormatString \
break; }
case \总体标准差\
= =
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.StdDevp;
pZZ.Caption += \统计类别\
pZZ.CellFormat.FormatType DevExpress.Utils.FormatType.Numeric;
pZZ.CellFormat.FormatString \
break;
= =
}
case \方差\
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Var;
pZZ.Caption += \统计类别\
pZZ.CellFormat.FormatType DevExpress.Utils.FormatType.Numeric;
pZZ.CellFormat.FormatString \
break; }
case \总体方差\
= =
{
pZZ.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Varp;
pZZ.Caption += \统计类别\
pZZ.CellFormat.FormatType DevExpress.Utils.FormatType.Numeric;
pZZ.CellFormat.FormatString \
break; } default: {
break; } }
switch (DT.Rows[i][\区域\
{
case \行字段\
{
pZZ.Area = PivotArea.RowArea; break; }
case \列字段\
{
pZZ.Area = PivotArea.ColumnArea; break; }
case \数据字段\ {
= =
相关推荐: