private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { SqlConnection conn = new SqlConnection(updatepswd.connectionString); String strterm = comboBox1.SelectedItem.ToString(); conn.Open(); string sql = "select claname as 课程名,sctime as 上课时间,location as 上课地点,term as 学期 from mywork1 where term='" + strterm + "'and teacherid='" + FrmLogin.gettid() + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp1.Fill(ds); //载入基本信息 dataGridView1.DataSource = ds.Tables[0].DefaultView; conn.Close(); } catch { MessageBox.Show("查询语句有误!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button4_Click(object sender, EventArgs e) { int flag = 0; try { conn.Open(); string fenshu = watermarkTextBox2.Text.Trim(); string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); //选择的当前行第一列的值,也就是学号 string classid = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); //当前行第二列的值 string update_by_id = "update sc set grades='" + fenshu + "'where stuxuehao='" + select_id + "'and claid='" + classid + "'"; //sql更新语句 SqlCommand cmd = new SqlCommand(update_by_id, conn); cmd.ExecuteNonQuery(); //执行命令 String select_by_chose = "select stuxuehao as 学号,claid as 课程号,stuname as 姓名,stugrade as 年级, stubanji as 班级,stusex as 性别,claname as 课程,grades as 成绩,term as 学期 from ownstu2 where teacherid='" + FrmLogin.gettid() + "'"; SqlCommand sqlCommand = new SqlCommand(select_by_chose, conn); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = sqlDataReader; dataGridView1.DataSource = bindingSource; } catch { flag = 1; MessageBox.Show("请正确选择行!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } if (flag == 0) { MessageBox.Show("录入成绩成功!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
private void button2_Click(object sender, EventArgs e) { try { string sql; string flags = "1"; SqlConnection conn = new SqlConnection(updatepswd.connectionString); conn.Open(); string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是课程号 sql = "select sctime from sctime where claid =" + select_id; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter adp = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string term = comboBox1.Text.Trim(); DataRow dr = ds.Tables[0].Rows[i]; string time = dr[0].ToString();//第一列 sql = "select * from sc,sctime,class where class.claid = sc.claid and class.claid = sctime.claid and sctime = '" + time + "' and sc.stuxuehao='" + FrmLogin.getStudent() + "'and class.term='" + term + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds1 = new DataSet(); adp1.Fill(ds1); if (ds1.Tables[0].Rows.Count > 0) { flags = "2"; MessageBox.Show("课程上课时间冲突!"); break; } if (flags == "1") { sql = "insert into sc(claid,stuxuehao,term) values(" + select_id + "," + FrmLogin.getStudent() + ",'" + term + "')"; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() > 0) { MessageBox.Show("选课成功!"); } } sql = "select class.claname from sc,class where sc.claid = class.claid and stuxuehao='" + FrmLogin.getStudent() + "'"; SqlDataAdapter adp2 = new SqlDataAdapter(sql, conn); DataSet ds2 = new DataSet(); adp2.Fill(ds2); conn.Close(); } } catch { MessageBox.Show("请正确点击!"); } }
private void tmanas_Load(object sender, EventArgs e) { try { conn.Open(); string jiancha = "IF (EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME=N'mycourse4')) DROP VIEW mycourse4"; SqlCommand cmd = new SqlCommand(jiancha, conn); cmd.ExecuteNonQuery(); //执行命令 string cj = "CREATE VIEW ownstu2 AS SELECT student.stuxuehao,student.stuname,student.stugrade,student.stubanji,student.stusex,class.claname,class.teacherid,sc.grades,class.term,class.claid FROM class,sc,student where class.claid=sc.claid and sc.stuxuehao=student.stuxuehao and teacherid='" + FrmLogin.gettid() + "'"; SqlCommand cmd2 = new SqlCommand(cj, conn); cmd.ExecuteNonQuery(); //执行命令 } catch { } finally { conn.Close(); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { SqlConnection conn = new SqlConnection(updatepswd.connectionString); String strterm = comboBox1.SelectedItem.ToString(); conn.Open(); // string select_by_term = "select * from class where term="+strsort; string sql = "select claname as 课程名,grades as 成绩,teachername as 任课老师,term as 学期 from mygrades where term='" + strterm + "'and stuxuehao='" + FrmLogin.getStudent() + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp1.Fill(ds); //载入基本信息 dataGridView1.DataSource = ds.Tables[0].DefaultView; conn.Close(); } catch { MessageBox.Show("查询语句有误!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { while (dataGridView1.Rows.Count != 0) { dataGridView1.DataSource = null; } if (comboBox1.Text == "" && textBox1.Text == "") { MessageBox.Show("请输入查询信息!"); } else if (comboBox1.Text != "" && textBox1.Text == "") { SqlConnection conn = new SqlConnection(updatepswd.connectionString); conn.Open(); string sql = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where term='" + comboBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp1.Fill(ds); //载入基本信息 dataGridView1.DataSource = ds.Tables[0].DefaultView; conn.Close(); } else if (textBox1.Text != "" && comboBox1.Text == "") { SqlConnection conn = new SqlConnection(updatepswd.connectionString); conn.Open(); //textBox1.Text.Trim() textBox2.Text.Trim() string sql = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where claname='" + textBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp1.Fill(ds); //载入基本信息 dataGridView1.DataSource = ds.Tables[0].DefaultView; conn.Close(); } else if (textBox1.Text != "" && comboBox1.Text != "") { SqlConnection conn = new SqlConnection(updatepswd.connectionString); conn.Open(); //textBox1.Text.Trim() textBox2.Text.Trim() string sql = "select claid as 课程号,claname as 课程名,sctime as 上课时间,term as 学期,location as 上课地点,teachername as 任课老师 from mycourse5 where claname='" + textBox1.Text.Trim() + "'and stuxuehao='" + FrmLogin.getStudent() + "'and term='" + comboBox1.Text.Trim() + "'"; SqlDataAdapter adp1 = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp1.Fill(ds); //载入基本信息 dataGridView1.DataSource = ds.Tables[0].DefaultView; conn.Close(); } }
private void button2_Click(object sender, EventArgs e) { string classes = textBox1.Text; string term = comboBox1.SelectedItem.ToString(); string flags = "1"; SqlConnection conn = new SqlConnection(updatepswd.connectionString); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; //将开课信息插入到开课表里 string sql = ""; string didian = comboBox2.SelectedItem.ToString(); //得到上课的地点 for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]); sql = "select * from sctime where sctime = '" + time + "'and location = '" + didian + "'and term='" + term + "'"; SqlDataAdapter adp = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { flags = "2"; MessageBox.Show("该时间该教室已经有课!"); break; } else { flags = "1"; break; } } } if (flags == "1") { string teachername = string.Empty; //conn = new SqlConnection(); // conn.Open(); SqlCommand getValueCom = conn.CreateCommand(); getValueCom.CommandText = "select tname from teacher where teachbm=" + FrmLogin.gettid(); SqlDataReader getValueReader = getValueCom.ExecuteReader(); if (getValueReader.Read()) { teachername = getValueReader[0].ToString().Trim(); } getValueReader.Close(); sql = "insert into class (claname,term,teacherid,teachername) values ('" + classes + "','" + term + "','" + FrmLogin.gettid() + "','" + teachername + "')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { string time = checkedListBox1.GetItemText(checkedListBox1.Items[i]); //将上课时间得到 sql = "select claid from class where claname = '" + classes + "' and term = '" + term + "' and teacherid = '" + FrmLogin.gettid() + "'"; cmd.CommandText = sql; String id1 = cmd.ExecuteScalar().ToString(); int id = 0; int.TryParse(id1, out id); sql = "insert into sctime values(" + id + ",'" + FrmLogin.gettid() + "','" + time + "','" + didian + "','" + term + "')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } } MessageBox.Show("开设课程成功!"); } conn.Close(); }
private void button1_Click(object sender, EventArgs e) { string passwd = textBox2.Text; string quepasswd = textBox3.Text; SqlConnection sqlCnt = new SqlConnection(connectionString); sqlCnt.Open(); if (passwd == "" || quepasswd == "") { MessageBox.Show("请将信息填写完整!"); } else { if (quepasswd != passwd) { MessageBox.Show("两次输入的密码不一致!"); } else { if (FrmLogin.getRole() == "学生") { SqlCommand command = new SqlCommand(); command.Connection = sqlCnt; string sql = "update student set stupasswd ='" + passwd + "' where stuxuehao = '" + FrmLogin.getStudent() + "'"; command.CommandText = sql; command.ExecuteNonQuery(); MessageBox.Show("修改密码成功!"); this.Close(); } else if (FrmLogin.getRole() == "教师") { SqlCommand command = new SqlCommand(); command.Connection = sqlCnt; string sql = "update Teacher set teachpasswd ='" + passwd + "' where teachbm = '" + FrmLogin.gettid() + "'"; command.CommandText = sql; command.ExecuteNonQuery(); MessageBox.Show("修改密码成功!"); this.Close(); } else { SqlCommand command = new SqlCommand(); command.Connection = sqlCnt; string sql = "update Users set userpassword ='******' where userid = '" + FrmLogin.getid() + "'"; command.CommandText = sql; command.ExecuteNonQuery(); MessageBox.Show("修改密码成功!"); this.Close(); } } sqlCnt.Close(); } }