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 ad_list : System.Web.UI.Page
{
    public long adSize = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        XabaraCom xc = new XabaraCom();
        dbDataFunction db = new dbDataFunction();

        if (!IsPostBack)
        {
            adSize = xc.SafeNum(Request.QueryString["size"]);
            if (adSize < 1)
            {
                adSize = 120;
            }
            adSize = adSize - 2;
            long topSql = xc.SafeNum(Request.QueryString["nums"]);
            if (topSql < 1)
            {
                topSql = 3;
            }
            string vh = Request.QueryString["vh"];
            if (string.IsNullOrEmpty(vh as string))
            {
                vh = "h";
            }
            
            string strSql = "select * from (select num_iid,title,nick,pic_url,price,click_url,shop_click_url from taobaoKe where isBad=0 and isGood>0) as newGood order by RAND() Limit 0," + topSql.ToString();
            DataTable dt = db.getDataTable(strSql);
            if (dt.Rows.Count < 1)
            {
                strSql = "select * from (select num_iid,title,nick,pic_url,price,click_url,shop_click_url from taobaoKe where isBad=0 order by volume DESC Limit 0,100) as news order by RAND() Limit 0," + topSql.ToString();
                dt = db.getDataTable(strSql);
            }

            if (vh.Equals("h"))
            {
                ad.Text = "<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-width:0px; border-collapse:collapse;\">";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string pic = dt.Rows[i]["pic_url"].ToString().Trim() + "_b.jpg";
                    ad.Text += "<tr><td class=\"adList\"><a href=\"/show/" + dt.Rows[i]["num_iid"].ToString().Trim() + ".htm\" target=\"_blank\"><img id=\"imgshow\" src=\"" + pic + "\" style=\"width:" + adSize.ToString() + "px;\" alt=\"" + dt.Rows[i]["title"].ToString().Trim() + "\" title=\"" + dt.Rows[i]["title"].ToString().Trim() + "\" /></a></td></tr>";
                }
                ad.Text += "</table>";
            }
            else
            {
                ad.Text = "<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-width:0px; border-collapse:collapse;\"><tr>";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string pic = dt.Rows[i]["pic_url"].ToString().Trim() + "_b.jpg";
                    ad.Text += "<td class=\"adList\"><a href=\"/show/" + dt.Rows[i]["num_iid"].ToString().Trim() + ".htm\" target=\"_blank\"><img id=\"imgshow\" src=\"" + pic + "\" style=\"width:" + adSize.ToString() + "px;\" alt=\"" + dt.Rows[i]["title"].ToString().Trim() + "\" title=\"" + dt.Rows[i]["title"].ToString().Trim() + "\" /></a></td>";
                }
                ad.Text += "</tr></table>";
            }

            dt.Dispose();
        }
    }
}