-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
72 lines (59 loc) · 3.35 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Linq;
using System.Drawing;
using Newtonsoft.Json;
using System.Collections.Generic;
using DashboardGaugeRanges.Models;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.XtraGauges.Core.Drawing;
using DevExpress.XtraReports.UI;
namespace DashboardGaugeRanges {
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ASPxDashboard1.SetDataSourceStorage(CreateDataSourceStorage());
}
public DataSourceInMemoryStorage CreateDataSourceStorage() {
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source", typeof(SalesPersonData));
objDataSource.DataMember = "GetSalesData";
dataSourceStorage.RegisterDataSource("objectDataSource", objDataSource.SaveToXml());
return dataSourceStorage;
}
protected void ASPxDashboard1_CustomExport(object sender, CustomExportWebEventArgs e) {
const string CustomPropertyName = "GaugeRanges";
Dictionary<string, XRControl> controls = e.GetPrintableControls();
foreach (var control in controls) {
string componentName = control.Key;
XRGaugeDashboardItem gaugeControl = control.Value as XRGaugeDashboardItem;
GaugeDashboardItem gaugeItem = e.GetDashboardItem(componentName) as GaugeDashboardItem;
if (gaugeControl != null && gaugeItem != null) {
gaugeControl.Gauges.ToList().ForEach(gauge => {
var xrGauge = gauge.Gauge;
var internalGauge = xrGauge.Gauge as DevExpress.XtraGauges.Core.Customization.DashboardGauge;
var scale = internalGauge.Elements.OfType<DevExpress.XtraGauges.Core.Model.ArcScale>().FirstOrDefault();
// Add a circular scale.
if (scale == null) {
scale = new DevExpress.XtraGauges.Core.Model.ArcScale();
internalGauge.Elements.Add(scale);
}
var layer = internalGauge.Elements.OfType<DevExpress.XtraGauges.Core.Model.ArcScaleBackgroundLayer>().FirstOrDefault();
// Display scales on top.
if (layer != null)
layer.ZOrder = 1000;
var rangesJSON = gaugeItem.CustomProperties[CustomPropertyName];
var customRanges = JsonConvert.DeserializeObject<List<CustomRange>>(rangesJSON);
customRanges.ForEach(customRange => {
var range = new DevExpress.XtraGauges.Core.Model.ArcScaleRange();
range.ShapeOffset = -10;
range.StartValue = customRange.startValue;
range.EndValue = customRange.endValue;
range.AppearanceRange.ContentBrush = new SolidBrushObject(ColorTranslator.FromHtml(customRange.color));
scale.Ranges.Add(range);
});
});
}
}
}
}
}