Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- @{
- FuelRecorderLog.Domain.Entities.RecorderLog recorderLog = new FuelRecorderLog.Domain.Entities.RecorderLog();
- }
- @{
- var fuelLogGrid = new WebGrid(Model, canPage: true, rowsPerPage: 10, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
- fuelLogGrid.Pager(WebGridPagerModes.NextPrevious);
- }
- <div id="gridContent">
- @fuelLogGrid.GetHtml(tableStyle: "webGrid",
- headerStyle: "header",
- alternatingRowStyle: "alt",
- selectedRowStyle: "select",
- columns: fuelLogGrid.Columns(
- fuelLogGrid.Column(
- columnName: "STRNumberID",
- header: "STR Number",
- canSort: true,
- format: item => Html.ActionLink(
- ((int)item.STRID).ToString(),
- "RecorderLog Details", "Details",
- new { id=item.STRID }, null)),
- fuelLogGrid.Column("STRNUMBER", "STR Number"),
- fuelLogGrid.Column("EquipmentRentalDetailedInfoID", "Equipment Rental Detailed Info ID"),
- fuelLogGrid.Column("VehicleTag", "Vehicle Tag"),
- fuelLogGrid.Column("ReservationNumber", "Reservation Number"),
- fuelLogGrid.Column("FuelDate", "Fuel Date"),
- fuelLogGrid.Column("GallonsConsumed", "Gallons Consumed"),
- fuelLogGrid.Column("FuelCost", "Fuel Cost"),
- //fuelLogGrid.Column(format: @<input type="button" value="View Record" onclick="window.location.href = 'GenerateExcel.html';"/>)
- fuelLogGrid.Column(header: "Export",
- format: item => Html.ActionLink("Export", "ExportRow", new { @STDID = item.STDID
- }))
- ))
- @if (fuelLogGrid.HasSelection)
- {
- recorderLog = (FuelRecorderLog.Domain.Entities.RecorderLog)fuelLogGrid.Rows[fuelLogGrid.SelectedIndex].Value;
- <b>STRNUMBER</b>@recorderLog.STRNUMBER<br />
- <b>EquipmentRentalDetailedInfoID</b>@recorderLog.EquipmentRentalDetailedInfoID<br />
- <b>VehicleTag</b>@recorderLog.VehicleTag<br />
- <b>ReservationNumber</b>@recorderLog.ReservationNumber<br />
- <b>FuelDate</b>@recorderLog.FuelDate<br />
- <b>FuelCost</b>@recorderLog.FuelCost<br />
- }
- </div>
- <div>
- @Html.ActionLink("Create Record", "Create")<br/>
- @Html.ActionLink("Export to Excel", "GenerateExcel")
- <p>
- @Html.ActionLink("Download File", "Download")
- </p>
- </div>
- </body>
- static void Main(string[] args)
- {
- var bankAccounts = new List<Account> <<<------ how can I do this with a webgrid?
- {
- new Account
- {
- ID = 345,
- Balance = 541.27,
- STRID = 333,
- STRNUMBER = 123321,
- EquipmentRentalDetailedInfoID = 222333
- },
- new Account
- {
- ID = 123,
- Balance = -127.44,
- STRID = 232,
- STRNUMBER = 456654,
- EquipmentRentalDetailedInfoID = 444555
- }
- };
- DisplayInExcel(bankAccounts, (account, cell) =>
- // This multiline lambda expression sets custom processing rules
- // for the bankAccounts.
- {
- cell.Value = account.ID;
- cell.Offset[0, 1].Value = account.Balance;
- cell.Offset[0, 2].Value = account.STRID;
- cell.Offset[0, 3].Value = account.STRNUMBER;
- cell.Offset[0, 4].Value = account.EquipmentRentalDetailedInfoID;
- if (account.Balance < 0)
- {
- cell.Interior.Color = 255;
- cell.Offset[0, 1].Interior.Color = 255;
- }
- });
- }
- public static void DisplayInExcel(IEnumerable<Account> accounts, Action<Account, Excel.Range> DisplayFunc)
- {
- var excelApp = new Excel.Application();
- // Add a new Excel workbook.
- excelApp.Workbooks.Add();
- excelApp.Visible = true;
- excelApp.Range["A1"].Value = "ID";
- excelApp.Range["B1"].Value = "Balance";
- excelApp.Range["C1"].Value = "STRID";
- excelApp.Range["D1"].Value = "STRNUMBER";
- excelApp.Range["E1"].Value = "EquipmentRentalDetailedInfoID";
- excelApp.Range["A2"].Select();
- excelApp.Range["A1"].Locked = true;
- foreach (var ac in accounts)
- {
- DisplayFunc(ac, excelApp.ActiveCell);
- excelApp.ActiveCell.Offset[1, 0].Select();
- }
- // Copy the results to the Clipboard.
- excelApp.Range["A1:F3"].Copy();
- excelApp.Range["A1:F3"].Locked = true;
- //excelApp.Columns[1].Autofit();
- excelApp.Columns[2].Autofit();
- excelApp.Columns[3].Autofit();
- excelApp.Columns[4].Autofit();
- excelApp.Columns[5].Autofit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement