MVCxGridViewGeneratorHelper.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. using Autofac;
  2. using DevExpress.Data;
  3. using DevExpress.XtraEditors.Controls;
  4. using DevExpress.XtraPrinting;
  5. using DevExpress.XtraReports.UI;
  6. using GreenTree.Nachtragsmanagement.Core;
  7. using GreenTree.Nachtragsmanagement.Core.Authentication;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net.Mime;
  15. using System.Web;
  16. namespace GreenTree.Nachtragsmanagement.Web.Extensions
  17. {
  18. public class MVCxGridViewGeneratorHelper
  19. {
  20. public delegate void CustomizeColumnsCollectionEventHandler(object source, ColumnsCreationEventArgs e);
  21. public delegate void CustomizeColumnEventHandler(object source, ControlCustomizationEventArgs e);
  22. public delegate void CustomizeFormattingRulesEventHandler(object source, CustomFormattingRulesEventArgs e);
  23. public delegate void CustomizeColumnTotalSummaryEventHandler(object source, ColumnSummaryCreationEventArgs e);
  24. public delegate void CustomizeColumnGroupSummaryEventHandler(object source, ColumnSummaryCreationEventArgs e);
  25. public delegate void SummaryResetEventHandler(object source, CustomSummaryResetEventArgs e);
  26. public delegate void SummaryRowChangedEventHandler(object source, CustomSummaryRowChangedEventArgs e);
  27. public class MVCReportGeneratonHelper
  28. {
  29. const int initialGroupOffset = 0;
  30. const int subGroupOffset = 10;
  31. const int bandHeight = 20;
  32. const bool shouldRepeatGroupHeadersOnEveryPage = false;
  33. XtraReport report;
  34. Hashtable detailsInfo = new Hashtable();
  35. Hashtable detailsWidth = new Hashtable();
  36. public event CustomizeColumnsCollectionEventHandler CustomizeColumnsCollection;
  37. public event CustomizeColumnEventHandler CustomizeColumn;
  38. public event CustomizeFormattingRulesEventHandler CustomizeFormattingRules;
  39. public event CustomizeColumnTotalSummaryEventHandler CustomizeTotalColumnSummary;
  40. public event CustomizeColumnGroupSummaryEventHandler CustomizeGroupColumnSummary;
  41. public event SummaryResetEventHandler SummaryReset;
  42. public event SummaryRowChangedEventHandler SummaryRowChanged;
  43. public event SummaryGetResultHandler PageSummaryGetResult;
  44. public event SummaryGetResultHandler TotalSummaryGetResult;
  45. public XtraReport GenerateMVCReport(MVCxGridViewState gridViewState, object model, string title)
  46. {
  47. report = new XtraReport
  48. {
  49. Font = new Font("Calibri", 10f, FontStyle.Regular),
  50. Landscape = true,
  51. PaperKind = System.Drawing.Printing.PaperKind.A4
  52. };
  53. InitStyles();
  54. InitReportTitle(title);
  55. InitDataSource(model);
  56. InitDetailsAndPageHeader(gridViewState);
  57. InitDetailReports(gridViewState);
  58. InitSortings(gridViewState);
  59. InitGroupHeaders(gridViewState);
  60. InitFilters(gridViewState);
  61. InitPageSummaries(gridViewState);
  62. InitTotalSummaries(gridViewState);
  63. InitPageFooter();
  64. return report;
  65. }
  66. private void InitStyles()
  67. {
  68. report.StyleSheet.Add(new XRControlStyle
  69. {
  70. Name = "Title",
  71. Borders = DevExpress.XtraPrinting.BorderSide.None,
  72. Font = new Font(report.Font.FontFamily, 24f, FontStyle.Regular),
  73. ForeColor = Color.FromArgb(35, 133, 160)
  74. });
  75. report.StyleSheet.Add(new XRControlStyle
  76. {
  77. Name = "OddRow",
  78. Borders = (DevExpress.XtraPrinting.BorderSide.Bottom |
  79. DevExpress.XtraPrinting.BorderSide.Left |
  80. DevExpress.XtraPrinting.BorderSide.Right),
  81. Padding = new PaddingInfo(30, 600)
  82. });
  83. report.StyleSheet.Add(new XRControlStyle
  84. {
  85. Name = "EvenRow",
  86. BackColor = Color.LightGray,
  87. Borders = (DevExpress.XtraPrinting.BorderSide.Bottom |
  88. DevExpress.XtraPrinting.BorderSide.Left |
  89. DevExpress.XtraPrinting.BorderSide.Right),
  90. Padding = new PaddingInfo(30, 600)
  91. });
  92. report.StyleSheet.Add(new XRControlStyle
  93. {
  94. Name = "HeaderRow",
  95. BackColor = Color.FromArgb(156, 183, 191),
  96. Borders = DevExpress.XtraPrinting.BorderSide.All,
  97. Padding = new PaddingInfo(30, 600),
  98. Font = new Font(report.Font, FontStyle.Bold)
  99. });
  100. report.StyleSheet.Add(new XRControlStyle
  101. {
  102. Name = "GroupHeader",
  103. BackColor = Color.Beige,
  104. Borders = DevExpress.XtraPrinting.BorderSide.All,
  105. Padding = new PaddingInfo(30, 600),
  106. Font = new Font(report.Font, FontStyle.Bold)
  107. });
  108. report.StyleSheet.Add(new XRControlStyle
  109. {
  110. Name = "SummaryRow",
  111. BackColor = Color.FromArgb(35, 133, 160),
  112. Borders = DevExpress.XtraPrinting.BorderSide.All,
  113. BorderColor = Color.FromArgb(35, 133, 160),
  114. Padding = new PaddingInfo(30, 600),
  115. ForeColor = Color.White,
  116. Font = new Font(report.Font, FontStyle.Bold)
  117. });
  118. report.StyleSheet.Add(new XRControlStyle
  119. {
  120. Name = "DetailRow",
  121. BackColor = Color.FromArgb(209, 228, 255),
  122. Borders = DevExpress.XtraPrinting.BorderSide.All
  123. });
  124. report.StyleSheet.Add(new XRControlStyle
  125. {
  126. Name = "DetailRowLabel",
  127. Padding = new PaddingInfo(30, 600),
  128. Borders = DevExpress.XtraPrinting.BorderSide.Bottom |
  129. DevExpress.XtraPrinting.BorderSide.Left |
  130. DevExpress.XtraPrinting.BorderSide.Right
  131. });
  132. report.StyleSheet.Add(new XRControlStyle
  133. {
  134. Name = "FooterRow",
  135. Font = new Font(report.Font, FontStyle.Italic)
  136. });
  137. }
  138. private void InitReportTitle(string title)
  139. {
  140. report.Bands.Add(new ReportHeaderBand
  141. {
  142. HeightF = 32f
  143. });
  144. report.Bands[BandKind.ReportHeader].Controls.Add(new XRLabel
  145. {
  146. Text = title,
  147. StyleName = "Title",
  148. WidthF = (report.PageWidth - (report.Margins.Left + report.Margins.Right))
  149. });
  150. }
  151. private void InitDataSource(object model)
  152. {
  153. report.DataSource = model;
  154. }
  155. private void InitDetailsAndPageHeader(MVCxGridViewState gridViewState)
  156. {
  157. var groupedColumns = gridViewState.GroupedColumns;
  158. var pagewidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right)) - groupedColumns.Count * subGroupOffset;
  159. var columns = GetColumnsInfo(gridViewState, pagewidth);
  160. if (CustomizeColumnsCollection != null)
  161. CustomizeColumnsCollection(report, new ColumnsCreationEventArgs(pagewidth)
  162. {
  163. ColumnsInfo = columns
  164. });
  165. report.Bands.Add(new DetailBand()
  166. {
  167. HeightF = bandHeight,
  168. KeepTogetherWithDetailReports = true
  169. });
  170. report.Bands.Add(new PageHeaderBand()
  171. {
  172. HeightF = bandHeight
  173. });
  174. var headerTable = new XRTable()
  175. {
  176. StyleName = "HeaderRow"
  177. };
  178. var row = new XRTableRow();
  179. var detailTable = new XRTable
  180. {
  181. OddStyleName = "OddRow",
  182. EvenStyleName = "EvenRow"
  183. };
  184. var row2 = new XRTableRow();
  185. for (var i = 0; i < columns.Count; i++)
  186. {
  187. if (columns[i].IsVisible)
  188. {
  189. var cell = new XRTableCell
  190. {
  191. Width = columns[i].ColumnWidth,
  192. Text = columns[i].GridViewColumn.Caption,
  193. Borders = DevExpress.XtraPrinting.BorderSide.All,
  194. TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft
  195. };
  196. row.Cells.Add(cell);
  197. var cell2 = new XRTableCell
  198. {
  199. Width = columns[i].ColumnWidth
  200. };
  201. var cc = new ControlCustomizationEventArgs
  202. {
  203. FieldName = columns[i].FieldName,
  204. IsModified = false,
  205. Owner = cell2,
  206. Header = cell
  207. };
  208. if (CustomizeColumn != null)
  209. CustomizeColumn(report, cc);
  210. if (cc.IsModified == false)
  211. {
  212. cell2.DataBindings.Add("Text", null, columns[i].FieldName,
  213. "{0:" + columns[i].GridViewColumn.DisplayFormat + "}");
  214. }
  215. detailsInfo.Add(columns[i].GridViewColumn, cell2);
  216. row2.Cells.Add(cell2);
  217. detailsWidth.Add(columns[i].GridViewColumn, cell2.WidthF);
  218. }
  219. }
  220. if (CustomizeFormattingRules != null)
  221. CustomizeFormattingRules(report, new CustomFormattingRulesEventArgs { Rules = report.FormattingRuleSheet });
  222. foreach (var rule in report.FormattingRuleSheet)
  223. detailTable.FormattingRules.Add(rule);
  224. headerTable.Rows.Add(row);
  225. headerTable.Width = pagewidth;
  226. headerTable.LocationF = new PointF(groupedColumns.Count * subGroupOffset, 0);
  227. headerTable.Borders = DevExpress.XtraPrinting.BorderSide.Bottom;
  228. detailTable.Rows.Add(row2);
  229. detailTable.LocationF = new PointF(groupedColumns.Count * subGroupOffset, 0);
  230. detailTable.Width = pagewidth;
  231. report.Bands[BandKind.PageHeader].Controls.Add(headerTable);
  232. report.Bands[BandKind.Detail].Controls.Add(detailTable);
  233. }
  234. private void InitDetailReports(MVCxGridViewState gridViewState)
  235. {
  236. var groupedColumns = gridViewState.GroupedColumns;
  237. var pagewidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right)) - groupedColumns.Count * subGroupOffset;
  238. var columns = GetColumnsInfo(gridViewState, pagewidth);
  239. if (CustomizeColumnsCollection != null)
  240. CustomizeColumnsCollection(report, new ColumnsCreationEventArgs(pagewidth)
  241. {
  242. ColumnsInfo = columns
  243. });
  244. var detailColumns = columns
  245. .Where(c => c.IsDetail)
  246. .ToList();
  247. if (!detailColumns.Any()) return;
  248. var detailReportBand = new DetailReportBand()
  249. {
  250. HeightF = bandHeight
  251. };
  252. report.Bands.Add(detailReportBand);
  253. var detailReportTable = new XRTable
  254. {
  255. OddStyleName = "DetailRow",
  256. EvenStyleName = "DetailRow",
  257. WidthF = pagewidth
  258. };
  259. var detailReportRow = new XRTableRow();
  260. foreach (var detailColumn in detailColumns)
  261. {
  262. var cellDetail = new XRTableCell
  263. {
  264. WidthF = pagewidth / detailColumns.Count
  265. };
  266. var label = new XRLabel
  267. {
  268. StyleName = "DetailRowLabel",
  269. WidthF = pagewidth / detailColumns.Count,
  270. WordWrap = true
  271. };
  272. label.DataBindings.Add("Text", null, detailColumn.FieldName,
  273. "{0:" + detailColumn.GridViewColumn.DisplayFormat + "}");
  274. cellDetail.Controls.Add(label);
  275. detailReportRow.Cells.Add(cellDetail);
  276. }
  277. detailReportTable.Rows.Add(detailReportRow);
  278. detailReportTable.LocationF = new PointF(groupedColumns.Count * subGroupOffset, 0);
  279. DetailBand detailBand = new DetailBand();
  280. detailBand.Height = detailReportTable.Height;
  281. detailReportBand.Bands.Add(detailBand);
  282. detailBand.Controls.Add(detailReportTable);
  283. }
  284. private void InitSortings(MVCxGridViewState gridViewState)
  285. {
  286. var columns = gridViewState.Columns;
  287. var groupedColumns = gridViewState.GroupedColumns;
  288. for (var i = 0; i < columns.Count; i++)
  289. {
  290. if (!groupedColumns.Contains(columns[i]))
  291. {
  292. if (columns[i].SortOrder != ColumnSortOrder.None)
  293. ((DetailBand)report.Bands[BandKind.Detail]).SortFields.Add(new GroupField(columns[i].FieldName, columns[i].SortOrder == ColumnSortOrder.Ascending ? XRColumnSortOrder.Ascending : XRColumnSortOrder.Descending));
  294. }
  295. }
  296. }
  297. private void InitGroupHeaders(MVCxGridViewState gridViewState)
  298. {
  299. var groupedColumns = gridViewState.GroupedColumns;
  300. for (var i = groupedColumns.Count - 1; i >= 0; i--)
  301. {
  302. var groupedColumn = groupedColumns[i];
  303. var gb = new GroupHeaderBand
  304. {
  305. Height = bandHeight
  306. };
  307. var groupHeaderTable = new XRTable
  308. {
  309. StyleName = "GroupHeader",
  310. LocationF = new PointF(initialGroupOffset + i * 10, 0),
  311. SizeF = new SizeF((report.PageWidth - (report.Margins.Left + report.Margins.Right)) - (initialGroupOffset + i * subGroupOffset), bandHeight)
  312. };
  313. var groupHeaderRow = new XRTableRow();
  314. var l = new XRTableCell
  315. {
  316. Text = groupedColumn.Caption + ": [" + groupedColumn.FieldName + "]",
  317. Borders = DevExpress.XtraPrinting.BorderSide.Left |
  318. DevExpress.XtraPrinting.BorderSide.Top |
  319. DevExpress.XtraPrinting.BorderSide.Bottom
  320. };
  321. groupHeaderRow.Cells.Add(l);
  322. foreach (MVCxSummaryItemState item in gridViewState.TotalSummary)
  323. {
  324. var sum = new XRTableCell
  325. {
  326. Borders = DevExpress.XtraPrinting.BorderSide.Top |
  327. DevExpress.XtraPrinting.BorderSide.Bottom
  328. };
  329. sum.Summary = new XRSummary
  330. {
  331. Running = SummaryRunning.Group
  332. };
  333. sum.Summary.Func = GetSummaryFunc(item.SummaryType);
  334. sum.DataBindings.Add("Text", null, item.FieldName);
  335. groupHeaderRow.Cells.Add(sum);
  336. if (CustomizeGroupColumnSummary != null)
  337. CustomizeGroupColumnSummary(report, new ColumnSummaryCreationEventArgs(item.FieldName, sum.Summary));
  338. }
  339. groupHeaderTable.Rows.Add(groupHeaderRow);
  340. gb.Controls.Add(groupHeaderTable);
  341. gb.RepeatEveryPage = shouldRepeatGroupHeadersOnEveryPage;
  342. var gf = new GroupField(
  343. groupedColumn.FieldName, groupedColumn.SortOrder == ColumnSortOrder.Ascending
  344. ? XRColumnSortOrder.Ascending
  345. : XRColumnSortOrder.Descending);
  346. gb.GroupFields.Add(gf);
  347. report.Bands.Add(gb);
  348. }
  349. }
  350. private void InitFilters(MVCxGridViewState gridViewState)
  351. {
  352. report.FilterString = gridViewState.FilterExpression;
  353. }
  354. private void InitPageSummaries(MVCxGridViewState gridViewState)
  355. {
  356. if (gridViewState.TotalSummary.Count == 0) return;
  357. report.Bands.Add(new PageFooterBand
  358. {
  359. HeightF = bandHeight,
  360. StyleName = "SummaryRow",
  361. PrintOn = PrintOnPages.NotWithReportFooter
  362. });
  363. foreach (MVCxSummaryItemState item in gridViewState.TotalSummary)
  364. {
  365. var col = gridViewState.Columns[item.ShowInColumn == string.Empty
  366. ? item.FieldName
  367. : item.ShowInColumn];
  368. if (col == null) continue;
  369. if (!detailsInfo.Contains(col)) continue;
  370. var label = new XRLabel
  371. {
  372. LocationF = new PointF(
  373. ((XRTableCell)detailsInfo[col]).LocationF.X + subGroupOffset * gridViewState.GroupedColumns.Count,
  374. ((XRTableCell)detailsInfo[col]).LocationF.Y),
  375. SizeF = ((XRTableCell)detailsInfo[col]).SizeF
  376. };
  377. label.Summary = new XRSummary
  378. {
  379. Running = SummaryRunning.Page
  380. };
  381. label.Summary.FormatString = item.DisplayFormat;
  382. label.Summary.Func = GetSummaryFunc(item.SummaryType);
  383. label.DataBindings.Add("Text", null, col.FieldName);
  384. label.Tag = item.FieldName;
  385. if (PageSummaryGetResult != null)
  386. label.SummaryGetResult += PageSummaryGetResult;
  387. report.Bands[BandKind.PageFooter].Controls.Add(label);
  388. if (CustomizeTotalColumnSummary != null)
  389. CustomizeTotalColumnSummary(report, new ColumnSummaryCreationEventArgs(col.FieldName, label.Summary));
  390. }
  391. }
  392. private void InitTotalSummaries(MVCxGridViewState gridViewState)
  393. {
  394. if (gridViewState.TotalSummary.Count == 0) return;
  395. report.Bands.Add(new ReportFooterBand
  396. {
  397. HeightF = bandHeight,
  398. StyleName = "SummaryRow"
  399. });
  400. foreach (MVCxSummaryItemState item in gridViewState.TotalSummary)
  401. {
  402. var col = gridViewState.Columns[item.ShowInColumn == string.Empty
  403. ? item.FieldName
  404. : item.ShowInColumn];
  405. if (col == null) continue;
  406. if (!detailsInfo.Contains(col)) continue;
  407. var label = new XRLabel
  408. {
  409. LocationF = new PointF(
  410. ((XRTableCell)detailsInfo[col]).LocationF.X + subGroupOffset * gridViewState.GroupedColumns.Count,
  411. ((XRTableCell)detailsInfo[col]).LocationF.Y),
  412. SizeF = ((XRTableCell)detailsInfo[col]).SizeF
  413. };
  414. label.DataBindings.Add("Text", null, col.FieldName);
  415. label.Summary = new XRSummary
  416. {
  417. Running = SummaryRunning.Report
  418. };
  419. label.Summary.FormatString = item.DisplayFormat;
  420. label.Summary.Func = GetSummaryFunc(item.SummaryType);
  421. label.Tag = item.FieldName;
  422. if (item.SummaryType == SummaryItemType.Custom)
  423. {
  424. label.SummaryReset += (source, e) =>
  425. {
  426. if (SummaryReset != null)
  427. SummaryReset(report, new CustomSummaryResetEventArgs { FieldName = item.FieldName });
  428. };
  429. label.SummaryRowChanged += (source, e) =>
  430. {
  431. if (SummaryRowChanged != null)
  432. SummaryRowChanged(report, new CustomSummaryRowChangedEventArgs { FieldName = item.FieldName });
  433. };
  434. }
  435. if (TotalSummaryGetResult != null)
  436. label.SummaryGetResult += TotalSummaryGetResult;
  437. report.Bands[BandKind.ReportFooter].Controls.Add(label);
  438. if (CustomizeTotalColumnSummary != null)
  439. CustomizeTotalColumnSummary(report, new ColumnSummaryCreationEventArgs(col.FieldName, label.Summary));
  440. }
  441. }
  442. private void InitPageFooter()
  443. {
  444. var userHelper = Singleton<IContainer>.Instance.Resolve<IUserHelper>();
  445. var user = userHelper.FromCookies();
  446. report.Bands.Add(new BottomMarginBand
  447. {
  448. HeightF = 46f
  449. });
  450. var footerTable = new XRTable
  451. {
  452. WidthF = (report.PageWidth - (report.Margins.Left + report.Margins.Right)),
  453. HeightF = 23f,
  454. Borders = DevExpress.XtraPrinting.BorderSide.Top,
  455. StyleName = "FooterRow"
  456. };
  457. var footerRow = new XRTableRow
  458. {
  459. Cells =
  460. {
  461. new XRTableCell
  462. {
  463. TextAlignment = TextAlignment.MiddleLeft,
  464. Text = DateTime.Now.ToString("dd.MM.yyyy - HH:mm \"Uhr\" |"),
  465. WidthF = 145f,
  466. HeightF = 23f
  467. },
  468. new XRTableCell
  469. {
  470. Controls =
  471. {
  472. new XRPageInfo
  473. {
  474. TextAlignment = TextAlignment.MiddleLeft,
  475. Format = "Seite {0} von {1}",
  476. PageInfo = PageInfo.NumberOfTotal,
  477. StartPageNumber = 1,
  478. Padding = 5,
  479. HeightF = 23f
  480. }
  481. },
  482. WidthF = 100f,
  483. HeightF = 23f
  484. },
  485. new XRTableCell
  486. {
  487. TextAlignment = TextAlignment.MiddleRight,
  488. Text = String.Format("{0}, {1}", user.Lastname, user.Forename),
  489. WidthF = (report.PageWidth - (report.Margins.Left + report.Margins.Right)) - 230
  490. }
  491. }
  492. };
  493. footerTable.Rows.Add(footerRow);
  494. report.Bands[BandKind.BottomMargin].Controls.Add(footerTable);
  495. }
  496. private List<MVCxColumnInfo> GetColumnsInfo(MVCxGridViewState gridViewState, int pagewidth)
  497. {
  498. var columns = new List<MVCxColumnInfo>();
  499. var visibleColumns = gridViewState.Columns;
  500. foreach (var dataColumn in visibleColumns)
  501. {
  502. MVCxColumnInfo column = new MVCxColumnInfo(dataColumn)
  503. {
  504. ColumnCaption = string.IsNullOrEmpty(dataColumn.Caption) ? dataColumn.FieldName : dataColumn.Caption,
  505. ColumnWidth = ((int)pagewidth / visibleColumns.Count),
  506. FieldName = dataColumn.FieldName,
  507. IsVisible = true
  508. };
  509. columns.Add(column);
  510. }
  511. return columns;
  512. }
  513. private SummaryFunc GetSummaryFunc(SummaryItemType summaryItemType)
  514. {
  515. switch (summaryItemType)
  516. {
  517. case SummaryItemType.Sum:
  518. return SummaryFunc.Sum;
  519. case SummaryItemType.Average:
  520. return SummaryFunc.Avg;
  521. case SummaryItemType.Max:
  522. return SummaryFunc.Max;
  523. case SummaryItemType.Min:
  524. return SummaryFunc.Min;
  525. case SummaryItemType.Count:
  526. return SummaryFunc.Count;
  527. default:
  528. return SummaryFunc.Custom;
  529. }
  530. }
  531. public void WritePdfToResponse(HttpResponseBase Response, string fileName, string type)
  532. {
  533. report.CreateDocument(false);
  534. using (MemoryStream ms = new MemoryStream())
  535. {
  536. report.ExportToPdf(ms);
  537. ms.Seek(0, SeekOrigin.Begin);
  538. WriteResponse(Response, ms.ToArray(), "application/pdf", type, fileName);
  539. }
  540. }
  541. public void WriteXlsToResponse(HttpResponseBase Response, string fileName, string type)
  542. {
  543. report.CreateDocument(false);
  544. using (MemoryStream ms = new MemoryStream())
  545. {
  546. report.ExportToXls(ms);
  547. ms.Seek(0, SeekOrigin.Begin);
  548. WriteResponse(Response, ms.ToArray(), "application/vnd.ms-excel", type, fileName);
  549. }
  550. }
  551. public void WriteXlsxToResponse(HttpResponseBase Response, string fileName, string type)
  552. {
  553. report.CreateDocument(false);
  554. using (MemoryStream ms = new MemoryStream())
  555. {
  556. report.ExportToXlsx(ms);
  557. ms.Seek(0, SeekOrigin.Begin);
  558. WriteResponse(Response, ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", type, fileName);
  559. }
  560. }
  561. public static void WriteResponse(HttpResponseBase response, byte[] filearray, string contentType, string type, string fileName)
  562. {
  563. response.ClearContent();
  564. response.Buffer = true;
  565. response.Cache.SetCacheability(HttpCacheability.Private);
  566. response.ContentType = contentType;
  567. ContentDisposition contentDisposition = new ContentDisposition();
  568. contentDisposition.FileName = fileName;
  569. contentDisposition.DispositionType = type;
  570. response.AddHeader("Content-Disposition", contentDisposition.ToString());
  571. response.BinaryWrite(filearray);
  572. HttpContext.Current.ApplicationInstance.CompleteRequest();
  573. try
  574. {
  575. response.End();
  576. }
  577. catch (System.Threading.ThreadAbortException)
  578. {
  579. }
  580. }
  581. }
  582. public class CustomFormattingRulesEventArgs : EventArgs
  583. {
  584. private FormattingRuleSheet rules;
  585. public FormattingRuleSheet Rules
  586. {
  587. get { return rules; }
  588. set { rules = value; }
  589. }
  590. }
  591. public class ControlCustomizationEventArgs : EventArgs
  592. {
  593. XRControl owner;
  594. public XRControl Owner
  595. {
  596. get
  597. {
  598. return owner;
  599. }
  600. set
  601. {
  602. owner = value;
  603. }
  604. }
  605. XRControl header;
  606. public XRControl Header
  607. {
  608. get
  609. {
  610. return header;
  611. }
  612. set
  613. {
  614. header = value;
  615. }
  616. }
  617. bool isModified;
  618. public bool IsModified
  619. {
  620. get
  621. {
  622. return isModified;
  623. }
  624. set
  625. {
  626. isModified = value;
  627. }
  628. }
  629. string fieldName;
  630. public string FieldName
  631. {
  632. get
  633. {
  634. return fieldName;
  635. }
  636. set
  637. {
  638. fieldName = value;
  639. }
  640. }
  641. }
  642. public class ColumnSummaryCreationEventArgs : EventArgs
  643. {
  644. public ColumnSummaryCreationEventArgs(string fieldName, XRSummary summary)
  645. {
  646. this.fieldName = fieldName;
  647. this.summary = summary;
  648. }
  649. XRSummary summary;
  650. public XRSummary Summary
  651. {
  652. get
  653. {
  654. return summary;
  655. }
  656. set
  657. {
  658. summary = value;
  659. }
  660. }
  661. string fieldName;
  662. public string FieldName
  663. {
  664. get
  665. {
  666. return fieldName;
  667. }
  668. set
  669. {
  670. fieldName = value;
  671. }
  672. }
  673. }
  674. public class ColumnsCreationEventArgs : EventArgs
  675. {
  676. int pageWidth;
  677. public int PageWidth
  678. {
  679. get
  680. {
  681. return pageWidth;
  682. }
  683. }
  684. public ColumnsCreationEventArgs(int pageWidth)
  685. {
  686. this.pageWidth = pageWidth;
  687. }
  688. List<MVCxColumnInfo> columnsInfo;
  689. public List<MVCxColumnInfo> ColumnsInfo
  690. {
  691. get
  692. {
  693. return columnsInfo;
  694. }
  695. set
  696. {
  697. columnsInfo = value;
  698. }
  699. }
  700. }
  701. public class CustomSummaryResetEventArgs : EventArgs
  702. {
  703. private string fieldName;
  704. public string FieldName
  705. {
  706. get { return fieldName; }
  707. set { fieldName = value; }
  708. }
  709. }
  710. public class CustomSummaryRowChangedEventArgs : EventArgs
  711. {
  712. private string fieldName;
  713. public string FieldName
  714. {
  715. get { return fieldName; }
  716. set { fieldName = value; }
  717. }
  718. }
  719. public class CustomSummaryGetResultEventArgs : SummaryGetResultEventArgs
  720. {
  721. public CustomSummaryGetResultEventArgs(IList calculatedValues) : base(calculatedValues)
  722. {
  723. }
  724. private string fieldName;
  725. public string FieldName
  726. {
  727. get { return fieldName; }
  728. set { fieldName = value; }
  729. }
  730. private XRControl control;
  731. public XRControl Control
  732. {
  733. get { return control; }
  734. set { control = value; }
  735. }
  736. }
  737. public class MVCxColumnInfo
  738. {
  739. public MVCxColumnInfo(GridViewDataColumnState gridViewColumn)
  740. {
  741. this.gridViewColumn = gridViewColumn;
  742. }
  743. GridViewDataColumnState gridViewColumn;
  744. public GridViewDataColumnState GridViewColumn
  745. {
  746. get
  747. {
  748. return gridViewColumn;
  749. }
  750. }
  751. string columnCaption;
  752. public string ColumnCaption
  753. {
  754. get
  755. {
  756. return columnCaption;
  757. }
  758. set
  759. {
  760. columnCaption = value;
  761. }
  762. }
  763. string fieldName;
  764. public string FieldName
  765. {
  766. get
  767. {
  768. return fieldName;
  769. }
  770. set
  771. {
  772. fieldName = value;
  773. }
  774. }
  775. int columnWidth;
  776. public int ColumnWidth
  777. {
  778. get
  779. {
  780. return columnWidth;
  781. }
  782. set
  783. {
  784. columnWidth = value;
  785. }
  786. }
  787. bool isVisible;
  788. public bool IsVisible
  789. {
  790. get
  791. {
  792. return isVisible;
  793. }
  794. set
  795. {
  796. isVisible = value;
  797. }
  798. }
  799. bool isDetail;
  800. public bool IsDetail
  801. {
  802. get
  803. {
  804. return isDetail;
  805. }
  806. set
  807. {
  808. isDetail = value;
  809. }
  810. }
  811. }
  812. }
  813. }