经过了整整17天的奋斗,我的大作业终于可以在此刻告一段落了,各方面的内容与功能已经实现的差不多了,现在我来把最后的这一部分展示出来。
首先是学生的登录界面和功能实现:
代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmStudentManage : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmStudentManage()
{
InitializeComponent();
}
private void ReadYXList()
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [department]”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
ComboBox1.Items.Clear();
while (myReader1.Read())
ComboBox1.Items.Add(myReader1[“dno”].ToString());
myReader1.Close();
cn1.Close();
if (ComboBox1.Items.Count > 0)
ComboBox1.Text = ComboBox1.Items[0].ToString();
}
private void ReadYXName(string S)
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [department] where dno=’” + S + “’”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Label2.Text = myReader1[“dname”].ToString();
myReader1.Close();
cn1.Close();
return;
}
else
{
Label2.Text = “”;
myReader1.Close();
cn1.Close();
}
}
private void LoadData(string S)
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select sno as 学生学号,sname as 学生姓名,ssex as 性别,sage as 年龄 from [student] where sdept='" + S + "'", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 180;
DataGridView1.Columns[1].Width = 220;
DataGridView1.Columns[2].Width = 110;
DataGridView1.Columns[3].Width = 110;
ClearT();
}
private void ClearT()
{
TextBox1.Text = "";
TextBox2.Text = "";
ComboBox2.Text = "男";
ComboBox3.Text = "20";
}
private void FrmStudentManage_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
ComboBox2.Items.Add("男");
ComboBox2.Items.Add("女");
ComboBox2.Text = "男";
for (var i = 14; i <= 24; i++)
ComboBox3.Items.Add(i.ToString());
ComboBox3.Text = "20";
ReadYXList();
}
private void Button1_Click(object sender, EventArgs e)
{
if (ComboBox1.Text == "")
{
MessageBox.Show("请选择院系信息!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox1.Text == "")
{
MessageBox.Show("学生学号不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("学生姓名不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [userinfo] where username='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
MessageBox.Show("该学生学号已经存在,请使用其他学号进行添加!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
else
{
myReader.Close();
cn.Close();
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString = "INSERT INTO student VALUES (";
SqlString = SqlString + "'" + TextBox1.Text + "',";
SqlString = SqlString + "'" + TextBox2.Text + "',";
SqlString = SqlString + "'" + ComboBox2.Text + "',";
SqlString = SqlString + ComboBox3.Text + ",";
SqlString = SqlString + "'" + ComboBox1.Text + "')";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
InsertYH(TextBox1.Text, "学生");
MessageBox.Show("学生信息添加完成!");
LoadData(ComboBox1.Text);
}
public void InsertYH(string UN, string UT)
{
SqlConnection cn1;
SqlCommand cm1;
cn1 = new SqlConnection(strConn);
cn1.Open();
string SqlString = "INSERT INTO userinfo VALUES (";
SqlString = SqlString + "'" + UN + "','"+CommonFunction.Encrypt("123456")+"',";
SqlString = SqlString + "'" + UT + "')";
cm1 = new SqlCommand(SqlString, cn1);
cm1.ExecuteNonQuery();
cn1.Close();
}
private void Button2_Click(object sender, EventArgs e)
{
if (ComboBox1.Text == "")
{
MessageBox.Show("请选择院系信息!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox1.Text == "")
{
MessageBox.Show("学生学号不能为空,请选择要修改的学生信息!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("学生姓名不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [student] where sno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该学号的学生信息不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString;
SqlString = "UPDATE student SET sname='" + TextBox2.Text + "',";
SqlString = SqlString + "ssex='" + ComboBox2.Text + "',";
SqlString = SqlString + "sdept='" + ComboBox1.Text + "',";
SqlString = SqlString + "sage=" + ComboBox3.Text + " ";
SqlString = SqlString + "where sno='" + TextBox1.Text + "'";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("学生信息修改成功!", "提示信息", MessageBoxButtons.OK);
LoadData(ComboBox1.Text);
}
private void Button3_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("学生学号不能为空,请先选择要删除的学生信息!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [student] where sno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该学生学号在数据库中不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
if (MessageBox.Show("确实要删除此条学生信息记录吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "delete from [student] where sno ='" + TextBox1.Text + "'";
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
DeleteYH(TextBox1.Text);
LoadData(ComboBox1.Text);
}
else
return;
}
public void DeleteYH(string UN)
{
SqlConnection cn1;
SqlCommand cm1;
cn1 = new SqlConnection(strConn);
cn1.Open();
string SqlString = "DELETE FROM userinfo WHERE username='" + UN + "'";
cm1 = new SqlCommand(SqlString, cn1);
cm1.ExecuteNonQuery();
cn1.Close();
}
private void Button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox1.Text != "")
{
ReadYXName(ComboBox1.Text);
LoadData(ComboBox1.Text);
}
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
ComboBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
ComboBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmStudentQuery : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmStudentQuery()
{
InitializeComponent();
}
private void ReadYXList()
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [department]”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
ComboBox1.Items.Clear();
while (myReader1.Read())
ComboBox1.Items.Add(myReader1[“dno”].ToString());
myReader1.Close();
cn1.Close();
if (ComboBox1.Items.Count > 0)
ComboBox1.Text = ComboBox1.Items[0].ToString();
}
private void ReadYXName(string S)
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [department] where dno=’” + S + “’”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Label2.Text = myReader1[“dname”].ToString();
myReader1.Close();
cn1.Close();
return;
}
else
{
Label2.Text = “”;
myReader1.Close();
cn1.Close();
}
}
private void LoadData(string S)
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select sno as 学生学号,sname as 学生姓名,ssex as 性别,sage as 年龄 from [student] where sdept='" + S + "'", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 180;
DataGridView1.Columns[1].Width = 220;
DataGridView1.Columns[2].Width = 110;
DataGridView1.Columns[3].Width = 110;
ClearT();
}
private void ClearT()
{
TextBox1.Text = "";
TextBox2.Text = "";
ComboBox2.Text = "男";
ComboBox3.Text = "20";
}
private void FrmStudentQuery_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
ComboBox2.Items.Add("男");
ComboBox2.Items.Add("女");
ComboBox2.Text = "男";
for (var i = 14; i <= 24; i++)
ComboBox3.Items.Add(i.ToString());
ComboBox3.Text = "20";
ComboBox4.Items.Add("学生学号");
ComboBox4.Items.Add("学生姓名");
ComboBox4.Text = "学生姓名";
ReadYXList();
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox1.Text != "")
{
ReadYXName(ComboBox1.Text);
LoadData(ComboBox1.Text);
}
}
private void LoadData1(string S)
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
string SqlS = "";
if (ComboBox4.Text == "学生学号")
SqlS = "select sno as 学生学号,sname as 学生姓名,ssex as 性别,sage as 年龄 from [student] where sdept='" + S + "' and sno like '%" + TextBox4.Text + "%'";
if (ComboBox4.Text == "学生姓名")
SqlS = "select sno as 学生学号,sname as 学生姓名,ssex as 性别,sage as 年龄 from [student] where sdept='" + S + "' and sname like '%" + TextBox4.Text + "%'";
da = new SqlDataAdapter(SqlS, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 180;
DataGridView1.Columns[1].Width = 220;
DataGridView1.Columns[2].Width = 110;
DataGridView1.Columns[3].Width = 110;
ClearT();
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
ComboBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
ComboBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
}
private void TextBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (TextBox4.Text.Trim() == "")
LoadData(ComboBox1.Text);
else
LoadData1(ComboBox1.Text);
}
}
}
}
接下来是教师的登陆界面及功能实现:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmTeacherManage : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmTeacherManage()
{
InitializeComponent();
}
private void ReadKCList()
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course]”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
ComboBox5.Items.Clear();
ComboBox6.Items.Clear();
ComboBox7.Items.Clear();
ComboBox5.Items.Add(" “);
ComboBox6.Items.Add(” “);
ComboBox7.Items.Add(” ");
while (myReader1.Read())
{
ComboBox5.Items.Add(myReader1[“cno”].ToString());
ComboBox6.Items.Add(myReader1[“cno”].ToString());
ComboBox7.Items.Add(myReader1[“cno”].ToString());
}
myReader1.Close();
cn1.Close();
if (ComboBox5.Items.Count > 0)
ComboBox5.Text = ComboBox5.Items[0].ToString();
if (ComboBox6.Items.Count > 0)
ComboBox6.Text = ComboBox6.Items[0].ToString();
if (ComboBox7.Items.Count > 0)
ComboBox7.Text = ComboBox7.Items[0].ToString();
}
private string ReadKCName(string S)
{
string Res = “”;
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course] where cno=’” + S + “’”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Res = myReader1[“cname”].ToString();
myReader1.Close();
cn1.Close();
}
else
{
myReader1.Close();
cn1.Close();
}
return Res;
}
private void LoadData()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 90;
DataGridView1.Columns[1].Width = 100;
DataGridView1.Columns[2].Width = 90;
DataGridView1.Columns[3].Width = 90;
DataGridView1.Columns[4].Width = 90;
DataGridView1.Columns[5].Width = 90;
DataGridView1.Columns[6].Width = 120;
DataGridView1.Columns[7].Width = 120;
DataGridView1.Columns[8].Width = 120;
ClearT();
}
private void ClearT()
{
TextBox1.Text = "";
TextBox2.Text = "";
ComboBox2.Text = "男";
ComboBox3.Text = "40";
}
private void FrmTeacherManage_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
ComboBox2.Items.Add("男");
ComboBox2.Items.Add("女");
ComboBox2.Text = "男";
for (var i = 24; i <= 70; i++)
ComboBox3.Items.Add(i);
ComboBox3.Text = "40";
ComboBox1.Items.Add("学士");
ComboBox1.Items.Add("硕士");
ComboBox1.Items.Add("博士");
ComboBox1.Text = "学士";
ComboBox4.Items.Add("助教");
ComboBox4.Items.Add("讲师");
ComboBox4.Items.Add("副教授");
ComboBox4.Items.Add("教授");
ComboBox4.Text = "讲师";
ReadKCList();
LoadData();
}
private void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("教师编号不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("教师姓名不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [teacher] where tno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
MessageBox.Show("该教师编号已经存在,请使用其他工号进行添加!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
else
{
myReader.Close();
cn.Close();
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString = "INSERT INTO teacher VALUES (";
SqlString = SqlString + "'" + TextBox1.Text + "',";
SqlString = SqlString + "'" + TextBox2.Text + "',";
SqlString = SqlString + "'" + ComboBox2.Text + "',";
SqlString = SqlString + ComboBox3.Text + ",";
SqlString = SqlString + "'" + ComboBox1.Text + "',";
SqlString = SqlString + "'" + ComboBox4.Text + "',";
SqlString = SqlString + "'" + ComboBox5.Text + "',";
SqlString = SqlString + "'" + ComboBox6.Text + "',";
SqlString = SqlString + "'" + ComboBox7.Text + "')";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
InsertYH(TextBox1.Text, "教师");
MessageBox.Show("教师信息添加完成!");
LoadData();
}
public void DeleteYH(string UN)
{
SqlConnection cn1;
SqlCommand cm1;
cn1 = new SqlConnection(strConn);
cn1.Open();
string SqlString = "DELETE FROM userinfo WHERE username='" + UN + "'";
cm1 = new SqlCommand(SqlString, cn1);
cm1.ExecuteNonQuery();
cn1.Close();
}
public void InsertYH(string UN, string UT)
{
SqlConnection cn1;
SqlCommand cm1;
cn1 = new SqlConnection(strConn);
cn1.Open();
string SqlString = "INSERT INTO userinfo VALUES (";
SqlString = SqlString + "'" + UN + "','"+CommonFunction.Encrypt("123456")+"',";
SqlString = SqlString + "'" + UT + "')";
cm1 = new SqlCommand(SqlString, cn1);
cm1.ExecuteNonQuery();
cn1.Close();
}
private void Button2_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("教师编号不能为空,请选择要修改的教师信息!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("教师姓名不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [teacher] where tno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该工号的教师信息不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString;
SqlString = "UPDATE teacher SET tname='" + TextBox2.Text + "',";
SqlString = SqlString + "tsex='" + ComboBox2.Text + "',";
SqlString = SqlString + "teb='" + ComboBox1.Text + "',";
SqlString = SqlString + "tage=" + ComboBox3.Text + ",";
SqlString = SqlString + "tpt='" + ComboBox4.Text + "',";
SqlString = SqlString + "cno1='" + ComboBox5.Text + "',";
SqlString = SqlString + "cno2='" + ComboBox6.Text + "',";
SqlString = SqlString + "cno3='" + ComboBox7.Text + "' ";
SqlString = SqlString + "where tno='" + TextBox1.Text + "'";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("教师信息修改成功!", "提示信息", MessageBoxButtons.OK);
LoadData();
}
private void Button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void Button3_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("教师工号不能为空,请先选择要删除的教师信息!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [teacher] where tno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该教师工号在数据库中不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
if (MessageBox.Show("确实要删除此条教师信息记录吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "delete from [teacher] where tno ='" + TextBox1.Text + "'";
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
DeleteYH(TextBox1.Text);
LoadData();
}
else
return;
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
ComboBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
ComboBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
ComboBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
ComboBox4.Text = DataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
ComboBox5.Text = DataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
ComboBox6.Text = DataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
ComboBox7.Text = DataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
}
}
private void ComboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox5.Text != "")
Label10.Text = ReadKCName(ComboBox5.Text);
}
private void ComboBox6_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox6.Text != "")
Label11.Text = ReadKCName(ComboBox6.Text);
}
private void ComboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox7.Text != "")
Label12.Text = ReadKCName(ComboBox7.Text);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmTeacherQuery : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmTeacherQuery()
{
InitializeComponent();
}
private void ReadKCList()
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course]”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
ComboBox5.Items.Clear();
ComboBox6.Items.Clear();
ComboBox7.Items.Clear();
ComboBox5.Items.Add(" “);
ComboBox6.Items.Add(” “);
ComboBox7.Items.Add(” ");
while (myReader1.Read())
{
ComboBox5.Items.Add(myReader1[“cno”].ToString());
ComboBox6.Items.Add(myReader1[“cno”].ToString());
ComboBox7.Items.Add(myReader1[“cno”].ToString());
}
myReader1.Close();
cn1.Close();
if (ComboBox5.Items.Count > 0)
ComboBox5.Text = ComboBox5.Items[0].ToString();
if (ComboBox6.Items.Count > 0)
ComboBox6.Text = ComboBox6.Items[0].ToString();
if (ComboBox7.Items.Count > 0)
ComboBox7.Text = ComboBox7.Items[0].ToString();
}
private string ReadKCName(string S)
{
string Res = “”;
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course] where cno=’” + S + “’”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Res = myReader1[“cname”].ToString();
myReader1.Close();
cn1.Close();
}
else
{
myReader1.Close();
cn1.Close();
}
return Res;
}
private void LoadData()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 90;
DataGridView1.Columns[1].Width = 100;
DataGridView1.Columns[2].Width = 90;
DataGridView1.Columns[3].Width = 90;
DataGridView1.Columns[4].Width = 90;
DataGridView1.Columns[5].Width = 90;
DataGridView1.Columns[6].Width = 120;
DataGridView1.Columns[7].Width = 120;
DataGridView1.Columns[8].Width = 120;
ClearT();
}
private void ClearT()
{
TextBox1.Text = "";
TextBox2.Text = "";
ComboBox2.Text = "男";
ComboBox3.Text = "40";
}
private void FrmTeacherQuery_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
ComboBox2.Items.Add("男");
ComboBox2.Items.Add("女");
ComboBox2.Text = "男";
for (var i = 24; i <= 70; i++)
ComboBox3.Items.Add(i);
ComboBox3.Text = "40";
ComboBox1.Items.Add("学士");
ComboBox1.Items.Add("硕士");
ComboBox1.Items.Add("博士");
ComboBox1.Text = "学士";
ComboBox4.Items.Add("助教");
ComboBox4.Items.Add("讲师");
ComboBox4.Items.Add("副教授");
ComboBox4.Items.Add("教授");
ComboBox4.Text = "讲师";
ReadKCList();
ComboBox8.Items.Add("教师编号");
ComboBox8.Items.Add("教师姓名");
ComboBox8.Items.Add("教师学历");
ComboBox8.Items.Add("教师职称");
ComboBox8.Text = "教师姓名";
LoadData();
}
private void LoadData1()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
string SqlS = "";
if (ComboBox8.Text == "教师编号")
SqlS = "select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher where tno like '%" + TextBox4.Text + "%'";
if (ComboBox8.Text == "教师姓名")
SqlS = "select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher where tname like '%" + TextBox4.Text + "%'";
if (ComboBox8.Text == "教师学历")
SqlS = "select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher where teb like '%" + TextBox4.Text + "%'";
if (ComboBox8.Text == "教师职称")
SqlS = "select tno as 工号,tname as 姓名,tsex as 性别,tage as 年龄,teb as 学历,tpt as 职称,cno1 as 主讲课程一,cno2 as 主讲课程二,cno3 as 主讲课程三 from teacher where tpt like '%" + TextBox4.Text + "%'";
da = new SqlDataAdapter(SqlS, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 90;
DataGridView1.Columns[1].Width = 100;
DataGridView1.Columns[2].Width = 90;
DataGridView1.Columns[3].Width = 90;
DataGridView1.Columns[4].Width = 90;
DataGridView1.Columns[5].Width = 90;
DataGridView1.Columns[6].Width = 120;
DataGridView1.Columns[7].Width = 120;
DataGridView1.Columns[8].Width = 120;
ClearT();
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
ComboBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
ComboBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
ComboBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
ComboBox4.Text = DataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
ComboBox5.Text = DataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
ComboBox6.Text = DataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
ComboBox7.Text = DataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
}
}
private void TextBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (TextBox4.Text.Trim() == "")
LoadData();
else
LoadData1();
}
}
private void ComboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox5.Text != "")
Label10.Text = ReadKCName(ComboBox5.Text);
}
private void ComboBox6_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox6.Text != "")
Label11.Text = ReadKCName(ComboBox6.Text);
}
private void ComboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox7.Text != "")
Label12.Text = ReadKCName(ComboBox7.Text);
}
}
}
接下来是管理员的功能:选课,录入,查询,修改,应有尽有,保证是面面俱到,话不多说,放内容:
相关代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmDepartmentManage : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmDepartmentManage()
{
InitializeComponent();
}
private void LoadData()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select dno as 院系编号,dname as 院系名称,dmanager as 系主任 from [department]", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 158;
DataGridView1.Columns[1].Width = 278;
DataGridView1.Columns[2].Width = 150;
ClearT();
}
private void ClearT()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
private void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("院系编号不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("院系名称不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox3.Text == "")
{
MessageBox.Show("系主任不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [department] where dno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
MessageBox.Show("该院系编号已经存在,请使用其他编号进行添加!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
else
{
myReader.Close();
cn.Close();
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString = "INSERT INTO department VALUES (";
SqlString = SqlString + "'" + TextBox1.Text + "',";
SqlString = SqlString + "'" + TextBox2.Text + "',";
SqlString = SqlString + "'" + TextBox3.Text + "')";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("院系信息添加完成!");
LoadData();
}
private void Button2_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("院系编号不能为空,请选择要修改的院系信息!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("院系名称不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox3.Text == "")
{
MessageBox.Show("系主任不能为空!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [department] where dno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该院系编号信息不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString;
SqlString = "UPDATE department SET dname='" + TextBox2.Text + "',";
SqlString = SqlString + "dmanager='" + TextBox3.Text + "' ";
SqlString = SqlString + "where dno='" + TextBox1.Text + "'";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("院系信息修改成功!", "提示信息", MessageBoxButtons.OK);
LoadData();
}
private void Button3_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("院系编号不能为空,请先选择要删除的院系信息!", "提示信息", MessageBoxButtons.OK);
return;
}
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from [department] where dno='" + TextBox1.Text + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
myReader.Close();
cn.Close();
}
else
{
MessageBox.Show("该院系编号在数据库中不存在,请检查!", "提示信息", MessageBoxButtons.OK);
myReader.Close();
cn.Close();
return;
}
if (MessageBox.Show("确实要删除此条院系信息记录吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "delete from [department] where dno ='" + TextBox1.Text + "'";
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
LoadData();
}
else
return;
}
private void Button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void FrmDepartmentManage_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
LoadData();
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
TextBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmCourseView : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmCourseView()
{
InitializeComponent();
}
private void LoadDataAll()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter("select sct.tno as 教师编号,teacher.tname as 教师姓名,sct.cno as 课程编号,course.cname as 课程名称,sct.sno as 学号,student.sname as 学生姓名,sct.grade as 课程成绩 from sct,student,teacher,course where sct.sno=student.sno and sct.tno=teacher.tno and sct.cno=course.cno", cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 110;
DataGridView1.Columns[1].Width = 170;
DataGridView1.Columns[2].Width = 110;
DataGridView1.Columns[3].Width = 280;
DataGridView1.Columns[4].Width = 110;
DataGridView1.Columns[5].Width = 170;
DataGridView1.Columns[6].Width = 148;
}
private void LoadDataQ()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
string SqlS = "select sct.tno as 教师编号,teacher.tname as 教师姓名,sct.cno as 课程编号,course.cname as 课程名称,sct.sno as 学号,student.sname as 学生姓名,sct.grade as 课程成绩 from sct,student,teacher,course where sct.sno=student.sno and sct.tno=teacher.tno and sct.cno=course.cno";
if (TextBox1.Text.Trim() != "")
SqlS = SqlS + " and sct.tno like '%" + TextBox1.Text.Trim() + "%'";
if (TextBox2.Text.Trim() != "")
SqlS = SqlS + " and teacher.tname like '%" + TextBox2.Text.Trim() + "%'";
if (TextBox3.Text.Trim() != "")
SqlS = SqlS + " and sct.cno like '%" + TextBox3.Text.Trim() + "%'";
if (TextBox4.Text.Trim() != "")
SqlS = SqlS + " and course.cname like '%" + TextBox4.Text.Trim() + "%'";
if (TextBox5.Text.Trim() != "")
SqlS = SqlS + " and sct.sno like '%" + TextBox5.Text.Trim() + "%'";
if (TextBox6.Text.Trim() != "")
SqlS = SqlS + " and student.sname like '%" + TextBox6.Text.Trim() + "%'";
da = new SqlDataAdapter(SqlS, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 110;
DataGridView1.Columns[1].Width = 170;
DataGridView1.Columns[2].Width = 110;
DataGridView1.Columns[3].Width = 280;
DataGridView1.Columns[4].Width = 110;
DataGridView1.Columns[5].Width = 170;
DataGridView1.Columns[6].Width = 148;
}
private void FrmCourseView_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
LoadDataAll();
}
private void Button1_Click(object sender, EventArgs e)
{
LoadDataQ();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmCourseQuery : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmCourseQuery()
{
InitializeComponent();
}
private void LoadData()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter(“select cno as 课程编号,cname as 课程名称,cpno as 先行课程编号,ccredit as 学分 from [course]”, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 150;
DataGridView1.Columns[1].Width = 382;
DataGridView1.Columns[2].Width = 150;
DataGridView1.Columns[3].Width = 150;
ClearT();
}
private void ClearT()
{
TextBox1.Text = “”;
TextBox2.Text = “”;
TextBox3.Text = “”;
ComboBox1.Text = " “;
}
private void LoadData1()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
string SqlS = “”;
if (ComboBox2.Text == “课程编号”)
SqlS = “select cno as 课程编号,cname as 课程名称,cpno as 先行课程编号,ccredit as 学分 from [course] where cno like '%” + TextBox4.Text + “%’”;
if (ComboBox2.Text == “课程名称”)
SqlS = “select cno as 课程编号,cname as 课程名称,cpno as 先行课程编号,ccredit as 学分 from [course] where cname like '%” + TextBox4.Text + “%’”;
da = new SqlDataAdapter(SqlS, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 150;
DataGridView1.Columns[1].Width = 382;
DataGridView1.Columns[2].Width = 150;
DataGridView1.Columns[3].Width = 150;
ClearT();
}
private void ReadCKList()
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course]”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
ComboBox1.Items.Clear();
ComboBox1.Items.Add(” ");
while (myReader1.Read())
ComboBox1.Items.Add(myReader1[“cno”]);
myReader1.Close();
cn1.Close();
if (ComboBox1.Items.Count > 0)
ComboBox1.Text = ComboBox1.Items[0].ToString();
}
private void ReadCKName(string S)
{
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = “select * from [course] where cno=’” + S + “’”;
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Label5.Text = myReader1[“cname”].ToString();
myReader1.Close();
cn1.Close();
return;
}
else
{
Label5.Text = “”;
myReader1.Close();
cn1.Close();
}
}
private void FrmCourseQuery_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr(“db.ini”);
LoadData();
Label5.Text = “”;
ReadCKList();
ComboBox2.Items.Add(“课程编号”);
ComboBox2.Items.Add(“课程名称”);
ComboBox2.Text = “课程名称”;
}
private void TextBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (TextBox4.Text.Trim() == "")
{
LoadData();
}
else
{
LoadData1();
}
}
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
ComboBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
TextBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ComboBox1.Text.Trim() != "")
ReadCKName(ComboBox1.Text);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmPasswordModify : Form
{
public string UserName;
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmPasswordModify()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
MessageBox.Show("原始密码不能为空,请输入原始密码!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox2.Text == "")
{
MessageBox.Show("新密码不能为空,请输入新设置的密码!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox3.Text == "")
{
MessageBox.Show("确认新密码不能为空,请再次输入设置的新密码!", "提示信息", MessageBoxButtons.OK);
return;
}
if (TextBox3.Text != TextBox2.Text)
{
MessageBox.Show("两次输入的新密码不一致,请检查!", "提示信息", MessageBoxButtons.OK);
TextBox2.Text = "";
TextBox3.Text = "";
return;
}
if (GetOldPassword(UserName) == "")
{
MessageBox.Show("您的用户已经不存在,请联系系统管理员!", "提示信息", MessageBoxButtons.OK);
TextBox2.Text = "";
TextBox3.Text = "";
TextBox1.Text = "";
return;
}
else if (GetOldPassword(UserName) != CommonFunction.Encrypt(TextBox1.Text))
{
MessageBox.Show("您输入的原始密码错误,请重新输入!", "提示信息", MessageBoxButtons.OK);
TextBox1.Text = "";
}
cn = new SqlConnection(strConn);
cn.Open();
string SqlString;
SqlString = "UPDATE userinfo SET userpass='" + CommonFunction.Encrypt(TextBox2.Text.Trim()) + "' ";
SqlString = SqlString + "where username='" + UserName + "'";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("用户密码修改成功!", "提示信息", MessageBoxButtons.OK);
this.Close();
}
private string GetOldPassword(string S)
{
string Res = "";
cn = new SqlConnection(strConn);
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from userinfo where username='" + S + "'";
cn.Open();
myReader = cm.ExecuteReader();
if (myReader.Read())
{
Res = myReader["userpass"].ToString();
myReader.Close();
cn.Close();
}
else
{
Res = "";
myReader.Close();
cn.Close();
}
return Res;
}
private void Button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void FrmPasswordModify_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr("db.ini");
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 教务信息管理系统
{
public partial class FrmSelectCourse : Form
{
public string UserName;
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds;
SqlDataReader myReader;
string strConn;
public FrmSelectCourse()
{
InitializeComponent();
}
private void LoadData()
{
cn = new SqlConnection(strConn);
// 这里的链接默认就是打开的
da = new SqlDataAdapter(“select teacher.tno as 教师编号,teacher.tname as 教师姓名,course.cno as 课程编号,course.cname as 课程名称,course.cpno as 先行课程,course.ccredit as 学分 from teacher,course where course.cno=teacher.cno1 or course.cno=teacher.cno2 or course.cno=teacher.cno3”, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridView1.DataSource = dt;
DataGridView1.Columns[0].Width = 100;
DataGridView1.Columns[1].Width = 100;
DataGridView1.Columns[2].Width = 100;
DataGridView1.Columns[3].Width = 239;
DataGridView1.Columns[4].Width = 100;
DataGridView1.Columns[5].Width = 100;
ClearT();
}
private void ClearT()
{
TextBox1.Text = “”;
TextBox2.Text = “”;
TextBox3.Text = “”;
TextBox4.Text = “”;
TextBox5.Text = “”;
TextBox6.Text = “”;
}
private void FrmSelectCourse_Load(object sender, EventArgs e)
{
strConn = CommonFunction.GetSqlConnStr(“db.ini”);
LoadData();
Label8.Visible = false;
Button1.Enabled = false;
}
private void Button1_Click(object sender, EventArgs e)
{
cn = new SqlConnection(strConn);
cn.Open();
string SqlString = "INSERT INTO sct (sno,cno,tno) VALUES (";
SqlString = SqlString + "'" + UserName + "',";
SqlString = SqlString + "'" + TextBox3.Text + "',";
SqlString = SqlString + "'" + TextBox1.Text + "')";
cm = new SqlCommand(SqlString, cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("选课成功!");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
Button1.Enabled = false;
}
private bool IsSelect(string S)
{
bool Res = false;
SqlConnection cn1;
SqlCommand cm1;
SqlDataReader myReader1;
cn1 = new SqlConnection(strConn);
cm1 = new SqlCommand();
cm1.Connection = cn1;
cm1.CommandText = "select * from [sct] where cno='" + S + "' and sno='" + UserName + "'";
cn1.Open();
myReader1 = cm1.ExecuteReader();
if (myReader1.Read())
{
Res = true;
myReader1.Close();
cn1.Close();
}
else
{
myReader1.Close();
cn1.Close();
}
return Res;
}
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
TextBox1.Text = DataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
TextBox2.Text = DataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
TextBox3.Text = DataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
TextBox4.Text = DataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
TextBox5.Text = DataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
TextBox6.Text = DataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
if (IsSelect(TextBox3.Text) == true)
{
Button1.Enabled = false;
Label8.Visible = true;
Label8.Text = "您已选择该课程,请勿重复选择";
}
else if (TextBox5.Text.Trim() != "")
{
if (IsSelect(TextBox5.Text) == false)
{
Button1.Enabled = false;
Label8.Visible = true;
Label8.Text = "您还未学习先行课程,请先学习先行课程后再选择该课程";
}
else
{
Button1.Enabled = true;
Label8.Visible = false;
}
}
else
{
Button1.Enabled = true;
Label8.Visible = false;
}
}
}
}
最后说一说感受吧,这十几天没日没夜肝系统概括起来可以用一个字形容:累。
经常碰壁,许多地方老师都是没有讲到的,需要一点一点的查,一点一点的学,在运用到系统里面,这一个过程往往就是一个上午或者一个下午的时间,有时候真的是很绝望,一个Bug够我研究2、3个小时也是没谁了。
不过啊,最后的最后还是把这玩意儿搞出来了,这成就感无法用语言形容出来。如今写着博客的我手都是抖得,简直迫不及待的想要把这份成果展示出来,也许这就是研究的快乐吧。:)