学生信息管理系统小结
ASP.NET+Access
一、登入部分
主界面 Fm = new 主界面();
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "select*from 登錄信息表 where 用戶名='" + this.ttbName.Text + "' and 密碼 ='" + ttbPwd.Text + "'and 身份='" + cbbId.Text + "'";
? ? ? ? ? ? if (ttbName.Text == "" || ttbName.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("信息不完整,請輸入密碼和用戶名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ttbName.Clear();
? ? ? ? ? ? ? ? ttbPwd.Clear();
? ? ? ? ? ? ? ? ttbName.Focus();
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? if (cbbId.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("信息錯誤,請選擇身份", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? cn.Open();//打開數據庫
? ? ? ? ? ? OleDbCommand cm = new OleDbCommand(s2, cn);
? ? ? ? ? ? OleDbDataReader dr = cm.ExecuteReader();//執行oledatacommand命令,
? ? ? ? ? ? if (dr.HasRows)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while (dr.Read())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? string strname = dr["用戶名"].ToString().Trim();
? ? ? ? ? ? ? ? ? ? string username = this.ttbName.Text;
? ? ? ? ? ? ? ? ? ? string shenfen = dr["身份"].ToString().Trim();
? ? ? ? ? ? ? ? ? ? if (username == strname)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? string strmima = dr["密碼"].ToString().Trim();
? ? ? ? ? ? ? ? ? ? ? ? string mima = this.ttbPwd.Text;
? ? ? ? ? ? ? ? ? ? ? ? if (strmima == mima)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (shenfen == this.cbbId.Text)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Fm.UserName = strname;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Fm.PassWord = strmima;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Fm.gly = shenfen;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Fm.Show();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ttbName.Text = "";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ttbPwd.Text = "";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cbbId.Text = "";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Hide();
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("對不起,輸入錯誤!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
? ? ? ? ? ? ? ? ttbName.Text = "";
? ? ? ? ? ? ? ? ttbPwd.Text = "";
? ? ? ? ? ? ? ? cbbId.Text = "";
? ? ? ? ? ? ? ? ttbName.Focus();
? ? ? ? ? ? }
? ? ? ? ? ? cn.Close();
二、查詢部分
string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string strSql = "select * from 學生信息表";
? ? ? ? ? ? FindValue = ""; ? ?//清空存儲查詢語句的變量
? ? ? ? ? ? string Find_SQL = strSql; ?//存儲顯示數據表中所有信息的SQL語句
? ? ? ? ? ? if (ttbName.Text == "" && ttbNumber.Text == "" && ttbSex.Text == "" && ttbSch.Text == "" && ttbPlace.Text == "" && ttbBrith.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? OleDbConnection cn;
? ? ? ? ? ? ? ? cn = new OleDbConnection(s1);
? ? ? ? ? ? ? ? cn.Open();
? ? ? ? ? ? ? ? OleDbDataAdapter da = new OleDbDataAdapter(strSql, cn);
? ? ? ? ? ? ? ? DataSet ds = new DataSet();
? ? ? ? ? ? ? ? da.Fill(ds, "學生信息表");
? ? ? ? ? ? ? ? dataGridView1.DataSource = ds.Tables[0];
? ? ? ? ? ? ? ? cn.Close();
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (FindValue.Length > 0)
? ? ? ? ? ? ? ? ? ? FindValue = FindValue + "and";
? ? ? ? ? ? ? ? if (ttbNumber.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(學號='" + ttbNumber.Text + "') and";
? ? ? ? ? ? ? ? if (ttbName.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(姓名='" + ttbName.Text + "') and";
? ? ? ? ? ? ? ? if (ttbPlace.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(籍貫='" + ttbPlace.Text + "') and";
? ? ? ? ? ? ? ? if (ttbSex.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(性別='" + ttbSex.Text + "') and";
? ? ? ? ? ? ? ? if (ttbSch.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(院系='" + ttbSch.Text + "') and";
? ? ? ? ? ? ? ? if (ttbBrith.Text != "")
? ? ? ? ? ? ? ? ? ? FindValue += "(生日='" + ttbBrith.Text + "') and";
? ? ? ? ? ? ? ? if (FindValue.Length > 0) ? //當存儲查詢條件的變量不為空時,刪除邏輯運算符AND
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (FindValue.IndexOf("and") > -1) ?//判斷是否用AND連接條件
? ? ? ? ? ? ? ? ? ? ? ? FindValue = FindValue.Substring(0, FindValue.Length - 4);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? FindValue = "";
? ? ? ? ? ? ? ? if (FindValue != "") ? //如果FindValue字段不為空
? ? ? ? ? ? ? ? ? ? //將查詢條件添加到SQL語句的尾部
? ? ? ? ? ? ? ? ? ? Find_SQL = Find_SQL + " where " + FindValue;
? ? ? ? ? ? ? ? //按照指定的條件進行查詢
? ? ? ? ? ? ? ? OleDbConnection cn;
? ? ? ? ? ? ? ? cn = new OleDbConnection(s1);
? ? ? ? ? ? ? ? cn.Open();
? ? ? ? ? ? ? ? OleDbDataAdapter da = new OleDbDataAdapter(Find_SQL, cn);
? ? ? ? ? ? ? ? DataSet ds = new DataSet();
? ? ? ? ? ? ? ? da.Fill(ds, "信息表");
? ? ? ? ? ? ? ? dataGridView1.DataSource = ds.Tables[0];
? ? ? ? ? ? ? ? cn.Close();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? private void btnCal_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();
? ? ? ? }
三、修改刪除部分
public partial class 用戶管理 : Form
? ? {
? ? ? ? public 用戶管理()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? panel1.Hide();
? ? ? ? }
? ? ? ? public void f()
? ? ? ? {
? ? ? ? ? ? cbbId.Items.Clear();
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "select 用戶名 from 登錄信息表 ";
? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? cn.Open();
? ? ? ? ? ? OleDbCommand cm = new OleDbCommand(s2, cn);
? ? ? ? ? ? OleDbDataReader dr = cm.ExecuteReader();
? ? ? ? ? ? while (dr.Read())
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cbbId.Items.Add(dr["用戶名"].ToString().Trim());
? ? ? ? ? ? }
? ? ? ? ? ? cn.Close();
? ? ? ? }
? ? ? ??
? ? ? ? //檢查用戶
? ? ? ? public bool dgResult_load()
? ? ? ? {
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "select*from 登錄信息表 where 用戶名='" + ttbUserName.Text + "'";
? ? ? ? ? ? string userName = "";
? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? cn.Open();//打開數據庫
? ? ? ? ? ? OleDbCommand cm = new OleDbCommand(s2, cn);
? ? ? ? ? ? OleDbDataReader dr = cm.ExecuteReader();//執行oledatacommand命令,
? ? ? ? ? ? while (dr.Read())
? ? ? ? ? ? {
? ? ? ? ? ? ? ? userName = dr["用戶名"].ToString().Trim();
? ? ? ? ? ? ? ? if (userName == ttbUserName.Text)
? ? ? ? ? ? ? ? {??
? ? ? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? panel1.Hide();
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return false;
? ? ? ? ? ??
? ? ? ? }
? ? ? ? //查詢用戶是否存在
? ? ? ? private void ttbSearch_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (ttbUserName.Text=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("輸入信息不能為空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }?
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (dgResult_load())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? panel1.Show();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //確定之后錄入數據庫
? ? ? ? private void button5_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "update 登錄信息表 set 用戶名='" + ttbUserName.Text + "',密碼='" + textBox4.Text + "',身份='" + comboBox1.Text + "'where 用戶名='" + ttbUserName.Text + "'";
? ? ? ? ? ? if (textBox4.Text == ""&& comboBox1.Text=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("輸入信息不能為空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? ? ? cn.Open();
? ? ? ? ? ? ? ? OleDbCommand cm = new OleDbCommand(s2, cn);
? ? ? ? ? ? ? ? cm.ExecuteNonQuery();
? ? ? ? ? ? ? ? cn.Close();
? ? ? ? ? ? ? ? MessageBox.Show("信息更改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ttbUserName.Text = ""; textBox4.Text = ""; comboBox1.Text = "";
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? private void button6_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();
? ? ? ? }
? ? ? ? //刪除用戶
? ? ? ? private void btnDel_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "delete * from 登錄信息表 where 用戶名='" + cbbId.Text + "'";
? ? ? ? ? ? if (ttbUserName.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("刪除用戶不能為空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (dgResult_load())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? ? ? ? ? cn.Open();
? ? ? ? ? ? ? ? ? ? OleDbCommand cmd = new OleDbCommand(s2, cn);
? ? ? ? ? ? ? ? ? ? cmd.ExecuteNonQuery();
? ? ? ? ? ? ? ? ? ? MessageBox.Show("用戶刪除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ? ? ttbUserName.Text = "";
? ? ? ? ? ? ? ? ? ? panel1.Hide();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? MessageBox.Show("該用戶不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
? ? ? ? ? ? ? ? ? ? ttbUserName.Text = "";
? ? ? ? ? ? ? ? ? ? ttbUserName.Focus();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? }
? ? ? ? //用戶添加的取消
? ? ? ? private void btnCal_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();
? ? ? ? }
? ? ? ? //用戶添加的OK
? ? ? ? private void btnOK_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (ttbUName.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請輸入名字!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ttbUserName.Focus();
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? if (ttbUPwd.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請輸入密碼!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ttbUPwd.Focus();
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? if(cbbId.Text=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請輸入身份!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
? ? ? ? ? ? ? ? cbbId.Focus();
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";
? ? ? ? ? ? string s2 = "insert into 登錄信息表 (用戶名,密碼,身份) values('" + ttbUName.Text + "','" + ttbUPwd.Text + "','" + cbbId.Text + "')";
? ? ? ? ? ? OleDbConnection cn = new OleDbConnection(s1);
? ? ? ? ? ? cn.Open();
? ? ? ? ? ? OleDbCommand cm = new OleDbCommand(s2, cn);
? ? ? ? ? ? cm.ExecuteNonQuery();
? ? ? ? ? ? cn.Close();
? ? ? ? ? ? MessageBox.Show("用戶添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ttbUName.Text = ""; ttbUPwd.Text = ""; cbbId.Text = "";
? ? ? ? }
? ? }
詳細源碼及注釋:http://download.csdn.net/detail/s10141303/5649101
轉載于:https://blog.51cto.com/dingxiaowei/1366784
總結
以上是生活随笔為你收集整理的学生信息管理系统小结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vsphere中虚机的cpu热插拔和内存
- 下一篇: orcal创建表空间、用户、授权