wpf-demos/olapgrid/ViewModel/GridLayoutViewModel.cs

128 строки
4.0 KiB
C#

#region Copyright Syncfusion Inc. 2001 - 2024
// Copyright Syncfusion Inc. 2001 - 2024. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
namespace syncfusion.olapgriddemos.wpf
{
using System;
using Syncfusion.Olap.Manager;
using Syncfusion.Olap.Reports;
using System.Collections.Generic;
using Syncfusion.Windows.Shared;
using System.Linq;
/// <summary>
/// Interaction logic for OlapGrid view.
/// </summary>
public class GridLayoutViewModel : NotificationObject, IDisposable
{
#region Members
/// <summary>
/// Shared connection string.
/// </summary>
public static string ConnectionString;
private OlapDataManager olapDataManager;
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="GridLayoutViewModel"/> class.
/// </summary>
public GridLayoutViewModel()
{
ConnectionString = KPIModel.Initialize(System.IO.Path.GetFullPath(@"Assets\Config\OLAPSample.config"));
olapDataManager = new OlapDataManager(ConnectionString);
olapDataManager.SetCurrentReport(CreateOlapReport());
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the grid data manager.
/// </summary>
/// <value>The grid data manager.</value>
public OlapDataManager GridDataManager
{
get { return olapDataManager; }
set { olapDataManager = value; }
}
/// <summary>
/// Gets the layouts.
/// </summary>
/// <value>The layouts.</value>
public IEnumerable<string> GridLayout
{
get
{
return Enum<Syncfusion.Olap.Engine.GridLayout>.GetNames();
}
}
#endregion
#region Methods
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposing && olapDataManager != null)
olapDataManager.Dispose();
}
/// <summary>
/// Creates the OlapReport.
/// </summary>
/// <returns></returns>
private OlapReport CreateOlapReport()
{
OlapReport olapReport = new OlapReport();
olapReport.CurrentCubeName = "Adventure Works";
DimensionElement dimensionElementColumn = new DimensionElement();
//Specifying the Name for the Dimension Element
dimensionElementColumn.Name = "Customer";
dimensionElementColumn.AddLevel("Customer Geography", "Country");
MeasureElements measureElementColumn = new MeasureElements();
//Specifying the Name for the Measure Element
measureElementColumn.Elements.Add(new MeasureElement { Name = "Internet Sales Amount" });
DimensionElement dimensionElementRow = new DimensionElement();
//Specifying the Dimension Name
dimensionElementRow.Name = "Date";
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year");
DimensionElement dimensionElementRow1 = new DimensionElement();
//Specifying the Dimension Name
dimensionElementRow1.Name = "Product";
dimensionElementRow1.AddLevel("Product Categories", "Category");
//Adding Column Members
olapReport.CategoricalElements.Add(dimensionElementColumn);
//Adding Measure Element
olapReport.CategoricalElements.Add(measureElementColumn);
//Adding Row Members
olapReport.SeriesElements.Add(dimensionElementRow);
olapReport.SeriesElements.Add(dimensionElementRow1);
return olapReport;
}
#endregion
}
}