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;
using System.Web.Mail;
public partial class WebMain_Product_ProductList : 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)
    {
        if (Session["Wtouser"] == "vipadmin")
        {
            this.huititle.Text = "会员价格";
        }
        else
        {
            this.huititle.Text = "销售价格";
        }
        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);
        Label11.Text = sdr["times"].ToString();
        this.IMG1.Attributes.Add("onclick", "window.open('picmore.aspx?id="+sdr.GetInt32(0)+"')");
        this.Products.Text = sdr.GetString(3);
        this.pn.Text = 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);
        this.Marketprice.Text = "￥" + Convert.ToString(sdr.GetDecimal(18).ToString("0.00"));
        Label9.Text = sdr.GetDateTime(36).ToString("d");
        if (Session["Wtouser"] == "vipadmin")
        {
            this.CjVipPrice.Text = Convert.ToString(sdr.GetDecimal(24).ToString("0.00"));
            this.LKJSPrice.Text = "立即节省： ￥" + Convert.ToString(Convert.ToDecimal(sdr.GetDecimal(18).ToString("0.00")) - Convert.ToDecimal(sdr.GetDecimal(24).ToString("0.00")));

        }
        else
        {
            this.CjVipPrice.Text = Convert.ToString(sdr.GetDecimal(19).ToString("0.00"));
            this.LKJSPrice.Text = "立即节省： ￥" + Convert.ToString(Convert.ToDecimal(sdr.GetDecimal(18).ToString("0.00")) - Convert.ToDecimal(sdr.GetDecimal(19).ToString("0.00")));

        }


        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).Trim();
        string Pnew = sdr.GetString(13).Trim();
        string Phot = sdr.GetString(14).Trim();
        string Pt = sdr.GetString(15).Trim();

        if (sdr.GetInt32(11) == 0)
        {
            this.ImageButton1.Visible = false;
            this.HyperLink2.Visible = true;
        }
        else
        {
            this.ImageButton1.Visible = true;
            this.HyperLink2.Visible = false;
            this.Panel1.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);
        }
        tb2.Controls.Add(trP);
        sdr.Close();
        SqlCommand smd35 = new SqlCommand("select BigCategory from BigProductCategory where id=" +bigid, conn);
        this.title.Text = Convert.ToString(smd35.ExecuteScalar());
        this.title.NavigateUrl = "~/china/productPP.aspx?BigID="+bigid;
        this.title.Target = "_blank";
        SqlCommand smd34 = new SqlCommand("select SmallCategory from SmallProductCategory where id=" + smaid, conn);
        this.title2.Text = Convert.ToString(smd34.ExecuteScalar());
        this.title2.NavigateUrl = "~/china/product.aspx?SmallId="+smaid;
        this.title2.Target = "_blank";
        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)
    {
      //取值开始
            string Cid;
            string Cattr = "";
            int Camount;
            decimal Cprice;
            Cid = Request.QueryString["id"].Trim();
            Camount = 1;
            int Cuserid =Convert.ToInt32(Session["userid"]);
            Cprice = Convert.ToDecimal(this.CjVipPrice.Text);
            //-------------------------------------------
            string strsql = "";
            if (TOPdo.ExecW(Cuserid, Convert.ToInt32(Cid.Trim()), Cattr))
            {
                strsql = "update cart set amount=amount+1 where userid=" + Cuserid + " and pid=" + Cid + " and Attribute='" + Cattr + "'";
            }
            else
            {
                strsql = "insert into cart(userid,pid,amount,price,Attribute,pic,pname) values(" + Cuserid + "," + Cid + "," + Camount + "," + Cprice + ",'" + Cattr + "','" + picurl + "','" + pn.Text + "')";
            }



            if (TOPdo.Execsql(strsql))
            {
                Response.Redirect("cart.aspx");
            }
            else
            {
                Response.Write("<script>alert('此次提交失败!!')</script>");
            }
      
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["Wtouser"] == "vipadmin")
        {
            string Cid;
            string Cattr = "";
            int Camount;
            decimal Cprice;
            Cid = Request.QueryString["id"].Trim();
            Camount = 1;
            int Cuserid = Convert.ToInt32(Session["userid"]);
            Cprice = Convert.ToDecimal(this.CjVipPrice.Text);


            //-------------------------------------------
            string strsql = "";
            if (TOPdo.ExecW(Cuserid, Convert.ToInt32(Cid.Trim()), Cattr))
            {
                strsql = "update Collection set amount=amount+1 where userid=" + Cuserid + " and pid=" + Cid + " and Attribute='" + Cattr + "'";
            }
            else
            {
                strsql = "insert into Collection(userid,pid,amount,price,Attribute,pic,pname) values(" + Cuserid + "," + Cid + "," + Camount + "," + Cprice + ",'" + Cattr + "','" + picurl + "','" + pn.Text + "')";
            }



            if (TOPdo.Execsql(strsql))
            {
                Response.Write("<script>alert('成功放入收藏夹中!!');window.location.href='productlist.aspx?id="+Request.QueryString["id"]+"'</script>");
            }
            else
            {
                Response.Write("<script>alert('此次提交失败!!')</script>");
            }
        }
        else
        {
            Response.Redirect("~/china/viplogin.aspx");
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string userip="0";
      if(Request.ServerVariables["HTTP_VIA"]!=null)
      {

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

　　  }
      else
      {

          userip = Request.ServerVariables["REMOTE_ADDR"].ToString();
 
　  　}
    string sqltxt = "insert into newscomm(username,tel,Content,ip,pid,pname,pic,lan,type,addtime) values('" + this.pm.Text + "','" + this.ptel.Text + "','" + this.pco.Text + "','" + userip + "','" + Request.QueryString["id"].ToString() + "','" + this.pn.Text + "','" + this.pic.ImageUrl.ToString() + "','china','1','"+DateTime.Now.ToString()+"')";
       if (Doadmin.Exec(sqltxt))
       {
           Response.Write("<script>alert('资料提交成功! ');window.location.href('/china/productlist.aspx?id=" + Request.QueryString["id"] + "')</script>");
       }
       else
       {
           Response.Write("<script>alert('资料提交失败；请认真填填写! ');window.location.href('/china/productlist.aspx?id=" + Request.QueryString["id"] + "')</script>");

       }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
                SqlConnection Mconn = CDatabase.wtoconn();
                Mconn.Open();
                SqlCommand Msmd = new SqlCommand("select * from SystemBasicInformation", Mconn);
                SqlDataReader Msdr = Msmd.ExecuteReader();
                Msdr.Read();
                string Mform, Muid, Mpwd, Mstmp, Misopen, Mcont, MCompanyName, MWEBName, MTel, MFax, MEmail, MQQ, MAddress, MMSN, TBWW, MLOGOpic, Memailto;
                Mform = Msdr.GetString(7);
                Muid = Mform;
                Mpwd = Msdr.GetString(26);
                Mstmp = Msdr.GetString(25);
                Misopen = Msdr.GetString(1).ToString().Trim();
                MCompanyName = Msdr.GetString(2);
                MWEBName =Msdr.GetString(3);
                MTel = Msdr.GetString(5);
                MFax = Msdr.GetString(6);
                MEmail = Msdr.GetString(7);
                MQQ = Msdr.GetString(8);
                MAddress = Msdr.GetString(10);
                MMSN = Msdr.GetString(13);
                TBWW = Msdr.GetString(14);
                Memailto = Msdr.GetString(20);
                MLOGOpic = "<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "/images/" + Msdr.GetString(15) + " border=0></a>";
                Msdr.Close();
                    SqlCommand Msmd2 = new SqlCommand("select content from email where lx='6'", Mconn);
                    Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar()));
                    SqlCommand Msmd3 = new SqlCommand("select title from email where lx='6'", Mconn);
                    string Mti = Convert.ToString(Msmd3.ExecuteScalar());
                    MailMessage msg = new MailMessage();
                    msg.From = Mform;  //发送方地址(如test@163.com)
                    msg.To = ffdd.Text;
                    msg.BodyFormat = MailFormat.Html;   //正文内容类型 
                    msg.BodyEncoding = System.Text.Encoding.Default;    //正文内容编码 
                    //msg.Attachments.Add(new MailAttachment("d:\\d.txt"));
                    //主题 
                    msg.Subject = Mti;
                    //内容 
                    //编码定义
                    Mcont = Mcont.Replace("$CMY$", MCompanyName);
                    Mcont = Mcont.Replace("$WEBN$", MWEBName);
                    Mcont = Mcont.Replace("$TEL$", MTel);
                    Mcont = Mcont.Replace("$FAX$", MFax);
                    Mcont = Mcont.Replace("$EMA$", MEmail);
                    Mcont = Mcont.Replace("$QQ$", MQQ);
                    Mcont = Mcont.Replace("$ADD$", MAddress);
                    Mcont = Mcont.Replace("$MSN$", MMSN);
                    Mcont = Mcont.Replace("$TBW$", TBWW);
                    Mcont = Mcont.Replace("$LOGO$", MLOGOpic);
                    Mcont = Mcont.Replace("$PN$", this.Products.Text);
                    Mcont = Mcont.Replace("$PP$", this.CjVipPrice.Text);
                    Mcont = Mcont.Replace("$PT$", this.Label9.Text);
                    Mcont = Mcont.Replace("$PC$", this.Description.Text);
                    Mcont = Mcont.Replace("$PIC$","<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img border=0 src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + this.pic.ImageUrl.ToString().Replace("~","")+"></a>");
                    Mcont = Mcont.Replace("$PD$", this.Unit.Text);
                    Mcont = Mcont.Replace("$PCOUNT$", this.concent.Text);
                    msg.Body = Mcont;
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置为需要用户验证 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Muid); //设置验证用户名 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Mpwd); //设置验证密码 
                    SmtpMail.SmtpServer = Mstmp;  //邮件服务器地址(如smtp.163.com) 
                    SmtpMail.Send(msg);  //发送 
                    Mconn.Close();
                    Response.Write("<script>alert('发送成功');window.location.href='productlist.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='productlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
        }
        else
        {
            Response.Write("<script>alert('发表失败，请您再次提交！\n感谢您对我们的支持！');window.location.href='productlist.aspx?id=" + Request.QueryString["id"] + "'</script>");
        }
    }
}
