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_vipedit : 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)
        {
            this.Label1.Visible = false;
            string UserName = this.vipusername.Text;
            if (TOPdo.chkadminuser(UserName))
            {
                this.Label1.Visible = true;
                this.Label1.Text = "该用户存在";
                
            }
            else
            {

                this.Label1.Visible = true;
                this.Label1.Text = "该用户不存在 您可以使用";
            }
            if (UserName == "")
            {
                this.Label1.Visible = true;
                this.Label1.Text = "不能为空 ";

            }
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        string vipname, username, vipuserpwd, vipemail, MobilePhone, Telephone, vipBirthday, viparear, vipAddress, Post, addtime, vipright, Integral, PWDQuestions, PWDAnswer,vipsex,isok;
        vipname = Request["vipname"].ToString().Trim();
        username = this.vipusername.Text;
        vipuserpwd = Request["vipuserpwd"].ToString().Trim();
        vipemail = Request["vipemail"].ToString().Trim();
        MobilePhone = Request["MobilePhone"].ToString().Trim();
        Telephone = Request["Telephone"].ToString().Trim();
        vipBirthday = Request["vipBirthday"].ToString().Trim();
        viparear = Request["viparear"].ToString().Trim();
        vipAddress = Request["vipAddress"].ToString().Trim();
        Post = Request["Post"].ToString().Trim();
        addtime = Request["addtime"].ToString().Trim();
        vipright = this.vipright.SelectedValue.ToString().Trim();
        PWDQuestions = Request["PWDQuestions"].ToString().Trim();
        PWDAnswer = Request["PWDAnswer"].ToString().Trim();
        Integral = Request["Integral"].ToString().Trim();
        if (n.Checked)
        {
            vipsex = "n";
        }
        else
        {
            vipsex = "v";
        }

        if (open.Checked)
        {
            isok = "y";
        }
        else
        {
            isok = "n";
        }
        string userip = "";
        if (Request.ServerVariables["HTTP_VIA"] != null)
        {

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

        }
        else
        {

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

        }
        float zk = 10.00f;
        if (Label1.Text.Trim() != "该用户存在")
        {
            string sql = "insert into  MemberVIP(isok,vipname,vipusername,vipuserpwd,PWDQuestions,PWDAnswer,vipemail,vipsex,vipBirthday,viparear,vipAddress,Post,MobilePhone,Telephone,addtime,logintimes,vipright,loginIP,Integral,enddate,tjren,intin,intout,vipzk) values(";
            sql += "'" + isok + "','" + vipname + "','" + username + "','" + vipuserpwd + "','" + PWDQuestions + "','" + PWDAnswer + "','" + vipemail + "','" + vipsex + "','" + vipBirthday + "','" + viparear + "','" + vipAddress + "','" + Post + "','" + MobilePhone + "','" + Telephone + "','" + DateTime.Now.ToString() + "',1,'1','" + userip + "'," + Integral + ",'" + DateTime.Now.ToString() + "','管理员','" + DateTime.Now.ToString() + "','" + DateTime.Now.ToString() + "',"+zk+")";
            if (Doadmin.Exec(sql))
            {
                Response.Write("<script>alert('添加成功!');location.href='vipmag.aspx'</script>");
                //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();
                //if (Memailto == "y")
                //{
                //    SqlCommand Msmd2 = new SqlCommand("select content from email where lx='1'", Mconn);
                //    Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar()));
                //    SqlCommand Msmd3 = new SqlCommand("select title from email where lx='1'", Mconn);
                //    string Mti = Convert.ToString(Msmd3.ExecuteScalar());
                //    MailMessage msg = new MailMessage();
                //    msg.From = Mform;  //发送方地址(如test@163.com)
                //    msg.To = vipemail; //接收方地址(如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("$UID$", vipusername)).Replace("$PWD$", vipuserpwd));
                //    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("$ORN$", this.vipname.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();
            }
            else
            {
                Response.Write(sql);
                //Response.Write("<script>alert('此次操作失败!')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('存在同名用户，请重新换用户名；!');window.location.href='vipmag.aspx'</script>");
        }
    }
}
