//--------------------------------------------------------------学生功能--------------------------------------------- //一、成绩查询 //1.查询个人成绩 private void 个人成绩查询ToolStripMenuItem1_Click(object sender, EventArgs e) { dataGridView1.Top = 25; dataGridView1.Left = 30; dataGridView1.Height = 350; dataGridView1.Rows.Clear(); //初始化dataGridView dataGridView1.Visible = true; //显示控件 DBlink db = new DBlink(); if (db.DBconn()) { db.GetScoreData("select * from student_score where number='" + LoginInfo.number + "'"); //执行sql for (int i = 0; i < ScoreInfo.id.Count; i++) //循环将数据实体类的数据存放到dataGridView中 { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = ScoreInfo.id[i]; //填充编号 this.dataGridView1.Rows[index].Cells[1].Value = ScoreInfo.number[i]; //填充学号 this.dataGridView1.Rows[index].Cells[2].Value = ScoreInfo.xueqi[i]; //填充课程归属 this.dataGridView1.Rows[index].Cells[3].Value = ScoreInfo.kecheng[i]; //填充课程名 this.dataGridView1.Rows[index].Cells[4].Value = ScoreInfo.chengji[i]; //填充成绩 this.dataGridView1.Rows[index].Cells[5].Value = ScoreInfo.name[i]; //填充姓名 } } db.DBclose(); }
//--------------------------------------------------------------教师功能--------------------------------------------- //一、成绩查询 //1.查询所有成绩 //查询所有成绩 private void 查询所有成绩ToolStripMenuItem_Click(object sender, EventArgs e) { //控制显示学生成绩的控件的初始位置 dataGridView1.Top = 25; dataGridView1.Left = 30; dataGridView1.Height = 350; dataGridView1.Rows.Clear(); //初始化dataGridView dataGridView1.Visible = true; //显示控件 GeRenChengji_op.Visible = false; DBlink db = new DBlink(); //创建数据库连接实例 if (db.DBconn()) //连接数据库 { db.GetScoreData("select * from student_score"); //执行sql } db.DBclose(); //关闭数据库连接 for (int i = 0; i < ScoreInfo.id.Count; i++) //循环将数据实体类的数据存放到dataGridView中 { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = ScoreInfo.id[i]; //填充编号 this.dataGridView1.Rows[index].Cells[1].Value = ScoreInfo.number[i]; //填充学号 this.dataGridView1.Rows[index].Cells[2].Value = ScoreInfo.xueqi[i]; //填充课程归属 this.dataGridView1.Rows[index].Cells[3].Value = ScoreInfo.kecheng[i]; //填充课程名 this.dataGridView1.Rows[index].Cells[4].Value = ScoreInfo.chengji[i]; //填充成绩 this.dataGridView1.Rows[index].Cells[5].Value = ScoreInfo.name[i]; //填充姓名 } }
//教师输入要查询的学号时验证该学号的成绩信息是否已经存在 private void StuNum_in_KeyUp(object sender, KeyEventArgs e) { dataGridView1.Rows.Clear(); //初始化dataGridView DBlink db = new DBlink(); Boolean tag = false; //辅助标记,先查询该学号是否存在,若存在再进行数据查询的操作 string str = "select * from login_info where number='" + StuNum_in.Text + "'"; if (db.DBconn()) //连接数据库成功 { if (db.search(str)) { Search_TS.Text = "查询到" + StuNum_in.Text + "同学的成绩信息如上!"; tag = true; } else { Search_TS.Text = "该用户不存在"; } } db.DBclose(); //避免多线程操作数据库,影响系统报错,先关闭数据连接 if (tag) //输入的学号在用户名中存在 { if (db.DBconn()) { db.GetScoreData("select * from student_score where number='" + StuNum_in.Text + "'"); //执行sql for (int i = 0; i < ScoreInfo.id.Count; i++) //循环将数据实体类的数据存放到dataGridView中 { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = ScoreInfo.id[i]; //填充编号 this.dataGridView1.Rows[index].Cells[1].Value = ScoreInfo.number[i]; //填充学号 this.dataGridView1.Rows[index].Cells[2].Value = ScoreInfo.xueqi[i]; //填充课程归属 this.dataGridView1.Rows[index].Cells[3].Value = ScoreInfo.kecheng[i]; //填充课程名 this.dataGridView1.Rows[index].Cells[4].Value = ScoreInfo.chengji[i]; //填充成绩 this.dataGridView1.Rows[index].Cells[5].Value = ScoreInfo.name[i]; //填充姓名 } } db.DBclose(); } }