📄 proctstuinfo.cs
字号:
boperate.getcom("delete from student where s_number='" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "'");
MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
ProctStuInfo_Load(sender, e);
txtStuNum.Clear();
txtStuName.Clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}
/// <选择专业>
/// 选择专业
/// </选择专业>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comBoxProfession_SelectedIndexChanged(object sender, EventArgs e)
{
if (comBoxProfession.Text.Trim() != "")
{
opvalidate.cboxBind("select Profession,class from Class where Profession = '" + comBoxProfession.Text.Trim() + "'", "class", "class", comBClass);
}
}
/// <summary>
/// 检索相应信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnLook_Click(object sender, EventArgs e)
{
switch (tscboxCondition.Text.Trim())
{
case "学号":
{
DataSet myds = boperate.getds(M_str_sql + " where S_number like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
break;
case "班级":
{
DataSet myds = boperate.getds(M_str_sql + " where class like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
break;
case "专业":
{
DataSet myds = boperate.getds(M_str_sql + " where profession like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
break;
case "院系":
{
DataSet myds = boperate.getds(M_str_sql + " where department like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
break;
case "姓名":
{
DataSet myds = boperate.getds(M_str_sql + " where s_name like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
if (myds.Tables[0].Rows.Count > 0)
dataGridView1.DataSource = myds.Tables[0];
else
MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
break;
default:
break;
}
}
#region 将excel表中的数据导入dataGridView1中
/// <summary>
/// 将excel表中的数据导入dataGridView1中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripBtnIn_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());
dataGridView1.DataSource = ds.Tables[0];
}
else
MessageBox.Show("该文件不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
#region 将学生信息导出到excel中
/// <summary>
/// 将学生信息导出到excel中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripBtnOut_Click(object sender, EventArgs e)
{
boperate.ExportStuExcel(dataGridView1, true, "student.xls");
}
#endregion
#region 将导入的信息添加到数据库中
private void toolStripBtnSave_Click(object sender, EventArgs e)
{
if (ifnew)
{
if (cn.State == ConnectionState.Closed)
cn.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
string snum = dataGridView1.Rows[i].Cells[0].Value.ToString();
string sname = dataGridView1.Rows[i].Cells[1].Value.ToString();
string depart = dataGridView1.Rows[i].Cells[2].Value.ToString();
string profession = dataGridView1.Rows[i].Cells[3].Value.ToString();
string clas = dataGridView1.Rows[i].Cells[4].Value.ToString();
string phto = dataGridView1.Rows[i].Cells[5].Value.ToString();
if (snum == "" || sname == "" || depart == "" || profession == "" || clas == "")
MessageBox.Show("请填写完整的试题", "提示");
else
{
SqlCommand cmd = new SqlCommand("select * from student where S_number='" + snum + "'", cn);
if (null != cmd.ExecuteScalar())
{
MessageBox.Show("学号" + snum + "已经存在", "提示");
}
else
{
boperate.getcom(" insert into student(s_number,s_name,department,profession,class,sphoto)values('" + snum + "','" + sname + "','" + depart + "','" + profession + "','" + clas + "','" + phto + "')");
}
}
}
MessageBox.Show("学生信息添加成功", "提示");
if (cn.State == ConnectionState.Open)
cn.Close();
}
ifnew = false;
}
#endregion
#region 关闭窗口
private void tsbtnExit_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region 显示所有信息
private void toolStripBtnAll_Click(object sender, EventArgs e)
{
ifnew = false;
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("记录为空!");
}
#endregion
#region 在datagridview中实现鼠标右键单击删除的功能
private void tSMItemDelete_Click(object sender, EventArgs e)
{
//删除选中的多条数据
boperate.delseldata(dataGridView1,"delete from student where s_number=");
ProctStuInfo_Load(sender, e);
txtStuNum.Clear();
txtStuName.Clear();
MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -