private void AddUpdateMealSideToCart(hccCartItem parentCartItem, hccMenuItem menuItem, int ordinal) { if (menuItem == null || parentCartItem == null) { throw new ArgumentException(); } var alcMenuItem = hccCartALCMenuItem.GetByOrdinal(parentCartItem.CartItemID, ordinal); if (alcMenuItem == null) { var newItem = new hccCartItem { CartID = parentCartItem.CartID, CreatedBy = parentCartItem.CreatedBy, CreatedDate = DateTime.Now, IsTaxable = menuItem.IsTaxEligible, ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)parentCartItem.Meal_MealSizeID, menuItem.Name, string.Empty, string.Empty, parentCartItem.DeliveryDate),//, parentCartItem.Quantity ItemDesc = menuItem.Description, ItemPrice = hccMenuItem.GetItemPriceBySize(menuItem, parentCartItem.Meal_MealSizeID), ItemTypeID = (int)Enums.CartItemType.AlaCarte, DeliveryDate = parentCartItem.DeliveryDate, Meal_MenuItemID = menuItem.MenuItemID, Meal_MealSizeID = parentCartItem.Meal_MealSizeID, Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost, UserProfileID = parentCartItem.UserProfileID, Quantity = parentCartItem.Quantity, OrderNumber = parentCartItem.OrderNumber, IsCompleted = false }; newItem.Save(); alcMenuItem = new hccCartALCMenuItem { CartItemID = newItem.CartItemID, ParentCartItemID = parentCartItem.CartItemID, Ordinal = ordinal }; alcMenuItem.Save(); } else { var cartItem = hccCartItem.GetById(alcMenuItem.CartItemID); cartItem.Quantity = parentCartItem.Quantity; cartItem.Meal_MealSizeID = parentCartItem.Meal_MealSizeID; if (cartItem.Meal_MenuItemID != menuItem.MenuItemID) { cartItem.IsTaxable = menuItem.IsTaxEligible; cartItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)parentCartItem.Meal_MealSizeID, menuItem.Name, string.Empty, string.Empty, parentCartItem.DeliveryDate);//, parentCartItem.Quantity cartItem.ItemDesc = menuItem.Description; cartItem.ItemPrice = hccMenuItem.GetItemPriceBySize(menuItem, parentCartItem.Meal_MealSizeID); cartItem.Meal_MenuItemID = menuItem.MenuItemID; cartItem.Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost; cartItem.UserProfileID = parentCartItem.UserProfileID; } cartItem.Save(); } }
protected void DisplayMenuItemOptions(hccMenuItem hmI) { // Because the form is reused, have to explicitly set checkboxes to false as state is saved between menu item selection cbCanyonRanchRecipe.Checked = false; cbCanyonRanchApproved.Checked = false; cbVegetarianOption.Checked = false; cbVeganOption.Checked = false; cbGlutenFreeOption.Checked = false; if (hmI.CanyonRanchRecipe != null) { cbCanyonRanchRecipe.Checked = hmI.CanyonRanchRecipe.Value; } if (hmI.CanyonRanchApproved != null) { cbCanyonRanchApproved.Checked = hmI.CanyonRanchApproved.Value; } if (hmI.VegetarianOptionAvailable != null) { cbVegetarianOption.Checked = hmI.VegetarianOptionAvailable.Value; } if (hmI.VeganOptionAvailable != null) { cbVeganOption.Checked = hmI.VeganOptionAvailable.Value; } if (hmI.GlutenFreeOptionAvailable != null) { cbGlutenFreeOption.Checked = hmI.GlutenFreeOptionAvailable.Value; } }
void BindcblPreferences(int menuItemId) { cblPreferences.ClearSelection(); cblPreferences.Items.Clear(); hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); if (menuItem != null) { List <hccPreference> prefs = menuItem.GetPreferences(); if (prefs.Count > 0) { cblPreferences.DataSource = prefs; cblPreferences.DataTextField = "Name"; cblPreferences.DataValueField = "PreferenceID"; cblPreferences.DataBind(); divPreferences.Visible = true; } else { divPreferences.Visible = false; } } }
protected override void SetButtons() { ShowDeactivate = false; if (this.PrimaryKeyIndex > 0) { ShowDeactivate = true; btnDeactivate.Attributes.Add("onclick", "return confirm('Are you sure that you want to reactivate/retire this menu item?');"); if (CurrentMenuItem == null) { CurrentMenuItem = hccMenuItem.GetById(this.PrimaryKeyIndex); } if (CurrentMenuItem != null) { if (CurrentMenuItem.IsRetired) { btnDeactivate.Text = "Reactivate"; } else { btnDeactivate.Text = "Retire"; } } } btnDeactivate.Visible = ShowDeactivate; }
//protected void BindMenuItems() //{ // //List<hccMenuItem> items = hccMenuItem.GetAll((HealthyChef.Common.Enums.MealTypes)CurrentMenuItem.MealType).Where(a => a.MenuItemID != CurrentMenuItem.MenuItemID).ToList(); // List<hccMenuItem> items = hccMenuItem.GetAll().Where(a => a.MenuItemID != CurrentMenuItem.MenuItemID).ToList(); // List<hccMenuItem> selected = CurrentMenuItem.GetChildren(); // lstMenuItems.DataBind<hccMenuItem>(items, selected); //} protected void btnDeactivate_Click(object sender, EventArgs e) { try { CurrentMenuItem = hccMenuItem.GetById(PrimaryKeyIndex); CurrentMenuItem.Retire(CurrentMenuItem.IsRetired); SetButtons(); OnSaved(new ControlSavedEventArgs(CurrentMenuItem.MenuItemID)); } catch (Exception) { throw; } }
public string ShowingPreferencesByMenuitemid(DefaultMenu Defaultmenudetails) { List <hccPreference> itemPrefs = new List <hccPreference>(); try { string menuitempreferences = ""; if (Defaultmenudetails.MenuItemID != 0) { hccMenuItem hccMenuItem = new hccMenuItem { MenuItemID = Convert.ToInt16(Defaultmenudetails.MenuItemID) }; itemPrefs = hccMenuItem.GetPreferences(); if (itemPrefs.Count > 0) { foreach (var preference in itemPrefs) { hccProgramDefaultMenuExPref excPref = hccProgramDefaultMenuExPref.GetBy(Defaultmenudetails.DefaultMenuID, preference.PreferenceID); if (excPref != null) { menuitempreferences += preference.PreferenceID.ToString() + "|" + 1.ToString() + "|" + preference.Name.ToString() + "&" + Defaultmenudetails.MealTypeID.ToString() + "|" + Defaultmenudetails.CalendarID.ToString() + "|" + Defaultmenudetails.ProgramID.ToString() + "|" + Defaultmenudetails.DayNumber.ToString() + "*"; } else { menuitempreferences += preference.PreferenceID.ToString() + "|" + 0.ToString() + "|" + preference.Name.ToString() + "&" + Defaultmenudetails.MealTypeID.ToString() + "|" + Defaultmenudetails.CalendarID.ToString() + "|" + Defaultmenudetails.ProgramID.ToString() + "|" + Defaultmenudetails.DayNumber.ToString() + "*"; } } } else { menuitempreferences = 0.ToString() + "|" + 0.ToString() + "|" + " " + "&" + Defaultmenudetails.MealTypeID.ToString() + "|" + Defaultmenudetails.CalendarID.ToString() + "|" + Defaultmenudetails.ProgramID.ToString() + "|" + Defaultmenudetails.DayNumber.ToString() + "*"; } } else { menuitempreferences = 0.ToString() + "|" + 0.ToString() + "|" + " " + "&" + Defaultmenudetails.MealTypeID.ToString() + "|" + Defaultmenudetails.CalendarID.ToString() + "|" + Defaultmenudetails.ProgramID.ToString() + "|" + Defaultmenudetails.DayNumber.ToString() + "*"; } return(menuitempreferences); } catch (Exception ex) { throw ex; } }
void gvwRetiredMenuItems_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { int menuItemId = int.Parse(e.Keys[0].ToString()); hccMenuItem delItem = hccMenuItem.GetById(menuItemId); if (delItem != null) { delItem.Retire(true); BindBothLists(); } } catch (Exception) { throw; } }
protected void SavePickers() { //delete existing CurrentMenu.RemoveItems(); //save all pickers foreach (EntityPicker picker in EntityLists) { List <int> selKeys = picker.GetSelectedKeys(); List <hccMenuItem> newItemList = new List <hccMenuItem>(); selKeys.ForEach(delegate(int key) { hccMenuItem saveItem = hccMenuItem.GetById(key); newItemList.Add(saveItem); }); CurrentMenu.AddItems(newItemList); } }
void BindcblPreferences(int menuItemId) { cblPreferences.ClearSelection(); cblPreferences.Items.Clear(); hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); if (menuItem != null) { List <hccPreference> prefs = menuItem.GetPreferences(); if (prefs.Count > 0) { cblPreferences.DataSource = prefs; cblPreferences.DataTextField = "Name"; cblPreferences.DataValueField = "PreferenceID"; cblPreferences.DataBind(); divPreferences.Visible = true; } else { divPreferences.Visible = false; } } List <hccPreference> cartprefs = hccCartItemMealPreference.GetPrefsBy(CurrentCartItem.CartItemID); foreach (hccPreference pref in cartprefs) { var t = cblPreferences.Items.FindByValue(pref.PreferenceID.ToString()); if (t != null) { t.Selected = true; } } }
public XmlDocument GetPreferences() { try { if (this.Context.Request.QueryString["mid"] != null && !string.IsNullOrWhiteSpace(this.Context.Request.QueryString["mid"])) { string prefString = string.Empty, nutInfo = string.Empty, allrgsList = string.Empty; int menuItemId = int.Parse(this.Context.Request.QueryString["mid"]); if (menuItemId > 0) { hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); if (menuItem != null) { // nutrition hccMenuItemNutritionData menuNut = hccMenuItemNutritionData.GetBy(menuItem.MenuItemID); if (menuNut != null) { nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2}, Carbohydrates: {3}, Fiber: {4}, Sodium: {5}", menuNut.Calories.ToString("f2"), menuNut.TotalFat.ToString("f2"), menuNut.Protein.ToString("f2"), menuNut.TotalCarbohydrates.ToString("f2"), menuNut.DietaryFiber.ToString("f2"), menuNut.Sodium.ToString("f2")); } else { nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2}, Carbohydrates: {3}, Fiber: {4}, Sodium: {5}", 0, 0, 0, 0, 0, 0); } // allergens allrgsList = "Allergens: " + menuItem.AllergensList; // prefs List <hccPreference> prefs = menuItem.GetPreferences(); prefs.ForEach(delegate(hccPreference pref) { prefString += pref.PreferenceID.ToString() + ":" + pref.Name + "|"; }); prefString = prefString.TrimEnd('|'); } if (prefString.Trim() == "") { prefString = "None"; } string retVal = string.Format("<menuData><nutrition>{0}</nutrition><allergens>{1}</allergens><prefs>{2}</prefs></menuData>", nutInfo, allrgsList, prefString); XmlDocument xml = new XmlDocument(); xml.LoadXml(retVal); return(xml); } else { return(null); } } else { return(null); } } catch { throw; } }
protected override void SaveForm() { try { Page.Validate(this.ValidationGroup); if (Page.IsValid) { if (CurrentCartItem != null) { if (chkIsComplete.Enabled) { CurrentCartItem.IsCompleted = chkIsComplete.Checked; } hccMenuItem menuItem = null; var itemSize = Enums.CartItemSize.NoSize; if (!string.IsNullOrWhiteSpace(ddlMenuItems.SelectedValue)) { menuItem = hccMenuItem.GetById(int.Parse(ddlMenuItems.SelectedValue)); } if (menuItem != null) { if (menuItem.MenuItemID != CurrentCartItem.Meal_MenuItemID) { CurrentCartItem.Meal_MenuItemID = menuItem.MenuItemID; } int selMenuOptionId = int.Parse(ddlOptions.SelectedValue); if (selMenuOptionId != CurrentCartItem.Meal_MealSizeID) { CurrentCartItem.Meal_MealSizeID = selMenuOptionId; } itemSize = (Enums.CartItemSize)(CurrentCartItem.Meal_MealSizeID); CurrentCartItem.ItemDesc = menuItem.Description; CurrentCartItem.ItemPrice = hccMenuItem.GetItemPriceBySize(menuItem, (int)itemSize); } var prefsString = string.Empty; var prefs = hccCartItemMealPreference.GetBy(CurrentCartItem.CartItemID); prefs.ForEach(a => a.Delete()); foreach (ListItem item in cblPreferences.Items) { if (item.Selected) { var pref = new hccCartItemMealPreference { CartItemID = CurrentCartItem.CartItemID, PreferenceID = int.Parse(item.Value) }; pref.Save(); if (string.IsNullOrWhiteSpace(prefsString)) { prefsString += item.Text; } else { prefsString += ", " + item.Text; } } } CurrentCartItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, itemSize, menuItem.Name, GetMealSides(menuItem.MealType), prefsString, CurrentCartItem.DeliveryDate);//,CurrentCartItem.Quantity CurrentCartItem.Save(); AddUpdateCartALCMenuItem(CurrentCartItem); lblFeedback.Text = "Item Saved: " + DateTime.Now.ToString(); lblFeedback.ForeColor = Color.Green; BindgvwALCItems(); btnSave.Visible = false; pnlItemEdit.Visible = false; } } } catch (Exception) { throw; } }
void BindddlOptions(int menuItemId) { ddlOptions.ClearSelection(); ddlOptions.Items.Clear(); List <Tuple <string, int> > itemSizes = Enums.GetEnumAsTupleList(typeof(Enums.CartItemSize)); List <Tuple <string, int> > pricedSizes = new List <Tuple <string, int> >(); itemSizes.Remove(itemSizes.Single(a => ((Enums.CartItemSize)(a.Item2)) == Enums.CartItemSize.NoSize)); hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); if (menuItem != null) { if (!menuItem.UseCostChild) { itemSizes.Remove(itemSizes.Single(a => ((Enums.CartItemSize)(a.Item2)) == Enums.CartItemSize.ChildSize)); } if (!menuItem.UseCostSmall) { itemSizes.Remove(itemSizes.Single(a => ((Enums.CartItemSize)(a.Item2)) == Enums.CartItemSize.SmallSize)); } if (!menuItem.UseCostRegular) { itemSizes.Remove(itemSizes.Single(a => ((Enums.CartItemSize)(a.Item2)) == Enums.CartItemSize.RegularSize)); } if (!menuItem.UseCostLarge) { itemSizes.Remove(itemSizes.Single(a => ((Enums.CartItemSize)(a.Item2)) == Enums.CartItemSize.LargeSize)); } if (itemSizes.Count > 0) { itemSizes.ForEach(delegate(Tuple <string, int> sizeItem) { Enums.CartItemSize cis = ((Enums.CartItemSize)(sizeItem.Item2)); switch (cis) { case Enums.CartItemSize.ChildSize: pricedSizes.Add(new Tuple <string, int>(sizeItem.Item1 + " - " + menuItem.CostChild.ToString("c"), sizeItem.Item2)); break; case Enums.CartItemSize.SmallSize: pricedSizes.Add(new Tuple <string, int>(sizeItem.Item1 + " - " + menuItem.CostSmall.ToString("c"), sizeItem.Item2)); break; case Enums.CartItemSize.RegularSize: pricedSizes.Add(new Tuple <string, int>(sizeItem.Item1 + " - " + menuItem.CostRegular.ToString("c"), sizeItem.Item2)); break; case Enums.CartItemSize.LargeSize: pricedSizes.Add(new Tuple <string, int>(sizeItem.Item1 + " - " + menuItem.CostLarge.ToString("c"), sizeItem.Item2)); break; default: break; } }); ddlOptions.DataSource = pricedSizes; ddlOptions.DataTextField = "Item1"; ddlOptions.DataValueField = "Item2"; ddlOptions.DataBind(); if (pricedSizes.Count > 1) { ddlOptions.Items.Insert(0, new ListItem("Select Size...", "-1")); ddlOptions.Enabled = true; } } else { itemSizes.Add(new Tuple <string, int>(Enums.CartItemSize.NoSize.ToString(), (int)Enums.CartItemSize.NoSize)); ddlOptions.DataSource = itemSizes; ddlOptions.DataTextField = "Item1"; ddlOptions.DataValueField = "Item2"; ddlOptions.DataBind(); ddlOptions.Enabled = false; } } }
protected override void SaveForm() { try { hccCart userCart = hccCart.GetById(this.PrimaryKeyIndex); MembershipUser user = Membership.GetUser(userCart.AspNetUserID); bool isFamilyStyle = false; if (user != null) { hccMenuItem menuItem = hccMenuItem.GetById(int.Parse(ddlMenuItems.SelectedValue)); var itemSize = (Enums.CartItemSize)(int.Parse(ddlOptions.SelectedValue)); if (chkFamilyStyle.Checked) { isFamilyStyle = true; } int profileId = 0; if (divProfiles.Visible) { profileId = int.Parse(ddlProfiles.SelectedValue); } else { profileId = hccUserProfile.GetParentProfileBy(userCart.AspNetUserID.Value).UserProfileID; } if (userCart != null) { hccCartItem cartItem = new hccCartItem { CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, IsTaxable = menuItem.IsTaxEligible, ItemDesc = menuItem.Description, ItemPrice = hccMenuItem.GetItemPriceBySize(menuItem, (int)itemSize), ItemTypeID = (int)Enums.CartItemType.AlaCarte, DeliveryDate = DateTime.Parse(ddlDeliveryDates.SelectedItem.Text), Meal_MealSizeID = (int)itemSize, Meal_MenuItemID = menuItem.MenuItemID, Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost, UserProfileID = profileId, Quantity = int.Parse(txtQuantity.Text.Trim()), Plan_IsAutoRenew = isFamilyStyle, IsCompleted = false }; cartItem.GetOrderNumber(userCart); List <hccCartItemMealPreference> prefsList = new List <hccCartItemMealPreference>(); foreach (ListItem item in cblPreferences.Items) { if (item.Selected) { hccCartItemMealPreference pref = new hccCartItemMealPreference { CartItemID = cartItem.CartItemID, PreferenceID = int.Parse(item.Value) }; prefsList.Add(pref); } } var prefsString = string.Empty; if (prefsList.Count > 0) { prefsString = prefsList .Select(a => hccPreference.GetById(a.PreferenceID)) .Select(a => a.Name).DefaultIfEmpty(string.Empty).Aggregate((a, b) => a + ", " + b); } cartItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, itemSize, menuItem.Name, GetMealSides(menuItem.MealType), prefsString, cartItem.DeliveryDate);//,cartItem.Quantity hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, cartItem.ItemName, profileId); if (existItem == null) { cartItem.CartID = userCart.CartID; cartItem.Save(); if (cartItem.CartItemID > 0) { prefsList.ForEach(delegate(hccCartItemMealPreference cartPref) { cartPref.CartItemID = cartItem.CartItemID; cartPref.Save(); }); } AddUpdateCartALCMenuItem(cartItem); OnSaved(new ControlSavedEventArgs(cartItem.CartItemID)); chkFamilyStyle.Checked = false; } else { existItem.Quantity += cartItem.Quantity; if (existItem.AdjustQuantity(existItem.Quantity)) { AddUpdateCartALCMenuItem(existItem); OnSaved(new ControlSavedEventArgs(existItem.CartItemID)); chkFamilyStyle.Checked = false; } } } } } catch (Exception) { throw; } }
protected override void LoadForm() { try { List <hccProgramDefaultMenu> defaultMenuSelections = hccProgramDefaultMenu.GetBy(CurrentCalendarId, CurrentProgramId); List <DropDownList> ddls = new List <DropDownList>(); List <CheckBoxList> chklists = new List <CheckBoxList>(); List <DailyNutrition> dailyNuts = new List <DailyNutrition>(); List <HtmlGenericControl> nutDisplays = new List <HtmlGenericControl>(); BindDropDownLists(); List <Panel> pnls = pnlDefaultMenu.Controls.OfType <Panel>().ToList(); int i = 1; pnls.ForEach(delegate(Panel pnl) { //foreach(var control in pnl.Controls.Count) ddls.AddRange(pnl.Controls.OfType <DropDownList>()); chklists.AddRange(pnl.Controls.OfType <CheckBoxList>()); //pnl.FindControl("mealItemDdl"); string divName = "divNutrition" + i.ToString(); nutDisplays.Add((HtmlGenericControl)pnl.FindControl(divName)); i++; }); if (defaultMenuSelections.Count != ddls.Count) { lblFeedback.Text += "No default values have been saved for the selected date and program combination. Select the default items and press 'Save' to set the default items."; } defaultMenuSelections.ForEach(delegate(hccProgramDefaultMenu selection) { if (dailyNuts.Where(a => a.DayNumber == selection.DayNumber).SingleOrDefault() == null) { dailyNuts.Add(new DailyNutrition { DayNumber = selection.DayNumber }); } DailyNutrition dailyNut = dailyNuts.Where(a => a.DayNumber == selection.DayNumber).Single(); hccMenuItemNutritionData menuNut = hccMenuItemNutritionData.GetBy(selection.MenuItemID); if (menuNut != null) { dailyNut.Calories += menuNut.Calories; dailyNut.Carbs += menuNut.TotalCarbohydrates; dailyNut.Fat += menuNut.TotalFat; dailyNut.Fiber += menuNut.DietaryFiber; dailyNut.Protein += menuNut.Protein; dailyNut.Sodium += menuNut.Sodium; } DropDownList ddl = ddls.Where(a => a.Attributes["day"] == selection.DayNumber.ToString() && a.Attributes["type"] == selection.MealTypeID.ToString() && a.Attributes["ord"] == selection.Ordinal.ToString()) .SingleOrDefault(); CheckBoxList chklist = chklists.Where(a => a.Attributes["day"] == selection.DayNumber.ToString() && a.Attributes["type"] == selection.MealTypeID.ToString() && a.Attributes["ord"] == selection.Ordinal.ToString()) .SingleOrDefault(); if (ddl != null) { string value = selection.MenuItemID.ToString() + "-" + selection.MenuItemSizeID.ToString(); ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value)); ddl.Attributes.Add("defMenuId", selection.DefaultMenuID.ToString()); } if (chklist != null) { List <ListItem> listItem = new List <ListItem>(); hccMenuItem hccMenuItem = new hccMenuItem { MenuItemID = Convert.ToInt32(selection.MenuItemID) }; List <hccPreference> itemPrefs = hccMenuItem.GetPreferences(); if (itemPrefs.Count > 0 && ddl.SelectedIndex > 0) { itemPrefs.ForEach(delegate(hccPreference pref) { ListItem chkPref = new ListItem(); chkPref.Value = pref.PreferenceID.ToString(); chkPref.Text = pref.Name; chkPref.Attributes.Add("prefID", pref.PreferenceID.ToString()); hccProgramDefaultMenuExPref excPref = hccProgramDefaultMenuExPref.GetBy(selection.DefaultMenuID, pref.PreferenceID); if (excPref != null) { chkPref.Selected = true; } chklist.Items.Add(chkPref); }); } else { ListItem li = new ListItem("", ""); li.Selected = false; li.Attributes.Add("Style", " max-height: 170px;display: block;overflow - y: auto; width: 100 %;min - height: 170px;display: none;"); chklist.Items.Add(li); } } }); nutDisplays.ForEach(delegate(HtmlGenericControl ctrl) { int nutDay = int.Parse(ctrl.Attributes["day"]); DailyNutrition dNut = dailyNuts.Where(a => a.DayNumber == nutDay).SingleOrDefault(); if (dNut == null) { ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Cals##", "0"); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Fats##", "0"); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Ptrns##", "0"); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Carbs##", "0"); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Fbrs##", "0"); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Sod##", "0"); } else { ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Cals##", dNut.Calories.ToString("f2")); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Fats##", dNut.Fat.ToString("f2")); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Ptrns##", dNut.Protein.ToString("f2")); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Carbs##", dNut.Carbs.ToString("f2")); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Fbrs##", dNut.Fiber.ToString("f2")); ctrl.InnerHtml = ctrl.InnerHtml.Replace("##Sod##", dNut.Sodium.ToString("f2")); } }); } catch (Exception) { throw; } }
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; } }
protected override void SaveForm() { try { if (CurrentMenuItem == null) { CurrentMenuItem = hccMenuItem.GetById(this.PrimaryKeyIndex); } hccMenuItemNutritionData nutData = null; if (CurrentMenuItem == null) { CurrentMenuItem = new hccMenuItem(); } else { nutData = hccMenuItemNutritionData.GetBy(CurrentMenuItem.MenuItemID); } if (nutData == null) { nutData = new hccMenuItemNutritionData(); } CurrentMenuItem.UseCostChild = chkUsePriceChild.Checked; CurrentMenuItem.CostChild = string.IsNullOrWhiteSpace(txtCostChild.Text.Trim()) ? 0.00m : decimal.Parse(txtCostChild.Text.Trim()); CurrentMenuItem.UseCostSmall = chkUsePriceSmall.Checked; CurrentMenuItem.CostSmall = string.IsNullOrWhiteSpace(txtCostSmall.Text.Trim()) ? 0.00m : decimal.Parse(txtCostSmall.Text.Trim()); CurrentMenuItem.UseCostRegular = chkUsePriceRegular.Checked; CurrentMenuItem.CostRegular = string.IsNullOrWhiteSpace(txtCostRegular.Text.Trim()) ? 0.00m : decimal.Parse(txtCostRegular.Text.Trim()); CurrentMenuItem.UseCostLarge = chkUsePriceLarge.Checked; CurrentMenuItem.CostLarge = string.IsNullOrWhiteSpace(txtCostLarge.Text.Trim()) ? 0.00m : decimal.Parse(txtCostLarge.Text.Trim()); CurrentMenuItem.Description = string.IsNullOrWhiteSpace(txtDescription.Text.Trim()) ? null : txtDescription.Text.Trim(); CurrentMenuItem.Name = txtMenuItemName.Text.Trim(); CurrentMenuItem.IsTaxEligible = chkIsTaxEligible.Checked; CurrentMenuItem.MealTypeID = int.Parse(ddlMealType.SelectedValue); //Check if File is available. if (Request.Files.Count > 0) { if (MenuItemImage.Value != "") { //Save the File. string filename = ""; string imagesfolder = "/Images"; String path = HttpContext.Current.Server.MapPath("~" + imagesfolder); //Path //if (CurrentMenuItem.Name.Contains("&")) //{ // filename = CurrentMenuItem.Name.Replace('&', ' '); //} //else //if (CurrentMenuItem.Name.Contains(",")) //{ // filename = CurrentMenuItem.Name.Replace(',', ' '); //} //else //{ // filename = CurrentMenuItem.Name; //} filename = RemoveSpecialChars(CurrentMenuItem.Name); string fileName = filename + "_" + CurrentMenuItem.MenuItemID + ".png"; string filePath = path + "/" + fileName; //Check if directory exist if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist } MenuItemImage.PostedFile.SaveAs(filePath); CurrentMenuItem.ImageUrl = imagesfolder + "/" + fileName; } } decimal temp; if (decimal.TryParse(txtCalories.Text.Trim(), out temp)) { nutData.Calories = temp; } if (decimal.TryParse(txtDietaryFiber.Text.Trim(), out temp)) { nutData.DietaryFiber = temp; } if (decimal.TryParse(txtProtein.Text.Trim(), out temp)) { nutData.Protein = temp; } if (decimal.TryParse(txtTotalCarbohydrates.Text.Trim(), out temp)) { nutData.TotalCarbohydrates = temp; } if (decimal.TryParse(txtTotalFat.Text.Trim(), out temp)) { nutData.TotalFat = temp; } if (decimal.TryParse(txtSodium.Text.Trim(), out temp)) { nutData.Sodium = temp; } List <int> currentIngredients = CurrentMenuItem.GetIngredients().Select(a => a.IngredientID).ToList(); List <int> selectedIngredients = lstIngredients.GetSelectedKeys(); List <int> delIngredients = currentIngredients.Except(selectedIngredients).ToList(); SetMenuItemOptions(); CurrentMenuItem.Save(); nutData.MenuItemID = CurrentMenuItem.MenuItemID; nutData.Save(); selectedIngredients.ForEach(delegate(int ingredientId) { hccMenuItemIngredient sel = hccMenuItemIngredient.GetBy(ingredientId, CurrentMenuItem.MenuItemID); if (sel == null) { sel = new hccMenuItemIngredient { IngredientID = ingredientId, MenuItemID = CurrentMenuItem.MenuItemID, } } ; sel.Save(); }); delIngredients.ForEach(delegate(int ingredientId) { hccMenuItemIngredient del = hccMenuItemIngredient.GetBy(ingredientId, CurrentMenuItem.MenuItemID); if (del != null) { del.Delete(); } }); List <int> currentPrefs = CurrentMenuItem.GetPreferences().Select(a => a.PreferenceID).ToList(); List <int> selectedPrefs = lstPreferences.GetSelectedKeys(); List <int> delPrefs = currentPrefs.Except(selectedPrefs).ToList(); selectedPrefs.ForEach(delegate(int prefId) { hccMenuItemPreference sel = hccMenuItemPreference.GetBy(prefId, CurrentMenuItem.MenuItemID); if (sel == null) { sel = new hccMenuItemPreference { PreferenceID = prefId, MenuItemID = CurrentMenuItem.MenuItemID } } ; sel.Save(); }); delPrefs.ForEach(delegate(int prefId) { hccMenuItemPreference del = hccMenuItemPreference.GetBy(prefId, CurrentMenuItem.MenuItemID); if (del != null) { del.Delete(); } }); //List<int> currentChildItems = CurrentMenuItem.GetChildren().Select(a => a.MenuItemID).ToList(); //List<int> selectedChildItems = lstMenuItems.GetSelectedKeys(); //List<int> delChildItems = currentChildItems.Except(selectedChildItems).ToList(); //selectedChildItems.ForEach(a => CurrentMenuItem.AddMenuItem(a, 1)); //delChildItems.ForEach(delegate(int itemId) //{ // hccMenuItem_MenuItems del = hccMenuItem_MenuItems.GetBy(CurrentMenuItem.MenuItemID, itemId); // if (del != null) del.Delete(); //}); //CurrentMenuItem.Save(); OnSaved(new ControlSavedEventArgs(CurrentMenuItem.MenuItemID)); Response.Redirect("~/WebModules/ShoppingCart/Admin/ItemManager.aspx", false); } catch (Exception) { throw; } }
protected void btnAddToCartClick(object sender, EventArgs e) { bool itemAdded = false; try { Button btnAddToCart = (Button)sender; ListViewDataItem dataItem = (ListViewDataItem)btnAddToCart.Parent; int menuItemId = int.Parse(lvwMealItems.DataKeys[dataItem.DataItemIndex].Value.ToString()); hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); hccCart userCart = hccCart.GetCurrentCart(); MembershipUser user = Helpers.LoggedUser; int profileId = GetProfileId(dataItem); int sizeId = GetSizeId(btnAddToCart); hccCartItem newItem = new hccCartItem { CartID = userCart.CartID, CreatedBy = (user == null ? Guid.Empty : (Guid)user.ProviderUserKey), CreatedDate = DateTime.Now, IsTaxable = menuItem.IsTaxEligible, ItemDesc = menuItem.Description, ItemPrice = hccMenuItem.GetItemPriceBySize(menuItem, sizeId), ItemTypeID = (int)Enums.CartItemType.AlaCarte, DeliveryDate = CurrentDeliveryDate, Meal_MenuItemID = menuItem.MenuItemID, Meal_MealSizeID = sizeId, Meal_ShippingCost = hccDeliverySetting.GetBy(menuItem.MealType).ShipCost, UserProfileID = profileId, Quantity = GetQuantity(dataItem), IsCompleted = false }; newItem.GetOrderNumber(userCart); List <CheckBox> prefChks = new List <CheckBox>(); List <RepeaterItem> rptPrefs = dataItem.FindControl("rptMealPrefs").Controls.OfType <RepeaterItem>().ToList(); rptPrefs.ForEach(delegate(RepeaterItem ri) { prefChks.AddRange(ri.Controls.OfType <CheckBox>().Where(a => a.Checked)); }); string prefsString = string.Empty; List <hccCartItemMealPreference> cartPrefs = new List <hccCartItemMealPreference>(); foreach (CheckBox chkPref in prefChks) { int prefId = int.Parse(chkPref.Attributes["value"]); hccPreference pref = hccPreference.GetById(prefId); if (pref != null) { if (string.IsNullOrWhiteSpace(prefsString)) { prefsString += pref.Name; } else { prefsString += ", " + pref.Name; } cartPrefs.Add(new hccCartItemMealPreference { CartItemID = newItem.CartItemID, PreferenceID = prefId }); } } //newItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)sizeId, menuItem.Name, GetMealSides(dataItem), prefsString, newItem.DeliveryDate, newItem.Quantity); newItem.ItemName = hccCartItem.BuildCartItemName(menuItem.MealType, (Enums.CartItemSize)sizeId, menuItem.Name, GetMealSides(dataItem), prefsString, newItem.DeliveryDate);//, newItem.Quantity hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, newItem.ItemName, profileId); if (existItem == null) { newItem.Save(); cartPrefs.ForEach(delegate(hccCartItemMealPreference cartPref) { cartPref.CartItemID = newItem.CartItemID; cartPref.Save(); }); } else { existItem.Quantity += newItem.Quantity; existItem.AdjustQuantity(existItem.Quantity); } AddCartALCMenuItem(dataItem, existItem ?? newItem, menuItem.MealTypeID); itemAdded = true; } catch (Exception ex) { throw ex; } if (itemAdded) { HealthyChef.Templates.HealthyChef.Controls.TopHeader header = (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1"); if (header != null) { header.SetCartCount(); } } }
void BindForm() { if (defaultMenuSelections.Count == 0) { defaultMenuSelections = hccProgramDefaultMenu.GetBy(CurrentCalendarId, CurrentProgramId); } List <DropDownList> ddls = new List <DropDownList>(); List <HtmlGenericControl> divDdls = new List <HtmlGenericControl>(); DailyNutrition totalNutInfo = new DailyNutrition { DayNumber = CurrentDay }; List <HtmlGenericControl> divItemContainers; string ddlBorderClass = string.Empty; List <hccAllergen> userAllergens; userAllergens = hccUserProfileAllergen.GetAllergensBy(CurrentCartItem.UserProfile.UserProfileID, true); BindDropDownLists(userAllergens); divItemContainers = pnlDefaultMenu.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divItemContainer").ToList(); divItemContainers.ForEach(delegate(HtmlGenericControl ctrl) { divDdls.AddRange(ctrl.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divDdl")); }); divDdls.ForEach(a => ddls.AddRange(a.Controls.OfType <DropDownList>())); int dailyDefaultsCount = defaultMenuSelections.Where(a => a.DayNumber == CurrentDay).Count(); if (dailyDefaultsCount == 0 || dailyDefaultsCount != ddls.Count) { lblFeedback.Text += "Not all default values have been created for the selected date and program combination. Select the default items on the Production Management -> Program Default Menus page, and press 'Save' to create the default items."; pnlDefaultMenu.Visible = false; } else { hccCartItemCalendar cartCalendar = hccCartItemCalendar.GetBy(this.PrimaryKeyIndex, CurrentCalendarId); defaultMenuSelections.ForEach(delegate(hccProgramDefaultMenu defaultSelection) { try { DropDownList ddl = ddls.Where(a => a.Attributes["day"] == defaultSelection.DayNumber.ToString() && a.Attributes["type"] == defaultSelection.MealTypeID.ToString() && a.Attributes["ord"] == defaultSelection.Ordinal.ToString()) .SingleOrDefault(); if (ddl != null) { int menuItemId = defaultSelection.MenuItemID; string value = menuItemId.ToString() + "-" + defaultSelection.MenuItemSizeID.ToString(); int DefaultMenuExceptID = 0; int cartcalendarid = 0; // bold face the default selection int defaultIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value)); ddl.Items[(defaultIndex <= -1 ? 0 : defaultIndex)].Attributes["class"] += "bold italic"; hccCartDefaultMenuException menuItemExc = hccCartDefaultMenuException.GetBy(defaultSelection.DefaultMenuID, cartCalendar.CartCalendarID); if (menuItemExc != null) { menuItemId = menuItemExc.MenuItemID; value = menuItemId.ToString() + "-" + menuItemExc.MenuItemSizeID.ToString(); DefaultMenuExceptID = menuItemExc.DefaultMenuExceptID; cartcalendarid = menuItemExc.CartCalendarID; } ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value)); ddl.Attributes.Add("defMenuId", defaultSelection.DefaultMenuID.ToString()); ddl.Attributes.Add("defMenuExceptionId", DefaultMenuExceptID.ToString()); ddl.Attributes.Add("defMenuCartCalendarId", cartcalendarid.ToString()); ddl.SelectedItem.Attributes["class"] += " bold"; HtmlGenericControl divItemContainer = (HtmlGenericControl)ddl.Parent.Parent; HtmlGenericControl divNuts = divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divNuts").SingleOrDefault(); HtmlGenericControl divAllrgs = divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divAllrgs").SingleOrDefault(); HtmlGenericControl divPrefs = divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divPrefs").SingleOrDefault(); if (menuItemId > 0) { hccMenuItem menuItem = null; if (menuItemExc == null) { if (defaultSelection.MenuItemID > 0) { menuItem = hccMenuItem.GetById(defaultSelection.MenuItemID); } } else if (menuItemExc.MenuItemID > 0) { menuItem = hccMenuItem.GetById(menuItemExc.MenuItemID); } if (menuItem != null) { // nutrition info if (divNuts != null) { string nutInfo = string.Empty; hccMenuItemNutritionData menuNut = hccMenuItemNutritionData.GetBy(menuItem.MenuItemID); if (menuNut != null) { nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2}, Carbohydrates: {3}, Fiber: {4},Sodium: {5}", menuNut.Calories.ToString("f2"), menuNut.TotalFat.ToString("f2"), menuNut.Protein.ToString("f2"), menuNut.TotalCarbohydrates.ToString("f2"), menuNut.DietaryFiber.ToString("f2"), menuNut.Sodium.ToString("f2")); divNuts.InnerHtml = nutInfo; totalNutInfo.Calories += menuNut.Calories; totalNutInfo.Carbs += menuNut.TotalCarbohydrates; totalNutInfo.Fat += menuNut.TotalFat; totalNutInfo.Fiber += menuNut.DietaryFiber; totalNutInfo.Protein += menuNut.Protein; totalNutInfo.Sodium += menuNut.Sodium; } else { nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2}, Carbohydrates: {3}, Fiber: {4},Sodium: {5}", 0, 0, 0, 0, 0, 0); } divNuts.InnerText = nutInfo; } // allergen displays List <hccAllergen> selectItemAllergens = new List <hccAllergen>(); string allrgsList = string.Empty; allrgsList = "Allergens: " + menuItem.AllergensList; selectItemAllergens = menuItem.GetAllergens(); if (divAllrgs != null) { divAllrgs.InnerText = allrgsList; } List <hccAllergen> matchedAllergens = selectItemAllergens.Intersect(userAllergens).ToList(); if (matchedAllergens.Count > 0) { ddl.SelectedItem.Attributes["class"] += " bold"; ddlBorderClass = "redBorder"; } else { if (menuItemExc == null) { ddlBorderClass = "greenBorder"; } else { ddlBorderClass = "blueBorder"; } } // preferences List <hccPreference> itemPrefs = menuItem.GetPreferences(); if (itemPrefs.Count > 0 && divPrefs != null) { itemPrefs.ForEach(delegate(hccPreference pref) { HtmlInputCheckBox chkPref = new HtmlInputCheckBox(); chkPref.Value = pref.PreferenceID.ToString(); Label lblPref = new Label(); lblPref.Text = pref.Name; divPrefs.Controls.Add(chkPref); divPrefs.Controls.Add(lblPref); hccCartMenuExPref cartMenuExPref = hccCartMenuExPref.GetById(cartCalendar.CartItemID, defaultSelection.DayNumber); if (cartMenuExPref != null) { if (cartMenuExPref.IsModified) { if (menuItemExc != null) { hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID); if (excPref != null) { chkPref.Checked = true; } } } //hccCartItem cartItem = hccCartItem.GetById(cartCalendar.CartItemID); //if (cartItem != null) //{ // if (Convert.ToBoolean(cartItem.IsModified)) // { // hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID); // if (excPref != null) // { // chkPref.Checked = true; // } // } // else // { // hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID); // if (excPref != null) // chkPref.Checked = true; // hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID); // if (programmenuexpref != null) // chkPref.Checked = true; // } //} } else { //hccCartItem cartItem = hccCartItem.GetById(cartCalendar.CartItemID); //if (cartItem != null) //{ // if (!Convert.ToBoolean(cartItem.IsModified)) // { // hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID); // if (programmenuexpref != null) // chkPref.Checked = true; // } //} hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID); if (programmenuexpref != null) { chkPref.Checked = true; } } }); } } else { divNuts.InnerText = string.Empty; divPrefs.InnerText = string.Empty; divAllrgs.InnerText = string.Empty; } ddl.CssClass = "mealItemDdl " + ddlBorderClass; } } } catch (Exception ex) { throw ex; } }); if (totalNutInfo == null) { divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Cals##", "0"); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fats##", "0"); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Ptrns##", "0"); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Carbs##", "0"); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fbrs##", "0"); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Sod##", "0"); } else { divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Cals##", totalNutInfo.Calories.ToString("f2")); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fats##", totalNutInfo.Fat.ToString("f2")); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Ptrns##", totalNutInfo.Protein.ToString("f2")); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Carbs##", totalNutInfo.Carbs.ToString("f2")); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fbrs##", totalNutInfo.Fiber.ToString("f2")); divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Sod##", totalNutInfo.Sodium.ToString("f2")); } divTotalNutrition.Visible = true; } }
protected override void LoadForm() { try { BindddlMealType(); CurrentMenuItem = hccMenuItem.GetById(this.PrimaryKeyIndex); DisplayMenuItemOptions(CurrentMenuItem); if (CurrentMenuItem == null) { CurrentMenuItem = new hccMenuItem(); } if (CurrentMenuItem.IsRetired) { btnDeactivate.Text = "Reactivate"; } else { btnDeactivate.Text = "Retire"; } txtMenuItemName.Text = CurrentMenuItem.Name; txtDescription.Text = CurrentMenuItem.Description; chkIsTaxEligible.Checked = CurrentMenuItem.IsTaxEligible; if (CurrentMenuItem.ImageUrl != null) { MenuItemImageName.Value = CurrentMenuItem.ImageUrl.Split('/')[2]; } else { MenuItemImageName.Value = string.Empty; } chkUsePriceChild.Checked = CurrentMenuItem.UseCostChild; txtCostChild.Text = CurrentMenuItem.CostChild.ToString("f2"); chkUsePriceSmall.Checked = CurrentMenuItem.UseCostSmall; txtCostSmall.Text = CurrentMenuItem.CostSmall.ToString("f2"); chkUsePriceRegular.Checked = CurrentMenuItem.UseCostRegular; txtCostRegular.Text = CurrentMenuItem.CostRegular.ToString("f2"); chkUsePriceLarge.Checked = CurrentMenuItem.UseCostLarge; txtCostLarge.Text = CurrentMenuItem.CostLarge.ToString("f2"); ddlMealType.SelectedIndex = ddlMealType.Items.IndexOf(ddlMealType.Items.FindByValue(((int)CurrentMenuItem.MealType).ToString())); hccMenuItemNutritionData nutData = hccMenuItemNutritionData.GetBy(CurrentMenuItem.MenuItemID); if (nutData != null) { txtCalories.Text = nutData.Calories.ToString(); txtDietaryFiber.Text = nutData.DietaryFiber.ToString(); txtProtein.Text = nutData.Protein.ToString(); txtTotalCarbohydrates.Text = nutData.TotalCarbohydrates.ToString(); txtTotalFat.Text = nutData.TotalFat.ToString(); txtSodium.Text = nutData.Sodium.ToString(); } BindlstIngredients(); BindlstPreferences(); BindgvwItemUsage(); SetButtons(); } catch (Exception) { throw; } }
List <Day> BindWeeklyGlance(List <hccProgramDefaultMenu> defaultMenuSelections, int numDaysPerWeek) { int i; for (i = 1; i <= numDaysPerWeek; i++) { StringBuilder sb = new StringBuilder(); int lastTypeId = 0; defaultMenuSelections.Where(a => a.DayNumber == i) .OrderBy(a => a.MealTypeID).ToList().ForEach(delegate(hccProgramDefaultMenu defaultSelection) { int menuItemId = defaultSelection.MenuItemID; int menuItemSizeId = defaultSelection.MenuItemSizeID; //hccProductionCalendar prodCal = hccProductionCalendar.GetBy(CurrentCartItem.DeliveryDate); hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(this.PrimaryKeyIndex, CurrentCalendarId); hccCartDefaultMenuException menuItemExc = hccCartDefaultMenuException.GetBy(defaultSelection.DefaultMenuID, cartCal.CartCalendarID); string prefString = string.Empty; if (menuItemExc != null) { menuItemId = menuItemExc.MenuItemID; menuItemSizeId = menuItemExc.MenuItemSizeID; prefString = hccCartDefaultMenuExPref.GetPrefsBy(menuItemExc.DefaultMenuExceptID) .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((a, b) => a + ", " + b); } if (menuItemId > 0) { hccMenuItem menuItem = hccMenuItem.GetById(menuItemId); if (defaultSelection.MealTypeID != lastTypeId) { lastTypeId = defaultSelection.MealTypeID; sb.Append("<span class='label'>" + ((Enums.MealTypes)lastTypeId).ToString() + "</span><br />"); } if (menuItem != null) { sb.Append(menuItem.Name); } if (((Enums.CartItemSize)menuItemSizeId) != Enums.CartItemSize.NoSize) { sb.Append(" - " + Enums.GetEnumDescription(((Enums.CartItemSize)menuItemSizeId))); } // prefs if (!string.IsNullOrWhiteSpace(prefString)) { sb.Append(" - " + prefString); } try { var t = defaultMenuSelections[defaultMenuSelections.IndexOf(defaultSelection) + 1]; if (t.MealTypeID == lastTypeId) { sb.Append(", "); } else { sb.Append("<p></p>"); } } catch { } } else { sb.Append("<p></p>"); } }); days.Add(new Day { DayTitle = "Day: " + i.ToString(), DayNumber = i, DayInfo = sb.ToString().Trim().TrimEnd(',') }); } lvwWeekGlance.DataSource = days; lvwWeekGlance.DataBind(); return(days); }
void lstSelectedItems_DataBound(object sender, EventArgs e) { ListBox lstSelectedItems = (ListBox)sender; List <ListItem> items = lstSelectedItems.Items.OfType <ListItem>().ToList(); items.ForEach(delegate(ListItem item) { if (EntityType == typeof(hccMenuItem)) { hccMenuItem t1 = hccMenuItem.GetById(int.Parse(item.Value)); if (t1.IsRetired) { item.Attributes.Add("class", "retired"); } else { item.Attributes.Add("class", "active"); } List <hccIngredient> ings = t1.GetIngredients(); ings.ForEach(delegate(hccIngredient ing) { if (ing.IsRetired) { item.Attributes.Add("class", "retired_child"); } }); } else if (EntityType == typeof(hccPreference)) { hccPreference t1 = hccPreference.GetById(int.Parse(item.Value)); if (t1.IsRetired) { item.Text += " - Retired"; item.Attributes.Add("class", "retired"); } else { item.Attributes.Add("class", "active"); } } else if (EntityType == typeof(hccAllergen)) { hccAllergen t1 = hccAllergen.GetById(int.Parse(item.Value)); if (!t1.IsActive) { item.Text += " - Retired"; item.Attributes.Add("class", "retired"); } else { item.Attributes.Add("class", "active"); } } else if (EntityType == typeof(hccIngredient)) { hccIngredient t1 = hccIngredient.GetById(int.Parse(item.Value)); if (t1.IsRetired) { item.Text += " - Retired"; item.Attributes.Add("class", "retired"); } else { item.Attributes.Add("class", "active"); } } else {//do nothing } }); }