Esempio n. 1
0
 //处理字段结合绑定的情况
 private void processUnitField(ColPivotList xmlCfgLst, DevExpress.XtraPivotGrid.PivotGridControl gridCtl)
 {
     if (xmlCfgLst == null || xmlCfgLst.FieldGroups == null || xmlCfgLst.FieldGroups.Length == 0)
     {
         return;
     }
     string[] groups = xmlCfgLst.FieldGroups.Split(';');
     foreach (string group in groups)
     {
         string[] fields = group.Split(',');
         DevExpress.XtraPivotGrid.PivotGridGroup pivotGridGroup = new DevExpress.XtraPivotGrid.PivotGridGroup();
         gridCtl.Groups.Add(pivotGridGroup);
         foreach (string field in fields)
         {
             DevExpress.XtraPivotGrid.PivotGridField pivField = gridCtl.Fields[field];
             if (pivField == null)
             {
                 continue;
             }
             pivotGridGroup.Add(pivField);
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 把数据加载到PivotGrid 控件中。
 /// </summary>
 /// <param name="gridCtl">PivotGrid 控件。</param>
 /// <param name="dataSource">准备加载的数据源。</param>
 /// <param name="baseRule">当前正在处理的业务类。</param>
 public void LoadPivotGridData(DevExpress.XtraPivotGrid.PivotGridControl gridCtl,
                               object dataSource, MB.WinBase.IFace.IClientRuleQueryBase baseRule, ColPivotList xmlCfgLst)
 {
     addDataToCtl(gridCtl, dataSource, baseRule, xmlCfgLst);
     RestoreLayout(gridCtl, baseRule);
 }
Esempio n. 3
0
        //通过配置的PivotList 设置PivotField 的信息
        private Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> setPivotFieldByCfg(ColPivotList xmlCfgLst, DevExpress.XtraPivotGrid.PivotGridControl gridCtl,
                                                                                                      MB.WinBase.Common.ColumnPropertyInfo fieldInfo)
        {
            if (xmlCfgLst == null)
            {
                return(null);
            }
            if (xmlCfgLst.Columns.Count == 0 && !xmlCfgLst.AutoCreatedGridField)
            {
                return(null);
            }

            IList <MB.XWinLib.PivotGrid.ColPivotInfo> infos = xmlCfgLst.GetColPivotInfos(fieldInfo.Name);

            DevExpress.XtraPivotGrid.PivotGridGroup pivotGridGroup = null;
            if (infos.Count > 1 && xmlCfgLst.SameFieldGroup)
            {
                pivotGridGroup = new DevExpress.XtraPivotGrid.PivotGridGroup();
                gridCtl.Groups.Add(pivotGridGroup);
            }
            if (infos.Count == 0)
            {
                createNewPivotField(fieldInfo.Name, fieldInfo.Description, gridCtl);
                //add by aifang 去掉汇总后金额显示格式(原来不管是金额还是数量都显示¥前缀)begin
                if (fieldInfo.DataType.Equals("System.Decimal"))
                {
                    gridCtl.Fields[fieldInfo.Name].CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                }
                //add by aifang end
                return(null);
            }
            else
            {
                Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> expressionFields =
                    new Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo>();


                //处理一个字段对应多个分组的情况
                foreach (ColPivotInfo info in infos)
                {
                    DevExpress.XtraPivotGrid.PivotGridField pivField = createNewPivotField(fieldInfo.Name, fieldInfo.Description, gridCtl);
                    //如果定义了Expression则表示该列的值是通过其他列或其他手段推算而出的
                    if (!string.IsNullOrEmpty(info.Expression))
                    {
                        expressionFields.Add(pivField, info);
                    }

                    if (info.Description != null && info.Description.Length > 0)
                    {
                        pivField.Caption = info.Description;
                    }

                    pivField.Area          = info.IniArea;
                    pivField.AreaIndex     = info.AreaIndex;
                    pivField.AllowedAreas  = info.AllowedAreas;
                    pivField.TopValueCount = info.TopValueCount;
                    pivField.GroupInterval = info.GroupInterval;

                    if (info.SummaryItemType != null && info.SummaryItemType.Length > 0)
                    {
                        pivField.SummaryType = (DevExpress.Data.PivotGrid.PivotSummaryType)Enum.Parse(typeof(DevExpress.Data.PivotGrid.PivotSummaryType), info.SummaryItemType);
                    }

                    //setDefaultFormatByGroup(pivField);
                    //格式化显示数据。
                    if (info.CellFormat != DevExpress.Utils.FormatInfo.Empty)
                    {
                        pivField.CellFormat.Format       = info.CellFormat.Format;
                        pivField.CellFormat.FormatType   = info.CellFormat.FormatType;
                        pivField.CellFormat.FormatString = info.CellFormat.FormatString;
                    }
                    if (info.ValueFormat != DevExpress.Utils.FormatInfo.Empty)
                    {
                        pivField.ValueFormat.Format       = info.CellFormat.Format;
                        pivField.ValueFormat.FormatType   = info.CellFormat.FormatType;
                        pivField.ValueFormat.FormatString = info.CellFormat.FormatString;
                    }
                    //加入字段绑定分组。
                    if (pivotGridGroup != null)
                    {
                        pivotGridGroup.Add(pivField);
                    }
                    //DevExpress.XtraPivotGrid.PivotGroupInterval.DateDayOfWeek
                }
                return(expressionFields);
            }
        }
Esempio n. 4
0
        //内部函数处理,把数据加载到pivot grid 控件中。
        private void addDataToCtl(DevExpress.XtraPivotGrid.PivotGridControl gridCtl, object dataSource
                                  , MB.WinBase.IFace.IClientRuleQueryBase baseRule, ColPivotList xmlCfgLst)
        {
            Dictionary <string, MB.WinBase.Common.ColumnPropertyInfo> colPros = XtraGridDynamicHelper.Instance.GetDynamicColumns(baseRule);

            //modify by aifang 2012-08-29 动态列加载  Dictionary<string, MB.WinBase.Common.ColumnPropertyInfo> colPros = baseRule.UIRuleXmlConfigInfo.GetDefaultColumns();

            if (colPros == null)
            {
                return;
            }

            //清除历史的设置
            gridCtl.Fields.Clear();
            gridCtl.Groups.Clear();

            List <Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> > expressionFieldsList = new List <Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> >();

            foreach (MB.WinBase.Common.ColumnPropertyInfo info in colPros.Values)
            {
                if (!info.IsPivotExpressionSourceColumn && (!info.Visibled || info.VisibleWidth < 1))
                {
                    continue;
                }
                var result = setPivotFieldByCfg(xmlCfgLst, gridCtl, info);
                if (result != null)
                {
                    expressionFieldsList.Add(result);
                }
            }

            //在绑定一般列以后再处理非绑定列的表达式,如果在一起处理会发生列的加载先后顺序
            foreach (Dictionary <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> expressionFields in expressionFieldsList)
            {
                foreach (KeyValuePair <DevExpress.XtraPivotGrid.PivotGridField, ColPivotInfo> expressionField in expressionFields)
                {
                    expressionField.Key.UnboundType = DevExpress.Data.UnboundColumnType.Object;

                    string[] sourceColumns          = expressionField.Value.ExpressionSourceColumns.Split(',');
                    string[] formattedSourceColumns = new string[sourceColumns.Length];
                    for (int i = 0; i < sourceColumns.Length; i++)
                    {
                        DevExpress.XtraPivotGrid.PivotGridField sourceField = gridCtl.Fields[sourceColumns[i]];
                        if (sourceField == null)
                        {
                            throw new MB.Util.APPException(string.Format("ExpressionSourceColumns中的列{0}中Expression中的列不存在,请注意配置中依赖列必需在被依赖列的前面", sourceColumns[i], MB.Util.APPMessageType.SysErrInfo));
                        }

                        formattedSourceColumns[i] = sourceField.ExpressionFieldName;
                    }

                    expressionField.Key.UnboundExpression = string.Format(expressionField.Value.Expression, formattedSourceColumns);
                }
            }

            //处理字段帮定的情况。
            processUnitField(xmlCfgLst, gridCtl);

            //通过条件增加样式
            addConditionsForStyles(gridCtl, baseRule);

            gridCtl.DataSource = dataSource;
        }