Imports BVSoftware.BVC.Core Imports BVSoftware.AmazonWebServices3 Public Class products_amazon Inherits BaseAdminPage #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Protected WithEvents lblKeyword As System.Web.UI.WebControls.Label Protected WithEvents lblProductLine As System.Web.UI.WebControls.Label Protected WithEvents lstProductLine As System.Web.UI.WebControls.DropDownList Protected WithEvents lstSearchType As System.Web.UI.WebControls.DropDownList Protected WithEvents KeywordField As System.Web.UI.WebControls.TextBox Protected WithEvents btnSearch As System.Web.UI.WebControls.ImageButton Protected WithEvents dgResults As System.Web.UI.WebControls.DataGrid Protected WithEvents lblResults As System.Web.UI.WebControls.Label Protected WithEvents btnNext As System.Web.UI.WebControls.ImageButton Protected WithEvents btnLast As System.Web.UI.WebControls.ImageButton 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object 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 SetupSearch() ViewState("CurrentPage") = 1 ViewState("TotalPages") = 1 End If End Sub Private Sub SetupSearch() SetMode(Me.lstSearchType.SelectedValue) 'Me.lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayProductLine 'lstProductLine.DataTextField = "DisplayName" 'lstProductLine.DataValueField = "id" 'lstProductLine.DataBind() End Sub Private Sub lstSearchType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSearchType.SelectedIndexChanged SetMode(Me.lstSearchType.SelectedValue) End Sub Private Sub SetMode(ByVal mode As BVSoftware.AmazonWebServices3.AmazonSearchMode) Select Case mode Case AmazonSearchMode.Actor Me.lblKeyword.Text = "Actor/Actress Name" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayVideoProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Artist Me.lblKeyword.Text = "Artist Name" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayMusicProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Asin Me.lblKeyword.Text = "ASIN" Me.lstProductLine.Visible = False Me.lblProductLine.Enabled = False Case AmazonSearchMode.Author Me.lblKeyword.Text = "Author Name" Me.lstProductLine.Visible = False Me.lblProductLine.Enabled = False Case AmazonSearchMode.Blended Me.lblKeyword.Text = "Search Phrase" Me.lstProductLine.Visible = False Me.lblProductLine.Enabled = False Case AmazonSearchMode.BrowseNode Me.lblKeyword.Text = "Browse Node Number" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Director Me.lblKeyword.Text = "Director Name" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayVideoProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Keyword Me.lblKeyword.Text = "Keyword" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Manufacturer Me.lblKeyword.Text = "Manufacturer Name" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayManufacturerProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() Case AmazonSearchMode.Similarity Me.lblKeyword.Text = "ASIN" Me.lstProductLine.Visible = False Me.lblProductLine.Enabled = False Case AmazonSearchMode.UPC Me.lblKeyword.Text = "UPC" Me.lstProductLine.Visible = True Me.lblProductLine.Enabled = True lstProductLine.DataSource = BVSoftware.AmazonWebServices3.AmazonWebServices3.DisplayMusicProductLine lstProductLine.DataTextField = "DisplayName" lstProductLine.DataValueField = "id" lstProductLine.DataBind() End Select End Sub Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSearch.Click ViewState("CurrentPage") = 1 ViewState("TotalPages") = 1 Me.dgResults.DataSource = Nothing Me.lblResults.Text = "" DoSearch() End Sub Private Sub DoSearch() Try Dim totalResults As Integer = 0 Dim totalPages As Integer = ViewState("TotalPages") Dim results As AmazonProductCollection Select Case Me.lstSearchType.SelectedValue Case AmazonSearchMode.Actor results = BVSoftware.AmazonWebServices3.AmazonWebServices3.ActorSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Artist results = BVSoftware.AmazonWebServices3.AmazonWebServices3.ArtistSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Asin results = BVSoftware.AmazonWebServices3.AmazonWebServices3.AsinIsbnSearch(KeywordField.Text.Trim, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite) Case AmazonSearchMode.Author results = BVSoftware.AmazonWebServices3.AmazonWebServices3.AuthorSearch(KeywordField.Text.Trim, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Blended results = BVSoftware.AmazonWebServices3.AmazonWebServices3.BlendedSearch(KeywordField.Text.Trim, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite) Case AmazonSearchMode.BrowseNode results = BVSoftware.AmazonWebServices3.AmazonWebServices3.BrowseNodeSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Director results = BVSoftware.AmazonWebServices3.AmazonWebServices3.DirectorSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Keyword results = BVSoftware.AmazonWebServices3.AmazonWebServices3.KeywordSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Manufacturer results = BVSoftware.AmazonWebServices3.AmazonWebServices3.ManufacturerSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite, ViewState("CurrentPage"), totalPages, totalResults) Case AmazonSearchMode.Similarity results = BVSoftware.AmazonWebServices3.AmazonWebServices3.SimilaritySearch(KeywordField.Text.Trim, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite) Case AmazonSearchMode.UPC results = BVSoftware.AmazonWebServices3.AmazonWebServices3.UPCSearch(KeywordField.Text.Trim, lstProductLine.SelectedValue, WebAppSettings.AmazonAssociateID, AmazonSearchType.Lite) End Select ViewState("TotalPages") = totalPages dgResults.DataSource = results dgResults.DataBind() 'Me.lstResults.DisplayMember = "ProductName" 'Me.lstResults.ValueMember = "asin" Me.lblResults.Text = "Page " & ViewState("CurrentPage") & " of " & totalPages & " pages, " & totalResults & " items." If results.Count < 1 Then msg.ShowWarning("No results were found") End If Catch ex As Exception msg.ShowException(ex) End Try End Sub Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLast.Click If ViewState("CurrentPage") > 1 Then ViewState("CurrentPage") -= 1 DoSearch() End If End Sub Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnNext.Click If ViewState("CurrentPage") < ViewState("TotalPages") Then ViewState("CurrentPage") += 1 DoSearch() End If End Sub Private Sub dgResults_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgResults.EditCommand Dim asin As String = dgResults.DataKeys(e.Item.ItemIndex) msg.Clear() If asin.Length > 0 Then Dim ap As AmazonProduct ap = AmazonWebServices3.FindAmazonProduct(asin, WebAppSettings.AmazonAssociateID) If Not ap Is Nothing Then Dim p As New Catalog.Product p.ID = ap.Asin p.CreationDate = DateTime.Now p.DropShipMode = Catalog.ProductDropShipMode.ShipFromSite p.GiftWrapAllowed = False p.ImageFileMedium = ap.ImageURLMedium p.ImageFileSmall = ap.ImageURLSmall p.InventoryAvailableQty = 1 p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.Available p.ListPrice = ap.ListPrice p.SitePrice = ap.OurPrice p.MetaDescription = ap.ProductName p.MetaKeywords = ap.ProductName p.MetaTitle = ap.ProductName p.MinimumQty = 1 p.NonShipping = True p.ProductName = ap.ProductName p.ProductTypeID = -100 p.Status = Catalog.ProductStatus.Active p.TaxExempt = True p.UseVolumePricing = False p.VariantDisplay = Catalog.VariantDisplayMode.IndividualFields Dim tempProduct As Catalog.Product tempProduct = CatalogServices.Products.CreateNewProduct(p) If tempProduct Is Nothing Then msg.ShowError("Could not add product to store. Unknown Error.") Else msg.ShowOK("Product " & ap.Asin & " added to your store") End If tempProduct = Nothing p = Nothing Else msg.ShowWarning("That ASIN could not be loaded from Amazon.com") End If Else msg.ShowWarning("No ASIN was found") End If End Sub End Class