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 WTOSYSadmin_vipmag_viewsedit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (!IsPostBack)
        {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd = new SqlCommand("select * from Comments where id=" + Request.QueryString["id"], conn);
            SqlDataReader sdr = smd.ExecuteReader();
            sdr.Read();
            if (sdr.GetString(12) == "y")
            {
                this.Image1.Visible = true;
                this.Label1.Visible = true;
            }
            this.username.Text = sdr.GetString(1);
            this.Content.Text = sdr.GetString(3);
            this.ip.Text = sdr.GetString(4);
            if (sdr.GetString(2) == "y")
            {
                this.y.Checked = true;
            }
            else
            {
                this.n.Checked = true;
            }
            if (sdr.GetString(6) != "n" && sdr.GetString(7) != "n")
            {
                this.shefen.Text = sdr.GetString(6);
                this.reContent.Text = sdr.GetString(7);
            }
            sdr.Close();

            
            conn.Close();

        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        string isfp, content, shenfen, recontent;
        if (this.y.Checked == true)
        {
            isfp = "y";
        }
        else
        {
            isfp = "n";
        }
        content = Request["Content"].ToString();
        shenfen = Request["shefen"].ToString();
        recontent = Request["reContent"].ToString();
        string sql = "update Comments set isfp='"+isfp+"',Content='"+content+"',shefen='"+shenfen+"',reContent='"+recontent+"',redate='"+DateTime.Now.ToString()+"' where id="+Request.QueryString["id"];
        if (Doadmin.Exec(sql))
        {
            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(23).Trim();
            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();

            string cn, ct, cc, rm, cemail;
            SqlCommand Msmd2 = new SqlCommand("select content from email where lx='7'", Mconn);
            Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar()));
            SqlCommand Msmd3 = new SqlCommand("select title from email where lx='7'", Mconn);
            string Mti = Convert.ToString(Msmd3.ExecuteScalar());
            SqlCommand Vsmd = new SqlCommand("select username,Content,reContent,FBdate,email from Comments where id=" + Request.QueryString["id"], Mconn);
            SqlDataReader Vsdr = Vsmd.ExecuteReader();
            Vsdr.Read();
            cn = Vsdr["username"].ToString();
            ct = Vsdr["FBdate"].ToString();
            cc = Vsdr["Content"].ToString();
            rm = Vsdr["reContent"].ToString();
            cemail = Vsdr["email"].ToString();
            Vsdr.Close();
            if (cemail != "")
            {
                MailMessage msg = new MailMessage();
                msg.From = Mform;  //发送方地址(如test@163.com)
                msg.To = cemail; //接收方地址(如test@163.com) 
                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("$CM$", cc);
                Mcont = Mcont.Replace("$RM$", rm);
                Mcont = Mcont.Replace("$CI$", ct);
                Mcont = Mcont.Replace("$MREN$", cn);
                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);  //发送 
            }


            Response.Write("<script>alert('修改成功!');location.href='views.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败!')</script>");
        }

    }
}
