<%@ Page Language="C#" Inherits="TopWinCMS.BLL.PageFactory.Pages.ShopSearchPage"
    EnableSessionState="false" EnableViewState="false" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TopWinCMS.BLL" %>
<%@ Import Namespace="TopWinCMS.Model" %>
<%@ Import Namespace="TopWinCMS.Common" %>
<%@ Import Namespace="TopWinCMS.IDAL" %>
<%@ Import Namespace="TopWinCMS.DALFactory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="Header.ascx" TagName="Header" TagPrefix="uc1" %>
<%@ Register Src="SearchBar.ascx" TagName="SearchBar" TagPrefix="uc2" %>
<%@ Register Src="Left.ascx" TagName="Left" TagPrefix="uc3" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>园玉商城</title>
    <link href="/Shop/css.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" src="/JS/TopWinCMS.js"></script>
    <script language="javascript" type="text/javascript" src="/JS/Ajax/Ajax.js"></script>
    <script language="javascript" type="text/javascript" src="/JS/Ajax/Shop.js"></script>
</head>
<script runat="server">  
    
    SQLModel s_model = new SQLModel();
    private void Page_Load(object sender, System.EventArgs e)
    {
        PageNavigation1.UrlPaging = true;

        Bind_GoodsList();

        if (DL_List.Items.Count > 0)
        {
            new HotKeyWordsManage().Add(4, Request["KeyWord"], DL_List.Items.Count);
        }

        TB_Min.Text = Request["Min"];
        TB_Max.Text = Request["Max"];
    }

    private void Bind_GoodsList()
    {

        s_model.Fields = "ID,ModelID,GoodsName,Hits,UpdateTime,Content,Stars,OnTop,Elite,IncludePic,ClassID,PicUrl,Brief,ColorStyle,FontStyle,PriceMarket,PriceMember";
        s_model.TableName = "TopWinCMS_Shop";
        s_model.WHERE = " deleted=0 and pass=1  and (GoodsName like '%" + MyString.SQL_ESC(Request["KeyWord"]) + "%'  )";

        if (Request["ClassID"] != null)
        {
            s_model.WHERE += " AND ClassID=" + int.Parse(Request["ClassID"]);
        }

        if (Request["BrandID"] != null)
        {
            s_model.WHERE += " AND BrandID=" + int.Parse(Request["BrandID"]);
        }

        if (Request["Min"] != null && Request["Max"] != null)
        {
            s_model.WHERE += " AND (PriceMember>=" + int.Parse(Request["Min"]) + " OR  PriceMember<=" + int.Parse(Request["Max"]) + ")";
        }

        s_model.FieldKey = "ID";

        s_model.OrderField = " ID Desc";


        s_model.PageSize = 20;
        s_model.PageNo = (Request["PageNo"] == null) ? 1 : int.Parse(Request["PageNo"]);

        ICommon MyCommonDAL = DataAccess.Instance<ICommon>();

        PageNavigation1.RecordCount = MyCommonDAL.Count(s_model);

        DL_List.DataSource = MyCommonDAL.DataRead(s_model);
        DL_List.DataBind();

        List<string> list = new List<string>();
        foreach (DataListItem DLI in DL_List.Items)
        {
            Literal id = (Literal)DLI.FindControl("L_ID");
            list.Add(id.Text);
        }
        Repeater1.DataSource = new Public_Class().GetClassInfoFromIDs(4, string.Join(",", list.ToArray()));
        Repeater1.DataBind();

        Repeater2.DataSource = new BrandManage().GetBrandInfoFromIDs(4, string.Join(",", list.ToArray()));
        Repeater2.DataBind();
    }


    protected void BT_OK_Click(object sender, EventArgs e)
    {
        int i;
        if (int.TryParse(TB_Min.Text, out i) == int.TryParse(TB_Max.Text, out i) == true)
        {
            Response.Redirect(UrlBuilding(Request["ClassID"], Request["BrandID"], TB_Min.Text, TB_Max.Text));
        }
    }

    private string UrlBuilding(string ClassID, string BrandID, string Min, string Max)
    {
        string url = "/Shop/Search.aspx?KeyWord=" + Request["KeyWord"];
        if (ClassID != null)
        {
            url += "&ClassID=" + ClassID;
        }
        if (BrandID != null)
        {
            url += "&BrandID=" + BrandID;
        }

        if (Min != null)
        {
            url += "&Min=" + Min;
        }
        if (Max != null)
        {
            url += "&Max=" + Max;
        }

        url += "&PageNo=1";
        return url;
    }
