private void 确定_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); if (dataGridView1.Rows.Count == 1) { Close(); return; } string sql = ""; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { string sql2 = "insert into 课程hjh(课程编号hjh,课程名称hjh,学院编号hjh,考核方式hjh,学时hjh,学分hjh,课程介绍hjh) values( "; for (int j = 0; j < dataGridView1.Columns.Count - 1; j++) //dataGridView1.Columns.Count-1 { sql2 += "'" + dataGridView1.Rows[i].Cells[j].Value.ToString().Trim() + "',"; } sql2 += "'" + dataGridView1.Rows[i].Cells[dataGridView1.Columns.Count - 1].Value.ToString().Trim() + "');"; sql += sql2; } try { cc.ExecuteNonQuery(sql); MessageBox.Show("添加成功!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); Close(); } }
private void button1_Click(object sender, EventArgs e) { if (textBox5.Text == "") { MessageBox.Show("开课编号不能为空!"); return; } if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("信息不足,不可添加!"); return; } string sql = "select * from 开课hjh where 开课编号hjh = '" + textBox5.Text + "'"; sqlConnect cc = new sqlConnect(); DataSet ds = cc.GetDataSet(sql); if (ds.Tables[0].Rows.Count != 0) { MessageBox.Show("已经存在该开课编号!"); return; } ds.Clear(); string sql2 = "select * from 开课hjh where 班级编号hjh = '" + textBox2.Text + "' " + " and 课程编号hjh = '" + textBox1.Text + "'"; ds = cc.GetDataSet(sql2); if (ds.Tables[0].Rows.Count != 0) { MessageBox.Show("发现该班级已经开设此课程!不能重复添加!"); return; } string[] row = { textBox5.Text, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text }; dataGridView1.Rows.Add(row); }
private void StudentGradeResult_Load(object sender, EventArgs e) { label18.Text = this.jidian.ToString(); label19.Text = this.unpassed.ToString(); label20.Text = this.excellent.ToString(); string sql = "select b.学生编号hjh,sum((g.成绩hjh-50)*h.学分hjh)/(SUM(h.学分hjh)*10) '绩点hjh'" + " from 学生hjh b,班级hjh c,开设hjh e,开课hjh f,选修hjh g,课程hjh h,教师hjh i " + " where " + " b.班级编号hjh = c.班级编号hjh and c.专业编号hjh = e.专业编号hjh "; if (this.type == "学期") { sql += " and e.开课学期hjh = '" + kk + "' "; } else if (this.type == "学年") { sql += " and e.开课学期hjh like '" + kk + "%' "; } sql += " and e.课程编号hjh = f.课程编号hjh and b.班级编号hjh = f.班级编号hjh " + " and g.开课编号hjh = f.开课编号hjh and g.学生编号hjh = b.学生编号hjh " + " and f.课程编号hjh = h.课程编号hjh and f.教师编号hjh = i.教师编号hjh " + " and b.班级编号hjh = ( " + " select b.班级编号hjh " + " from 学生hjh a,班级hjh b " + " where a.学生编号hjh = '" + this.num + "' and a.班级编号hjh = b.班级编号hjh ) " + " group by b.学生编号hjh,g.成绩hjh " + " having (g.成绩hjh >=60 and sum((g.成绩hjh-50)*h.学分hjh)/(SUM(h.学分hjh)*10) >" + this.jidian + ") "; string sql2 = "select b.学生编号hjh,sum((g.成绩hjh-50)*h.学分hjh)/(SUM(h.学分hjh)*10) '绩点hjh'" + " from 学生hjh b,班级hjh c,开设hjh e,开课hjh f,选修hjh g,课程hjh h,教师hjh i " + " where " + " b.班级编号hjh = c.班级编号hjh and c.专业编号hjh = e.专业编号hjh "; if (this.type == "学期") { sql2 += " and e.开课学期hjh = '" + kk + "' "; } else if (this.type == "学年") { sql2 += " and e.开课学期hjh like '" + kk + "%' "; } sql2 += " and e.课程编号hjh = f.课程编号hjh and b.班级编号hjh = f.班级编号hjh " + " and g.开课编号hjh = f.开课编号hjh and g.学生编号hjh = b.学生编号hjh " + " and f.课程编号hjh = h.课程编号hjh and f.教师编号hjh = i.教师编号hjh " + " and c.专业编号hjh = ( " + " select b.专业编号hjh " + " from 学生hjh a,班级hjh b " + " where a.学生编号hjh = '" + this.num + "' and a.班级编号hjh = b.班级编号hjh ) " + " group by b.学生编号hjh,g.成绩hjh " + " having (g.成绩hjh >=60 and sum((g.成绩hjh-50)*h.学分hjh)/(SUM(h.学分hjh)*10) >" + this.jidian + ") "; sqlConnect cc = new sqlConnect(); try { DataSet ds = cc.GetDataSet(sql); DataSet ds2 = cc.GetDataSet(sql2); MessageBox.Show(ds.Tables[0].Rows.Count.ToString()); label21.Text = (ds.Tables[0].Rows.Count + 1).ToString(); label22.Text = (ds2.Tables[0].Rows.Count + 1).ToString(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }
private void button1_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); string sql = "update 学生hjh set "; int flag = 0; if (comboBox1.Text != dgvr.Cells[3].Value.ToString().Trim() || textBox5.Text != dgvr.Cells[4].Value.ToString().Trim() || textBox6.Text != dgvr.Cells[5].Value.ToString().Trim() ) { string sql2 = "select 班级编号hjh from 学院hjh a, 专业hjh b ,班级hjh c where " + " a.学院名称hjh = '" + comboBox1.Text + "' and " + " b.专业名称hjh = '" + textBox5.Text + "' and " + " c.班级序号hjh = " + textBox6.Text + " and " + " a.学院编号hjh = b.学院编号hjh and " + " b.专业编号hjh = c.专业编号hjh"; try { DataSet ds = cc.GetDataSet(sql2); if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("找到该学生的班级编号,学院、专业、或班级信息有误!"); return; } string str = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim(); ds.Dispose(); sql += "班级编号hjh = '" + str + "' "; flag = 1; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { } } if (textBox2.Text != dgvr.Cells[1].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "姓名hjh = '" + textBox2.Text + "'"; flag = 1; } if (textBox3.Text != dgvr.Cells[2].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "性别hjh = '" + textBox3.Text + "'"; flag = 1; } if (textBox7.Text != dgvr.Cells[6].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "出生年月hjh = '" + textBox7.Text + "'"; flag = 1; } if (textBox8.Text != dgvr.Cells[7].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "联系电话hjh = '" + textBox8.Text + "'"; flag = 1; } if (textBox9.Text != dgvr.Cells[8].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "已修学分hjh = " + textBox9.Text; flag = 1; } if (textBox10.Text != dgvr.Cells[9].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "平均绩点hjh = " + textBox10.Text; flag = 1; } if (textBox11.Text != dgvr.Cells[10].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "生源地hjh = '" + textBox11.Text + "'"; flag = 1; } if (textBox12.Text != dgvr.Cells[11].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "权限级别hjh = " + textBox12.Text; flag = 1; } sql += " where 学生编号hjh = '" + label13.Text + "'"; try { if (flag == 1) { cc.ExecuteNonQuery(sql); MessageBox.Show("修改成功!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("课程号不能为空!"); return; } if (textBox2.Text == "") { MessageBox.Show("课程名称不能为空!"); return; } sqlConnect cc = new sqlConnect(); string sql = "select * from 课程hjh where 课程编号hjh = '" + textBox1.Text + "'"; DataSet ds = cc.GetDataSet(sql); if (ds.Tables[0].Rows.Count != 0) { MessageBox.Show("对不起,课程号已经存在!"); return; } ds.Dispose(); if (comboBox1.Text == " ------选择------") { MessageBox.Show("请选择开课学院!"); return; } if (comboBox2.Text == " ----选择----") { comboBox2.Text = ""; } if (comboBox3.Text == " ----选择----") { comboBox3.Text = ""; } string sql2 = "select * from 学院hjh where 学院名称hjh = '" + comboBox1.Text + "'"; ds = cc.GetDataSet(sql2); if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("未能到该学院名称的学院编号,学院信息有误!"); return; } comboBox1.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim(); ds.Dispose(); string str = ""; if (radioButton1.Checked) { str = radioButton1.Text; } else { str = radioButton2.Text; } string[] row = { textBox1.Text, textBox2.Text, comboBox1.Text, str, comboBox2.Text, comboBox3.Text, textBox4.Text }; dr.Rows.Add(row); Close(); }
private void button1_Click(object sender, EventArgs e) { string tp = comboBox1.Text; string num = textBox1.Text; string pwd = textBox2.Text; if (tp != "教师" && tp != "学生" && tp != "系统管理员") { MessageBox.Show("请选择登录身份!"); return; } if (num == "") { MessageBox.Show("用户名不能为空!"); return; } if (pwd == "") { MessageBox.Show("请输入密码!"); return; } string strSQL = ""; if (tp == "系统管理员") { strSQL += "select * from 系统管理员hjh where '" + num + "' = 用户名hjh and 登录密码hjh = '" + pwd + "'"; } else { strSQL += "select * from " + tp + "hjh where '" + num + "' = " + tp + "编号hjh and 登录密码hjh = '" + pwd + "'"; } sqlConnect cc = new sqlConnect(); DataSet dataset = new DataSet(); try { dataset = cc.GetDataSet(strSQL); if (dataset.Tables[0].Rows.Count == 0) { MessageBox.Show("密码错误,请重新登录!"); return; } DataRow dr = dataset.Tables[0].Rows[0]; if (dr["权限级别hjh"].ToString() == "1") { StudentMain frm = new StudentMain(tp, num); frm.Show(); } else if (dr["权限级别hjh"].ToString() == "2") { TeacherMain frm2 = new TeacherMain(tp, num); frm2.Show(); } else if (dr["权限级别hjh"].ToString() == "5") { SystemManage frm3 = new SystemManage(tp, num); frm3.Show(); } this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); dataset.Dispose(); } }
private void button1_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); string sql = "update 教师hjh set "; int flag = 0; if (comboBox1.Text != dgvr.Cells[3].Value.ToString().Trim()) { string sql2 = "select * from 学院hjh where 学院名称hjh = '" + comboBox1.Text + "'"; DataSet ds = cc.GetDataSet(sql2); if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("未能到该学院名称的学院编号,学院信息有误!"); return; } string str = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim(); ds.Dispose(); sql += "学院编号hjh = '" + str + "' "; flag = 1; } if (textBox2.Text != dgvr.Cells[1].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "姓名hjh = '" + textBox2.Text + "'"; flag = 1; } if (textBox3.Text != dgvr.Cells[2].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "性别hjh = '" + textBox3.Text + "'"; flag = 1; } if (textBox5.Text != dgvr.Cells[4].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "出生年月hjh = '" + textBox5.Text + "'"; flag = 1; } if (textBox6.Text != dgvr.Cells[5].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "学历hjh = '" + textBox6.Text + "'"; flag = 1; } if (textBox7.Text != dgvr.Cells[6].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "职称hjh = '" + textBox7.Text + "'"; flag = 1; } if (textBox8.Text != dgvr.Cells[7].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "电子邮箱hjh = '" + textBox8.Text + "'"; flag = 1; } if (textBox9.Text != dgvr.Cells[8].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "联系电话hjh = '" + textBox9.Text + "'"; flag = 1; } if (textBox10.Text != dgvr.Cells[9].Value.ToString().Trim()) { if (flag == 1) { sql += ","; } sql += "权限级别hjh = " + textBox10.Text; flag = 1; } sql += " where 教师编号hjh = '" + label11.Text + "'"; try { if (flag == 1) { cc.ExecuteNonQuery(sql); MessageBox.Show("修改成功!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); string sql = " select h.课程名称hjh,i.姓名hjh '授课教师hjh',h.学分hjh,h.考核方式hjh,e.开课学期hjh,g.成绩hjh " + " from 学生hjh b,班级hjh c,开设hjh e,开课hjh f,选修hjh g,课程hjh h,教师hjh i " + " where b.学生编号hjh = '" + this.num + "' " + " and b.班级编号hjh = c.班级编号hjh and c.专业编号hjh = e.专业编号hjh " + " and e.课程编号hjh = f.课程编号hjh and b.班级编号hjh = f.班级编号hjh " + " and g.开课编号hjh = f.开课编号hjh and g.学生编号hjh = b.学生编号hjh " + " and f.课程编号hjh = h.课程编号hjh and f.教师编号hjh = i.教师编号hjh "; if (checkBox1.Checked) { sql += " and g.成绩hjh >=0 "; } if (comboBox1.Text.ToString().Trim() != "*") { sql += " and e.开课学期hjh = '" + comboBox1.Text.ToString().Trim() + "' "; } try { cc.BindDataGridView(dataGridView1, sql); dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[1].ReadOnly = true; dataGridView1.Columns[2].ReadOnly = true; dataGridView1.Columns[3].ReadOnly = true; dataGridView1.Columns[4].ReadOnly = true; dataGridView1.Columns[5].ReadOnly = true; double total = 0; int CourseNum = 0; int totalCredit = 0; int excellent = 0; int unPassed = 0; for (int i = 0; i < dataGridView1.RowCount - 1; i++) { int tmp = int.Parse(dataGridView1.Rows[i].Cells["成绩hjh"].Value.ToString()); if (tmp <= 0) { continue; } int credit = int.Parse(dataGridView1.Rows[i].Cells["学分hjh"].Value.ToString()); CourseNum++; if (tmp < 60) { unPassed++; } if (tmp >= 95) { excellent++; } total += (double)(tmp - 50) * credit; totalCredit += credit; } total = total / (totalCredit * 10); StudentGradeResult frm = new StudentGradeResult(this.num, total, unPassed, excellent, comboBox1.Text.ToString().Trim(), "学期"); frm.ShowDialog(); frm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }
private void button21_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); if (comboBox10.SelectedValue == null || comboBox10.DisplayMember == null) { MessageBox.Show("请选择一个班级!"); return; } string sql = "select 开课编号hjh from 开课hjh where 班级编号hjh = '" + comboBox10.SelectedValue.ToString().Trim() + "'"; DataSet ds = cc.GetDataSet(sql); sql = "select 学生编号hjh from 学生hjh where 班级编号hjh = '" + comboBox10.SelectedValue.ToString().Trim() + "'"; DataSet ds2 = cc.GetDataSet(sql); int synNum = 0; foreach (DataRow dr in ds.Tables[0].Rows) { foreach (DataRow dr2 in ds2.Tables[0].Rows) { string sql2 = "select * from 选修hjh where 开课编号hjh = '" + dr[0].ToString() + "' and " + "学生编号hjh = '" + dr2[0].ToString() + "'"; DataSet ds3 = cc.GetDataSet(sql2); if (ds3.Tables[0].Rows.Count == 0) { synNum++; if (synNum == 1) { DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn(); col1.Name = "开课编号hjh"; col1.HeaderText = "开课编号hjh"; col2.Name = "学生编号hjh"; col2.HeaderText = "学生编号hjh"; dataGridView1.Columns.Clear(); dataGridView1.DataSource = null; dataGridView1.Columns.Add(col1); dataGridView1.Columns.Add(col2); } sql += " insert into 选修hjh(开课编号hjh,学生编号hjh) values( '" + dr[0].ToString() + "','" + dr2[0].ToString() + "' );"; string[] row = { dr[0].ToString(), dr2[0].ToString() }; dataGridView1.Rows.Add(row); } ds3.Dispose(); } } try { if (synNum != 0) { cc.ExecuteNonQuery(sql); MessageBox.Show("共同步" + synNum.ToString() + "条记录!"); } else { MessageBox.Show("无需再次同步,该班级同学选修情况已经全部与班级开课同步!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }
private void NewClassCourse_Load(object sender, EventArgs e) { DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn col6 = new DataGridViewTextBoxColumn(); col1.Name = "开课编号hjh"; col1.HeaderText = "开课编号hjh"; col2.Name = "课程编号hjh"; col2.HeaderText = "课程编号hjh"; col3.Name = "班级编号hjh"; col3.HeaderText = "班级编号hjh"; col4.Name = "教师编号hjh"; col4.HeaderText = "教师编号hjh"; col5.Name = "上课时间地点hjh"; col5.HeaderText = "上课时间地点hjh"; dataGridView1.Columns.Add(col1); dataGridView1.Columns.Add(col2); dataGridView1.Columns.Add(col3); dataGridView1.Columns.Add(col4); dataGridView1.Columns.Add(col5); sqlConnect cc = new sqlConnect(); try { string sql = "select * from 学院hjh"; SqlDataAdapter da = new SqlDataAdapter(sql, cc.conn); DataSet ds = new DataSet(); da.Fill(ds, "学院hjh"); comboBox1.ValueMember = "学院hjh.学院编号hjh"; comboBox1.DataSource = ds; comboBox1.DisplayMember = "学院hjh.学院名称hjh"; sql = "select * from 课程hjh "; SqlDataAdapter da2 = new SqlDataAdapter(sql, cc.conn); da2.Fill(ds, "课程hjh"); comboBox4.ValueMember = "课程hjh.课程编号hjh"; comboBox4.DataSource = ds; comboBox4.DisplayMember = "课程hjh.课程名称hjh"; sql = "select * from 教师hjh "; SqlDataAdapter da3 = new SqlDataAdapter(sql, cc.conn); da3.Fill(ds, "教师hjh"); comboBox5.ValueMember = "教师hjh.教师编号hjh"; comboBox5.DataSource = ds; comboBox5.DisplayMember = "教师hjh.姓名hjh"; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }