Imports BVSoftware.BVC.Core Public Class products_products Inherits BaseAdminPage Protected WithEvents btnAddProduct As System.Web.UI.WebControls.ImageButton Protected WithEvents DeleteButton As MetaBuilders.WebControls.ConfirmedImageButton Protected WithEvents FirstFocus1 As MetaBuilders.WebControls.FirstFocus Protected WithEvents DefaultButtons1 As MetaBuilders.WebControls.DefaultButtons Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents lstProductTypes As System.Web.UI.WebControls.DropDownList Protected WithEvents btnEdit As System.Web.UI.WebControls.ImageButton Protected WithEvents btnDelete As MetaBuilders.WebControls.ConfirmedImageButton Protected WithEvents NewIDField As System.Web.UI.WebControls.TextBox Protected WithEvents btnClone As System.Web.UI.WebControls.ImageButton Protected WithEvents CloneIDField As System.Web.UI.WebControls.TextBox Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Protected WithEvents btnAmazon As System.Web.UI.WebControls.ImageButton 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 LoadProductTypes() End If End Sub Private Sub LoadProductTypes() Me.lstProductTypes.DataSource = CatalogServices.ProductTypes.ListProductTypes Me.lstProductTypes.DataTextField = "ProductTypeName" Me.lstProductTypes.DataValueField = "ID" Me.lstProductTypes.DataBind() For i As Integer = 0 To Me.lstProductTypes.Items.Count - 1 If lstProductTypes.Items(i).Text = "Generic Product" Then Me.lstProductTypes.ClearSelection() lstProductTypes.Items(i).Selected = True End If Next End Sub Private Sub btnAddProduct_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAddProduct.Click msg.Clear() Me.NewIDField.Text = Me.NewIDField.Text.Trim.ToUpper If Me.NewIDField.Text.Trim.Length < 1 Then msg.ShowWarning("Please enter a unique ID for the new product.") Else Dim p As Catalog.Product p = CatalogServices.Products.GetProduct(Me.NewIDField.Text, True) If p.ID.Trim.ToUpper = Me.NewIDField.Text Then msg.ShowWarning("A product with that ID already exists. Please choose another ID.") Else p = CatalogServices.Products.CreateNewProduct(Me.lstProductTypes.SelectedValue, Me.NewIDField.Text) If Not p Is Nothing Then Response.Redirect("products_products_edit.aspx?id=" & p.ID) Else msg.ShowError("Error While Adding New Product!") End If End If End If End Sub Private Overloads Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnEdit.Click msg.Clear() Dim editID As String = "" For i As Integer = 0 To ProductPicker1.SelectedProducts.Count - 1 editID = ProductPicker1.SelectedProducts(i) Exit For Next 'For i As Integer = 0 To ProductPicker1.ProductList.Items.Count - 1 ' If ProductPicker1.ProductList.Items(i).Checked = True Then ' editID = ProductPicker1.ProductList.Items(i).ItemValue ' Exit For ' End If 'Next If editID = "" Then msg.ShowWarning("Please select a product from the list before clicking the edit button.") Else Response.Redirect("products_products_edit.aspx?id=" & editID) End If End Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click For i As Integer = 0 To ProductPicker1.SelectedProducts.Count - 1 CatalogServices.Products.Delete(ProductPicker1.SelectedProducts(i)) Next ProductPicker1.LoadLastSearch() End Sub Private Sub btnClone_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnClone.Click msg.Clear() Me.CloneIDField.Text = Me.CloneIDField.Text.Trim.ToUpper If Me.CloneIDField.Text.Trim.Length < 1 Then msg.ShowWarning("Please enter a new ID for the clone product") Else Dim editID As String = "" For i As Integer = 0 To ProductPicker1.SelectedProducts.Count - 1 editID = ProductPicker1.SelectedProducts(i) Exit For Next If editID = "" Then msg.ShowWarning("Please select an item to clone from the list first.") Else Dim p As Catalog.Product p = CatalogServices.Products.GetProduct(Me.CloneIDField.Text, True) If p.ID.Trim.ToUpper = Me.CloneIDField.Text Then msg.ShowWarning("A product with that ID already exists. Please choose another ID.") Else p = CatalogServices.Products.Clone(editID, CloneIDField.Text.Trim.ToUpper) If Not p Is Nothing Then Response.Redirect("products_products_edit.aspx?id=" & p.ID) Else msg.ShowError("Error While Cloning Product!") End If End If End If End If End Sub Private Sub btnAmazon_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAmazon.Click Response.Redirect("products_amazon.aspx") End Sub End Class