Imports BVSoftware.BVC.Core Public Class discounts_edit Inherits BaseAdminPage Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents lstApplyTo As BVSoftware.WebControls.SelectDropDownList Protected WithEvents btnCancel As System.Web.UI.WebControls.ImageButton Protected WithEvents btnSave As System.Web.UI.WebControls.ImageButton Protected WithEvents AmountField As System.Web.UI.WebControls.TextBox Protected WithEvents lstAmountType As BVSoftware.WebControls.SelectDropDownList Protected WithEvents StartDateField As BVSoftware.WebControls.DropdownDate Protected WithEvents EndDateField As BVSoftware.WebControls.DropdownDate Protected WithEvents QualifyQtyField As System.Web.UI.WebControls.TextBox Protected WithEvents CouponCodeField As System.Web.UI.WebControls.TextBox Protected WithEvents chkRequiredCoupon As System.Web.UI.WebControls.CheckBox Protected WithEvents QualifyTotalField As System.Web.UI.WebControls.TextBox Protected WithEvents MaxUsesPerCustomerField As System.Web.UI.WebControls.TextBox Protected WithEvents chkExclusiveOffer As System.Web.UI.WebControls.CheckBox Protected WithEvents inProducts As System.Web.UI.WebControls.ListBox Protected WithEvents btnAddProducts As System.Web.UI.WebControls.ImageButton Protected WithEvents btnDelProducts As System.Web.UI.WebControls.ImageButton Protected WithEvents inNOTProducts As System.Web.UI.WebControls.ListBox Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Protected WithEvents trProducts As System.Web.UI.HtmlControls.HtmlTableRow Protected WithEvents lstShipMethodID As BVSoftware.WebControls.SelectDropDownList Protected WithEvents trShipMethod As System.Web.UI.HtmlControls.HtmlTableRow Protected WithEvents ProductPicker1 As ProductPicker #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load BVC2004Store.CheckThisPage(Security.RolePermission.LoginToAdmin) BVC2004Store.CheckThisPage(Security.RolePermission.AccessProductArea) If Not Page.IsPostBack Then MetaKeywordsControl.Content = WebAppSettings.MetaKeywords MetaDescriptionControl.Content = WebAppSettings.MetaDescription Me.StartDateField.SetYearRange(Date.Now.AddYears(-50).Year, Date.Now.AddYears(50).Year) Me.EndDateField.SetYearRange(Date.Now.AddYears(-50).Year, Date.Now.AddYears(50).Year) If Request.Params("id") Is Nothing Then msg.ShowError("No Discount ID was found!") Else ViewState("ID") = Request.Params("ID") End If PopulateShipMethodList() LoadDiscount() End If DisplayAppropriateControls() End Sub Private Sub PopulateShipMethodList() Me.lstShipMethodID.Items.Clear() Me.lstShipMethodID.Items.Add(New ListItem("- All Shipping Methods -", 0)) Dim dtMethods As DataTable = ShippingServices.GetAllShippingMethods() If Not dtMethods Is Nothing Then For i As Integer = 0 To dtMethods.Rows.Count - 1 Me.lstShipMethodID.Items.Add(New ListItem(dtMethods.Rows(i).Item("Name"), dtMethods.Rows(i).Item("id"))) Next End If End Sub Private Sub LoadDiscount() Dim discountID As Integer = ViewState("ID") If discountID > 0 Then Dim d As Discounting.Discount = DiscountingServices.Discounts.GetByID(discountID) If Not d Is Nothing Then Me.lstApplyTo.SelectByValue(d.ApplyTo) Me.lstAmountType.SelectByValue(d.AmountType) Me.AmountField.Text = d.Amount Me.StartDateField.SelectedDate = d.StartDate Me.EndDateField.SelectedDate = d.EndDate Me.QualifyQtyField.Text = d.QualifyQty Me.QualifyTotalField.Text = d.QualifyTotal Me.chkRequiredCoupon.Checked = d.RequiresCoupon Me.CouponCodeField.Text = d.CouponCode.Trim.ToUpper Me.MaxUsesPerCustomerField.Text = d.MaxUsesPerCustomer Me.chkExclusiveOffer.Checked = d.ExclusiveOffer If d.ApplyTo = Discounting.DiscountType.Product Then LoadProducts() End If Me.lstShipMethodID.SelectByValue(d.ShipMethodID) Else msg.ShowError("There was an error while attemping to load the discount.") End If End If End Sub Private Sub DisplayAppropriateControls() Select Case CType(Me.lstApplyTo.SelectedValue, Discounting.DiscountType) Case Discounting.DiscountType.Order Me.trProducts.Visible = False Me.trShipMethod.Visible = False Case Discounting.DiscountType.Product Me.trProducts.Visible = True Me.trShipMethod.Visible = False Case Discounting.DiscountType.ShippingMethod Me.trProducts.Visible = False Me.trShipMethod.Visible = True End Select End Sub Sub Save() Me.CouponCodeField.Text = Me.CouponCodeField.Text.ToUpper msg.Clear() Dim d As Discounting.Discount = DiscountingServices.Discounts.GetByID(ViewState("ID")) If Not d Is Nothing Then Try d.Amount = Decimal.Parse(Me.AmountField.Text) d.AmountType = Me.lstAmountType.SelectedValue d.ApplyTo = Me.lstApplyTo.SelectedValue d.CouponCode = Me.CouponCodeField.Text.Trim.ToUpper d.EndDate = Me.EndDateField.SelectedDate d.EndDate = d.EndDate.AddDays(1) d.EndDate = d.EndDate.AddSeconds(-1) d.StartDate = Me.StartDateField.SelectedDate d.ExclusiveOffer = Me.chkExclusiveOffer.Checked d.MaxUsesPerCustomer = Integer.Parse(Me.MaxUsesPerCustomerField.Text) d.QualifyQty = Integer.Parse(Me.QualifyQtyField.Text) d.QualifyTotal = Decimal.Parse(Me.QualifyTotalField.Text) d.RequiresCoupon = Me.chkRequiredCoupon.Checked d.ShipMethodID = Me.lstShipMethodID.SelectedValue If DiscountingServices.Discounts.Update(d) = True Then msg.ShowOK("Changes Saved!") Else msg.ShowWarning("The system was unable to update this discount.") End If Catch ex As Exception EventLog.LogEvent(ex) msg.ShowException(ex) End Try Else msg.ShowError("There was an error while attemping to load the discount for save.") End If End Sub Sub LoadProducts() inProducts.Items.Clear() inProducts.DataSource = DiscountingServices.Discounts.GetProductsForDiscount(ViewState("ID")) inProducts.DataTextField = "ProductName" inProducts.DataValueField = "id" inProducts.DataBind() End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnCancel.Click If Request.Params("doc") = 1 Then DiscountingServices.Discounts.Delete(Request.Params("id")) End If Response.Redirect("products_discounts.aspx") End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSave.Click Save() Response.Redirect("Products_Discounts.aspx") End Sub Private Sub lstApplyTo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstApplyTo.SelectedIndexChanged DisplayAppropriateControls() End Sub Private Sub btnAddProducts_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAddProducts.Click 'For i As Integer = 0 To Me.ProductPicker1.ProductList.Items.Count - 1 ' If ProductPicker1.ProductList.Items(i).Checked = True Then ' DiscountingServices.Discounts.AddProductToDiscount(ProductPicker1.ProductList.Items(i).ItemValue, ViewState("ID")) ' End If 'Next For i As Integer = 0 To Me.ProductPicker1.SelectedProducts.Count - 1 DiscountingServices.Discounts.AddProductToDiscount(ProductPicker1.SelectedProducts(i), ViewState("ID")) Next LoadProducts() End Sub Private Sub btnDelProducts_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelProducts.Click Dim li As ListItem For Each li In inProducts.Items If li.Selected = True Then DiscountingServices.Discounts.RemoveProductFromDiscount(li.Value, ViewState("ID")) End If Next LoadProducts() End Sub End Class