6 Star 0 Fork 1

中南云麓谷/dangXueTu_testSystem

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
testAddSingle.aspx.cs 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
小坏蛋 提交于 2019-03-04 19:18 . 数据库
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");
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/znylg/dangXueTu_testSystem.git
git@gitee.com:znylg/dangXueTu_testSystem.git
znylg
dangXueTu_testSystem
dangXueTu_testSystem
master

搜索帮助