private void btSearch_Click(object sender, EventArgs e) { bsStudent.Clear(); DBControl ADB = new DBControl(); SqlDataReader sr = ADB.linkQuery("select * from Student where Name like '%" + tbS.Text + "%';"); if (sr.HasRows) { bsStudent.DataSource = sr; dataGridView1.DataSource = bsStudent; dataGridView1.Columns[0].HeaderText = "学号"; dataGridView1.Columns[1].HeaderText = "姓名"; dataGridView1.Columns[2].HeaderText = "性别"; dataGridView1.Columns[3].HeaderText = "学院"; dataGridView1.Columns[4].HeaderText = "班级"; dataGridView1.Columns[5].HeaderText = "专业"; dataGridView1.Columns[6].HeaderText = "登陆密码"; } else { MessageBox.Show("没有数据!"); } dataGridView1.Refresh(); sr.Close(); ADB.Close(); }
//查询教学计划页面的操作 private void btTShowAll_Click(object sender, EventArgs e) { bsTeaching.Clear(); DBControl ADB = new DBControl(); SqlDataReader sr = ADB.linkQuery("select Student.Name,Course.Name,Teacher.Name,Teaching.Achievement,Course.Credit,Teaching.Classroom,Teaching.TeachTime,Teaching.Remarks from Student,Teaching,Course,Teacher where Teaching.StuID=Student.ID and Teaching.CourseID=Course.ID and Teaching.TeachID=Teacher.ID;"); if (sr.HasRows) { bsTeaching.DataSource = sr; dataGridView2.DataSource = bsTeaching; dataGridView2.Columns[0].HeaderText = "学生姓名"; dataGridView2.Columns[1].HeaderText = "课程名"; dataGridView2.Columns[2].HeaderText = "教师姓名"; dataGridView2.Columns[3].HeaderText = "成绩"; dataGridView2.Columns[4].HeaderText = "学分"; dataGridView2.Columns[5].HeaderText = "上课地点"; dataGridView2.Columns[6].HeaderText = "上课时间"; dataGridView2.Columns[7].HeaderText = "备注"; } else { MessageBox.Show("没有数据!"); } dataGridView2.Refresh(); sr.Close(); ADB.Close(); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { ArrayList al = new ArrayList(); String[] temp = listBox1.SelectedItem.ToString().Split('*'); DBControl SDB = new DBControl(); //SqlDataReader getCourseInfo = SDB.linkQuery("select * from Course where ID=" + al[1].ToString() + ";"); //getCourseInfo.Read(); //al.Add(getCourseInfo.GetValue(0).ToString()); SqlDataReader getTeachingInfo = SDB.linkQuery("select * from Teaching where StuID=" + id + " and CourseID=" + temp[1] + ";"); getTeachingInfo.Read(); for (int j = 0; j < 7; j++) { al.Add(getTeachingInfo.GetValue(j).ToString()); } getTeachingInfo.Close(); SqlDataReader getTeacherName = SDB.linkQuery("select Name from Teacher where ID=" + al[1].ToString() + ";"); getTeacherName.Read(); al.Add(getTeacherName.GetValue(0).ToString()); getTeacherName.Close(); SDB.Close(); MessageBox.Show("课程名:" + temp[0] + "\n" + "授课教师:" + al[7].ToString() + "\n成绩:" + al[3].ToString() + "\n授课教室" + al[4].ToString() + "\n授课时间:" + al[5].ToString() + "\n备注:" + al[6].ToString()); }
private void initialCB() { cbSID.Items.Clear(); cbTID.Items.Clear(); cbCID.Items.Clear(); DBControl ADB = new DBControl(); SqlDataReader ssdr = ADB.linkQuery("select * from Student;"); while (ssdr.Read()) { cbSID.Items.Add(ssdr.GetValue(1).ToString()); } ssdr.Close(); SqlDataReader tsdr = ADB.linkQuery("select * from Teacher;"); while (tsdr.Read()) { cbTID.Items.Add(tsdr.GetString(1)); } tsdr.Close(); SqlDataReader csdr = ADB.linkQuery("select * from Course;"); while (csdr.Read()) { cbCID.Items.Add(csdr.GetString(1)); } csdr.Close(); ADB.Close(); }
private void btTSearch_Click(object sender, EventArgs e) { bsTeacher.Clear(); DBControl ADB = new DBControl(); SqlDataReader sr = ADB.linkQuery("select * from Teacher where Name like '%" + tbT.Text + "%';"); if (sr.HasRows) { bsTeacher.DataSource = sr; dataGridViewTeacher.DataSource = bsTeacher; dataGridViewTeacher.Columns[0].HeaderText = "工号"; dataGridViewTeacher.Columns[1].HeaderText = "姓名"; dataGridViewTeacher.Columns[2].HeaderText = "学院"; dataGridViewTeacher.Columns[3].HeaderText = "登陆密码"; } else { MessageBox.Show("没有数据!"); } dataGridViewTeacher.Refresh(); sr.Close(); ADB.Close(); }
private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { // String[] temp = listBox2.SelectedItem.ToString().Split('*'); DBControl SDB = new DBControl(); SqlDataReader getTeacherInfo = SDB.linkQuery("select College from Teacher where Name='" + listBox2.SelectedItem.ToString() + "' ;"); getTeacherInfo.Read(); MessageBox.Show("教师姓名:" + listBox2.SelectedItem.ToString() + "\n所属学院:" + getTeacherInfo.GetValue(0).ToString()); getTeacherInfo.Close(); SDB.Close(); }
//添加教师表 private void btAddTeacher_Click(object sender, EventArgs e) { if (tbTCollege.Text != null && tbTID.Text != null && tbTName.Text != null) { DBControl ADB = new DBControl(); ADB.linkUpdate("insert into Teacher(ID,Name,College,Password) values(" + tbTID.Text + ",'" + tbTName.Text + "','" + tbTCollege.Text + "'," + tbTID.Text + ");"); MessageBox.Show("更新成功!"); ADB.Close(); tbTCollege.Clear(); tbTID.Clear(); tbTName.Clear(); } else { MessageBox.Show("您的数据输入不完整,请检查您的数据!"); } }
//添加数据至课程表 private void btAddCourse_Click(object sender, EventArgs e) { if (tbCID.Text != null && tbCName.Text != null && tbCCredit.Text != null) { DBControl ADB = new DBControl(); ADB.linkUpdate("insert into Course(ID,Name,Credit,Remarks) values(" + tbCID.Text + ",'" + tbCName.Text + "'," + tbCCredit.Text + ",'" + tbCRemarks.Text + "');"); MessageBox.Show("更新成功!"); ADB.Close(); tbCID.Clear(); tbCName.Clear(); tbCCredit.Clear(); tbCRemarks.Clear(); } else { MessageBox.Show("您的数据输入不完整,请检查您的数据!"); } }
//更新学生表 private void btAddStudent_Click(object sender, EventArgs e) { if (tbSID.Text != null && tbSMajor.Text != null && tbSClass.Text != null && tbSCollege.Text != null && tbSName.Text != null && cbSSex.SelectedItem != null) { DBControl ADB = new DBControl(); ADB.linkUpdate("insert into Student(ID,Name,Sex,College,Class,Major,Password) values(" + tbSID.Text + ",'" + tbSName.Text + "','" + cbSSex.SelectedItem.ToString() + "','" + tbSCollege.Text + "','" + tbSClass.Text + "','" + tbSMajor.Text + "'," + tbSID.Text + ");"); MessageBox.Show("更新成功!"); ADB.Close(); tbSID.Clear(); tbSMajor.Clear(); tbSClass.Clear(); tbSCollege.Clear();; tbSName.Clear(); } else { MessageBox.Show("您的数据输入不完整,请检查您的数据!"); } }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem != null) { setSQL(); DBControl ldb = new DBControl(); SqlDataReader checkAdmin = ldb.linkQuery(s); if (checkAdmin.Read()) { this.Hide(); MessageBox.Show("欢迎使用学生管理系统!"); if (m == 1) { setIDInfo(checkAdmin.GetValue(0).ToString()); Administrator oa = new Administrator(); oa.Show(); } else if (m == 2) { setIDInfo(checkAdmin.GetValue(0).ToString()); Student os = new Student(); os.Show(); } else if (m == 3) { setIDInfo(checkAdmin.GetValue(0).ToString()); Teacher ot = new Teacher(); ot.Show(); } } else { MessageBox.Show("登陆失败,请检查您的数据"); } ldb.Close(); } else { MessageBox.Show("您必须选择登陆角色!"); } }
private void btTTDelete_Click(object sender, EventArgs e) { if (dataGridView2.RowCount <= 0) { MessageBox.Show("请选择记录!"); return; } if (MessageBox.Show(this, "是否删除此记录", "请确认", MessageBoxButtons.YesNo) == DialogResult.Yes) { for (int i = this.dataGridView2.SelectedRows.Count; i > 0; i--) { int ID = Convert.ToInt32(dataGridView2.SelectedRows[i - 1].Cells[0].Value); dataGridView2.Rows.RemoveAt(dataGridView2.SelectedRows[i - 1].Index); //使用获得的ID删除数据库的数据 string sql2 = "delete from Teaching where StuID=" + ID.ToString() + ";"; DBControl ADB = new DBControl(); ADB.linkUpdate(sql2); ADB.Close(); } } }
//添加教学计划 private void btAddTeaching_Click(object sender, EventArgs e) { if (tbTeachTime.Text != null && tbClassroom.Text != null && cbSID.SelectedItem != null && cbTID.SelectedItem != null && cbCID.SelectedItem != null) { int sid = 0; int tid = 0; int cid = 0; DBControl ADB = new DBControl(); SqlDataReader gSID = ADB.linkQuery("select ID from Student where Name='" + cbSID.SelectedItem.ToString() + "';"); if (gSID.Read()) { sid = gSID.GetInt32(0); } gSID.Close(); SqlDataReader gTID = ADB.linkQuery("select ID from Teacher where Name='" + cbTID.SelectedItem.ToString() + "';"); if (gTID.Read()) { tid = gTID.GetInt32(0); } gTID.Close(); SqlDataReader gCID = ADB.linkQuery("select ID from Course where Name='" + cbCID.SelectedItem.ToString() + "';"); if (gCID.Read()) { cid = gCID.GetInt32(0); } gCID.Close(); //MessageBox.Show(sid.ToString()+"**"+tid.ToString()+"$$"+cid.ToString()); ADB.linkUpdate("insert into Teaching(StuID,TeachID,CourseID,Classroom,TeachTime,Remarks) values(" + sid.ToString() + "," + tid.ToString() + "," + cid.ToString() + ",'" + tbClassroom.Text + "','" + tbTeachTime.Text + "','" + tbRemarks.Text + "')"); MessageBox.Show("更新成功"); ADB.Close(); tbTeachTime.Clear(); tbClassroom.Clear(); tbRemarks.Clear(); } else { MessageBox.Show("您的数据输入不完整,请检查您的数据!"); } }
private void getThisInformation() { ArrayList al = new ArrayList(); DBControl SDB = new DBControl(); SqlDataReader getID = SDB.linkQuery("select * from Student where ID=" + id + ";"); getID.Read(); for (int j = 0; j < 7; j++) { al.Add(getID.GetValue(j).ToString()); } getID.Close(); SDB.Close(); listBox3.Items.Clear(); listBox3.Items.Add("学号:" + al[0].ToString()); listBox3.Items.Add("姓名:" + al[1].ToString()); listBox3.Items.Add("性别:" + al[2].ToString()); listBox3.Items.Add("学院:" + al[3].ToString()); listBox3.Items.Add("班级:" + al[4].ToString()); listBox3.Items.Add("专业:" + al[5].ToString()); listBox3.Items.Add("密码:" + al[6].ToString()); }
private void getAllClass() { ArrayList al = new ArrayList(); DBControl SDB = new DBControl(); SqlDataReader gAchievement = SDB.linkQuery("select CourseID from Teaching where StuID=" + id + ";"); while (gAchievement.Read()) { //listBox1.Items.Add(gAchievement.GetInt32(0)); al.Add(gAchievement.GetInt32(0)); } gAchievement.Close(); listBox1.Items.Clear(); for (int i = 0; i < al.Count; i++) { SqlDataReader getName = SDB.linkQuery("select Name from Course where ID=" + al[i].ToString() + ";"); getName.Read(); listBox1.Items.Add(getName.GetString(0) + "*" + al[i]); getName.Close(); } SDB.Close(); }
//更改密码 private void btUpdatePWD_Click(object sender, EventArgs e) { if (tbThisPWD.Text != null && tbForePWD.Text != null && tbCheckPWD.Text != null) { DBControl ADB = new DBControl(); SqlDataReader gForePWD = ADB.linkQuery("select Password from Admin where [ID]=" + id + ";"); gForePWD.Read(); String forePWD = gForePWD.GetString(0); gForePWD.Close(); //MessageBox.Show(gForePWD.GetString(0)); if (tbThisPWD.Text.Equals(tbCheckPWD.Text)) { if (tbThisPWD.Text.Equals(forePWD)) { MessageBox.Show("不能与原密码相同!"); } else { ADB.linkUpdate("update Admin set [Password]='" + tbThisPWD.Text + "' where [ID]=" + id + ";"); MessageBox.Show("更改成功!"); } } else { MessageBox.Show("密码确认框输入不一致!"); } ADB.Close(); } else { MessageBox.Show("您的数据输入不完整,请检查您的数据!"); } tbForePWD.Clear(); tbThisPWD.Clear(); tbCheckPWD.Clear(); }
private void btSUpdatePWD_Click(object sender, EventArgs e) { DBControl ADB = new DBControl(); SqlDataReader gForePWD = ADB.linkQuery("select Password from Student where [ID]=" + id + ";"); gForePWD.Read(); String forePWD = gForePWD.GetString(0); gForePWD.Close(); //MessageBox.Show(forePWD + "\n" + tbForePWD.Text); if (tbNewPWD.Text.Equals(tbCheckPWD.Text)) { if (tbForePWD.Text.Trim().Equals(forePWD)) { if (tbNewPWD.Text.Equals(tbForePWD.Text)) { MessageBox.Show("不能与原密码相同!"); } else { ADB.linkUpdate("update Student set [Password]='" + tbNewPWD.Text + "' where [ID]=" + id + ";"); MessageBox.Show("更改成功!"); } } else { MessageBox.Show("请正确输入原密码!"); } } else { MessageBox.Show("密码确认框输入不一致!"); } ADB.Close(); }