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;
        DataTable cu = new DataTable();
        cu.Columns.Add("id", typeof(int));
        cu.Columns.Add("Products", typeof(string));
        cu.Columns.Add("Description", typeof(string));
        cu.Columns.Add("SalePrice", typeof(decimal));
        cu.Columns.Add("Marketprice", typeof(decimal));
        cu.Columns.Add("VIPPrice", typeof(decimal));
        cu.Columns.Add("ThumbnailsPic", typeof(string));
        smd = new SqlCommand("select Related from ProductInfo where ISPublished='y'and id="+id, conn);
        string strtxt = Convert.ToString(smd.ExecuteScalar());
        string[] txt = strtxt.Split('$');
        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)
            {
                DataRow dr = cu.NewRow();
                dr["id"] = sdr["id"].ToString();
                dr["Products"] = sdr["Products"].ToString();
                dr["Description"] = sdr["Description"].ToString();
                dr["SalePrice"] = Convert.ToDecimal(sdr["SalePrice"].ToString());
                dr["VIPPrice"] = Convert.ToDecimal(sdr["VIPPrice"].ToString());
                dr["Marketprice"] = Convert.ToDecimal(sdr["Marketprice"].ToString());
                dr["ThumbnailsPic"] = sdr["ThumbnailsPic"].ToString();
                cu.Rows.Add(dr);
            }
            sdr.Close();
        }
        DataSet ds = new DataSet();
        ds.Tables.Add(cu);
        this.prductpt.DataSource = Doadmin.psgb(ds, Table1,16, 1);//分页类调用
        this.prductpt.DataKeyField = "id";
        this.prductpt.DataBind();
        if (ds.Tables[0].Rows.Count != 0)
        {
            SqlCommand smdj;
            SqlDataReader sdrj;
            Label laj;
            HyperLink hyj;
            for (int j = 0; j < prductpt.Items.Count; j++)
            {
                smdj = new SqlCommand("select * from ProductInfo where id=" + prductpt.DataKeys[j].ToString(), conn);
                sdrj = smdj.ExecuteReader();
                sdrj.Read();
                if (Session["Wtouser"] == "vipadmin")
                {
                    laj = (Label)prductpt.Items[j].FindControl("hui");
                    laj.Text = "会";
                    laj = (Label)prductpt.Items[j].FindControl("Price");
                    laj.Text = sdrj.GetDecimal(24).ToString("0");
                    hyj = (HyperLink)prductpt.Items[j].FindControl("buyto");
                    hyj.NavigateUrl = "~/china/cart.aspx?pid=" + sdrj["id"].ToString() + "&do=addPP&price=" + Convert.ToString(sdrj.GetDecimal(24));
                    hyj.Target = "_blank";
                }
                else
                {
                    laj = (Label)prductpt.Items[j].FindControl("hui");
                    laj.Text = "销";
                    laj = (Label)prductpt.Items[j].FindControl("Price");
                    laj.Text = sdrj.GetDecimal(19).ToString("0");
                    hyj = (HyperLink)prductpt.Items[j].FindControl("buyto");
                    hyj.NavigateUrl = "~/china/cart.aspx?pid=" + sdrj["id"].ToString() + "&do=addPP&price=" + Convert.ToString(sdrj.GetDecimal(19));
                    hyj.Target = "_blank";
                }
                sdrj.Close();
            }
        }
        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;
    }
}
