学生信息管理系统小结

简介:

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





















本文转自蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366784,如需转载请自行联系原作者


相关文章
|
缓存 运维 容灾
入行5年,谈谈我在阿里做测试开发的经验
作者在阿里一直从事测试开发相关工作,这几年学习很多、收获很多,作者希望给还在该方向摸爬滚打的同学一些启发和方向。
|
机器学习/深度学习 数据采集 供应链
使用Python实现智能食品库存管理的深度学习模型
使用Python实现智能食品库存管理的深度学习模型
560 63
|
传感器 安全 物联网
蓝牙5.0:革新无线通信的新时代
蓝牙5.0:革新无线通信的新时代
827 12
|
存储 监控 安全
端口安全:交换机上的网络守护者
【8月更文挑战第27天】
365 1
IDEA之Stream表达式生成、调试
IDEA之Stream表达式生成、调试
517 1
|
前端开发 数据中心
数据中心框式交换机如何配置堆叠?
数据中心框式交换机如何配置堆叠?
411 0
|
自然语言处理 监控 搜索推荐
【大模型】探索LLM在各个行业的潜在未来应用
【5月更文挑战第7天】【大模型】探索LLM在各个行业的潜在未来应用
uniCloud 云对象
uniCloud 云对象
208 0
|
存储 安全 Java
Java list set map等接口及其实现类
Java list set map等接口及其实现类
200 0
|
缓存
服务器的丢包率高怎么办
服务器的丢包率高怎么办
633 0

热门文章

最新文章