Beispiel #1
0
 private void xrPivotGrid1_PrintCell(object sender, DevExpress.XtraReports.UI.PivotGrid.CustomExportCellEventArgs e)
 {
     if (e.Value != null && (int)e.Value > 0)
     {
         DevExpress.XtraPrinting.TextBrick  tb = e.Brick as DevExpress.XtraPrinting.TextBrick;
         DevExpress.XtraPrinting.ImageBrick ib = tb.PrintingSystem.CreateBrick("ImageBrick") as DevExpress.XtraPrinting.ImageBrick;
         ib.Rect      = DevExpress.XtraPrinting.GraphicsUnitConverter.DocToPixel(e.Brick.Rect);
         tb.IsVisible = false;
         Image im = GetImageByValue((int)e.Value, ib.Rect);
         ib.Image    = im;
         ib.SizeMode = DevExpress.XtraPrinting.ImageSizeMode.ZoomImage;
         tb.PrintingSystem.Graph.DrawBrick(ib);
     }
 }
Beispiel #2
0
        static PivotGridSettings GetSettings()
        {
            PivotGridSettings settings = new PivotGridSettings();

            settings.Name = "PivotGrid";
            settings.CallbackRouteValues = new { Controller = "Report", Action = "_PivotAccountsGridPartial" };
            settings.OptionsView.HorizontalScrollBarMode = DevExpress.Web.ScrollBarMode.Visible;
            settings.Width = new System.Web.UI.WebControls.Unit(90, System.Web.UI.WebControls.UnitType.Percentage);

            settings.SettingsExport.OptionsPrint.PrintColumnAreaOnEveryPage = true;
            settings.SettingsExport.OptionsPrint.PrintRowAreaOnEveryPage    = true;
            settings.SettingsExport.OptionsPrint.PageSettings.Landscape     = true;

            settings.SettingsExport.CustomExportCell = (sender, e) =>
            {
                // Determine whether the cell is Grand Total.
                if ((e.ColumnField == null) || (e.RowField == null))
                {
                    // Specify the text to display in a cell.
                    ((DevExpress.XtraPrinting.TextBrick)e.Brick).Text = string.Format(
                        "=> {0}",
                        ((DevExpress.XtraPrinting.TextBrick)e.Brick).Text);
                    // Specify the colors used to paint the cell.
                    e.Appearance.BackColor = Color.Gray;
                    e.Appearance.ForeColor = Color.Orange;
                    return;
                }

                MVCxPivotGrid pivot                = ((MVCxPivotGridExporter)sender).PivotGrid as MVCxPivotGrid;
                int           lastRowFieldIndex    = pivot.Fields.GetVisibleFieldCount(PivotArea.RowArea) - 1;
                int           lastColumnFieldIndex = pivot.Fields.GetVisibleFieldCount(PivotArea.ColumnArea) - 1;

                // Determine whether the cell is an ordinary cell.
                if (e.RowField.AreaIndex == lastRowFieldIndex && e.ColumnField.AreaIndex == lastColumnFieldIndex)
                {
                    e.Appearance.ForeColor = Color.Gray;
                }
                // The cell is a Total cell.
                else
                {
                    e.Appearance.BackColor = Color.DarkOliveGreen;
                    e.Appearance.ForeColor = Color.White;
                }
            };

            settings.SettingsExport.CustomExportFieldValue = (sender, e) =>
            {
                if (e.Field != null)
                {
                    if (e.Field.FieldName == "ProductName")
                    {
                        e.Brick.Url = String.Format("https://www.google.com/search?q={0}", e.Text);
                        ((DevExpress.XtraPrinting.TextBrick)e.Brick).Target = "_blank";
                    }
                    if (e.Field.FieldName == "Country" && e.Text == "USA")
                    {
                        DevExpress.XtraPrinting.ImageBrick imBrick = new DevExpress.XtraPrinting.ImageBrick();
                        imBrick.Image    = Image.FromFile(HttpContext.Current.Server.MapPath("~/Content/us.png"));
                        imBrick.SizeMode = DevExpress.XtraPrinting.ImageSizeMode.AutoSize;
                        e.Brick          = imBrick;
                    }
                }
            };

            settings.Fields.Add(field =>
            {
                field.Area      = PivotArea.RowArea;
                field.FieldName = "CategoryName";
                field.Caption   = "Category";
                field.AreaIndex = 0;
            });
            settings.Fields.Add(field =>
            {
                field.Area      = PivotArea.ColumnArea;
                field.FieldName = "Country";
                field.Caption   = "Country";
                field.AreaIndex = 0;
            });
            settings.Fields.Add(field =>
            {
                field.Area      = PivotArea.DataArea;
                field.FieldName = "Extended Price";
                field.Caption   = "Extended_Price";
                field.AreaIndex = 0;
            });
            settings.Fields.Add(field =>
            {
                field.Area      = PivotArea.RowArea;
                field.FieldName = "ProductName";
                field.Caption   = "Product Name";
                field.AreaIndex = 1;
            });
            settings.Fields.Add(field =>
            {
                field.Area      = PivotArea.ColumnArea;
                field.FieldName = "Sales Person";
                field.Caption   = "Sales Person";
                field.AreaIndex = 1;
            });

            return(settings);
        }