📄 proctparinfo.cs
字号:
panduan = false;
if (!ifnew)
{
DataSet myds = boperate.getds(M_str_sql2, M_str_table2);
dataGridView3.DataSource = myds.Tables[0];
if (myds.Tables[0].Rows.Count <= 0)
{
dataGridView3.AllowUserToAddRows = true;
}
labPnum.Text = dataGridView3.Rows.Count.ToString();
if (myds.Tables[0].Rows.Count > 0)
btnDelete.Enabled = true;
else
btnDelete.Enabled = false;
}
}
#endregion
#region 点击选择题标签
private void tabChoose_Click(object sender, EventArgs e)
{
choose = true;
program = false;
panduan = false;
if (!ifnew)
{
DataSet myds = boperate.getds(M_str_sql, M_str_table);
dataGridView1.DataSource = myds.Tables[0];
if (myds.Tables[0].Rows.Count <= 0)
{
dataGridView1.AllowUserToAddRows = true;
}
labCnum.Text = dataGridView1.Rows.Count.ToString();
if (myds.Tables[0].Rows.Count > 0)
btnCDelete.Enabled = true;
else
btnCDelete.Enabled = false;
}
}
#endregion
#region 将导入的信息添加到数据库
private void toolStripBtnSave_Click(object sender, EventArgs e)
{
//添加所有信息,只有当导入新信息,ifnew为true时,
if (ifnew)
{
if (cn.State == ConnectionState.Closed)
cn.Open();
if (tscboxCondition.Text.Trim() == "选择题")
{
for (int i = 0; i < dataGridView1.Rows.Count ; i++)
{
string title = dataGridView1.Rows[i].Cells[0].Value.ToString().Replace("'","''");
string selecta = dataGridView1.Rows[i].Cells[1].Value.ToString().Replace("'", "''");
string selectb = dataGridView1.Rows[i].Cells[2].Value.ToString().Replace("'", "''");
string selectc = dataGridView1.Rows[i].Cells[3].Value.ToString().Replace("'", "''");
string selectd = dataGridView1.Rows[i].Cells[4].Value.ToString().Replace("'", "''");
string answer = dataGridView1.Rows[i].Cells[5].Value.ToString();
string quotiety = dataGridView1.Rows[i].Cells[6].Value.ToString();
if (title == "" || selecta == "" || selectb == "" || selectc == "" || selectd == "" || answer == "" || quotiety == "")
MessageBox.Show("请填写完整的试题", "提示");
else
{
if (ifadd[i] == false)
{
opAndvalidate.autoNum("select id from choose", "choose", "id", "A", "1000001", txtnum);
boperate.getcom("insert into choose(id,types,title,selecta,selectb,selectc,selectd,"
+ "answer,quotiety) values('" + txtnum.Text.ToString().Trim() + "','" + "A" + "','" + title + "','" + selecta + "','" + selectb + "','" + selectc + "','" + selectd + "','" + answer + "','" + quotiety + "')");
}
ifadd[i] = true;
}
}
}
if (tscboxCondition.Text.Trim() == "判断题")
{
for (int i = 0; i < dataGridView2.Rows.Count ; i++)
{
string title = dataGridView2.Rows[i].Cells[0].Value.ToString().Replace("'", "''");
string answer = dataGridView2.Rows[i].Cells[1].Value.ToString();
string quotiety = dataGridView2.Rows[i].Cells[2].Value.ToString();
if (title == "" || answer == "" || quotiety == "")
MessageBox.Show("请填写完整的试题", "提示");
else
{
if (ifadd[i] == false)
{
opAndvalidate.autoNum("select id from panduan", "panduan", "id", "B", "1000001", txtpnum);
boperate.getcom("insert into panduan(id,types,title,answer,quotiety) values('" + txtpnum.Text.ToString().Trim() + "','" + "B" + "','" + title + "','" + answer + "','" + quotiety + "')");
}
ifadd[i] = true;
}
}
}
if (tscboxCondition.Text.Trim() == "程序设计题")
{
for (int i = 0; i < dataGridView3.Rows.Count ; i++)
{
string title = dataGridView3.Rows[i].Cells[0].Value.ToString().Replace("'", "''");
string answer = dataGridView3.Rows[i].Cells[1].Value.ToString().Replace("'", "''");
string quotiety = dataGridView3.Rows[i].Cells[2].Value.ToString();
if (title == "" || answer == "" || quotiety == "")
MessageBox.Show("请填写完整的试题", "提示");
else
{
if (ifadd[i] == false)
{
opAndvalidate.autoNum("select id from program", "program", "id", "C", "1000001", txtpronum);
boperate.getcom("insert into program(id,types,title,quotiety,answer) values('" + txtpronum.Text.ToString().Trim() + "','" + "C" + "','" + title + "','" + quotiety + "','" + answer + "')");
}
ifadd[i] = true;
}
}
}
//判断是否所有信息添加成功
IsOK(ifadd);
if (cn.State == ConnectionState.Open)
cn.Close();
}
}
#endregion
#region 判断导入的信息是否全部存入数据库
/// <summary>
/// 判断导入的信息是否全部存入数据库
/// </summary>
/// <param name="add">存放某一题的存储情况,如果存入到数据库则为true,否则为false</param>
public void IsOK(bool[] add )
{
int ok = 0;
for(int i=0;i<add.Length;i++)
{
if (add[i] == false)
break;
else
ok++;
}
if (ok == add.Length)
{
MessageBox.Show("所有信息已经添加到数据库", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
ifnew = false;
}
}
#endregion
#region 初始化数组
public bool[] arraybegin(bool []add)
{
for(int i=0;i<add.Length;i++)
add[i] = false;
return add;
}
#endregion
#region 显示所有信息
private void toolStripBtnAll_Click(object sender, EventArgs e)
{
//显示数据表中的所有信息
ifnew = false;
if (choose)
{
//如果当然显示的是选择题界面,加载选择题表
DataSet myds = boperate.getds(M_str_sql, M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("记录为空!");
}
else if(panduan)
{
//如果当然显示的是判断题界面,加载判断题表
DataSet myds = boperate.getds(M_str_sql1, M_str_table1);
if (myds.Tables[0].Rows.Count > 0)
dataGridView2.DataSource = myds.Tables[0];
else
MessageBox.Show("记录为空!");
}
else if(program)
{
//如果当然显示的是程序题界面,加载程序题表
DataSet myds = boperate.getds(M_str_sql2, M_str_table2);
if (myds.Tables[0].Rows.Count > 0)
dataGridView3.DataSource = myds.Tables[0];
else
MessageBox.Show("记录为空!");
}
}
#endregion
#region 导入试题信息
private void ToolStripMenuIn_Click(object sender, EventArgs e)
{
ifnew = true;
openFDInport.Filter = "Excel文件(*.XLS)|*.xls";
if (openFDInport.ShowDialog() == DialogResult.OK)
{
if (openFDInport.CheckFileExists)
{
DataSet ds = boperate.ExcelToDS(openFDInport.FileName.ToString().Trim());
ifadd = arraybegin(ifadd);
if (tscboxCondition.Text.Trim() == "选择题")
{
//选中“选择题”选项卡
tabControl1.SelectedIndex = 0;
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.ReadOnly = false;
ifadd = new bool[dataGridView1.Rows.Count]; //标记该题是否已经被添加到数据库中
}
else if (tscboxCondition.Text.Trim() == "判断题")
{
//选中“判断题”选项卡
tabControl1.SelectedIndex = 1;
dataGridView2.DataSource = ds.Tables[0];
dataGridView2.ReadOnly = false;
ifadd = new bool[dataGridView2.Rows.Count]; //标记该题是否已经被添加到数据库中
}
else if (tscboxCondition.Text.Trim() == "程序设计题")
{
//选中“程序设计题”选项卡
tabControl1.SelectedIndex = 2;
dataGridView3.DataSource = ds.Tables[0];
dataGridView3.ReadOnly = false;
ifadd = new bool[dataGridView3.Rows.Count]; //标记该题是否已经被添加到数据库中
}
}
else
{
MessageBox.Show("该文件不存在!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
#endregion
#region 添加程序设计题
private void btnAdd_Click(object sender, EventArgs e)
{
if (richprogram.Text.Trim() == "" || richanswer.Text.Trim() == "" || comboBnandu.Text.Trim()=="")
MessageBox.Show("请填写完整的试题", "提示");
else
{
string question = richprogram.Text.Trim().Replace("'","''");
string answer = richanswer.Text.Trim().Replace("'","''");
opAndvalidate.autoNum("select id from program", "program", "id", "C", "1000001", txtpronum);
boperate.getcom("insert into program(id,types,title,quotiety,answer) values('" + txtpronum.Text.ToString().Trim() + "','" + "C" + "','" + question + "','" + comboBnandu.Text.Trim() + "','" + answer + "')");
tabProgram_Click(sender, e);
MessageBox.Show("试题信息添加成功", "提示");
clear();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -