using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    static int nSurveyID=-1;
    static int nTotal = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = ConfigurationManager.AppSettings["WebTitle"].ToString() + "--在线调查";
        if (!Page.IsPostBack)
        {
            Gettitle();
            lblDanwei.Text = ConfigurationManager.AppSettings["WebTitle"];
            lblDate.Text = System.DateTime.Now.ToString();
            Gettotal();
            Bindsurvey(nSurveyID);
        }
        
    }
    //取标题
    private void Gettitle()
    {
        INews shownews = new Mynews();
        SqlDataReader dr = shownews.SqlGetinfo("SELECT SurveyID,Title FROM Survey WHERE ShowID=1");
        if (dr.Read())
        {
            lblTitle.Text = dr["Title"].ToString();
            nSurveyID = Int32.Parse(dr["SurveyID"].ToString());
           
        }
    }
    //绑定控件
    private void Bindsurvey(int nParrentID)
    {
        INews shownews = new Mynews();
        DataSet ds=shownews.DsGetinfo("SELECT * FROM Surveyitem WHERE ParrentID=" + nSurveyID);
        TongjiGridView.DataSource = ds.Tables["aa"].DefaultView;
        TongjiGridView.DataBind();
    }
   //取总票数
    private void Gettotal()
    {
        INews shownews=new Mynews();
        SqlDataReader dr = shownews.SqlGetinfo("SELECT SUM(Hit) AS Thenum FROM Surveyitem WHERE ParrentID=" + nSurveyID);
        if(dr.Read())
        {
            nTotal = Int32.Parse(dr["Thenum"].ToString());
        }
    }
    protected int Imgwidth(int nHit)
    {
        if (nHit < 1 || nTotal < 1) { return 0; }
        int thenum = nHit * 100 / nTotal * 3;
        return thenum;
    }
    protected int Imgwidth1(int nHit)
    {
        if (nHit < 1 || nTotal < 1) { return 0; }
        int thenum = nHit * 100 / nTotal;
        return thenum;
    }
}
