<%@ Page Language="C#" Inherits="TopWinCMS.BLL.PageFactory.Pages.ClassPage" EnableSessionState="false"
    EnableViewState="false" %><%@ Import Namespace="System" %><%@ Import Namespace="System.Web" %><%@ Import Namespace="System.Web.UI.WebControls" %><%@ Import Namespace="System.Collections.Generic" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Text.RegularExpressions" %><%@ 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/MemberLoginBar.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/Shop.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/GetVote.js"></script></head><script runat="server">
    private int ClassID;
    private int BrandID;
    SQLModel s_model = new SQLModel();
    private void Page_Load(object sender, System.EventArgs e)
    {
        ClassID = int.Parse(Request.QueryString["ClassID"]);
        BrandID = Request["BrandID"] == null ? 0 : int.Parse(Request["BrandID"]);

        PageNavigation1.UrlPaging = true;

        string newurl = UrlRewrite(Request.Url.LocalPath.ToString());

        newurl = System.Text.RegularExpressions.Regex.Replace(newurl, "-(\\d+).htm", "-{0}.htm", RegexOptions.IgnoreCase);
        PageNavigation1.UrlRewritePattern = newurl;


        Bind_Brand();
        Bind_GoodsList();
    }
    private void Bind_Brand()
    {
        R_Brand.DataSource = new ShopManage(4).CountBrandWhithClassID(ClassID);
        R_Brand.DataBind();
    }
    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 PresentExp>=0 and ClassID in (select [ID] from TopWinCMS_Class where ModelID = 4 and path like (select path+'%' from TopWinCMS_Class where [ID] = " + ClassID + "))";

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

        s_model.OrderField = Request["Action"] + " " + Request["OrderBy"];
        s_model.OrderField += ",ID Desc";


        s_model.PageSize = PageNavigation1.PageSize;
        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();


    }

    private string UrlBuilding(string Action, string OrderBy, object BrandID)
    {
        string url = "/Shop/Class.aspx?Action=" + Action;
        if (OrderBy == "DESC")
        {
            url += "&OrderBy=ASC";
        }
        else
        {
            url += "&OrderBy=DESC";
        }


        url += "&BrandID=" + BrandID;
        url += "&ModelID=4";
        url += "&ClassID=" + ClassID;
        url += "&PageNo=1";

        return UrlRewrite(url);


    }
    private static string UrlRewrite(string OutPut)
    {
        if (Config.UrlRewrite == false)
        {
            return OutPut;
        }

        object obj = MyCache.ReadCache("TopWinCMS_RewriterCache");
        List<RegexInfo> _regex_list;
        if (obj == null)
        {
            _regex_list = new List<RegexInfo>();

            DataSet ds = new DataSet();
            //读取url重写规则文件,并写入RegexInfo结构的实例中 
            ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("~/Config/TopWinCMS.UrlRewriter.config"));
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                string NewPath = r["NewPath"].ToString();
                string RealPath = r["RealPath"].ToString();

                if (NewPath.StartsWith(@"~/"))
                    NewPath = HttpContext.Current.Request.ApplicationPath + NewPath.Substring(2);
                if (RealPath.StartsWith(@"~/"))
                    RealPath = HttpContext.Current.Request.ApplicationPath + RealPath.Substring(2);

                _regex_list.Add(new RegexInfo(NewPath.ToString(), RealPath, r["ReverseNewPath"].ToString(), r["ReverseRealPath"].ToString()));
            }
            MyCache.InsertCache("TopWinCMS_RewriterCache", _regex_list, 90000);
            //return OutPut;
        }
        else
        {
            _regex_list = obj as List<RegexInfo>;
        }


        foreach (RegexInfo r in _regex_list)
        {

            Regex Reg = new Regex(r.ReverseRealPath, RegexOptions.IgnoreCase);

            string url = OutPut;

            Match m = Reg.Match(url);//匹配
            if (m.Success == false)
            {
                continue;
            }


            url = Regex.Replace(url, r.ReverseRealPath, r.ReverseNewPath, RegexOptions.IgnoreCase);      //匹配出其真实的URL          

            return url;
        }

        return OutPut;
    }
</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"><uc3:Left ID="Left1" runat="server" /></td><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center"><script type="text/javascript" src="/js/JsAd2.js"></script></td></tr><tr><td height="5"></td></tr><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">                                                    &nbsp;&nbsp;<span class="black02"><strong>{Path}</strong></span></td></tr></table></td></tr><tr><td height="5"></td></tr><tr><td height="30" class="chen02">                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/Shop/narrow.gif" width="6"
                                            height="8" hspace="5" align="absmiddle" /><a href='<%=UrlBuilding("Hits",Request["OrderBy"],BrandID) %>'>按热卖度排序</a>&nbsp;
                                        <img src="images/Shop/narrow.gif" width="6" height="8" hspace="5" align="absmiddle" /><a href="<%=UrlBuilding("OnTop",Request["OrderBy"],BrandID) %>">按推荐度排序</a>&nbsp;
                                        <img src="images/Shop/narrow.gif" width="6" height="8" hspace="5" align="absmiddle" /><a href="<%=UrlBuilding("PriceMember",Request["OrderBy"],BrandID) %>">按价格排序</a>&nbsp;
                                        <img src="images/Shop/narrow.gif" width="6" height="8" hspace="5" align="absmiddle" /><a href="<%=UrlBuilding("UpdateTime",Request["OrderBy"],BrandID) %>">按上架时间</a></td></tr><tr><td height="50" class="chen02"><table width="780" border="0" align="center" cellpadding="0" cellspacing="0" class="box3"><tr><td height="30" bgcolor="#F3F3F3"><asp:Repeater ID="R_Brand" runat="server"><ItemTemplate>                                                            &nbsp;&nbsp;<a href="<%# UrlBuilding(Request["Action"],"ASC",Eval("BrandID")) %>"><span
                                                                class="black01"><%# Eval("Brand")%></span></a> (<%# Eval("Num")%>)
                                                        </ItemTemplate></asp:Repeater><%
                                                        if (R_Brand.Items.Count == 0)
                                                        {
                                                    %>                                                    没有品牌数据
                                                    <%
                            
                                                        } %></td></tr></table></td></tr><tr><td height="5"></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"><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(<%=Request["ModelID"] %>,<%#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; width: 90%"><TopWinCMS:PageNavigation ID="PageNavigation1" runat="server" PageSize="15" HorizontalAlign="Center"
                                    EnableUrlRewriting="True"></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">            图标标题..</div><img id="ShowContentImg" src="images/Shop/Ajax_Loading.gif" border="0" alt="读取中" /><div id="ShowConfig">            配置信息：</div></div></form></body></html>