using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class WebMain_Product_Indexproduct_jstx_topdownleftright : System.Web.UI.UserControl
{
    private int co = 7;//一行显示多少个
    protected void Page_Load(object sender, EventArgs e)
    {
        this.databind();
    }
    protected void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select Products,ThumbnailsPic,SalePrice,id from ProductInfo", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        TableRow tr;
        TableRow tr1;
        TableCell tc;
        TableCell tc1;
        Image img;
        HyperLink hy;
        Label l1;
        Table TB1;
        tr = new TableRow();
        int i=0;
        while (sdr.Read())
        {
            tc = new TableCell();
            TB1 = new Table();
            tr1 = new TableRow();
            tc1 = new TableCell();
            tc1.CssClass = "imghw";
            img = new Image();
            img.ImageUrl = "~/upfile/" + sdr.GetString(1);
            img.Attributes.Add("onclick", "window.open('china/productlist.aspx?id="+sdr.GetInt32(3)+"')");
            img.CssClass = "imghw2";
            tc1.Controls.Add(img);
            tr1.Controls.Add(tc1);
            TB1.Controls.Add(tr1);
            tr1 = new TableRow();
            tr1.Height = 20;
            tc1 = new TableCell();
            hy = new HyperLink();
            hy.Text =SubStr(sdr.GetString(0),8);
            hy.CssClass = "fonttb";
            hy.NavigateUrl = "~/china/productlist.aspx?id="+sdr.GetInt32(3);
            hy.Target = "_blank";
            tc1.Controls.Add(hy);
            tr1.Controls.Add(tc1);
            tr1.Height = 20;
            TB1.Controls.Add(tr1);
            tr1 = new TableRow();
            tc1 = new TableCell();
            l1 = new Label();
            l1.Text ="￥"+Convert.ToString(sdr.GetDecimal(2).ToString("0.00"));
            tc1.Controls.Add(l1);
            tr1.Controls.Add(tc1);
            TB1.Controls.Add(tr1);
            tc.Controls.Add(TB1);
            tr.Controls.Add(tc);
            i++;
            if (i % co == 0)
            {
                TB.Controls.Add(tr);
                tr = new TableRow();
            }
        }
        TB.Controls.Add(tr);
        TB.BorderWidth = 0;
        TB.CellPadding = 0;
        TB.CellSpacing = 0;
        sdr.Close();
        conn.Close();
    }
    public string SubStr(string sString, int nLeng)
    {
        if (sString.Length <= nLeng)
        {
            return sString;
        }
        string sNewStr = sString.Substring(0, nLeng);
        sNewStr = sNewStr + "...";
        return sNewStr;
    }
}
