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 SYSadmin_Vote_Votemag : 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)
        {
            databind();
        }
    }
    protected void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from vote where id="+Request.QueryString["id"],conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        this.title.Text = sdr["title"].ToString();
        Label1.Text = sdr["title"].ToString();
        this.item1.Text = sdr["q1"].ToString();
        this.item2.Text = sdr["q2"].ToString();
        this.item3.Text = sdr["q3"].ToString();
        this.item4.Text = sdr["q4"].ToString();
        this.item5.Text = sdr["q5"].ToString();
        if (sdr["isfp"].ToString().Trim()== "y")
        {
            isy.Checked = true;
        }
        else
        {
            isn.Checked = true;
        }
        if (sdr["qtv"].ToString().Trim() == "y")
        {
            RadioButton1.Checked = true;
        }
        else
        {
            RadioButton2.Checked = true;
        }
        this.i1.Text = sdr["d1"].ToString();
        this.i2.Text = sdr["d2"].ToString();
        this.i3.Text = sdr["d3"].ToString();
        this.i4.Text = sdr["d4"].ToString();
        this.i5.Text = sdr["d5"].ToString();
        this.title2.Text = sdr["title"].ToString();
        this.titall.Text = sdr["votoall"].ToString();

        sdr.Close();
        conn.Close();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        string isfp = "",isvi = "";
        if (isy.Checked)
        {
            isfp = "y";
        }
        else
        {
            isfp = "n";
        }
        if (RadioButton1.Checked)
        {
            isvi = "y";
        }
        else
        {
            isvi = "n";
        }
        string sqltxt = "update Vote set title='" + this.title.Text + "',q1='" + this.item1.Text + "',q2='" + this.item2.Text + "',q3='" + this.item3.Text + "',q4='" + this.item4.Text + "',q5='" + this.item5.Text + "',isfp='" + isfp + "',qtv='"+isvi+"' where id=" + Request.QueryString["id"]; ;
        if (Doadmin.Exec(sqltxt))
        {
            if (isfp == "y")
            {
                Doadmin.Execsql("update vote set isfp='n' where id<>" +Request.QueryString["id"]);
            }
            Response.Write("<script>alert('提交成功');window.location.href='Votemag.aspx'</script>");
        }
        else
        {
            Response.Write(sqltxt);
            //Response.Write("<script>alert('添加失败');window.location.href='Voteadd.aspx'</script>");
        }
    }
}
