void DisplayDailyPrice(object sender, EventArgs e) { if (ddlPlans.SelectedIndex > 0 && ddlOptions.SelectedIndex > 0) { hccProgramPlan plan = hccProgramPlan.GetById(int.Parse(ddlPlans.SelectedValue)); hccProgram program = hccProgram.GetById(int.Parse(ddlPrograms.SelectedValue)); hccProgramOption option = hccProgramOption.GetBy(program.ProgramID).SingleOrDefault(a => a.ProgramOptionID == int.Parse(ddlOptions.SelectedValue)); if (plan != null && option != null) { int numDays = plan.NumDaysPerWeek * plan.NumWeeks; decimal dailyPrice = plan.PricePerDay + option.OptionValue; decimal itemPrice = numDays * dailyPrice; lblPlanPrice.Text = string.Format("Daily Price: {0}; Total Price: {1}", dailyPrice.ToString("c"), itemPrice.ToString("c")); } else { lblPlanPrice.Text = string.Empty; } } else { lblPlanPrice.Text = string.Empty; } }
void rpet_plan_options_ItemDataBound(object sender, RepeaterItemEventArgs e) { hccProgramOption progOpt = (hccProgramOption)e.Item.DataItem; Label lblOptionPrice = (Label)e.Item.FindControl("lblOptionPrice"); if (lblOptionPrice != null) { if (progOpt.OptionValue == 0) { lblOptionPrice.Text = string.Format("{0:f2}", progOpt.OptionValue); } else if (progOpt.OptionValue < 0) { lblOptionPrice.Text = "-$" + string.Format("{0:f2}", Math.Abs(progOpt.OptionValue)); } else if (progOpt.OptionValue > 0) { lblOptionPrice.Text = "+$" + string.Format("{0:f2}", progOpt.OptionValue); } } }
protected override void SaveForm() { try { CurrentProgram = hccProgram.GetById(this.PrimaryKeyIndex); if (CurrentProgram == null) { CurrentProgram = new hccProgram { IsActive = true } } ; CurrentProgram.Name = txtProgramName.Text.Trim(); CurrentProgram.Description = txtProgramDesc.Text.Trim(); if (PagePicker1.SelectedNavigationId > 0) { CurrentProgram.MoreInfoNavID = PagePicker1.SelectedNavigationId; } else { CurrentProgram.MoreInfoNavID = 0; } if (!String.IsNullOrWhiteSpace(ImagePicker1.ImagePath)) { CurrentProgram.ImagePath = ImagePicker1.ImagePath; } CurrentProgram.DisplayOnWebsite = chkDisplayOnWebsite.Checked; if (this.PrimaryKeyIndex == 0) { CurrentProgram.Save(); this.PrimaryKeyIndex = CurrentProgram.ProgramID; } //set req meal type vals List <hccProgramMealType> mt = hccProgramMealType.GetBy(CurrentProgram.ProgramID); foreach (GridViewRow row in gvwMealTypes.Rows) { if (row.RowType == DataControlRowType.DataRow) { int rowMealTypeId = int.Parse(gvwMealTypes.DataKeys[row.RowIndex].Value.ToString()); hccProgramMealType progMealType = mt.Where(a => a.ProgramID == this.PrimaryKeyIndex && a.MealTypeID == rowMealTypeId).SingleOrDefault(); if (progMealType == null) { progMealType = new hccProgramMealType { ProgramID = this.PrimaryKeyIndex, MealTypeID = rowMealTypeId, RequiredQuantity = 0 } } ; TextBox txtReqQuantity = (TextBox)row.FindControl("txtReqQuantity"); if (txtReqQuantity != null) { progMealType.RequiredQuantity = string.IsNullOrWhiteSpace(txtReqQuantity.Text.Trim()) ? 0 : int.Parse(txtReqQuantity.Text.Trim()); } progMealType.Save(); } } List <hccProgramOption> cr = hccProgramOption.GetBy(CurrentProgram.ProgramID); var optionValue = 0m; hccProgramOption opt; try { opt = cr.FirstOrDefault(x => x.OptionIndex == 1); //hccProgramOption opt1 = cr.SingleOrDefault(a => a.OptionIndex == 1); optionValue = txtCalRange1Value.Text.Trim() != "" ? decimal.Parse(txtCalRange1Value.Text.Trim()) : 0m; if (opt == null) { opt = new hccProgramOption { OptionIndex = 1, ProgramID = CurrentProgram.ProgramID, OptionText = txtCalRange1Text.Text.Trim(), OptionValue = optionValue, IsDefault = chkIsDefault1.Checked }; //opt.Save(); } else { opt.OptionIndex = 1; opt.ProgramID = CurrentProgram.ProgramID; opt.OptionText = txtCalRange1Text.Text.Trim(); opt.OptionValue = optionValue; opt.IsDefault = chkIsDefault1.Checked; }; opt.Save(); } catch { } try { opt = cr.FirstOrDefault(x => x.OptionIndex == 2); //hccProgramOption opt2 = cr.SingleOrDefault(a => a.OptionIndex == 2); optionValue = txtCalRange2Value.Text.Trim() != "" ? decimal.Parse(txtCalRange2Value.Text.Trim()) : 0m; if (opt == null) { opt = new hccProgramOption { OptionIndex = 2, ProgramID = CurrentProgram.ProgramID, OptionText = txtCalRange2Text.Text.Trim(), OptionValue = optionValue, IsDefault = chkIsDefault2.Checked }; } else { opt.OptionIndex = 2; opt.ProgramID = CurrentProgram.ProgramID; opt.OptionText = txtCalRange2Text.Text.Trim(); opt.OptionValue = optionValue; opt.IsDefault = chkIsDefault2.Checked; }; opt.Save(); } catch { } try { //hccProgramOption opt3 = cr.SingleOrDefault(a => a.OptionIndex == 3); opt = cr.FirstOrDefault(x => x.OptionIndex == 3); optionValue = txtCalRange3Value.Text.Trim() != "" ? decimal.Parse(txtCalRange3Value.Text.Trim()) : 0m; if (opt == null) { opt = new hccProgramOption { OptionIndex = 3, ProgramID = CurrentProgram.ProgramID, OptionText = txtCalRange3Text.Text.Trim(), OptionValue = optionValue, IsDefault = chkIsDefault3.Checked }; //opt3.Save(); } else { opt.OptionIndex = 3; opt.ProgramID = CurrentProgram.ProgramID; opt.OptionText = txtCalRange3Text.Text.Trim(); opt.OptionValue = optionValue; opt.IsDefault = chkIsDefault3.Checked; }; opt.Save(); } catch { } try { opt = cr.FirstOrDefault(a => a.OptionIndex == 4); optionValue = txtCalRange4Value.Text.Trim() != "" ? decimal.Parse(txtCalRange4Value.Text.Trim()) : 0m; if (opt == null) { opt = new hccProgramOption { OptionIndex = 4, ProgramID = CurrentProgram.ProgramID, OptionText = txtCalRange4Text.Text.Trim(), OptionValue = optionValue, IsDefault = chkIsDefault4.Checked }; //opt4.Save(); } else { opt.OptionIndex = 4; opt.ProgramID = CurrentProgram.ProgramID; opt.OptionText = txtCalRange4Text.Text.Trim(); opt.OptionValue = optionValue; opt.IsDefault = chkIsDefault4.Checked; }; opt.Save(); } catch { } try { opt = cr.FirstOrDefault(a => a.OptionIndex == 5); optionValue = txtCalRange5Value.Text.Trim() != "" ? decimal.Parse(txtCalRange5Value.Text.Trim()) : 0m; if (opt == null) { opt = new hccProgramOption { OptionIndex = 5, ProgramID = CurrentProgram.ProgramID, OptionText = txtCalRange5Text.Text.Trim(), OptionValue = optionValue, IsDefault = chkIsDefault5.Checked }; //opt5.Save(); } else { opt.OptionIndex = 5; opt.ProgramID = CurrentProgram.ProgramID; opt.OptionText = txtCalRange5Text.Text.Trim(); opt.OptionValue = optionValue; opt.IsDefault = chkIsDefault5.Checked; }; opt.Save(); } catch { } CurrentProgram.Save(); this.OnSaved(new ControlSavedEventArgs(CurrentProgram.ProgramID)); } catch { throw; } Response.Redirect("~/WebModules/ShoppingCart/Admin/ProgramManager.aspx", false); }
//public string GetProgramImage(string programName) //{ // var fileName = "/userfiles/images/programs/" + programName.Replace(" ", "-") + ".jpg"; // if (!File.Exists(Server.MapPath(fileName))) // return ""; // return "<img width='150' height='126' alt='' src='/userfiles/images/programs/" + programName.Replace(" ", "-") + ".jpg' class='left' />"; //} protected void btn_add_to_cart_Click(object sender, EventArgs e) { try { Page.Validate("AddToCartGroup"); if (Page.IsValid) { hccCart userCart = hccCart.GetCurrentCart(); //Define form variables int itemId = Convert.ToInt32(Request.Form["plan_type"]); int optionId = ((Request.Form["plan_option"] == null) ? 0 : Convert.ToInt32(Request.Form["plan_option"])); //Select chosen Program Plan hccProgramPlan plan = hccProgramPlan.GetById(itemId); if (plan == null) { throw new Exception("ProgramPlan not found: " + itemId.ToString()); } hccProgram prog = hccProgram.GetById(plan.ProgramID); hccProgramOption option = hccProgramOption.GetBy(plan.ProgramID).Where(a => a.ProgramOptionID == optionId).SingleOrDefault(); int numDays = plan.NumDaysPerWeek * plan.NumWeeks; int numMeals = numDays * plan.MealsPerDay; decimal dailyPrice = plan.PricePerDay + option.OptionValue; decimal itemPrice = numDays * dailyPrice; DateTime deliveryDate = DateTime.Parse(ddl_delivery_date.SelectedValue); MembershipUser user = Helpers.LoggedUser; hccCartItem newItem = new hccCartItem { CartID = userCart.CartID, CreatedBy = (user == null ? Guid.Empty : (Guid)user.ProviderUserKey), CreatedDate = DateTime.Now, IsTaxable = plan.IsTaxEligible, ItemDesc = plan.Description, NumberOfMeals = numMeals, //ItemName = string.Format("{0} - {1} - {2} - {3} & {4}", (prog == null ? string.Empty : prog.Name), plan.Name, option.OptionText, deliveryDate.ToShortDateString(), numMeals), ItemName = string.Format("{0} - {1} - {2} - {3}", (prog == null ? string.Empty : prog.Name), plan.Name, option.OptionText, deliveryDate.ToShortDateString()), ItemPrice = itemPrice, ItemTypeID = (int)Enums.CartItemType.DefinedPlan, Plan_IsAutoRenew = false, //chx_renew.Checked, Plan_PlanID = itemId, Plan_ProgramOptionID = optionId, DeliveryDate = deliveryDate, Quantity = int.Parse(txt_quantity.Text), UserProfileID = ((ddlProfiles.Items.Count == 0) ? 0 : Convert.ToInt32(ddlProfiles.SelectedValue)), IsCompleted = false }; Meals obj = new Meals(); obj.CartID = newItem.CartID; obj.MealCount = newItem.NumberOfMeals; obj.NoOfWeeks = plan.NumWeeks; var ID = obj.CartID; var Meal = obj.MealCount; var Weeks = obj.NoOfWeeks; HealthyChef.Templates.HealthyChef.Controls.TopHeader header = (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1"); if (header != null) { header.MealsCountVal(ID, Meal); } newItem.GetOrderNumber(userCart); int profileId = 0; if (divProfiles.Visible) { profileId = int.Parse(ddlProfiles.SelectedValue); } else { if (CartUserASPNetId != Guid.Empty) { profileId = hccUserProfile.GetParentProfileBy(CartUserASPNetId).UserProfileID; } } if (profileId > 0) { newItem.UserProfileID = profileId; } hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, newItem.ItemName, profileId); if (existItem == null) { newItem.Save(); hccProductionCalendar cal; for (int i = 0; i < plan.NumWeeks; i++) { cal = hccProductionCalendar.GetBy(newItem.DeliveryDate.AddDays(7 * i)); if (cal != null) { hccCartItemCalendar cartCal = new hccCartItemCalendar { CalendarID = cal.CalendarID, CartItemID = newItem.CartItemID }; cartCal.Save(); } else { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise( "No production calendar found for Delivery Date: " + newItem.DeliveryDate.AddDays(7 * i).ToShortDateString(), this); } } } else { existItem.AdjustQuantity(existItem.Quantity + newItem.Quantity); } //Recurring Order Record if (cbxRecurring.Checked) { List <hccRecurringOrder> lstRo = null; if (Session["autorenew"] != null) { lstRo = ((List <hccRecurringOrder>)Session["autorenew"]); } else { lstRo = new List <hccRecurringOrder>(); } //var filter = cartItemsRecurring.Where(ci => ci.ItemType == Enums.CartItemType.DefinedPlan); //for(var i = 0; i < int.Parse(txt_quantity.Text); i++) //{ lstRo.Add(new hccRecurringOrder { CartID = userCart.CartID, CartItemID = newItem.CartItemID, UserProfileID = newItem.UserProfileID, AspNetUserID = userCart.AspNetUserID, PurchaseNumber = userCart.PurchaseNumber, TotalAmount = newItem.ItemPrice }); Session["autorenew"] = lstRo; //} } HealthyChef.Templates.HealthyChef.Controls.TopHeader header1 = (HealthyChef.Templates.HealthyChef.Controls.TopHeader) this.Page.Master.FindControl("TopHeader1"); if (header1 != null) { header.SetCartCount(); } //Redirect user to Program Selection screen Response.Redirect("~/meal-programs.aspx"); //multi_programs.ActiveViewIndex = 0; //litMessage.Text = "Your Meal Program has been added to your cart."; } else { } } catch (Exception ex) { throw ex; } }
protected override void SaveForm() { try { hccCart userCart = hccCart.GetById(this.PrimaryKeyIndex); MembershipUser user = Membership.GetUser(userCart.AspNetUserID); if (user != null) { hccProgramPlan selPlan = hccProgramPlan.GetById(int.Parse(ddlPlans.SelectedValue)); if (selPlan != null) { List <hccProgramOption> progOptions = hccProgramOption.GetBy(selPlan.ProgramID); hccProgramOption option = progOptions.Where(a => a.ProgramOptionID == (int.Parse(ddlOptions.SelectedValue))).SingleOrDefault(); hccProgram prog = hccProgram.GetById(selPlan.ProgramID); int numDays = selPlan.NumDaysPerWeek * selPlan.NumWeeks; decimal dailyPrice = selPlan.PricePerDay + option.OptionValue; decimal itemPrice = numDays * dailyPrice; int profileId = 0; //bool autoRenew = chkAutoRenew.Checked; string itemFullName = string.Empty; DateTime startDate = DateTime.Parse(ddlStartDates.SelectedItem.Text); itemFullName = string.Format("{0} - {1} - {2} - {3}", prog == null ? string.Empty : prog.Name, selPlan.Name, option.OptionText, startDate.ToShortDateString()); if (divProfiles.Visible) { profileId = int.Parse(ddlProfiles.SelectedValue); } else { profileId = hccUserProfile.GetParentProfileBy(userCart.AspNetUserID.Value).UserProfileID; } if (userCart != null && selPlan != null) { int currentQty = int.Parse(txtQuantity.Text.Trim()); hccCartItem existItem = hccCartItem.GetBy(userCart.CartID, itemFullName, profileId); if (existItem == null) { hccCartItem planItem = new hccCartItem { CartID = userCart.CartID, CreatedBy = (Guid)Membership.GetUser().ProviderUserKey, CreatedDate = DateTime.Now, IsTaxable = selPlan.IsTaxEligible, ItemDesc = selPlan.Description, ItemName = itemFullName, ItemPrice = itemPrice, ItemTypeID = (int)Enums.CartItemType.DefinedPlan, Plan_IsAutoRenew = false, //autoRenew, Plan_PlanID = selPlan.PlanID, Plan_ProgramOptionID = option.ProgramOptionID, DeliveryDate = startDate, UserProfileID = profileId, Quantity = currentQty, IsCompleted = false }; planItem.GetOrderNumber(userCart); planItem.Save(); hccProductionCalendar cal; for (int i = 0; i < selPlan.NumWeeks; i++) { cal = hccProductionCalendar.GetBy(planItem.DeliveryDate.AddDays(7 * i)); if (cal != null) { hccCartItemCalendar cartCal = new hccCartItemCalendar { CalendarID = cal.CalendarID, CartItemID = planItem.CartItemID, IsFulfilled = false }; cartCal.Save(); } else { BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise( "No production calendar found for Delivery Date: " + planItem.DeliveryDate.AddDays(7 * i).ToShortDateString(), this); } } if (cbxRecurring.Checked) { var cartItemsRecurring = hccCartItem.GetBy(userCart.CartID); var filter = cartItemsRecurring.Where(ci => ci.ItemType == Enums.CartItemType.DefinedPlan); var roItem = new hccRecurringOrder(); roItem.CartID = planItem.CartID; roItem.CartItemID = planItem.CartItemID; roItem.UserProfileID = planItem.UserProfileID; roItem.AspNetUserID = userCart.AspNetUserID; roItem.PurchaseNumber = userCart.PurchaseNumber; roItem.TotalAmount = Math.Round(Convert.ToDecimal(Convert.ToDouble(planItem.ItemPrice) - Convert.ToDouble(planItem.ItemPrice) * 0.05), 2); roItem.Save(); if (planItem != null) { planItem.Plan_IsAutoRenew = true; planItem.Save(); } //foreach (var recurringOrder in filter.Select(item => new hccRecurringOrder //{ // CartID = item.CartID, // CartItemID = item.CartItemID, // UserProfileID = item.UserProfileID, // AspNetUserID = userCart.AspNetUserID, // PurchaseNumber = userCart.PurchaseNumber, // TotalAmount = userCart.TotalAmount //})) //{ // recurringOrder.Save(); //} } OnSaved(new ControlSavedEventArgs(planItem.CartItemID)); cbxRecurring.Checked = false; } else { if (existItem.AdjustQuantity(existItem.Quantity + currentQty)) { OnSaved(new ControlSavedEventArgs(existItem.CartItemID)); } cbxRecurring.Checked = false; } } } } //Page.Response.Redirect(Page.Request.Url.ToString()+ "#tabs9", true); } catch (Exception) { throw; } }