private void button8_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); if (dataGridView1.Rows.Count == 1) { MessageBox.Show("无可评教条目!"); return; } string sql = ""; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (dataGridView1.Rows[i].Cells["教学评定hjh"].Value.ToString() != "") { string sql2 = " update 选修hjh set 教学评定hjh = '" + dataGridView1.Rows[i].Cells["教学评定hjh"].Value.ToString() + "'" + " where 学生编号hjh = '" + this.num + "'" + " and 开课编号hjh = '" + dataGridView1.Rows[i].Cells["开课编号hjh"].Value.ToString() + "' "; sql += sql2; } } try { cc.ExecuteNonQuery(sql); MessageBox.Show("评教成功!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }
private void button2_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 button19_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageBox.Show("请选中要删除的行!"); return; } if (dataGridView1.CurrentRow.Index < 0 || dataGridView1.CurrentRow.Index >= dataGridView1.Rows.Count - 1) { MessageBox.Show("无效的行!"); return; } if (MessageBox.Show("确认删除这一行?", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } DataGridViewRow row = dataGridView1.SelectedRows[0]; string id = row.Cells[0].Value.ToString().Trim(); string sql = "delete from 开课hjh where 开课编号hjh = '" + id + "'"; sqlConnect cc = new sqlConnect(); try { cc.ExecuteNonQuery(sql); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } }
private void button23_Click(object sender, EventArgs e) { if (comboBox10.SelectedValue == null || comboBox10.DisplayMember == null) { MessageBox.Show("请选择一个班级!"); return; } if (MessageBox.Show("确定要取消该班同步课程吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } else { string sql = " delete " + " from 选修hjh " + " where 选修hjh.学生编号hjh in " + "( select 学生编号hjh " + " from 学生hjh a " + " where a.班级编号hjh = '" + comboBox10.SelectedValue.ToString().Trim() + "')"; sqlConnect cc = new sqlConnect(); try { cc.ExecuteNonQuery(sql); MessageBox.Show("成功取消同步记录!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); } } }
private void button22_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); string sql = "select b.开课编号hjh, a.学生编号hjh from 学生hjh a,开课hjh b where a.班级编号hjh = b.班级编号hjh"; DataSet ds = cc.GetDataSet(sql); int synNum = 0; foreach (DataRow dr in ds.Tables[0].Rows) { string sql2 = "select * from 选修hjh where 开课编号hjh = '" + dr[0].ToString() + "' " + " and 学生编号hjh = '" + dr[1].ToString() + "'"; DataSet ds2 = cc.GetDataSet(sql2); if (ds2.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() + "','" + dr[1].ToString() + "' );"; string[] row = { dr[0].ToString(), dr[1].ToString() }; dataGridView1.Rows.Add(row); } ds2.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 button1_Click(object sender, EventArgs e) { sqlConnect cc = new sqlConnect(); string sql = "update 教师hjh set "; if (radioButton1.Checked) { sql += "性别hjh = '男'"; } else { sql += "性别hjh = '女'"; } if (textBox1.Text != "") { sql += ",出生年月hjh = '" + textBox1.Text + "'"; } if (textBox2.Text != "") { sql += ",联系电话hjh = '" + textBox2.Text + "'"; } if (textBox3.Text != "") { sql += ",电子邮箱hjh = '" + textBox3.Text + "'"; } sql += " where 教师编号hjh = '" + this.num + "'"; try { 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(); if (dataGridView1.Rows.Count == 1) { Close(); return; } string sql = ""; // int count = 0; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (dataGridView1.Rows[i].Cells["成绩hjh"].Value.ToString() != "") { // count++; string sql2 = " update 选修hjh set 成绩hjh = " + dataGridView1.Rows[i].Cells["成绩hjh"].Value.ToString() + " where 学生编号hjh = '" + dataGridView1.Rows[i].Cells["学生编号hjh"].Value.ToString() + "'" + " and 开课编号hjh = '" + dataGridView1.Rows[i].Cells["开课编号hjh"].Value.ToString() + "' "; sql += sql2; } } try { cc.ExecuteNonQuery(sql); // MessageBox.Show("共添加"+count+"个成绩!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cc.closeConnect(); Close(); } }
private void button1_Click(object sender, EventArgs e) { string pwd1 = textBox3.Text.Trim(); string pwd2 = textBox4.Text.Trim(); if (pwd1 == "" || pwd2 == "") { Close(); return; } if (!pwd1.Equals(pwd2)) { textBox3.Text = ""; textBox4.Text = ""; MessageBox.Show("密码不一致,请重新输入!"); return; } sqlConnect cc = new sqlConnect(); string sql = ""; if (this.tp == "系统管理员") { sql = "update " + this.tp + "hjh set 登录密码hjh = '" + pwd1 + "' where 用户名hjh = '" + this.num + "'"; } else { sql = "update " + this.tp + "hjh set 登录密码hjh = '" + pwd1 + "' where " + this.tp + "编号hjh = '" + this.num + "'"; } cc.ExecuteNonQuery(sql); cc.closeConnect(); MessageBox.Show("修改成功!"); textBox3.Text = ""; textBox4.Text = ""; Close(); }
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) { 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 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(); } }