📄 guest.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.SqlClient;
//5_1_a_s_p_x.c_o_m
public partial class guest : System.Web.UI.Page
{
DB db = new DB();//引用数据库类
protected void Page_Load(object sender, EventArgs e)
{
//this.Label2.Text = "欢迎"+Request.QueryString["guest"].ToString()+"到来!";
}
protected void Button1_Click(object sender, EventArgs e)
{
//客户添加投票项目,可选择是否上传图片
int ip = Convert.ToInt32(this.DropDownList1.SelectedValue);
if (FileUpload1.HasFile)
{ //需要上传图片
string filename = Server.MapPath("image/master/") + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(filename);
string strmaster1 = "insert into voteMaster(voteTitle,image,endTime) values('" + this.TextBox1.Text.ToString() + "','" + this.FileUpload1.FileName.ToString() + "','" +this.TextBox2.Text.ToString()+ "')";
db.NonQueryexecute(strmaster1);
insertItem();
this.Label1.Text = "添加图片投票成功!";
}
else
{
string strmaster2 = "insert into voteMaster(voteTitle,endTime) values('" + this.TextBox1.Text.ToString().Trim() + "','" + this.TextBox2.Text.ToString().Trim() + "')";
db.NonQueryexecute(strmaster2);
insertItem();
this.Label1.Text = "添加文字投票成功!";
}
}
//定义一个方法,用来添加选项表和系统设置,模式
public void insertItem()
{
int ip = Convert.ToInt32(this.DropDownList1.SelectedValue);
string strid = "select id from voteMaster where voteTitle='" + this.TextBox1.Text.ToString() + "'";
int b = Convert.ToInt32(db.executeGetReturn(strid));
string striconfig = "insert into voteConfig(id,checkIP,checkTime) values(" + b + "," + ip + "," + this.TextBox3.Text + ")";
//判断模式:单选模式和多选模式
if (this.DropDownList2.Text == "单选模式")
{ //投票标题添加到选项表并储存模式记录
string stritem = "insert into voetDetails(voteItem,id) values('" + this.TextBox1.Text + "'," + b + ")";
string strmode = "update voteMaster set mode=" + 0+"where id="+b;
string[] arq= new string[3];
arq[0]=stritem;
arq[1]=strmode;
arq[2] = striconfig;
if (db.trantion(arq))
{
Response.Write("<script>alert('添加单选模式成功!')</script>");
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script>alert('添加单选模式不成功!')</script>");
}
}
if (this.DropDownList2.Text == "双选模式")
{ //添加系统设置和模式记录并跳转到添加选项页面
string strmode2 = "update voteMaster set mode=" + 1 + "where id=" + b;
string[] arq1 = new string[2];
arq1[0] = strmode2;
arq1[1] = striconfig;
if (db.trantion(arq1))
{
Response.Redirect("addItems.aspx?voteTitle=" + this.TextBox1.Text.ToString());//跳转到添加选项页面并把投票标题传过去
}
else
{
Response.Write("<script>alert('添加双选模式不成功!')</script>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -