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_intProductList : System.Web.UI.UserControl
{
    private string id;
    DropDownList dd1 = new DropDownList();
    DropDownList dd2 = new DropDownList();
    DropDownList dd3 = new DropDownList();
    DropDownList dd4 = new DropDownList();
    DropDownList dd5 = new DropDownList();
    DropDownList dd6 = new DropDownList();
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    string picurl = "";
    string pname = "";
    public string Id
    {
        set
        {
            this.id = value.ToString().Trim();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        Session["pid"] = id;
        SqlCommand smd = new SqlCommand("select * from ProductInfo where id=" + id, conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        int bigid = sdr.GetInt32(1);
        int smaid = sdr.GetInt32(2);
        this.IMG1.Attributes.Add("onclick", "window.open('picmore.aspx?id=" + sdr.GetInt32(0) + "')");
        this.Products.Text = sdr.GetString(3);
        pname = sdr.GetString(3);
        this.ProductsNo.Text = sdr.GetString(4);
        string BRANDid = sdr.GetString(7);
        this.Unit.Text = sdr.GetString(9);
        this.Unitweight.Text = sdr.GetString(10);
        this.Description.Text = sdr.GetString(8);
        Label9.Text = sdr.GetDateTime(36).ToString("d");
        this.pic.ImageUrl = "~/upfile/" + sdr.GetString(26);
        this.pic.Attributes.Add("onclick", "window.open('picmore.aspx?id=" + sdr.GetInt32(0) + "')");
        this.pic.Style.Add("cursor", "hand");
        picurl = sdr.GetString(26);
        this.concent.Text = Server.HtmlDecode(sdr.GetString(33)).Replace("http://127.0.0.1/", "../");
        string picmove = sdr.GetString(34);
        string Pnew = sdr.GetString(13).Trim();
        string Phot = sdr.GetString(14).Trim();
        string Pt = sdr.GetString(15).Trim();
        this.LKJSPrice.Text = sdr["intj"].ToString();
        Label10.Text = sdr["Stockvolume"].ToString() + sdr.GetString(9);


        if (sdr.GetInt32(11) == 0)
        {
            this.ImageButton1.Visible = false;
            this.HyperLink2.Visible = true;
        }
        else
        {
            this.ImageButton1.Visible = true;
            this.HyperLink2.Visible = false;
        }
        TableRow trP = new TableRow();
        if (Pnew == "y")
        {
            TableCell tcP = new TableCell();
            Image picnew = new Image();
            picnew.ImageUrl = "~/images/newicon.gif";
            tcP.Controls.Add(picnew);
            trP.Controls.Add(tcP);
        }
        if (Phot == "y")
        {
            TableCell tcP2 = new TableCell();
            Image pichot = new Image();
            pichot.ImageUrl = "~/images/hoticon.gif";
            tcP2.Controls.Add(pichot);
            trP.Controls.Add(tcP2);
        }
        if (Pt == "y")
        {
            TableCell tcP3 = new TableCell();
            Image pt = new Image();
            pt.ImageUrl = "~/images/commendicon.gif";
            tcP3.Controls.Add(pt);
            trP.Controls.Add(tcP3);
        }
        sdr.Close();
        SqlCommand smdtxt = new SqlCommand("select SmallCategory from SmallProductCategory where id=" + smaid, conn);
        this.title2.Text = Convert.ToString(smdtxt.ExecuteScalar());


        SqlCommand smd35 = new SqlCommand("select BigCategory from BigProductCategory where id=" + bigid, conn);
        SqlCommand smddd = new SqlCommand("select BrandName from Brand where id=" + BRANDid, conn);
        this.Brand.Text = Convert.ToString(smddd.ExecuteScalar());
        SqlDataAdapter smdp = new SqlDataAdapter("select * from Comments where pid=" + id + " and isfp='y' order by FBdate desc", conn);
        DataSet ds = new DataSet();
        smdp.Fill(ds, "cu");
        this.pl.DataSource = Doadmin.psgb(ds, Table1, 5, 1);
        this.pl.DataBind();
        conn.Close();
        Doadmin.Execsql("update ProductInfo set times=times+1 where id=" + Request.QueryString["id"]);
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["Wtouser"] == "vipadmin")
        {

            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd;
            SqlDataReader sdr;
            smd = new SqlCommand("select * from ProductInfo where id=" + Request.QueryString["id"].Trim(), conn);
            sdr = smd.ExecuteReader();
            sdr.Read();
            int intj = 0, Pid = 0;
            string ProductName = "", pic = "";
            if (sdr["Stockvolume"].ToString() != "0")
            {
                //产品信息取值
                intj = Convert.ToInt32(sdr["intj"].ToString());
                Pid = Convert.ToInt32(sdr["id"].ToString());
                ProductName = sdr["Products"].ToString();
                pic = sdr["ThumbnailsPic"].ToString();

            }
            sdr.Close();
            smd = new SqlCommand("select * from MemberVIP where id=" + Session["userid"], conn);
            sdr = smd.ExecuteReader();
            sdr.Read();
            int vipint = Convert.ToInt32(sdr["Integral"].ToString());
            string Ordername = sdr["vipname"].ToString();
            string OrderEmail = sdr["vipemail"].ToString();
            string OrderTel = sdr["Telephone"].ToString();
            string OrderMobi = sdr["MobilePhone"].ToString();
            string OrderAdd = sdr["vipAddress"].ToString();
            string OrderPost = sdr["Post"].ToString();
            string OrderMone = "这是积分所换的订单";
            string OrderPayM = "积分";
            string OrderSonF = "配送";
            string Orderaear = "10000012";
            int OrderTatal = 0;
            string OrderAddDate = DateTime.Now.ToString();
            string OrderState = "22";//积分订单
            string isvip = "y";
            sdr.Close();
            if (vipint >= intj)
            {
                //会员信息取值
                string Orderno = "INT" + DateTime.Now.ToString("yymmddssffssss");
                string OrderUserId = Session["userid"].ToString();

                string sql1 = "insert into Orderw(Orderno,OrderUserId,Ordername,OrderEmail,OrderTel,OrderMobi,OrderAdd,OrderPost,Orderaear,OrderPostTime,OrderMone,OrderPayM,OrderSonF,OrderTatal,OrderAddDate,OrderState,isvip,b3) ";
                sql1 += "values ('" + Orderno + "'," + OrderUserId + ",'" + Ordername + "','" + OrderEmail + "','" + OrderTel + "','" + OrderMobi + "','" + OrderAdd + "','" + OrderPost + "','" + Orderaear + "','" + DateTime.Now.ToString() + "','" + OrderMone + "','" + OrderPayM + "','" + OrderSonF + "'," + Convert.ToDecimal(OrderTatal) + ",'" + OrderAddDate + "'," + OrderState + ",'" + isvip + "'," + intj + ")";
                if (Doadmin.Exec(sql1))
                {
                    Doadmin.Execsql("update MemberVIP set Integral=Integral-" + intj + ",intout='" + DateTime.Now.ToString() + "' where id=" + Session["userid"]);
                    Doadmin.Execsql("update ProductInfo set Stockvolume=Stockvolume-1 where id=" +Request.QueryString["id"].Trim());
                    Session["intj"] = Convert.ToInt32(Session["intj"]) - intj;
                    smd = new SqlCommand("select id from Orderw where Orderno='" + Orderno + "'", conn);
                    int OrderID = Convert.ToInt32(smd.ExecuteScalar());

                    TOPdo.Execsql("insert into OrderInfo(OrderID,Pid,ProductName,price,Amount,Attr,pic) values (" + OrderID + "," + Pid + ",'" + ProductName + "',0,1,'','" + pic + "')");
                    Response.Write("<script>alert('兑换成功!我们会在最短时间为您送到! \\n 积分赠送详情请到商城服务的积分制度。');window.location.href='/china/intproductlist.aspx?id="+Request.QueryString["id"]+"'</script>");

                }
                else
                {
                    Response.Write("<script>alert('兑换失败! \\n 积分赠送详情请到商城服务的积分制度。');window.location.href='/china/intproductlist.aspx?id=" + Request.QueryString["id"] + "'</script>");

                }
            }
            else
            {
                Response.Write("<script>alert('您积分不够，请购买本网的商品获取更多积分! \\n 积分赠送详情请到商城服务的积分制度。');window.location.href='/china/intproductlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
            }

            conn.Close();
        }
        else
        {
            Response.Write("<script>alert('请登录，只有会员凭积分换此赠品! \\n积分赠送详情请到商城服务的积分制度。');window.location.href='/china/intproductlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
        }
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        string a, b, c = "y", d = "0"; //a用户名  b内容  c 是否匿名 d 评分
        a = this.username.Text;
        b = countnet.Text;
        if (a == "")
            a = "游客";
        if (b == "")
            b = "这家伙很懒，什么也没留";
        if (isuser.Checked)
        {
            c = "y";

        }
        else
        {
            c = "n";
        }
        if (pf1.Checked)
        {
            d = "1";
        }
        if (pf2.Checked)
        {
            d = "2";
        }
        if (pf3.Checked)
        {
            d = "3";
        }
        if (pf4.Checked)
        {
            d = "4";
        }
        if (pf5.Checked)
        {
            d = "5";
        }


        string isusertrue;
        if (Session["Wtouser"] != "vipadmin")
        {
            isusertrue = "n";
        }
        else
        {
            isusertrue = "y";
            SqlConnection connzf = CDatabase.wtoconn();
            connzf.Open();
            SqlCommand smdzf = new SqlCommand("select bbsson from Integral", connzf);
            string bbsjf = Convert.ToString(smdzf.ExecuteScalar());
            connzf.Close();
            Doadmin.Execsql("update MemberVIP set Integral=Integral+" + Convert.ToInt32(bbsjf) + " where id=" + Session["userid"].ToString());
        }
        string userip = "";
        if (Request.ServerVariables["HTTP_VIA"] != null)
        {

            userip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();

        }
        else
        {

            userip = Request.ServerVariables["REMOTE_ADDR"].ToString();

        }
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select Products,ThumbnailsPic from ProductInfo where id=" + Session["pid"], conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        string pname = sdr.GetString(0);
        string pic = sdr.GetString(1);
        sdr.Close();


        SqlCommand smd2 = new SqlCommand("select ProcuctMSet from SystemBasicInformation", conn);
        string closeandopen = Convert.ToString(smd2.ExecuteScalar());
        conn.Close();

        string sql = "insert into comments(username,isfp,content,ip,pid,FBdate,Pf,isuser,userid,isusertrue,pname,pic,shefen,reContent) values ('" + a + "','" + closeandopen + "','" + b + "','" + userip + "','" + Session["pid"] + "','" + System.DateTime.Now.ToString() + "'," + d + ",'" + c + "'," + Session["userid"] + ",'" + isusertrue + "','" + pname + "','" + pic + "','客服回复','您好，这是系统自动回复，我们会尽快回复您；')";
        if (TOPdo.Execsql(sql))
        {
            Response.Write("<script>alert('发表成功，感谢您对我们的支持！');window.location.href='intproductlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
        }
        else
        {
            Response.Write("<script>alert('发表失败，请您再次提交！\n感谢您对我们的支持！');window.location.href='intproductlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
        }
    }
}