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 = 4;//一行显示多少个
    protected void Page_Load(object sender, EventArgs e)
    {
        this.databind();
    }
    protected void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select top 4 * from Package where b2='y' and isfp='y' order by adddate desc", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        TableRow tr;
        TableRow tr1;
        TableCell tc;
        TableCell tc1;
        Image img;
        HyperLink hy;
        Label l1;
        Table TB1;
        Panel pp1;
        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["pic"].ToString();
            img.Attributes.Add("onclick", "window.open('china/producttc.aspx?id="+sdr.GetInt32(0)+"')");
            img.Height = 120;
            img.Width = 120;
            img.Style.Add("cursor", "hand");
            pp1 = new Panel();
            pp1.CssClass = "imghw2";
            pp1.Controls.Add(img);
            tc1.Controls.Add(pp1);
            tr1.Controls.Add(tc1);
            TB1.Controls.Add(tr1);
            tr1 = new TableRow();
            tr1.Height = 20;
            tc1 = new TableCell();
            hy = new HyperLink();
            hy.Text =SubStr(sdr["title"].ToString(),8);
            hy.CssClass = "fonttb";
            hy.NavigateUrl = "~/china/producttc.aspx?id="+sdr.GetInt32(0);
            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 =SubStr(sdr["b1"].ToString(),8);
            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;
    }
}
