Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <body>
  2. @{
  3. FuelRecorderLog.Domain.Entities.RecorderLog recorderLog = new FuelRecorderLog.Domain.Entities.RecorderLog();
  4. }
  5.  
  6. @{
  7. var fuelLogGrid = new WebGrid(Model, canPage: true, rowsPerPage: 10, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
  8. fuelLogGrid.Pager(WebGridPagerModes.NextPrevious);
  9. }
  10. <div id="gridContent">
  11. @fuelLogGrid.GetHtml(tableStyle: "webGrid",
  12. headerStyle: "header",
  13. alternatingRowStyle: "alt",
  14. selectedRowStyle: "select",
  15. columns: fuelLogGrid.Columns(
  16. fuelLogGrid.Column(
  17. columnName: "STRNumberID",
  18. header: "STR Number",
  19. canSort: true,
  20. format: item => Html.ActionLink(
  21. ((int)item.STRID).ToString(),
  22. "RecorderLog Details", "Details",
  23. new { id=item.STRID }, null)),
  24. fuelLogGrid.Column("STRNUMBER", "STR Number"),
  25. fuelLogGrid.Column("EquipmentRentalDetailedInfoID", "Equipment Rental Detailed Info ID"),
  26. fuelLogGrid.Column("VehicleTag", "Vehicle Tag"),
  27. fuelLogGrid.Column("ReservationNumber", "Reservation Number"),
  28. fuelLogGrid.Column("FuelDate", "Fuel Date"),
  29. fuelLogGrid.Column("GallonsConsumed", "Gallons Consumed"),
  30. fuelLogGrid.Column("FuelCost", "Fuel Cost"),
  31. //fuelLogGrid.Column(format: @<input type="button" value="View Record" onclick="window.location.href = 'GenerateExcel.html';"/>)
  32. fuelLogGrid.Column(header: "Export",
  33. format: item => Html.ActionLink("Export", "ExportRow", new { @STDID = item.STDID
  34. }))
  35. ))
  36. @if (fuelLogGrid.HasSelection)
  37. {
  38. recorderLog = (FuelRecorderLog.Domain.Entities.RecorderLog)fuelLogGrid.Rows[fuelLogGrid.SelectedIndex].Value;
  39. <b>STRNUMBER</b>@recorderLog.STRNUMBER<br />
  40. <b>EquipmentRentalDetailedInfoID</b>@recorderLog.EquipmentRentalDetailedInfoID<br />
  41. <b>VehicleTag</b>@recorderLog.VehicleTag<br />
  42. <b>ReservationNumber</b>@recorderLog.ReservationNumber<br />
  43. <b>FuelDate</b>@recorderLog.FuelDate<br />
  44. <b>FuelCost</b>@recorderLog.FuelCost<br />
  45. }
  46. </div>
  47. <div>
  48. @Html.ActionLink("Create Record", "Create")<br/>
  49. @Html.ActionLink("Export to Excel", "GenerateExcel")
  50. <p>
  51. @Html.ActionLink("Download File", "Download")
  52. </p>
  53. </div>
  54.  
  55. </body>
  56.  
  57. static void Main(string[] args)
  58. {
  59. var bankAccounts = new List<Account> <<<------ how can I do this with a webgrid?
  60. {
  61.  
  62. new Account
  63. {
  64. ID = 345,
  65. Balance = 541.27,
  66. STRID = 333,
  67. STRNUMBER = 123321,
  68. EquipmentRentalDetailedInfoID = 222333
  69. },
  70. new Account
  71. {
  72. ID = 123,
  73. Balance = -127.44,
  74. STRID = 232,
  75. STRNUMBER = 456654,
  76. EquipmentRentalDetailedInfoID = 444555
  77. }
  78. };
  79.  
  80. DisplayInExcel(bankAccounts, (account, cell) =>
  81. // This multiline lambda expression sets custom processing rules
  82. // for the bankAccounts.
  83. {
  84. cell.Value = account.ID;
  85. cell.Offset[0, 1].Value = account.Balance;
  86. cell.Offset[0, 2].Value = account.STRID;
  87. cell.Offset[0, 3].Value = account.STRNUMBER;
  88. cell.Offset[0, 4].Value = account.EquipmentRentalDetailedInfoID;
  89.  
  90. if (account.Balance < 0)
  91. {
  92. cell.Interior.Color = 255;
  93. cell.Offset[0, 1].Interior.Color = 255;
  94. }
  95. });
  96. }
  97.  
  98. public static void DisplayInExcel(IEnumerable<Account> accounts, Action<Account, Excel.Range> DisplayFunc)
  99. {
  100. var excelApp = new Excel.Application();
  101.  
  102. // Add a new Excel workbook.
  103. excelApp.Workbooks.Add();
  104.  
  105. excelApp.Visible = true;
  106. excelApp.Range["A1"].Value = "ID";
  107. excelApp.Range["B1"].Value = "Balance";
  108. excelApp.Range["C1"].Value = "STRID";
  109. excelApp.Range["D1"].Value = "STRNUMBER";
  110. excelApp.Range["E1"].Value = "EquipmentRentalDetailedInfoID";
  111.  
  112. excelApp.Range["A2"].Select();
  113. excelApp.Range["A1"].Locked = true;
  114.  
  115.  
  116. foreach (var ac in accounts)
  117. {
  118. DisplayFunc(ac, excelApp.ActiveCell);
  119. excelApp.ActiveCell.Offset[1, 0].Select();
  120. }
  121.  
  122. // Copy the results to the Clipboard.
  123. excelApp.Range["A1:F3"].Copy();
  124. excelApp.Range["A1:F3"].Locked = true;
  125.  
  126. //excelApp.Columns[1].Autofit();
  127. excelApp.Columns[2].Autofit();
  128. excelApp.Columns[3].Autofit();
  129. excelApp.Columns[4].Autofit();
  130. excelApp.Columns[5].Autofit();
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement