From a6ea6df17728daef5f0bd65133914f8a56e62076 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Fri, 25 Sep 2015 12:52:21 -0400 Subject: [PATCH] A couple of fixes --- Web/Controllers/FuelLogController.cs | 24 ++++++++++++++++++++++++ Web/Utility/ExcelWriter.cs | 3 +++ Web/Views/FuelLog/ImportUpload.cshtml | 2 +- Web/Views/FuelLog/Index.cshtml | 2 +- Web/Views/Shared/_Layout.cshtml | 4 ++-- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Web/Controllers/FuelLogController.cs b/Web/Controllers/FuelLogController.cs index 2f82f5b..7937ee7 100644 --- a/Web/Controllers/FuelLogController.cs +++ b/Web/Controllers/FuelLogController.cs @@ -38,6 +38,30 @@ namespace MileageTraker.Web.Controllers return View(viewModel); } + [ActionLog] + public ActionResult Export(FuelLogQueryViewModel query) + { + var validLogYearMonths = DataService.GetValidFuelLogMonths(); + + // default parameter processing + if (!query.HasParameters()) + { + query.FiscalYear = validLogYearMonths.First().Year; + query.Month = validLogYearMonths.First().Month; + } + + var fuelLogs = DataService.GetFuelLogs(); + var filteredLogs = + from fl in DataService.FilterFuelLogs(fuelLogs, query).ToList() + orderby fl.Date ascending + select new FuelLogIndexViewModel(fl); + + var name = string.Format("FuelLogs_{0}", query); + + var export = ExcelWriter.WriteXls(filteredLogs, name, name); + return File(export, "application/ms-excel", name + ".xls"); + } + public ViewResult Details(int id) { var fuelLog = DataService.GetFuelLog(id); diff --git a/Web/Utility/ExcelWriter.cs b/Web/Utility/ExcelWriter.cs index 4bb9eef..a4556d8 100644 --- a/Web/Utility/ExcelWriter.cs +++ b/Web/Utility/ExcelWriter.cs @@ -104,6 +104,9 @@ namespace MileageTraker.Web.Utility else if (value is DateTime) formatString = @"MM/DD/YYYY hh:mm:ss"; + if (p.Name == "GasPurchased") // format to the .000 place + formatString = "#,##0.000"; + int intValue; // write int-looking values as numbers if (value is string && int.TryParse((string) value, out intValue)) value = intValue; diff --git a/Web/Views/FuelLog/ImportUpload.cshtml b/Web/Views/FuelLog/ImportUpload.cshtml index 858ad56..bbf4901 100644 --- a/Web/Views/FuelLog/ImportUpload.cshtml +++ b/Web/Views/FuelLog/ImportUpload.cshtml @@ -5,7 +5,7 @@ @Html.Partial("_StatusMessage") -

@ViewBag.Title

+

@ViewBag.Title

@using (Html.BeginForm("Import", "FuelLog", FormMethod.Post, new { enctype="multipart/form-data", @class = "form-horizontal well center-content", style="max-width:440px"})) { diff --git a/Web/Views/FuelLog/Index.cshtml b/Web/Views/FuelLog/Index.cshtml index 42f4f9e..592792c 100644 --- a/Web/Views/FuelLog/Index.cshtml +++ b/Web/Views/FuelLog/Index.cshtml @@ -4,7 +4,7 @@ @{ ViewBag.Title = "Fuel Logs"; var grid = new WebGrid(Model.FuelLogs, rowsPerPage: 45); - var parameters = new {Year = Model.FiscalYear, Model.Month}; + var parameters = new {FiscalYear = Model.FiscalYear, Model.Month, Model.Unmatched}; } @section Styles { diff --git a/Web/Views/Shared/_Layout.cshtml b/Web/Views/Shared/_Layout.cshtml index 938c375..d470ed6 100644 --- a/Web/Views/Shared/_Layout.cshtml +++ b/Web/Views/Shared/_Layout.cshtml @@ -36,9 +36,9 @@ @if (User.IsInRole("Developer") || User.IsInRole("Administrator")) {
  • @Html.ActionLink("Logs", "Index", "Log")
  • -
  • @Html.ActionLink("Vehicles", "Index", "Vehicle")
  • +
  • @Html.ActionLink("Vehicles", "Index", "Vehicle")
  • +
  • @Html.ActionLink("Fuel Logs", "Index", "FuelLog")
  • @Html.ActionLink("Users", "Index", "User")
  • -
  • @Html.ActionLink("Fuel Logs", "Index", "FuelLog")