using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class item_show : System.Web.UI.Page
{
    XabaraCom xc = new XabaraCom();
    dbDataFunction db = new dbDataFunction();
    xabaraAD ad = new xabaraAD();
    XabaraClass xClass = new XabaraClass();
    webPublic wp = new webPublic();

    protected void Page_Load(object sender, EventArgs e)
    {
        string classNav = "找店铺_ZDianPU.com";
        string titleStr = "找店铺_ZDianPU.com";

        if (!IsPostBack)
        {
            DataTable dt;

            long id = xc.SafeNum(Request.QueryString["id"]);
            if (id < 1)
            {
                string urlID = Page.RouteData.Values["sID"].ToString();
                urlID = urlID.Replace(".htm", "");
                id = xc.SafeNum(urlID);
            }

            long cidTemp = 0;
            //读取信息
            if (id > 0)
            {
                dt = db.getDataTable("select newstree.TreeName,newstree.treeNameTxt,taobaoke.click_url,taobaoke.title,taobaoke.classID,taobaoke.pic_url,taobaoke.price,taobaoke.volume,taobaoke.shop_click_url,taobaoke.nick,taobaoke.seller_credit_score,taobaoke.item_location from taobaoke left join newstree on taobaoke.classID=newstree.Tid where taobaoke.num_iid='" + id.ToString() + "'");
                if (dt.Rows.Count > 0)
                {
                    string url = dt.Rows[0]["click_url"].ToString().Trim();
                    string shopUrl=dt.Rows[0]["shop_click_url"].ToString().Trim();
                    titleStr = dt.Rows[0]["title"].ToString().Trim();
                    cidTemp = xc.SafeNum(dt.Rows[0]["classID"].ToString().Trim());
                    classNav = xClass.getClass(cidTemp, "/*.htm", "");

                    //根分类读取
                    DataTable dtClass = db.getDataTable("select Tid,TreeName from newsTree where TreeID=0  AND TreeType='taobaoke' order by ListID ASC, Tid ASC");
                    for (int t = 0; t < dtClass.Rows.Count; t++)
                    {
                        if (cidTemp == xc.SafeNum(dtClass.Rows[t]["Tid"].ToString().Trim()) || classNav.IndexOf(dtClass.Rows[t]["TreeName"].ToString().Trim()) > -1)
                        {
                            classTD.Text += "<td style=\"background-image:url('/images/classBg2.gif'); background-repeat:no-repeat; width:84px; height:44px; line-height:36px; text-align:center; color:white; font-size:16px;\">" + dtClass.Rows[t]["TreeName"].ToString().Trim() + "</td><td style=\"width:10px; font-size:0px;\"></td>";
                        }
                        else
                        {
                            classTD.Text += "<td style=\"background-image:url('/images/classBg.gif'); background-repeat:no-repeat; width:84px; height:44px; line-height:36px; text-align:center;\"><a href=\"/" + dtClass.Rows[t]["Tid"].ToString().Trim() + ".htm\" target=\"_top\" class=\"classID\">" + dtClass.Rows[t]["TreeName"].ToString().Trim() + "</a></td><td style=\"width:10px; font-size:0px;\"></td>";
                        }
                    }
                    dt.Dispose();

                    //读取标签关键词
                    string strSql = "select id,wordName from keywordid where isBad=0 and useType='bq' and treeID=" + cidTemp.ToString() + " order by ListID ASC,id ASC LIMIT 0,8";
                    //Response.Write(strSql);
                    dtClass = db.getDataTable(strSql);
                    for (int p = 0; p < dtClass.Rows.Count; p++)
                    {
                        bqClass.Text += "<a href=\"/" + cidTemp.ToString() + "-0-" + dtClass.Rows[p]["id"].ToString().Trim() + "-0.htm\" target=\"_blank\">" + dtClass.Rows[p]["wordName"].ToString().Trim() + "</a>&nbsp;&nbsp;";
                    }
                    dtClass.Dispose();

                    
                    navClass.Text = "当前位置：<a href=\"/\" target=\"_top\">首页</a>&nbsp;-&nbsp;" + classNav;                    
                    pic.Text = "<a href=\"" + url + "\" target=\"_blank\"><img src=\"" + dt.Rows[0]["pic_url"].ToString().Trim() + "\" style=\"width:560px; height:560px;\" title=\"" + titleStr + "\" id=\"bigImg\" /></a>";
                    tbTitle.Text = titleStr;
                    tbPrice.Text = xc.getMoney(dt.Rows[0]["price"].ToString().Trim());
                    buyNums.Text = dt.Rows[0]["volume"].ToString().Trim();
                    shopStar.Text = wp.taobaoCredit(dt.Rows[0]["seller_credit_score"].ToString().Trim());
                    location.Text = dt.Rows[0]["item_location"].ToString().Trim();
                    buy.Text = "<a href=\"" + url + "\" target=\"_blank\"><img src=\"../images/buyBottom.gif\" title=\"点击进入购买\" /></a>";
                }
                else
                {
                    Response.Redirect("/", true);
                }
                dt.Dispose();

                RepeaterList.DataSource = db.getDataTable("select * from taobaoke where isGood=1 and classID=" + cidTemp.ToString() + " order by RAND() Limit 0,8");
                RepeaterList.DataBind();
                RepeaterList.Dispose();
            }
            else
            {
                Response.Redirect("/", true);
            }           

            xc.webMeta(this.Page, titleStr + xc.readXmlData("xabara.config", "KeyWord"), xc.readXmlData("xabara.config", "metaStr"));
        }

        this.Page.Title = titleStr + " " + xc.readXmlData("xabara.config", "webName");
    }

    public string money(string str)
    {
        return xc.getMoney(str);
    }
}