/// <summary> /// Creates a new Report template /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnNext_Click(object sender, EventArgs e) { try { ReportTemplate.ReportType type = (ReportTemplate.ReportType)int.Parse(Request.QueryString["reportType"]); ReportTemplate template = null; Template templateRow = new Template(); templateRow.TemplateName = "New Template"; switch (type) { case ReportTemplate.ReportType.GroceryRescue: { templateRow.TemplateType = (int)ReportTemplate.ReportType.GroceryRescue; template = new GroceryRescueReportTemplate(); break; } case ReportTemplate.ReportType.InOut: { templateRow.TemplateType = (int)ReportTemplate.ReportType.InOut; template = new InOutReportTemplate(); break; } case ReportTemplate.ReportType.Inventory: { templateRow.TemplateType = (int)ReportTemplate.ReportType.Inventory; template = new InventoryReportTemplate(); break; } case ReportTemplate.ReportType.Incoming: { templateRow.TemplateType = (int)ReportTemplate.ReportType.Incoming; template = new IncomingReportTemplate(); break; } case ReportTemplate.ReportType.Outgoing: { templateRow.TemplateType = (int)ReportTemplate.ReportType.Outgoing; template = new OutgoingReportTemplate(); break; } } Session["reportTemplateRow"] = templateRow; Session["reportTemplate"] = template; NextPage(type); } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("~/errorpages/error.aspx"); } }
/// <summary> /// Loads the data specified by the template into a dataset /// </summary> /// <param name="template">The template to base the queries on</param> /// <returns>The dataset with the data laoded into it.</returns> private ReportsDataSet LoadData(InventoryReportTemplate template) { ReportsDataSet ds = new ReportsDataSet(); using (CCSEntities db = new CCSEntities()) { List<Container> regularContainers = new List<Container>(); List<Container> usdaContainers = new List<Container>(); if (template.USDASelection == ReportTemplate.SelectionType.ALL) { usdaContainers = db.Containers.Where(c => c.isUSDA == true).ToList(); } else if (template.USDASelection == ReportTemplate.SelectionType.SOME) { List<short> usdaCategories = new List<short>(); foreach (var i in template.FoodCategories) usdaCategories.Add(short.Parse(i)); usdaContainers = (from c in db.Containers where c.isUSDA == true && usdaCategories.Contains((short)c.USDAID) select c).ToList(); } if (template.CategoriesSelection == ReportTemplate.SelectionType.ALL) { regularContainers = db.Containers.Where( c => c.isUSDA == false).ToList(); } else if (template.CategoriesSelection == ReportTemplate.SelectionType.REGULAR) { regularContainers = (from c in db.Containers where c.isUSDA == false && c.FoodCategory.Perishable == false && c.FoodCategory.NonFood == false select c).ToList(); } else if (template.CategoriesSelection == ReportTemplate.SelectionType.PERISHABLE) { regularContainers = (from c in db.Containers where c.isUSDA == false && c.FoodCategory.Perishable == true && c.FoodCategory.NonFood == false select c).ToList(); } else if (template.CategoriesSelection == ReportTemplate.SelectionType.NONFOOD) { regularContainers = (from c in db.Containers where c.isUSDA == false && c.FoodCategory.Perishable == false && c.FoodCategory.NonFood == true select c).ToList(); } else if (template.CategoriesSelection == ReportTemplate.SelectionType.SOME) { List<short> selectedCategories = new List<short>(); foreach (var i in template.FoodCategories) selectedCategories.Add(short.Parse(i)); regularContainers = (from c in db.Containers where c.isUSDA == false && selectedCategories.Contains((short)c.FoodCategoryID) select c).ToList(); } regularContainers.AddRange(usdaContainers); List<short> selectedLocations = new List<short>(); if (template.LocationsSelection == ReportTemplate.SelectionType.SOME) { foreach (var i in template.Locations) selectedLocations.Add(short.Parse(i)); regularContainers = (from c in regularContainers where selectedLocations.Contains(c.Location.LocationID) select c).ToList(); } List<int> foundLocations = new List<int>(); foreach (var c in regularContainers) { if(c.FoodCategory != null || c.USDACategory != null) ds.Inventory.AddInventoryRow(c.Location.RoomName, c.USDACategory != null ? c.USDACategory.Description : c.FoodCategory.CategoryType, c.BinNumber.ToString(), c.Cases == null ? 0 : (double)c.Cases, (double)c.Weight); if (!foundLocations.Contains(c.LocationID)) foundLocations.Add(c.LocationID); } if (template.LocationsSelection != ReportTemplate.SelectionType.SOME) selectedLocations = db.Locations.Select(x => x.LocationID).ToList(); foreach(var l in selectedLocations.Where( x => !(foundLocations.Contains(x)))) { var location = db.Locations.FirstOrDefault( x => x.LocationID == l); ds.Inventory.AddInventoryRow(location.RoomName, "EMPTY", "", 0, 0); } } return ds; }