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 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)
        {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd = new SqlCommand("select * from MemberVIP where id=" + Request.QueryString["id"], conn);
            SqlDataReader sdr = smd.ExecuteReader();
            sdr.Read();
            if (sdr.GetString(1) == "y")
            {
                this.open.Checked = true;
            }
            else
            {
                this.close.Checked = true;
            }

            if (sdr.GetString(8) == "n")
            {
                this.n.Checked = true;
            }
            else
            {
                this.v.Checked = true;
            }
            this.id.Text = Convert.ToString(sdr.GetInt32(0));
            this.vipname.Text = sdr.GetString(2);
            this.username.Text = sdr.GetString(3);
            this.vipuserpwd.Text = sdr.GetString(4);
            this.vipemail.Text = sdr.GetString(7);
            this.MobilePhone.Text = sdr.GetString(13);
            this.Telephone.Text = sdr.GetString(14);

            this.tjren.Text = sdr["tjren"].ToString();
            this.vipBirthday.Text = Convert.ToString(sdr.GetDateTime(9));
            this.viparear.Text = sdr.GetString(10);
            this.vipAddress.Text = sdr.GetString(11);
            this.Post.Text = sdr.GetString(12);
            this.addtime.Text = Convert.ToString(sdr.GetDateTime(15));
            this.vipright.SelectedValue = sdr.GetString(17);
            this.Integral.Text = Convert.ToString(sdr.GetInt32(19));
            this.PWDQuestions.Text = sdr.GetString(5);
            this.PWDAnswer.Text = sdr.GetString(6);
            this.enddate.Text = Convert.ToString(sdr.GetDateTime(20));
            this.logintimes.Text = Convert.ToString(sdr.GetInt32(16));
            this.loginIP.Text = sdr.GetString(18);
            this.TextBox1.Text = sdr["vipzk"].ToString();
            sdr.Close();
            SqlCommand smdt = new SqlCommand("select sum(OrderTatal) from Orderw where OrderUserId=" + Request.QueryString["id"], conn);
            this.total.Text = Convert.ToString(smdt.ExecuteScalar());
            if (Convert.ToString(smdt.ExecuteScalar()) == "")
            {
                this.total.Text = "0";
            }
            conn.Close();
        }
    }
    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 = Request["username"].ToString().Trim();
        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();
        float zk =Convert.ToSingle(this.TextBox1.Text);
        if (n.Checked)
        {
            vipsex = "n";
        }
        else
        {
            vipsex = "v";
        }

        if (open.Checked)
        {
            isok = "y";
        }
        else
        {
            isok = "n";
        }
        string sql = "update  MemberVIP set isok='"+isok+"',vipsex='"+vipsex+"',vipname='" + vipname + "',vipusername='" + username + "',vipuserpwd='" + vipuserpwd + "',vipemail='" + vipemail + "',MobilePhone='" + MobilePhone + "',";
        sql+="Telephone='"+Telephone+"',vipBirthday='"+vipBirthday+"',viparear='"+viparear+"',vipAddress='"+vipAddress+"',";
        sql += "Post='" + Post + "',addtime='" + addtime + "',vipright='" + vipright + "',Integral=" + Integral + ",PWDQuestions='" + PWDQuestions + "',PWDAnswer='" + PWDAnswer + "',vipzk="+zk+" where id=" + Request.QueryString["id"];
        if (Doadmin.Exec(sql))
        {
            Response.Write("<script>alert('修改成功!');location.href='vipmag.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败!')</script>");
        }
    }
}
