?? vote.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace vote
{
/// <summary>
/// index 的摘要說明。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder2;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
protected System.Web.UI.WebControls.Label label1;
private void Page_Load(object sender, System.EventArgs e)
{
//if(!IsPostBack)
//{
string strConnection,strSQL;
strConnection="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
strSQL="select vote,votenum,votetype from vote order by voteid desc";
OleDbConnection objConnection=new OleDbConnection (strConnection);
OleDbCommand objCommand = new OleDbCommand (strSQL,objConnection);
OleDbDataReader objDataReader = null;
objConnection.Open ();
objDataReader=objCommand.ExecuteReader();
objDataReader.Read();
string strvote="";
strvote+=objDataReader["vote"];
string strvotenum="";
strvotenum+=objDataReader["votenum"];
string strvotetype="";
strvotetype+=objDataReader["votetype"];
string [] vote=strvote.Split('|');
string [] votenum=strvotenum.Split('|');
RadioButtonList objRadioButtonList=new RadioButtonList();
CheckBoxList objCheckBoxList=new CheckBoxList();
int InAll=0;
if(Convert.ToInt32(strvotetype)==0)
{
for(int i=0;i<vote.Length;i++)
{
objRadioButtonList.Items.Add(vote[i]);
InAll=InAll+Convert.ToInt32(votenum[i]);
}
objRadioButtonList.ID="radio1";
PlaceHolder1.Controls.Add (objRadioButtonList);
}
else
{
for(int i=0;i<vote.Length;i++)
{
objCheckBoxList.Items.Add(vote[i]);
InAll=InAll+Convert.ToInt32(votenum[i]);
}
objCheckBoxList.ID="check1";
PlaceHolder1.Controls.Add (objCheckBoxList);
}
objDataReader.Close();
objConnection.Close();
label1.Text=Convert.ToString(InAll);
//}
//else
//{
//}
}
private void Button2_Click(object sender, System.EventArgs e)
{
//Response.Redirect("voteview.aspx");
Response.Write(@"<script language=JavaScript>window.open('voteview.aspx','_blank','left=10,top=20,width=710,height=400');</script>");
}
private void Button1_Click(object sender, System.EventArgs e)
{
string strConnection,strSQL;
strConnection="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
strSQL="select voteid,vote,votenum,votetype from vote order by voteid desc";
OleDbConnection objConnection=new OleDbConnection (strConnection);
OleDbCommand objCommand = new OleDbCommand (strSQL,objConnection);
OleDbDataReader objDataReader = null;
objConnection.Open ();
objDataReader=objCommand.ExecuteReader();
objDataReader.Read();
int voteid=Convert.ToInt32(objDataReader["voteid"]);
string strvotenum="";
strvotenum+=objDataReader["votenum"];
string strvote="";
strvote+=objDataReader["vote"];
string [] vote=strvote.Split('|');
string [] votenum=strvotenum.Split('|');
string [] postvote=new string [votenum.Length];
string votenum_1="";
int strvotetype=Convert.ToInt32 (objDataReader["votetype"]);
objDataReader.Close();
objCommand.Dispose();
objConnection.Close();
if(strvotetype==1)//如是多選項
{
for(int i=0;i<votenum.Length ;i++)//取得多選項值
{
if(Request.Form ["check1:"+i+""]=="on")
{
postvote[i]="1";
}
else
{
postvote[i]="0";
}
}
}
for(int j=0; j<vote.Length ;j++)//循環投票項目數
{
if(strvotetype==0)//如是單選項
{
if(Request.Form["radio1"]==vote[j])
{
votenum[j]=Convert.ToString(Convert.ToInt32(votenum[j])+1);
}
votenum_1=""+votenum_1+""+votenum[j]+"|";
}
else
{
if(postvote[j]!="0")
{
votenum[j]=Convert.ToString(Convert.ToInt32(votenum[j])+1);
}
votenum_1=""+votenum_1+""+votenum[j]+"|";
}
}
int votenumlen;
votenumlen=votenum_1.Length ;
votenum_1=votenum_1.Substring(0,votenumlen-1);
string strconn="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
string strsql="update vote set votenum='"+votenum_1+"' where voteid="+voteid+"";
OleDbConnection myConnection = new OleDbConnection(strconn);
OleDbCommand myCommand = new OleDbCommand(strsql, myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Dispose();
myConnection.Close();
//Response.Write (strsql);
//Response.Redirect("voteview.aspx");
Response.Write(@"<script language=JavaScript>window.open('voteview.aspx','_blank','left=10,top=20,width=710,height=400');</script>");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -