代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class testAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string content = test_content.Text;
string ans1 = tbx_ans1.Text;
string ans2 = tbx_ans2.Text;
string ans3 = tbx_ans3.Text;
string ans4 = tbx_ans4.Text;
int score = Convert.ToInt32(test_score.Text);
int pub;
if (cbx_isPub.Checked)
pub = 1;
else
pub = 0;
if(content == "")
{
Response.Write("<script>alert(\"添加失败!\");</script>");
return;
}
DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM [dangXueTu_testSystem].[dbo].[single] WHERE content ='" + content + "' ");
if (dt.Tables[0].Rows.Count > 0)
{
Response.Write("<script>alert('问题已存在,请重新添加!')</script>");
return;
}
if (content == "" || ans1 == "" || ans2 == "" || ans3 == "" || ans4 == "")
{
Response.Write("<script>alert('请填写完整!')</script>");
return;
}
if (ans1 == ans2 || ans1 == ans3 || ans1 == ans4 || ans2 == ans3 || ans2 == ans4 || ans3 == ans4)
{
Response.Write("<script>alert('选项重复!')</script>");
return;
}
if (!choose1.Checked && !choose2.Checked && !choose3.Checked && !choose4.Checked)
{
Response.Write("<script>alert('请选择正确答案!')</script>");
return;
}
if (test_score.Text == null)
{
score = 2;
}
String rightAns = "";
if (choose1.Checked)
rightAns = ans1;
else if (choose2.Checked)
rightAns = ans2;
else if (choose3.Checked)
rightAns = ans3;
else if (choose4.Checked)
rightAns = ans4;
int ins = SqlHelper.ExecuteNonQuery(CommandType.Text, "insert into [dangXueTu_testSystem].[dbo].[single](content,ans1,ans2,ans3,ans4,rightAns,score,pub) values('" + content + "','" + ans1 + "','" + ans2 + "','" + ans3 + "','" + ans4 + "','" + rightAns + "','" + score + "','" + pub + "')");
if (ins == 1&&!cbx_continue.Checked)
{
Response.Write("<script>alert('添加成功!');location.href='https://www.baidu.com/';</script>");
return;
}
if (ins == 1 && cbx_continue.Checked)
{
Response.Write("<script>alert('添加成功!');location.href='testAddSingle.aspx';</script>");
return;
}
else
{
Response.Write("<script>alert('跳转失败!');location.href='testAddSingle.aspx';</script>");
return;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("testAddSingle.aspx");
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。