-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeController.cs
66 lines (55 loc) · 2.25 KB
/
HomeController.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
using System;
using System.IO;
using System.Web;
using System.Web.Mvc;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
using DevExpress.Web.Mvc;
using CS.Model;
using DevExpress.Web;
using System.Globalization;
namespace CS.Controllers {
public class HomeController : Controller {
public ActionResult Index() {
return View(new MyViewModel { Products = MyModel.GetProducts() });
}
public ActionResult GridViewPartialProducts() {
return PartialView(MyModel.GetProducts());
}
public ActionResult ExportTo() {
XlsxExportOptionsEx exportOptions = new XlsxExportOptionsEx();
exportOptions.CustomizeCell += new DevExpress.Export.CustomizeCellEventHandler(exportOptions_CustomizeCell);
return GridViewExtension.ExportToXlsx(GridViewHelper.ExportGridViewSettings, MyModel.GetProducts(), exportOptions);
}
void exportOptions_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs ea) {
if(ea.AreaType != DevExpress.Export.SheetAreaType.Header && ea.ColumnFieldName == "UnitPrice") {
if(Convert.ToDecimal(ea.Value) > 15)
ea.Formatting.BackColor = System.Drawing.Color.Yellow;
else
ea.Formatting.BackColor = System.Drawing.Color.Green;
ea.Handled = true;
}
}
}
}
public static class GridViewHelper {
private static GridViewSettings exportGridViewSettings;
public static GridViewSettings ExportGridViewSettings {
get {
if(exportGridViewSettings == null)
exportGridViewSettings = CreateExportGridViewSettings();
return exportGridViewSettings;
}
}
private static GridViewSettings CreateExportGridViewSettings() {
GridViewSettings settings = new GridViewSettings();
settings.Name = "gvProducts";
settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartialProducts" };
settings.KeyFieldName = "ProductID";
settings.Settings.ShowFilterRow = true;
settings.Columns.Add("ProductID");
settings.Columns.Add("ProductName");
settings.Columns.Add("UnitPrice");
return settings;
}
}