private void button2_Click(object sender, EventArgs e)//提交选课按钮 { try { string classname = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); string credit = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); DialogResult dr = MessageBox.Show("确认提交这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { if (JudgeClass(credit) == 0)//符合规则 { string sql1 = $"insert into SelectClassTB values ('{StuData.StuID}','{classname}',{credit})"; pipe pip = new pipe(); if (pip.Execute(sql1) > 0) { MessageBox.Show("添加成功"); SelectClassTB(); } else { MessageBox.Show("添加失败" + sql1); } //插入学分到学生信息表 ClassData.credit = int.Parse(label5.Text) + int.Parse(credit);//已选学分 ClassData.classnum = int.Parse(label6.Text) + 1; string sql2 = $"UPDATE StuInfoTB SET StuCredit = {ClassData.credit},ClassNum = {ClassData.classnum} WHERE StuID = '{StuData.StuID}'"; if (pip.Execute(sql2) > 0) { label6.Text = ClassData.classnum.ToString(); label5.Text = ClassData.credit.ToString(); MessageBox.Show("更改成功!"); } else { MessageBox.Show("更改失败" + sql2); } pip.PipClose(); } else//不符合规则 { MessageBox.Show("不符合选课规则"); } } } catch { MessageBox.Show("请选择课程!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddClass_Click(object sender, EventArgs e) { try { string classname = dataGridView2.SelectedRows[0].Cells[0].Value.ToString(); string teacher = dataGridView2.SelectedRows[0].Cells[1].Value.ToString(); string credit = dataGridView2.SelectedRows[0].Cells[2].Value.ToString(); label13.Text = classname; label14.Text = teacher; DialogResult dr = MessageBox.Show("确认选这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { string sql = $"insert into TempSelectClassTB values ('{StuData.StuID}','{classname}',{credit})"; pipe pip = new pipe(); if (pip.Execute(sql) > 0) { MessageBox.Show("添加成功"); SelectClassTB(); } else { MessageBox.Show("添加失败" + sql); } pip.PipClose(); } } catch { MessageBox.Show("请选择课程!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DeleteClass_Click(object sender, EventArgs e) { string classname = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); string credit = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); DialogResult dr = MessageBox.Show("确认删除这门课吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { string sql = $"delete from TempSelectClassTB where ClassName = '{classname}'"; pipe pip = new pipe(); if (pip.Execute(sql) > 0) { MessageBox.Show("删除成功"); SelectClassTB(); } else { MessageBox.Show("删除失败" + sql); } pip.PipClose(); } }