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_product_prductgl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        databind();
    }
    public void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        string id = Request.QueryString["id"].ToString();
        SqlCommand smd;
        SqlDataReader sdr;
        TableRow tr;
        TableCell tc;
        ImageButton hy;
        smd = new SqlCommand("select Related from ProductInfo where ISPublished='y'and id="+id, conn);
        string strtxt = Convert.ToString(smd.ExecuteScalar());
        if (strtxt != "")
        {
            string[] txt = strtxt.Split('$');
            tr = new TableRow();
            for (int i = 0; i < txt.Length - 1; i++)
            {
                smd = new SqlCommand("select * from ProductInfo where ISPublished='y'and id=" + txt[i], conn);
                sdr = smd.ExecuteReader();
                
                sdr.Read();
                if (sdr.HasRows)
                {
                    tc = new TableCell();
                    hy = new ImageButton();
                    hy.ImageUrl = "~/upfile/" + sdr["ThumbnailsPic"].ToString();
                    hy.PostBackUrl = "~/china/productlist.aspx?id=" + sdr["id"].ToString();
                    hy.CausesValidation = false;
                    tc.VerticalAlign = VerticalAlign.Top;
                    hy.Width = 120;
                    hy.Height = 120;
                    tc.Controls.Add(hy);
                    tr.Controls.Add(tc);
                }
                sdr.Close();
            }
            TB.Controls.Add(tr);
            
        }
        else
        {
            this.Panel1.Visible = false;
            this.Panel2.Visible = true;
        }
        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;
    }
}