</script>
<body>
    <form id="form1" runat="server">
    <table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <uc1:Header ID="Header1" runat="server" />
                <table width="1002
      " border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td height="68" colspan="2" valign="top" background="../images/Shop/top_nav.gif">
                            <uc2:SearchBar ID="SearchBar1" runat="server" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td height="5">
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="204" valign="top">
                            <table width="202" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="187" height="28" background="../images/Shop/left_nav.gif">
                                        <span id="chen2">&nbsp;&nbsp;<span class="white02"><strong>热门调查</strong></span></span><span
                                            class="white02">&nbsp;Inquire</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <table width="204" border="0" cellpadding="0" cellspacing="6" class="box3" style="line-height: 150%">
                                            <tr>
                                                <td height="28">
                                                    按类别筛选结果：
                                                    <br />
                                                    <asp:Repeater ID="Repeater1" runat="server">
                                                        <ItemTemplate>
                                                            <a href='<%# UrlBuilding(Eval("ID").ToString(), Request["BrandID"], Request["Min"], Request["Max"]) %>'>
                                                                <%# Eval("ClassName") %></a> (<%# Eval("CountNum")%>)<br />
                                                        </ItemTemplate>
                                                    </asp:Repeater>
                                                    <%
                                                        if (Repeater1.Items.Count == 0)
                                                        {
                                                    %>
                                                    没有数据
                                                    <%
                            
                                                        } %>
                                                    <br />
                                                    按品牌筛选结果：
                                                    <br />
                                                    <asp:Repeater ID="Repeater2" runat="server">
                                                        <ItemTemplate>
                                                            <%# Eval("Name") %>
                                                            (<%# Eval("CountNum")%>)<br />
                                                        </ItemTemplate>
                                                    </asp:Repeater>
                                                    <%
                                                        if (Repeater2.Items.Count == 0)
                                                        {
                                                    %>
                                                    没有数据
                                                    <%
                            
                                                        } %>
                                                    <br />
                                                    按价格筛选结果：
                                                    <br />
                                                    <asp:TextBox ID="TB_Min" runat="server" Width="50px"></asp:TextBox>
                                                    --<asp:TextBox ID="TB_Max" runat="server" Width="50px"></asp:TextBox>
                                                    <asp:Button ID="BT_OK" runat="server" OnClick="BT_OK_Click" Text="确定" />
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td valign="top">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <table width="794" border="0" align="center" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td width="794" height="29" background="../images/Shop/middle_bg2.gif">
                                                    园玉商城 &gt; 商品搜索
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:DataList ID="DL_List" runat="server" HorizontalAlign="Center" RepeatColumns="3"
                                            RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False" CellSpacing="20"
                                            CellPadding="1" Width="98%">
                                            <ItemTemplate>
                                                <table width="0" border="0" align="center" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td>
                                                            <div align="center">
                                                                <asp:Literal ID="L_ID" runat="server" Visible="False" Text='<%#Eval("ID") %>' />
                                                                <a href="/ShopShow-<%#Eval("ID") %>.htm">
                                                                    <img alt="" src="<%#Eval("PicUrl") %>" width="111" height="111" onmouseout="ClearImg()"
                                                                        onmouseover="onmouseshow(event,document.documentElement,<%#Eval("ID") %>)" /></a></div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td height="20" class="black01">
                                                            产品名称：<%#Eval("GoodsName") %></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <img src="../images/Shop/icon2.gif" width="16" height="16" align="absmiddle" /><span class="black01">&nbsp;原价：<%# Eval("PriceMarket", "{0:c}")%></span><br /><img src="../images/Shop/icon3.gif" width="16" height="16" align="absmiddle" /><span class="chen02">&nbsp;特价：<%# Eval("PriceMember", "{0:c}")%></span></td>
                                                    </tr>
                                                    <tr>
                                                        <td height="30">
                                                            <input type="image" src="../images/Shop/bt_6.gif" width="99" height="21" onclick="JoinCart(4,<%#Eval("ID") %>); return false;" />
                                                            <input type="image" src="../images/Shop/bt_7.gif" width="53" height="21" hspace="10" onclick="Favorite('<%#Eval("GoodsName") %>','<%=Request.Url %>'); return false;" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </asp:DataList>
                                        <%
                                            if (DL_List.Items.Count == 0)
                                            {
                                        %>
                                        没有商品数据
                                        <%
                            
                                            } %>
                                    </td>
                                </tr>
                            </table>
                            <br />
                            <div style="margin-left: auto; margin-right: auto">
                                <TopWinCMS:PageNavigation ID="PageNavigation1" runat="server" PageSize="15" HorizontalAlign="Center">
                                </TopWinCMS:PageNavigation>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <!--#include file="../Footer.aspx"-->
            </td>
        </tr>
    </table>
    <script language="javascript" type="text/javascript">
      //Ajax显示购物车界面
                ShowShopingCart(<%=Request["ModelID"] %>);
    </script>
    <div id="showLayers" style="display: none">
        <div id="ShowContentTitle">
            图标标题..               ShowShopingCart(<%=Request["ModelID"] %>);
    </div>
    <div id="showLayers" style="display: none">
        <div id="ShowContentTitle">
            图标标题..</div>
        <img id="ShowContentImg" src="../images/Shop/Ajax_Loading.gif" border="0" alt="读取中" />
        <div id="ShowConfig">
            配置信息：</div>
    </div>
    </form>
</body>
</html>
