/
HomeController.cs
67 lines (55 loc) · 2.2 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
67
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;
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.ExportType = DevExpress.Export.ExportType.WYSIWYG;
return GridViewExtension.ExportToXlsx(GridViewHelper.ExportGridViewSettings, MyModel.GetProducts(), exportOptions);
}
}
}
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");
settings.SettingsExport.RenderBrick = (sender, e) => {
if(e.RowType != GridViewRowType.Data)
return;
if((e.Column as GridViewDataColumn).FieldName == "UnitPrice" && e.RowType != GridViewRowType.Header) {
if(Convert.ToInt32(e.TextValue) > 15)
e.BrickStyle.BackColor = System.Drawing.Color.Yellow;
else
e.BrickStyle.BackColor = System.Drawing.Color.Green;
}
};
return settings;
}
}