DataSet中的数据我导到excel里也一起发给您看下做为参考。
您好,我的数据集是用DataSet的,绑定都没问题。
以下为PrepareSchema()的方法:
- private static SchemaDefinition PrepareSchema()
- {
- SB sb = new SB("TestingPubsTitles");
- sb.AddQueryFields(
- "最后一次拜访日期",
- new QueryFieldBuilder("PubDate")
- .SetExpression<DateTime>("=CDate(Fields!最后一次拜访日期.Value)"),
- new QueryFieldBuilder("PubDate_Year")
- .SetExpression<int>("=Year(Fields!PubDate.Value)"),
- new QueryFieldBuilder("PubDate_Quarter")
- .SetExpression<int>("=DatePart(DateInterval.Quarter, Fields!PubDate.Value)"),
- new QueryFieldBuilder("PubDate_Month")
- .SetExpression<int>("=Month(Fields!PubDate.Value)"),
- new QueryFieldBuilder("PubDate_Day")
- .SetExpression<int>("=Day(Fields!PubDate.Value)"), "系列", "大类", "产品条码", "产品名称", "产品简称", "英文名称", "行政大区", "地区", "城市", "渠道", "所属连锁", "门店编码", "门店名称", "主负责人", "被拜访次数", "断货次数", "断货率", "最后一次拜访库存"
- );
- AttributeBuilder defaultField3 = new AttributeBuilder("系列")
- .SetCaption("系列")
- .SetExpression<string>("=Fields!系列.Value");
- AttributeBuilder defaultField4 = new AttributeBuilder("大类")
- .SetCaption("大类")
- .SetExpression<string>("=Fields!大类.Value");
- AttributeBuilder defaultField5 = new AttributeBuilder("产品条码")
- .SetCaption("产品条码")
- .SetExpression<string>("=Fields!产品条码.Value");
- AttributeBuilder defaultField6 = new AttributeBuilder("产品名称")
- .SetCaption("产品名称")
- .SetExpression<string>("=Fields!产品名称.Value");
- AttributeBuilder defaultField7 = new AttributeBuilder("产品简称")
- .SetCaption("产品简称")
- .SetExpression<string>("=Fields!产品简称.Value");
- AttributeBuilder defaultField8 = new AttributeBuilder("英文名称")
- .SetCaption("英文名称")
- .SetExpression<string>("=Fields!英文名称.Value");
- AttributeBuilder defaultField9 = new AttributeBuilder("行政大区")
- .SetCaption("行政大区")
- .SetExpression<string>("=Fields!行政大区.Value");
- AttributeBuilder defaultField10 = new AttributeBuilder("地区")
- .SetCaption("地区")
- .SetExpression<string>("=Fields!地区.Value");
- AttributeBuilder defaultField11 = new AttributeBuilder("城市")
- .SetCaption("城市")
- .SetExpression<string>("=Fields!城市.Value");
- AttributeBuilder defaultField12 = new AttributeBuilder("渠道")
- .SetCaption("渠道")
- .SetExpression<string>("=Fields!渠道.Value");
- AttributeBuilder defaultField13 = new AttributeBuilder("所属连锁")
- .SetCaption("所属连锁")
- .SetExpression<string>("=Fields!所属连锁.Value");
- AttributeBuilder defaultField14 = new AttributeBuilder("门店编码")
- .SetCaption("门店编码")
- .SetExpression<string>("=Fields!门店编码.Value");
- AttributeBuilder defaultField15 = new AttributeBuilder("门店名称")
- .SetCaption("门店名称")
- .SetExpression<string>("=Fields!门店名称.Value");
- AttributeBuilder defaultField16 = new AttributeBuilder("主负责人")
- .SetCaption("主负责人")
- .SetExpression<string>("=Fields!主负责人.Value");
- AttributeBuilder defaultField17 = new AttributeBuilder("被拜访次数")
- .SetCaption("被拜访次数")
- .SetExpression<string>("=Fields!被拜访次数.Value");
- AttributeBuilder defaultField18 = new AttributeBuilder("断货次数")
- .SetCaption("断货次数")
- .SetExpression<string>("=Fields!断货次数.Value");
- AttributeBuilder defaultField19 = new AttributeBuilder("断货率")
- .SetCaption("断货率")
- .SetExpression<string>("=Fields!断货率.Value");
- AttributeBuilder defaultField21 = new AttributeBuilder("最后一次拜访库存")
- .SetCaption("最后一次拜访库存")
- .SetExpression<string>("=Fields!最后一次拜访库存.Value");
- AttributeBuilder defaultField2 = new HierarchyBuilder("最后一次拜访日期")
- .AddLevel(
- new LevelBuilder("Year")
- .SetExpression("=Fields!PubDate_Year.Value")
- .SetCaptionExpression("=Fields!PubDate_Year.Value")
- )
- .AddLevel(
- new LevelBuilder("Quarter")
- .SetExpression<int>("=Fields!PubDate_Quarter.Value")
- .SetCaptionExpression("="Q" & Fields!PubDate_Quarter.Value & " " & Fields!PubDate_Year.Value")
- )
- .AddLevel(
- new LevelBuilder("Month")
- .SetExpression<int>("=Fields!PubDate_Month.Value")
- .SetCaptionExpression("=MonthName(Fields!PubDate_Month.Value) & ", " & Fields!PubDate_Year.Value")
- )
- .AddLevel(
- new LevelBuilder("Day")
- .SetExpression<int>("=Fields!PubDate_Day.Value")
- .SetCaptionExpression(
- "=MonthName(Fields!PubDate_Month.Value) & " " & Fields!PubDate_Day.Value & ", " & Fields!PubDate_Year.Value")
- );
- sb.AddDimensions(
- new MeasuresDimBuilder("Measures")
- .AddField(
- new MeasureBuilder("被拜访次数")
- .SetAggregateFunction(AggregateFunction.Count)
- .SetExpression<int>("=Fields!被拜访次数.Value")
- .SetForeColor(Color.DarkBlue)
- )
- .AddField(
- new MeasureBuilder("断货次数")
- .SetExpression<float>("=Fields!断货次数.Value")
- .SetAggregateFunction(AggregateFunction.Count)
- .SetFontFlags(FontFlags.Italic)
- )
- .AddField(
- new MeasureBuilder("最后一次拜访库存")
- .SetExpression<float>("=Fields!最后一次拜访库存.Value")
- .SetAggregateFunction(AggregateFunction.Count)
- .SetFontFlags(FontFlags.Italic)
- )
- ,
- new AttributesDimBuilder("Dimension")
- .SetCaption("字段")
- .SetDefaultField(
- defaultField3)
- .AddField(defaultField3)
- .AddField(defaultField4)
- .AddField(defaultField5)
- .AddField(defaultField6)
- .AddField(defaultField7)
- .AddField(defaultField8)
- .AddField(defaultField9)
- .AddField(defaultField10)
- .AddField(defaultField11)
- .AddField(defaultField12)
- .AddField(defaultField13)
- .AddField(defaultField14)
- .AddField(defaultField15)
- .AddField(defaultField16)
- .AddField(defaultField17)
- .AddField(defaultField18)
- .AddField(defaultField19)
- .AddField(defaultField21)
-
- .AddFields(
- defaultField2
- )
- );
- return sb.BuildSchema();
- }
复制代码 以下为ConnectUnbound()方法:
- private void ConnectUnbound()
- {
- SchemaDefinition schema = PrepareSchema();
- UnboundDataSource ds = new UnboundDataSource();
- ds.CustomSchema = schema;
- ds.DataSource = PrepareDataSet();
- ds.Connect();
- pivotView.DataSource = ds;
- using (ILayoutActions la = pivotView.BeginLayoutUpdate("Initialization"))
- {
-
- // set marking type to the Circle
- la.SetMarkingType(MarkingType.Text);
-
- la.AppendField("[Dimension].[系列]", ShelfKind.RowShelf);
- la.AppendField("[Dimension].[大类]", ShelfKind.RowShelf);
-
- la.Commit();
- } // NOTE: la.Dispose() must reject our changes if la.Commit() or la.Reject() isn't called yet.
- }
复制代码 |