-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormAdd_Judge.cs
73 lines (68 loc) · 2.41 KB
/
FormAdd_Judge.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class FormAdd_Judge : Form
{
public FormAdd_Judge()
{
InitializeComponent();
string sql = "select (Course_Name) from Course";
cmb_Course.DataSource = SqlHelper.ExecuteReader(sql);
cmb_Course.DisplayMember = "Course_Name";
string name = cmb_Course.SelectedItem.ToString();
Console.WriteLine();
}
private void Bt_Add_Click(object sender, EventArgs e)
{
int flag = 0;
if (cmb_Answ.SelectedIndex == -1)
{
MessageBox.Show("你没有选择答案");
flag++;
}
if (cmb_Level.SelectedIndex == -1)
{
MessageBox.Show("你没有选择难度");
flag++;
}
if(flag==0)
{
string sql = "select question_Id from Question where question_Name='判断题' and Question_Course = @Question_Course";
SqlParameter[] pm =
{
new SqlParameter("@Question_Course",cmb_Course.SelectedItem.ToString())
};
object row = SqlHelper.ExecuteScalar(sql, pm);
if (row == null)
{
MessageBox.Show("该课程不存在,请检查或添加该课程!");
}
else
{
sql = "insert Judge(Jud_Info ,Jud_Level ,Jud_question ,answer) values(@info ,@level ,@sc_question ,@answer)";
SqlParameter[] pms =
{
new SqlParameter("@info",tbInfo.Text),
new SqlParameter("@level",cmb_Level.SelectedItem.ToString()),
new SqlParameter("@sc_question",(int)row),
new SqlParameter("@answer",cmb_Answ.SelectedIndex)
};
int r = SqlHelper.ExecuteNonQuery(sql, pms);
if (r > 0)
{
MessageBox.Show("添加成功!");
}
}
}
}
}
}