void BindDropDownLists(List <hccAllergen> userAllergens) { try { if (CurrentProgramId > 0 && CurrentCalendarId > 0) { hccProgram program = hccProgram.GetById(CurrentProgramId); hccProductionCalendar cal = hccProductionCalendar.GetById(CurrentCalendarId); hccMenu menu = cal.GetMenu(); if (program != null && menu != null) { List <hccProgramMealType> requiredMealTypes = hccProgramMealType.GetBy(program.ProgramID) .Where(a => a.RequiredQuantity > 0).ToList(); int day = int.Parse(rdoDays.SelectedValue); // Display for selected day pnlDefaultMenu.CssClass += " dayPanel"; HtmlGenericControl pName = new HtmlGenericControl("p"); pName.Attributes.Add("class", "dayName label"); pName.InnerText = "Day " + day.ToString(); pnlDefaultMenu.Controls.Add(pName); pnlDefaultMenu.Controls.Add(new HtmlGenericControl("hr")); requiredMealTypes.ForEach(delegate(hccProgramMealType mealType) { HtmlGenericControl liType = new HtmlGenericControl("li"); liType.InnerText = ((Enums.MealTypes)mealType.MealTypeID).ToString() + ": " + mealType.RequiredQuantity.ToString(); HtmlGenericControl mealTypespan = new HtmlGenericControl("span"); mealTypespan.InnerHtml = "<b>" + ((Enums.MealTypes)mealType.MealTypeID).ToString() + "</b>"; pnlDefaultMenu.Controls.Add(mealTypespan); int i = 1; while (i <= mealType.RequiredQuantity) { // container for meanu item HtmlGenericControl divItemContainer = new HtmlGenericControl("div"); divItemContainer.Attributes.Add("class", "divItemContainer"); pnlDefaultMenu.Controls.Add(divItemContainer); // container for ddl HtmlGenericControl divDdl = new HtmlGenericControl("div"); divDdl.Attributes.Add("class", "divDdl"); divItemContainer.Controls.Add(divDdl); DropDownList ddlMealItem = new DropDownList(); ddlMealItem.CssClass = "mealItemDdl"; ddlMealItem.Attributes.Add("calId", CurrentCalendarId.ToString()); ddlMealItem.Attributes.Add("progId", CurrentProgramId.ToString()); ddlMealItem.Attributes.Add("day", day.ToString()); ddlMealItem.Attributes.Add("type", mealType.MealTypeID.ToString()); ddlMealItem.Attributes.Add("ord", i.ToString()); List <hccMenuItem> menuItems = hccMenuItem.GetByMenuId(menu.MenuID) .Where(a => a.MealTypeID == mealType.MealTypeID).OrderBy(a => a.Name).ToList(); List <ListItem> menuItemsWithSizes = new List <ListItem>(); menuItems.ForEach(delegate(hccMenuItem mainItem) { hccMenuItem menuItem = hccMenuItem.GetById(mainItem.MenuItemID); bool hasAllergen = false; ListItem lItem = null; if (menuItem != null) { List <hccAllergen> matchAllergens = new List <hccAllergen>(); List <hccAllergen> menuItemAllergens = menuItem.GetAllergens(); matchAllergens = menuItemAllergens.Intersect(userAllergens).ToList(); if (matchAllergens.Count > 0) { hasAllergen = true; } } lItem = new ListItem(mainItem.Name + " : " + Enums.CartItemSize.ChildSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.ChildSize).ToString()); if (hasAllergen) { lItem.Attributes["class"] += " redFont"; } menuItemsWithSizes.Add(lItem); lItem = new ListItem(mainItem.Name + " : " + Enums.CartItemSize.SmallSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.SmallSize).ToString()); if (hasAllergen) { lItem.Attributes["class"] += " redFont"; } menuItemsWithSizes.Add(lItem); lItem = new ListItem(mainItem.Name + " : " + Enums.CartItemSize.RegularSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.RegularSize).ToString()); if (hasAllergen) { lItem.Attributes["class"] += " redFont"; } menuItemsWithSizes.Add(lItem); lItem = new ListItem(mainItem.Name + " : " + Enums.CartItemSize.LargeSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.LargeSize).ToString()); if (hasAllergen) { lItem.Attributes["class"] += " redFont"; } menuItemsWithSizes.Add(lItem); }); ddlMealItem.DataSource = new List <ListItem>(); ddlMealItem.DataTextField = "Text"; ddlMealItem.DataValueField = "Value"; ddlMealItem.DataBind(); ddlMealItem.Items.AddRange(menuItemsWithSizes.ToArray()); ddlMealItem.Items.Insert(0, new ListItem("None", "0")); divDdl.Controls.Add(ddlMealItem); // container for nutrition HtmlGenericControl divNuts = new HtmlGenericControl("div"); divNuts.Attributes.Add("class", "divNuts"); divItemContainer.Controls.Add(divNuts); // container for allergens HtmlGenericControl divAllrgs = new HtmlGenericControl("div"); divAllrgs.Attributes.Add("class", "divAllrgs"); divItemContainer.Controls.Add(divAllrgs); // container for prefs HtmlGenericControl divPrefs = new HtmlGenericControl("div"); divPrefs.Attributes.Add("class", "divPrefs"); divItemContainer.Controls.Add(divPrefs); divItemContainer.Controls.Add(new HtmlGenericControl("p")); i++; } pnlDefaultMenu.Controls.Add(new HtmlGenericControl("hr")); }); if (cal.DeliveryDate < DateTime.Now) { pnlDefaultMenu.Enabled = false; chkIsComplete.Enabled = false; //chkIsCancelled.Enabled = false; } } else { if (menu == null) { lblFeedback.Text += "No menu has been assigned to the Production Calendar associated with the Delivery Date assigned to this item. " + "Please assign a menu to the Production Calendar and select a Default Menu for this program, prior to continuing. "; pnlDefaultMenu.Visible = false; } } } } catch (Exception) { throw; } }
void BindDropDownLists() { if (CurrentProgramId > 0 && CurrentCalendarId > 0) { hccProductionCalendar cal = hccProductionCalendar.GetById(CurrentCalendarId); hccMenu menu = cal.GetMenu(); if (menu == null) { lblFeedback.Text += "The selected delivery date does not have an associated menu. Please select a menu to use for the Production Calendar corresponding with this delivery date."; } else { hccProgram program = hccProgram.GetById(CurrentProgramId); if (program != null) { List <hccProgramMealType> mt = hccProgramMealType.GetBy(program.ProgramID); List <hccProgramMealType> requiredMealTypes = mt.Where(a => a.RequiredQuantity > 0).ToList(); // Display for 7 days for (int day = 1; day <= 7; day++) { Panel pnlDay = new Panel(); pnlDay.CssClass = "dayPanel"; HtmlGenericControl pName = new HtmlGenericControl("p"); pName.InnerHtml = "<center><b>Day " + day.ToString() + "</b></center>"; pnlDay.Controls.Add(pName); pnlDay.Controls.Add(new HtmlGenericControl("hr")); requiredMealTypes.ForEach(delegate(hccProgramMealType mealType) { if (day == 1) // list on the first item { HtmlGenericControl liType = new HtmlGenericControl("li"); liType.InnerText = ((Enums.MealTypes)mealType.MealTypeID).ToString() + ": " + mealType.RequiredQuantity.ToString(); ulReqTypes.Controls.Add(liType); HtmlGenericControl mealTypespan = new HtmlGenericControl("h4"); mealTypespan.InnerHtml = "<b>" + ((Enums.MealTypes)mealType.MealTypeID).ToString() + "</b>"; pnlDay.Controls.Add(mealTypespan); } else { HtmlGenericControl mealTypespan = new HtmlGenericControl("h4"); mealTypespan.InnerHtml = "<div> </div>"; pnlDay.Controls.Add(mealTypespan); } int i = 1; while (i <= mealType.RequiredQuantity) { DropDownList ddlMealItem = new DropDownList(); ddlMealItem.CssClass = "mealItemDdl"; ddlMealItem.Attributes.Add("calId", CurrentCalendarId.ToString()); ddlMealItem.Attributes.Add("progId", CurrentProgramId.ToString()); ddlMealItem.Attributes.Add("day", day.ToString()); ddlMealItem.Attributes.Add("type", mealType.MealTypeID.ToString()); ddlMealItem.Attributes.Add("ord", i.ToString()); List <hccMenuItem> menuItems = hccMenuItem.GetByMenuId(menu.MenuID) .Where(a => a.MealTypeID == mealType.MealTypeID).OrderBy(a => a.Name).ToList(); List <ListItem> menuItemsWithSizes = new List <ListItem>(); menuItems.ForEach(delegate(hccMenuItem mainItem) { menuItemsWithSizes.Add(new ListItem(mainItem.Name + " : " + Enums.CartItemSize.ChildSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.ChildSize).ToString())); menuItemsWithSizes.Add(new ListItem(mainItem.Name + " : " + Enums.CartItemSize.SmallSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.SmallSize).ToString())); menuItemsWithSizes.Add(new ListItem(mainItem.Name + " : " + Enums.CartItemSize.RegularSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.RegularSize).ToString())); menuItemsWithSizes.Add(new ListItem(mainItem.Name + " : " + Enums.CartItemSize.LargeSize.ToString(), mainItem.MenuItemID.ToString() + "-" + ((int)Enums.CartItemSize.LargeSize).ToString())); }); ddlMealItem.DataSource = menuItemsWithSizes; ddlMealItem.DataTextField = "Text"; ddlMealItem.DataValueField = "Value"; ddlMealItem.DataBind(); ddlMealItem.Items.Insert(0, new ListItem("None", "0")); pnlDay.Controls.Add(ddlMealItem); CheckBoxList menuitempreferencescheckBoxList = new CheckBoxList(); menuitempreferencescheckBoxList.CssClass = "mealItemchk"; menuitempreferencescheckBoxList.Attributes.Add("calId", CurrentCalendarId.ToString()); menuitempreferencescheckBoxList.Attributes.Add("progId", CurrentProgramId.ToString()); menuitempreferencescheckBoxList.Attributes.Add("day", day.ToString()); menuitempreferencescheckBoxList.Attributes.Add("type", mealType.MealTypeID.ToString()); menuitempreferencescheckBoxList.Attributes.Add("ord", i.ToString()); pnlDay.Controls.Add(menuitempreferencescheckBoxList); pnlDay.Controls.Add(new HtmlGenericControl("p")); i++; } pnlDay.Controls.Add(new HtmlGenericControl("hr")); }); HtmlGenericControl nut = new HtmlGenericControl("div"); nut.ID = "divNutrition" + day.ToString(); nut.Attributes.Add("day", day.ToString()); nut.Attributes.Add("class", "nutrition" + day); nut.InnerHtml = "<fieldset><legend>Calories</legend><p id='cals" + day.ToString() + "'>##Cals##</p></fieldset>" + "<fieldset><legend>Fat</legend><p id='fat" + day.ToString() + "'>##Fats##</p></fieldset>" + "<fieldset><legend>Protein</legend><p id='prtn" + day.ToString() + "'>##Ptrns##</p></fieldset>" + "<fieldset><legend>Carbohydrates</legend><p id='carb" + day.ToString() + "'>##Carbs##</p></fieldset>" + "<fieldset><legend>Dietary Fiber</legend><p id='fbr" + day.ToString() + "'>##Fbrs##</p></fieldset>" + "<fieldset><legend>Sodium</legend><p id='sod" + day.ToString() + "'>##Sod##</p></fieldset>"; pnlDay.Controls.Add(nut); pnlDefaultMenu.Controls.Add(pnlDay); } if (cal.DeliveryDate < DateTime.Now) { pnlDefaultMenu.Enabled = true; //[BWE] pnlDefaultMenu.Attributes.Add("class", "enabled"); //[BWE] } else { pnlDefaultMenu.Enabled = true; pnlDefaultMenu.Attributes.Remove("class"); } } } } }