public CustomDataSourceStorage() { DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource(sqlDataSourceId, "sqlCategories"); SelectQuery query = SelectQueryFluentBuilder .AddTable("Categories") .SelectAllColumnsFromTable() .Build("Categories"); query.Parameters.Add(new QueryParameter("CategoryNameStartsWith", typeof(DevExpress.DataAccess.Expression), new DevExpress.DataAccess.Expression("[Parameters.CategoryPattern]"))); sqlDataSource.Queries.Add(query); DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource(jsonDataSourceId) { RootElement = "Customers", ConnectionName = "jsonCustomers" }; DashboardObjectDataSource objDataSource = new DashboardObjectDataSource(odsDataSourceId) { DataId = "odsSales" }; DashboardOlapDataSource olapDataSource = new DashboardOlapDataSource(olapDataSourceId, "olapAdventureWorks"); DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource(extractDataSourceId) { ConnectionName = "extractSalesPerson" }; DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource(excelDataSourceId) { ConnectionName = "excelSales", SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1")) }; DashboardEFDataSource efDataSource = new DashboardEFDataSource(efDataSourceId, new EFConnectionParameters(typeof(NorthwindDbContext))); documents[sqlDataSourceId] = new XDocument(sqlDataSource.SaveToXml()); documents[jsonDataSourceId] = new XDocument(jsonDataSource.SaveToXml()); documents[odsDataSourceId] = new XDocument(objDataSource.SaveToXml()); documents[olapDataSourceId] = new XDocument(olapDataSource.SaveToXml()); documents[extractDataSourceId] = new XDocument(extractDataSource.SaveToXml()); documents[excelDataSourceId] = new XDocument(excelDataSource.SaveToXml()); documents[efDataSourceId] = new XDocument(efDataSource.SaveToXml()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddMvc() .AddDefaultDashboardController((configurator, serviceProvider) => { configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Registers an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); sqlDataSource.DataProcessingMode = DataProcessingMode.Client; SelectQuery query = SelectQueryFluentBuilder .AddTable("Categories") .Join("Products", "CategoryID") .SelectAllColumns() .Build("Products_Categories"); sqlDataSource.Queries.Add(query); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); // Registers an Object data source. DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source"); dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml()); // Registers an Excel data source. DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source"); excelDataSource.FileName = FileProvider.GetFileInfo("Data/Sales.xlsx").PhysicalPath; excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1")); dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml()); configurator.SetDataSourceStorage(dataSourceStorage); configurator.DataLoading += (s, e) => { if (e.DataSourceName == "Object Data Source") { e.Data = Invoices.CreateData(); } }; }); services.AddDevExpressControls(options => options.Resources = ResourcesType.ThirdParty | ResourcesType.DevExtreme); }
static Customer() { try { SqlDataSource ds = new SqlDataSource("NWindConnectionString"); SelectQuery query = SelectQueryFluentBuilder .AddTable("Customers") .SelectAllColumns() .Build("Customers"); ds.Queries.Add(query); ds.RebuildResultSchema(); ds.Fill(); ITable src = ds.Result["Customers"]; foreach (var row in src) { currentCustomers.Add(new Customer() { CustomerID = row.GetValue <string>("CustomerID"), Address = row.GetValue <string>("Address"), CompanyName = row.GetValue <string>("CompanyName"), ContactName = row.GetValue <string>("ContactName"), ContactTitle = row.GetValue <string>("ContactTitle"), Country = row.GetValue <string>("Country"), City = row.GetValue <string>("City"), Fax = row.GetValue <string>("Fax"), Phone = row.GetValue <string>("Phone"), PostalCode = row.GetValue <string>("PostalCode"), Region = row.GetValue <string>("Region") }); } } catch { currentCustomers.Add(new Customer() { Address = "Obere Str. 57", City = "Berlin", CompanyName = "Alfreds Futterkiste", ContactName = "Maria Anders", ContactTitle = "Sales Representative", Country = "Germany", CustomerID = "ALFKI", Fax = "030-0076545", Phone = "030-0074321", PostalCode = "12209" }); } }
private SqlQuery CreateQuery(string builderName) { switch (builderName) { case "fluent": return(SelectQueryFluentBuilder .AddTable("SalesPersons") .SelectColumns("CategoryName", "SalesPerson", "OrderDate", "ExtendedPrice") .Build("Query 1")); default: return(new CustomSqlQuery() { Name = "Query 1", Sql = @"SELECT CategoryName, SalesPerson, OrderDate, ExtendedPrice FROM SalesPersons" }); } }
private void BindToData() { // Create a data source with the required connection parameters. Access97ConnectionParameters connectionParameters = new Access97ConnectionParameters("../../Data/nwind.mdb", "", ""); SqlDataSource ds = new SqlDataSource(connectionParameters); // Create a query to access fields of the Products data table. SelectQuery query = SelectQueryFluentBuilder .AddTable("Products") .SelectColumns("CategoryID", "ProductName") .Build("Products"); // Add a query parameter to be used as a criterion for data source level data filtering. // In this example the query parameter has the Expression type and contains // a simple expression that references a value of a report parameter named "catID". QueryParameter parameter = new QueryParameter() { Name = "catID", Type = typeof(Expression), Value = new Expression("[Parameters.catID]", typeof(System.Int32)) }; query.Parameters.Add(parameter); query.FilterString = "CategoryID = ?catID"; ds.Queries.Add(query); // Assign the data source to the report. this.DataSource = ds; this.DataMember = "Products"; // Bind report controls to appropriate data fields depending on the report's data binding mode. if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings) { xrLabel1.DataBindings.Add("Text", ds, "Products.CategoryID"); xrLabel2.DataBindings.Add("Text", ds, "Products.ProductName"); } else { xrLabel1.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[CategoryID]")); xrLabel2.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]")); } }
private void Form1_Load(object sender, EventArgs e) { // Creates a new dashboard and data source for this dashboard. Dashboard dashboard = new Dashboard(); DashboardSqlDataSource xmlDataSource = new DashboardSqlDataSource(); xmlDataSource.ConnectionParameters = new XmlFileConnectionParameters(@"..\..\Data\DashboardEnergyStatictics.xml"); SelectQuery sqlQuery = SelectQueryFluentBuilder .AddTable("Countries") .SelectColumns("Latitude", "Longitude", "Production", "EnergyType", "Country") .Build("Query 1"); xmlDataSource.Queries.Add(sqlQuery); dashboard.DataSources.Add(xmlDataSource); // Creates a Pie Map dashboard item and specifies its data source. PieMapDashboardItem pieMap = new PieMapDashboardItem(); pieMap.DataSource = xmlDataSource; pieMap.DataMember = "Query 1"; // Loads the map of the europe. pieMap.Area = ShapefileArea.Europe; // Provides countries coordinates. pieMap.Latitude = new Dimension("Latitude"); pieMap.Longitude = new Dimension("Longitude"); // Specifies pie values and argument. pieMap.Values.Add(new Measure("Production")); pieMap.Argument = new Dimension("EnergyType"); // Specifies values displayed within pie tooltips. pieMap.TooltipDimensions.Add(new Dimension("Country")); pieMap.Legend.Visible = true; // Adds the Pie Map dashboard item to the dashboard and opens this // dashboard in the Dashboard Viewer. dashboard.Items.Add(pieMap); dashboardViewer1.Dashboard = dashboard; }
private static DashboardExtractDataSource CreateExtractDataSource() { DashboardSqlDataSource nwindDataSource = new DashboardSqlDataSource("Northwind Invoices", "nwindConnection"); SelectQuery invoicesQuery = SelectQueryFluentBuilder .AddTable("Invoices") .SelectColumns("City", "Country", "Salesperson", "OrderDate", "Shippers.CompanyName", "ProductName", "UnitPrice", "Quantity", "Discount", "ExtendedPrice", "Freight") .Build("Invoices"); nwindDataSource.Queries.Add(invoicesQuery); nwindDataSource.ConnectionOptions.DbCommandTimeout = 600; DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Invoices Extract Data Source"); extractDataSource.ExtractSourceOptions.DataSource = nwindDataSource; extractDataSource.ExtractSourceOptions.DataMember = "Invoices"; extractDataSource.FileName = extractFileName; return(extractDataSource); }
protected void Page_Load(object sender, EventArgs e) { DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards"); ASPxDashboard1.SetDashboardStorage(dashboardFileStorage); DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "access97Connection"); SelectQuery query = SelectQueryFluentBuilder .AddTable("SalesPerson") .SelectAllColumns() .Build("Sales Person"); sqlDataSource.Queries.Add(query); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); ASPxDashboard1.SetDataSourceStorage(dataSourceStorage); }
public static DashboardSqlDataSource CreateNWindDataSource() { DashboardSqlDataSource dashboardSqlDataSource1 = new DashboardSqlDataSource("NWind DataSource", "NorthwindConnectionString"); dashboardSqlDataSource1.DataProcessingMode = DataProcessingMode.Client; dashboardSqlDataSource1.Queries.Add(SelectQueryFluentBuilder .AddTable("Categories") .SelectColumns("CategoryName", "Description") .Join("Products", "CategoryID") .SelectColumns("QuantityPerUnit", "UnitsInStock", "UnitsOnOrder", "ReorderLevel", "Discontinued", "ProductName") .SelectColumn("UnitPrice", "Products_UnitPrice") .Join("OrderDetailsExtended", "ProductName") .SelectColumns("Quantity", "UnitPrice", "Discount") .Join("Orders", "OrderID") .SelectColumns("OrderDate", "RequiredDate", "ShippedDate", "ShipVia", "Freight", "ShipName", "ShipAddress", "ShipCity") .Join("Customers", "CustomerID") .SelectColumns("CompanyName", "ContactName", "ContactTitle", "City", "Region", "Country") .Build("Orders")); return(dashboardSqlDataSource1); }
private void Form1_Load(object sender, EventArgs e) { Dashboard dashboard = new Dashboard(); DashboardSqlDataSource xmlDataSource = new DashboardSqlDataSource(); xmlDataSource.ConnectionParameters = new XmlFileConnectionParameters(@"..\..\Data\DashboardEnergyStatictics.xml"); SelectQuery sqlQuery = SelectQueryFluentBuilder .AddTable("Countries") .SelectColumns("Latitude", "Longitude", "Production", "EnergyType", "Country") .Build("Query 1"); xmlDataSource.Queries.Add(sqlQuery); dashboard.DataSources.Add(xmlDataSource); PieMapDashboardItem pieMap = CreatePieMap(xmlDataSource); dashboard.Items.Add(pieMap); dashboardViewer1.Dashboard = dashboard; }
public static void RegisterService(RouteCollection routes) { routes.MapDashboardRoute("dashboardControl"); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards"); DashboardConfigurator.Default.SetDashboardStorage(dashboardFileStorage); // Uncomment this string to allow end users to create new data sources based on predefined connection strings. //DashboardConfigurator.Default.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider()); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Registers an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); SelectQuery query = SelectQueryFluentBuilder .AddTable("SalesPerson") .SelectAllColumns() .Build("Sales Person"); sqlDataSource.Queries.Add(query); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); // Registers an Object data source. DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source"); dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml()); // Registers an Excel data source. DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source"); excelDataSource.FileName = HostingEnvironment.MapPath(@"~/App_Data/Sales.xlsx"); excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1")); dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml()); DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage); DashboardConfigurator.Default.DataLoading += DataLoading; DashboardConfigurator.Default.CustomParameters += Default_CustomParameters; }
public Form1() { InitializeComponent(); Dashboard dashboard = new Dashboard(); XmlFileConnectionParameters xmlParams = new XmlFileConnectionParameters(); xmlParams.FileName = @"..\..\Data\DashboardProductDetails.xml"; DashboardSqlDataSource xmlDataSource = new DashboardSqlDataSource("Data Source 1", xmlParams); SelectQuery selectQuery = SelectQueryFluentBuilder .AddTable("Products") .SelectColumns("Id", "Name", "Description") .Build("Query 1"); xmlDataSource.Queries.Add(selectQuery); xmlDataSource.Fill(); dashboard.DataSources.Add(xmlDataSource); BoundImageDashboardItem boundImage = new BoundImageDashboardItem(); boundImage.DataSource = xmlDataSource; boundImage.DataMember = "Query 1"; boundImage.DataBindingMode = ImageDataBindingMode.Uri; boundImage.ImageDimension = new Dimension("Name"); boundImage.UriPattern = @"..\..\ProductDetailsImages\{0}.jpg"; boundImage.SizeMode = ImageSizeMode.Stretch; ListBoxDashboardItem comboBox = new ListBoxDashboardItem(); comboBox.ShowCaption = false; comboBox.DataSource = xmlDataSource; comboBox.DataMember = "Query 1"; comboBox.FilterDimensions.Add(new Dimension("Name")); comboBox.ListBoxType = ListBoxDashboardItemType.Radio; comboBox.ShowAllValue = false; dashboard.Items.AddRange(comboBox, boundImage); dashboardViewer1.Dashboard = dashboard; }
protected void Page_Load(object sender, EventArgs e) { #region #DashboardStorage DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards"); ASPxDashboard1.SetDashboardStorage(dashboardFileStorage); #endregion #DashboardStorage #region #DataSourceStorage DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "sqlConnection"); SelectQuery countriesQuery = SelectQueryFluentBuilder .AddTable("Countries") .SelectColumns("Country", "Latitude", "Longitude", "Year", "EnergyType", "Production", "Import") .Build("Countries"); sqlDataSource.Queries.Add(countriesQuery); DashboardOlapDataSource olapDataSource = new DashboardOlapDataSource("OLAP Data Source", "olapConnection"); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); dataSourceStorage.RegisterDataSource("sqlDataSource1", sqlDataSource.SaveToXml()); dataSourceStorage.RegisterDataSource("olapDataSource1", olapDataSource.SaveToXml()); ASPxDashboard1.SetDataSourceStorage(dataSourceStorage); #endregion #DataSourceStorage }
private void Form1_Load(object sender, EventArgs e) { Dashboard dashboard = new Dashboard(); DashboardSqlDataSource dataSource = new DashboardSqlDataSource(); dataSource.ConnectionParameters = new XmlFileConnectionParameters(@"..\..\Data\DashboardEnergyStatictics.xml"); SelectQuery sqlQuery = SelectQueryFluentBuilder .AddTable("Countries") .SelectColumns("Latitude", "Longitude", "Production", "Import", "Country") .Build("Countries"); dataSource.Queries.Add(sqlQuery); dashboard.DataSources.Add(dataSource); BubbleMapDashboardItem bubbleMap = new BubbleMapDashboardItem(); bubbleMap.DataSource = dashboard.DataSources[0]; bubbleMap.DataMember = "Countries"; bubbleMap.Area = ShapefileArea.Europe; bubbleMap.Latitude = new Dimension("Latitude"); bubbleMap.Longitude = new Dimension("Longitude"); bubbleMap.Weight = new Measure("Production", SummaryType.Sum); bubbleMap.Color = new Measure("Import", SummaryType.Sum); bubbleMap.Color.NumericFormat.FormatType = DataItemNumericFormatType.General; bubbleMap.TooltipDimensions.Add(new Dimension("Country")); CustomizeScale(bubbleMap); ShowLegends(bubbleMap); dashboard.Items.Add(bubbleMap); dashboardViewer1.Dashboard = dashboard; }
public static void RegisterService(RouteCollection routes) { routes.MapDashboardRoute("dashboardControl", "DefaultDashboard"); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards"); DashboardConfigurator.Default.SetDashboardStorage(dashboardFileStorage); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Registers an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); SelectQuery query = SelectQueryFluentBuilder .AddTable("SalesPerson") .SelectAllColumns() .Build("Sales Person"); sqlDataSource.Queries.Add(query); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); // Registers an Object data source. DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source"); objDataSource.DataId = "odsInvoices"; dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml()); // Registers an Excel data source. DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source"); excelDataSource.ConnectionName = "xlsSales"; excelDataSource.FileName = HostingEnvironment.MapPath(@"~/App_Data/Sales.xlsx"); excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1")); dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml()); DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage); DashboardConfigurator.Default.DataLoading += DataLoading; }
private XtraReport CreateReport() { Access97ConnectionParameters parameters = new Access97ConnectionParameters(@"|DataDirectory|\nwind.mdb", "", ""); SqlDataSource ds = new SqlDataSource(parameters); SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumns().Build("Products"); ds.Queries.Add(query); ds.RebuildResultSchema(); XtraReport report = new XtraReport() { DataSource = ds, DataMember = query.Name }; float actualPageWidth = report.PageWidth - (report.Margins.Left + report.Margins.Right); int colCount = 3; float colWidth = actualPageWidth / colCount; XRTable tableDetail = new XRTable() { HeightF = 25f, WidthF = actualPageWidth }; tableDetail.BeginInit(); XRTableRow detailRow = new XRTableRow(); detailRow.WidthF = tableDetail.WidthF; tableDetail.Rows.Add(detailRow); XRTableCell detailCell = new XRTableCell() { WidthF = colWidth }; detailCell.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]")); detailRow.Cells.Add(detailCell); detailCell = new XRTableCell() { WidthF = colWidth }; detailCell.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[QuantityPerUnit]")); detailRow.Cells.Add(detailCell); detailCell = new XRTableCell() { WidthF = colWidth }; detailCell.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]")); detailRow.Cells.Add(detailCell); tableDetail.EndInit(); report.Bands.Add(new DetailBand() { HeightF = 25f }); report.Bands[BandKind.Detail].Controls.Add(tableDetail); return(report); }
private void button1_Click(object sender, EventArgs e) { using (XtraReport1 report = new XtraReport1()) { XRCrossTab crossTab = new XRCrossTab(); report.Detail.Controls.Add(crossTab); SqlDataSource ds = new SqlDataSource(new Access97ConnectionParameters(@"|DataDirectory|\nwind.mdb", String.Empty, String.Empty)); ds.Queries.Add(SelectQueryFluentBuilder .AddTable("Order Details") .SelectColumns( "UnitPrice", "Quantity", "OrderID" ) .Join("Products", "ProductID") .SelectColumns( "ProductName" ) .Filter("[Order Details].[OrderID] < 10250") .Build("SalesInfo")); crossTab.DataSource = ds; crossTab.DataMember = "SalesInfo"; crossTab.RowFields.Add(new CrossTabRowField() { FieldName = "ProductName" }); crossTab.ColumnFields.Add(new CrossTabColumnField() { FieldName = "OrderID" }); crossTab.DataFields.Add(new CrossTabDataField() { FieldName = "UnitPrice" }); crossTab.DataFields.Add(new CrossTabDataField() { FieldName = "Quantity" }); crossTab.DataFields.Add(new CrossTabDataField()); crossTab.GenerateLayout(); /* +---------------------+---------------------------------------+---------------------------------------+ | ProductName | [OrderID] | Grand total | | +-------------+------------+------------+-------------+------------+------------+ | | Unit Price | Quantity | Empty cell | UnitPrice | Quantity | Empty cell | +---------------------+-------------+------------+------------+-------------+------------+------------+ | [ProductName] | [UnitPrice] | [Quantity] | Empty cell | [UnitPrice] | [Quantity] | Empty cell | +---------------------+-------------+------------+------------+-------------+------------+------------+ | Grand Total | | | | | | | +---------------------+-------------+------------+------------+-------------+------------+------------+ */ //Adjust generated cells foreach (var c in crossTab.ColumnDefinitions) { //Enable auto-width for all columns c.AutoWidthMode = DevExpress.XtraReports.UI.AutoSizeMode.ShrinkAndGrow; } foreach (XRCrossTabCell c in crossTab.Cells) { if (c.DataLevel == 0 && c.RowIndex != 1) { //Adjust format string for the "UnitPrice" cells c.TextFormatString = "{0:c}"; } if (c.RowIndex == 0 && c.ColumnLevel == 0) { //Adjust format string for the "OrderID" cells c.TextFormatString = "Order {0}"; } if (c.DataLevel == 2 && c.RowIndex != 1) { //Set custom expression for empty data cells c.ExpressionBindings.Add(new ExpressionBinding("Text", "[UnitPrice] * [Quantity]")); c.Font = new Font(c.Font, FontStyle.Bold); c.TextFormatString = "{0:c}"; } if (c.DataLevel == 2 && c.RowIndex == 1) { //Set text for empty header cells c.Font = new Font(c.Font, FontStyle.Bold); c.Text = "Total"; } } // Assign styles to cross tab crossTab.CrossTabStyles.GeneralStyle = new XRControlStyle() { Name = "Default", Borders = BorderSide.All, Padding = new PaddingInfo() { All = 2 } }; crossTab.CrossTabStyles.DataAreaStyle = crossTab.CrossTabStyles.TotalAreaStyle = new XRControlStyle() { Name = "Data", TextAlignment = TextAlignment.TopRight }; crossTab.CrossTabStyles.HeaderAreaStyle = new XRControlStyle() { Name = "HeaderAndTotals", BackColor = Color.WhiteSmoke }; report.ShowRibbonPreviewDialog(); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddResponseCompression() .AddDevExpressControls() .AddMvc(); services.AddScoped <DashboardConfigurator>((IServiceProvider serviceProvider) => { DashboardConfigurator configurator = new DashboardConfigurator(); configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Configures an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); sqlDataSource.DataProcessingMode = DataProcessingMode.Client; SelectQuery query = SelectQueryFluentBuilder .AddTable("Orders") .SelectAllColumnsFromTable() .Build("SQL Orders"); sqlDataSource.Queries.Add(query); // Configures an Object data source. DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source"); objDataSource.DataId = "odsInvoices"; // Configures an Excel data source. DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source"); excelDataSource.ConnectionName = "excelSales"; excelDataSource.FileName = FileProvider.GetFileInfo("Data/SalesPerson.xlsx").PhysicalPath; excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Data")); // Configures a JSON data source. DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource("JSON Data Source"); jsonDataSource.ConnectionName = "jsonCategories"; Uri fileUri = new Uri(FileProvider.GetFileInfo("Data/Categories.json").PhysicalPath, UriKind.RelativeOrAbsolute); jsonDataSource.JsonSource = new UriJsonSource(fileUri); // Registers a Federated data source. dataSourceStorage.RegisterDataSource("federatedDataSource", CreateFederatedDataSource(sqlDataSource, excelDataSource, objDataSource, jsonDataSource).SaveToXml()); configurator.SetDataSourceStorage(dataSourceStorage); configurator.DataLoading += (s, e) => { if (e.DataId == "odsInvoices") { e.Data = Invoices.CreateData(); } }; configurator.ConfigureDataConnection += (s, e) => { if (e.ConnectionName == "excelSales") { (e.ConnectionParameters as ExcelDataSourceConnectionParameters).FileName = FileProvider.GetFileInfo("Data/SalesPerson.xlsx").PhysicalPath; } else if (e.ConnectionName == "jsonCategories") { UriJsonSource source = new UriJsonSource(new Uri(FileProvider.GetFileInfo("Data/Categories.json").PhysicalPath, UriKind.RelativeOrAbsolute)); (e.ConnectionParameters as JsonSourceConnectionParameters).JsonSource = source; } }; return(configurator); }); }
public Dictionary <string, object> GetAvailableDataSources() { var dataSources = new Dictionary <string, object>(); dataSources.Add("Northwind", CreateDataSource("Northwind_Json", SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products"))); dataSources.Add("Countries", CreateDataSource("Countries_DevelopmentJson", SelectQueryFluentBuilder.AddTable("Regions").SelectAllColumnsFromTable().Build("Regions"))); dataSources.Add("Vehicles", CreateDataSource("Vehicles_InMemory", SelectQueryFluentBuilder.AddTable("Model").SelectAllColumnsFromTable().Build("Model"))); dataSources.Add("Cars", CreateDataSource("Cars_InMemory", SelectQueryFluentBuilder.AddTable("Cars").SelectAllColumnsFromTable().Build("Cars"))); return(dataSources); }
private XtraReport CreateReport() { // Create a blank report. XtraReport crossTabReport = new XtraReport() { VerticalContentSplitting = VerticalContentSplitting.Smart, HorizontalContentSplitting = HorizontalContentSplitting.Smart }; // Create a detail band and add it to the report. DetailBand detail = new DetailBand(); crossTabReport.Bands.Add(detail); // Create a cross tab and add it to the Detail band. XRCrossTab crossTab = new XRCrossTab(); detail.Controls.Add(crossTab); crossTab.PrintOptions.RepeatColumnHeaders = true; crossTab.PrintOptions.RepeatRowHeaders = true; // Create a data source Access97ConnectionParameters connectionParameters = new Access97ConnectionParameters(@"|DataDirectory|\nwind.mdb", "", ""); SqlDataSource ds = new SqlDataSource(connectionParameters); // Create an SQL query to access the SalesPerson view. SelectQuery query = SelectQueryFluentBuilder.AddTable("SalesPerson") .SelectColumn("CategoryName") .SelectColumn("ProductName") .SelectColumn("Country") .SelectColumn("Sales Person") .SelectColumn("Quantity") .SelectColumn("Extended Price").Build("SalesPerson"); ds.Queries.Add(query); // Bind the cross tab to data. crossTab.DataSource = ds; crossTab.DataMember = "SalesPerson"; // Generate cross tab's fields. crossTab.RowFields.Add(new CrossTabRowField() { FieldName = "CategoryName" }); crossTab.RowFields.Add(new CrossTabRowField() { FieldName = "ProductName" }); crossTab.ColumnFields.Add(new CrossTabColumnField() { FieldName = "Country" }); crossTab.ColumnFields.Add(new CrossTabColumnField() { FieldName = "Sales Person" }); crossTab.DataFields.Add(new CrossTabDataField() { FieldName = "Quantity" }); crossTab.DataFields.Add(new CrossTabDataField() { FieldName = "Extended Price" }); crossTab.GenerateLayout(); /* +----------------+---------------+-------------------------------+---------------------------+---------------------------+ | Category Name | Product Name | [Country] | Total [Country] | Grand total | | | +-------------------------------+ | | | | | [Sales Person] | | | | | +------------+------------------+----------+----------------+----------+----------------+ | | | Quantity | Extended Price | Quantity | Extended Price | Quantity | Extended Price | +----------------+---------------+------------+------------------+----------+----------------+----------+----------------+ | [CategoryName] | [ProductName] | [Quantity] | [Extended Price] | | | | | +----------------+---------------+------------+------------------+----------+----------------+----------+----------------+ | Total [CategoryName] | | | | | | | +--------------------------------+------------+------------------+----------+----------------+----------+----------------+ | Grand Total | | | | | | | +--------------------------------+------------+------------------+----------+----------------+----------+----------------+ */ //Adjust generated cells foreach (var c in crossTab.ColumnDefinitions) { //Enable auto-width for all columns c.AutoWidthMode = DevExpress.XtraReports.UI.AutoSizeMode.GrowOnly; } foreach (XRCrossTabCell c in crossTab.Cells) { if (c.DataLevel == 1 && c.RowIndex != 2) { //Adjust format string for the "Extended Price" cells c.TextFormatString = "{0:c}"; } } // Assign styles to cross tab crossTab.CrossTabStyles.GeneralStyle = new XRControlStyle() { Name = "Default", Borders = BorderSide.All, Padding = new PaddingInfo() { All = 2 } }; crossTab.CrossTabStyles.DataAreaStyle = crossTab.CrossTabStyles.TotalAreaStyle = new XRControlStyle() { Name = "Data", TextAlignment = TextAlignment.TopRight }; crossTab.CrossTabStyles.HeaderAreaStyle = new XRControlStyle() { Name = "HeaderAndTotals", BackColor = Color.WhiteSmoke }; return(crossTabReport); }