<%@Register TagPrefix="Localized" TagName="Footer" src="footer.ascx" %>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="Microsoft.CommerceServer.Runtime"%>
<%@Import Namespace="Microsoft.CommerceServer.Runtime.Catalog"%>
<%@Import Namespace="Microsoft.CommerceServer.Runtime.Configuration"%>
<%@Import Namespace="Microsoft.CommerceServer.Runtime.Diagnostics"%>
<%@Import Namespace="catalogsitelet"%>
<%@Import Namespace="System.Threading"%>
<%@Import Namespace="System.Resources"%>
<%@Import Namespace="System.Globalization"%>
<%@ Page Description="Localized Page" CodePage="65001" %>
<!---------------------------------------------------------------------
-- File: propsearch.aspx
--
-- Summary: Page performs property search and displays the result
--
-- Sample: Catalog Sitelet
--
-----------------------------------------------------------------------
-- This file is part of the Microsoft Commerce Server 2002 SDK
--
-- Copyright (C) 2002 Microsoft Corporation. All rights reserved.
--
-- This source code is intended only as a supplement to Microsoft
-- Commerce Server 2002 and/or on-line documentation. See these other
-- materials for detailed information regarding Microsoft code samples.
--
-- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
-- KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
-- PARTICULAR PURPOSE.
---------------------------------------------------------------------->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="VB">
<meta name="vs_defaultClientScript" content="JavaScript (ECMAScript)">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script runat="Server" Language="VB">
Private rm As ResourceManager
Private strLanguage As String = Nothing
Private catDisplayName As String = Nothing
Private productCode As String = Nothing
Private introductionDate As String = Nothing
Private productName As String = Nothing
Sub Page_Init(ByVal sender As Object, ByVal args As EventArgs)
'Get the ResourceManager from the Application object
rm = ResourceFactory.RManager
If rm Is Nothing Then
'Do something sensible if resources are unavailable
Server.Transfer(Utility.errorPage)
End If
End Sub
Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)
Dim SelectedCulture As CultureInfo
Dim coll As NameValueCollection = Request.QueryString
strLanguage = coll(Utility.languageLabel)
Try
SelectedCulture = CultureInfo.CreateSpecificCulture(strLanguage)
Catch e As Exception
'Fallback to English language
SelectedCulture = CultureInfo.CreateSpecificCulture(Utility.englishLanguage)
strLanguage = Utility.englishLanguage
End Try
'Set Language on footer control
Footer.Language = strLanguage
'Set culture for current thread
If Not (SelectedCulture Is Nothing) Then
Thread.CurrentThread.CurrentCulture = SelectedCulture
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
End If
'Initialize controls with appropriate texts
ProdCode.Text = rm.GetString(Utility.productPageCode)
IntroDate.Text = rm.GetString(Utility.propSearchIntro)
Name.Text = rm.GetString(Utility.propSearchTitle)
Button.Text = rm.GetString(Utility.ftSearchSearch)
catDisplayName = Utility.GetDisplayName(Utility.catalogName, strLanguage)
End Sub
Sub Button_Click(ByVal sender As Object, ByVal args As EventArgs)
Dim searchClause As String = Nothing
Try
'To keep count of records found
Dim totalRecords As Integer = 0
Dim startPage As Integer = 1
'Product code
productCode = ProdCodeText.Text.Trim
If Not ("" = productCode) Then
BuildClause(searchClause, "productcode", productCode, False)
End If
'Introduction date
introductionDate = IntroDateText.Text.Trim
If Not ("" = introductionDate) Then
BuildClause(searchClause, "introductiondate", introductionDate, True)
End If
'Product name
productName = NameText.Text.Trim
If Not ("" = productName) Then
BuildClause(searchClause, "name", productName, False)
End If
Dim searchResult As DataSet = PropertySearch(searchClause, startPage, totalRecords)
Paging.Visible = False
'If products found
If Not (searchResult Is Nothing) AndAlso 0 < searchResult.Tables(0).Rows.Count Then
SearchResultRepeater.Visible = True
SearchResultRepeater.DataSource = searchResult
SearchResultRepeater.DataBind
Matches.Text = totalRecords.ToString & " " & rm.GetString(Utility.propSearchTotal)
Else
SearchResultRepeater.Visible = False
Seprator.InnerHtml = Nothing
Pages.Text = Nothing
Matches.Text = Nothing
End If
'Do paging
If totalRecords > Utility.numberOfRecordToDisplay Then
Dim pagingTable As DataTable = Utility.DoPaging(totalRecords, Utility.numberOfRecordToDisplay, searchClause)
Paging.DataSource = pagingTable.DefaultView
Paging.DataBind
Paging.Visible = True
Seprator.InnerHtml = "<BR>"
Pages.Text = rm.GetString(Utility.ftSearchPage)
End If
ProdCodeText.Text = Nothing
IntroDateText.Text = Nothing
NameText.Text = Nothing
Catch e As Exception
'Eat exception
End Try
End Sub
'Redirects to product page
Sub ProductListing_ItemCommand(ByVal sender As Object, ByVal args As RepeaterCommandEventArgs)
Response.Redirect(rm.GetString(Utility.productPageUrl) & "?" & Utility.languageLabel & "=" & strLanguage & "&" & Utility.productID & "=" & CType(args.CommandArgument, String))
End Sub
'Page click response
Sub PageClick_ItemCommand(ByVal sender As Object, ByVal args As RepeaterCommandEventArgs)
Dim searchClause As String = CType(args.CommandArgument, String)
Dim totalRecords As Integer = 0
Dim page As Integer = args.Item.ItemIndex + 1
Dim searchResult As DataSet = PropertySearch(searchClause, page, totalRecords)
'If products found
If 0 < searchResult.Tables(0).Rows.Count Then
SearchResultRepeater.Visible = True
SearchResultRepeater.DataSource = searchResult
SearchResultRepeater.DataBind
Seprator.InnerHtml = "<BR>"
Pages.Text = rm.GetString("L_Page_FTSearch_Page")
Matches.Text = totalRecords.ToString & " " & rm.GetString(Utility.propSearchTotal)
Else
SearchResultRepeater.Visible = False
Seprator.InnerHtml = Nothing
Pages.Text = Nothing
End If
End Sub
'Creates Where clause for SQL statement
Public Sub BuildClause(ByRef searchCaluse As String, ByVal sKey As String, ByVal sValue As String, ByVal bEquals As Boolean)
If bEquals Then
If searchCaluse Is Nothing Then
searchCaluse = sKey & " = N" & "'" & sValue & "'"
Else
searchCaluse = searchCaluse & " or " & sKey & " = N" & "'" & sValue & "'"
End If
Else
If searchCaluse Is Nothing Then
searchCaluse = sKey & " like N" & "'" & sValue & "'"
Else
searchCaluse = searchCaluse & " or " & sKey & " like N" & "'" & sValue & "'"
End If
End If
End Sub
Function PropertySearch(ByVal searchstring As String, ByVal page As Integer, ByRef totalRecords As Integer) As DataSet
'Search Options
Dim searchOptions As CatalogSearchOptions = Utility.SetSearchOptions(page, Utility.numberOfRecordToDisplay, "name")
'Look for the products supporting search criteria
Dim search As CatalogSearch = New CatalogSearch(CommerceContext.Current.CatalogSystem)
search.CatalogNames = Utility.catalogName
search.SqlWhereClause = searchstring
search.SearchOptions = searchOptions
Return search.Search(totalRecords)
End Function
</script>
<title>
<%=rm.GetString(Utility.propPageTitle) & " " & catDisplayName%>
</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="sitelet.css">
</HEAD>
<body>
<DIV CLASS="Heading">
<%= rm.GetString(Utility.propPageTitle) & " " & catDisplayName%>
</DIV>
<form id="propSearch" method="post" runat="server">
<BR>
<asp:Table id="display" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Label id="ProdCode" runat="server">Product Code:</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox id="ProdCodeText" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label id="IntroDate" runat="server">Introduction date:</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox id="IntroDateText" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label id="Name" runat="server">Name:</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox id="NameText" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button id="Button" runat="server" Text="Button" OnClick="Button_Click" />
<br>
<br>
<asp:Label id="Matches" runat="server" />
<br>
<br>
<asp:Repeater id="SearchResultRepeater" OnItemCommand="ProductListing_ItemCommand" runat="server">
<ItemTemplate>
<asp:LinkButton id="SelectProductBtn" CommandName="Select" CommandArgument='<%# CType(Container.DataItem, DataRowView)("ProductID") %>' runat="server">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</asp:LinkButton>
(
<asp:Label id="Describe" runat="server">
<%# DataBinder.Eval(Container.DataItem, "description") %>
</asp:Label>
)
</ItemTemplate>
<SeparatorTemplate>
<BR>
<BR>
</SeparatorTemplate>
</asp:Repeater>
<DIV id="Seprator" runat="server" />
<asp:Label id="Pages" runat="server" />
<asp:Repeater id="Paging" OnItemCommand="PageClick_ItemCommand" runat="server">
<ItemTemplate>
<asp:LinkButton id="PageClick" CommandName="Select" CommandArgument='<%# CType(Container.DataItem, DataRowView)("Clause") %>' runat="server">
<%# DataBinder.Eval(Container.DataItem, "Page") %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<Localized:Footer runat="server" id="Footer" />
</form>
</body>
</HTML>