📄 votemanage.aspx.cs
字号:
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.OleDb;
public partial class Default2 : System.Web.UI.Page
{
public void listbox1Bind()
{
string sql_sel = "select * from voteMaster";
ListBox1.DataSource = db.select(sql_sel);
ListBox1.DataValueField = "voteID";
ListBox1.DataTextField = "voteTitle";
ListBox1.DataBind();
}
public void listbox2Bind(string voteID)
{
string sql_sel = "select * from voteDetails,voteMaster where voteTitle='"+ListBox1.SelectedItem.Text+"' and voteDetails.voteID=voteMaster.voteID ";
ListBox2.DataSource = db.select(sql_sel);
ListBox2.DataValueField = "voteDetailsID";
ListBox2.DataTextField = "voteItem";
ListBox2.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
listbox1Bind();
this.Button2.Attributes.Add("onclick", "javascript:return confirm('删除此项从表的内容也要删除,确定要删除吗');");
this.Button3.Attributes.Add("onclick", "javascript:return confirm('确定要删除吗');");
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "select * from voteDetails,voteMaster where voteTitle='" + ListBox1.SelectedItem.Text + "'and voteDetails.voteID=voteMaster.voteID";
db.ExecSel(sql);
listbox2Bind(ListBox1.SelectedValue);
}
protected void Button4_Click(object sender, EventArgs e)
{//主表添加
string add = "insert into voteMaster(voteTitle) values('" + TextBox1.Text + "')";
db.execsql(add);
listbox1Bind();
}
protected void Button5_Click(object sender, EventArgs e)
{//从表添加
try
{
string sql_itemadd = "insert into voteDetails(voteID,voteDetailsID,voteItem) values(" + ListBox1.SelectedValue + "," + ListBox2.Items.Count + 1 + ",'" + this.TextBox2.Text + "')";
db.execsql(sql_itemadd);
listbox2Bind(this.ListBox1.SelectedValue);
}
catch
{
Response.Write("<script language='javascript'>alert('请先在主表中选择一项');</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{//主表删除
try
{
string del = "delete from voteMaster where voteMaster.voteID=" + ListBox1.SelectedValue;
db.execsql(del);
listbox1Bind();
ListBox2.Items.Clear();
}
catch
{
Response.Write("<script language='javascript'>alert('请选中要删除的项');</script>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{//选择当前投票项目
try
{
Label1.Text = "当前投票项目为" + ListBox1.SelectedItem.Text;
Application.Lock();
Application["voteID"] = ListBox1.SelectedValue;
Application.UnLock();
Response.Redirect("vote.aspx");
}
catch (Exception)
{
Response.Write("<script language='javascript'>alert('请重试!');</script>");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//从表删除
if(ListBox2.SelectedItem!=null)
{
string del2 = "delete from voteDetails where voteID=" + ListBox1.SelectedValue + " and voteDetailsID=" + ListBox2.SelectedValue;
db.execsql(del2);
listbox2Bind(this.ListBox1.SelectedValue);
}
else
{
Response.Write("<script language='javascript'>alert('请选中要删除的项');</script>");
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -