使用三层架构实现Student管理系统,分为Studrnt.Model层,Student.DAL层,Student.BLL层和Student.UI层

步骤分析:

1.在Student.Model添加StudentModel类,每一个类对应数据库表中的字段

2.在每一层添加引用,DAL层引用Model层,BLL层引用DAL和Model层,UI层引用BLL层和Model层

3.在Student.DAL层建一个StudentDAL类

在StudentDAL类中添加一个DataTable类型的方法,进行所有学生信息查询

 public DataTable Select()
        {
            string str = "Data Source=.;Initial catalog=StudentDB;uid=sa";
            using (SqlConnection con = new SqlConnection(str))
            {
                string sql = "select * from Student";
                SqlDataAdapter da = new SqlDataAdapter(sql,con);
                DataSet ds = new DataSet();
                da.Fill(ds, "Student");
                return ds.Tables["Student"];
            }
        }

在BLL层添加StudentBLL类,在StudentBLL层中添加与StudentDAL层中方法重名的Select()类

调用StudentDAL的Select()方法,返回dal.Select()

public DataTable Select()
        {
            //调用StudentDAL层Select()方法

            return dal.Select();
        }

在Load事件中对StudentBLL类中的Select()方法进行调用,再将数据动态绑定到DataGridView(dgvList)控件上

private void FrmStudent_Load(object sender, EventArgs e)
        {
            //dgvList加载数据
            DataTable table = bll.Select();
            dgvList.DataSource = table;
        }

运行结果如下:

4.在StudentDAL类中添加一个DataTable类型的方法,进行根据学生姓名查询学生信息的方法

 public DataTable SelectName(string name)
        {
            string str = "Data Source=.;Initial catalog=StudentDB;uid=sa";
            //con释放资源
            using (SqlConnection con = new SqlConnection(str))
            {
                //模糊查询语句
                string sql = "select * from Student where stu_name like'%"+name+"%'";
                using (SqlDataAdapter da = new SqlDataAdapter(sql, con))
                {
                    DataSet ds = new DataSet();
                    da.Fill(ds, "StudentName");
                    return ds.Tables["StudentName"];

                }
            }
        }

在StudentBLL层中添加与StudentDAL层中方法重名的SelectName()类

调用StudentDAL的SelectName()方法,返回dal.SelectName()

      public DataTable SelectName(string name)
        {
            return dal.SelectName(name);
        }

在窗体中的查询按钮中写入代码,定义一个count接收txtSname中输入的值,调用BLL层中SelectName()方法进行模糊查询,将查询的数据动态绑定到dgvlist上

 private void btnSelect_Click(object sender, EventArgs e)
        {
            string count = txtSname.Text;
            dgvList.DataSource = bll.SelectName(count);
        }

运行结果如下:

5.在StudentDAL类中添加一个Bool类型的AddStudent()类,默认返回False

 public bool AddStudent(StudentModel model)
        {
            bool result = false;
            string str = "Data Source=.;Initial catalog=StudentDB;uid=sa";
            using (SqlConnection con = new SqlConnection(str))
            {
                string sql = "Insert into Student(stu_name,stu_age,stu_sex,stu_email) values(@name,@age,@gender,@email)";
                SqlParameter[] para =
                {
                    new SqlParameter("@name",model.Name),
                    new SqlParameter("@age",model.Age),
                    new SqlParameter("@gender",model.Gender),
                    new SqlParameter("@email",model.Email)
                };
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddRange(para);
                try
                {
                    con.Open();
                    int count = cmd.ExecuteNonQuery();
                    )
                    {
                        result = true;
                    }

                }
                catch (Exception)
                {

                    throw;
                }
                finally
                {

                }

            }
            return result;
        }

在StudentBLL类中添加对StudentDAL类中对AddStudent方法的调用

 public bool AddStudent(StudentModel model)
        {
            //调用StudentDAL层AddStudent()方法
            return dal.AddStudent(model);
        }

在窗体中的录入数据按钮中写入代码

        private void btnAdd_Click(object sender, EventArgs e)
        {
            //当姓名不为空时,进行添加
            if(txtName.Text!="")
            {
                //给StudentModel中属性赋值
                model.Name = txtName.Text;
                model.Age = Convert.ToInt32(txtAge.Text);
                model.Gender = cmbGender.SelectedItem.ToString();
                model.Email = txtEmail.Text;
                bool result = bll.AddStudent(model);
                if (result)
                {
                    MessageBox.Show("添加成功!");
                    //即时刷新
                    dgvList.DataSource = bll.Select();
                }
                else
                {
                    MessageBox.Show("添加失败!");
                }
            }
            else
            {
                //否则提示
                MessageBox.Show("姓名不能为空!");
            }

        }

6.项目完成

Student管理系统的更多相关文章

  1. MVC丶 (未完待续······)

         希望你看了此小随 可以实现自己的MVC框架     也祝所有的程序员身体健康一切安好                                                     ...

  2. 学生信息管理系统总结——student数据库中表关系分析

    说到关系,那就不得不提两个东西: 1.E-R图,也称实体-联系图(Entity Relationship Diagram),提供了表示实体类型.属性和联系的方法,用来描述现实世界的概念模型 2.关系模 ...

  3. Student学生管理系统

    1.定义各个层 2.添加各个层之间的引用 DAL 层调用Model BLL层调用DAL和Model UI层调用BLL和Model层 Model层供各个层调用 3.根据数据库建立实体类,每张表对应一个实 ...

  4. 【IOS开发笔记02】学生管理系统

    端到端的机会 虽然现在身处大公司,但是因为是内部创业团队,产品.native.前端.服务器端全部坐在一起开发,大家很容易做零距离交流,也因为最近内部有一个前端要转岗过来,于是手里的前端任务好像可以抛一 ...

  5. 数据结构(c语言)之学生信息管理系统

    程序思维导图 代码表示(代码参考:长春大学-牛言涛老师) 如有错误请指出欢迎交流 #include<stdio.h> #include<malloc.h>//动态存储分配函数头 ...

  6. C程序范例(2)——学生管理系统”链表“实现

    1.对于学生管理系统,能够实现的方法有许多,但是今天我们用链表的方法来实现.虽然初学者很可能看不懂,但是不要紧,这是要在整体的系统的学习完C语言之后,我才编写出的程序.所以大家不必要担心.在这里与大家 ...

  7. Python开发程序:学员管理系统(mysql)

    主题:学员管理系统 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图: 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节 ...

  8. Java项目:学生成绩管理系统(二)

    学生成绩管理系统(二):项目介绍 一.设计要求: 1.1 简单的图形界面登录功能. 1.2 对数据库的的信息的查询功能. 1.3 对数据库的的信息的修改功能. 1.4 对数据库的的信息的删除功能. 1 ...

  9. 基于数据库MySQL的简易学生信息管理系统

    通过这几天学习Mysql数据库,对其也有了基本的了解,为了加深印象,于是就写了一个最简易的学生信息管理系统. 一:基本要求 1.通过已知用户名和密码进行登录: 2.可以显示菜单: 3.可以随时插入学生 ...

随机推荐

  1. Source Insight基本使用和快捷键

    Source Insight基本使用和快捷键 为什么要用Source Insight呢?貌似是因为比完整的IDE要更快一些,比较利于查看大量的代码. 软件的安装很简单,设置好安装目录. 配置好文档路径 ...

  2. yii cookie ,session 操作

    一,在Yii中使用session 1,CHttpSession 与原生态php5的session使用差别是,php5使用session_start();$_session['key'] = $valu ...

  3. Android Studio教程--给Android Studio安装Genymotion插件

    打开Android Studio,依次[File]-[Settings] 在打开的settings界面里找到plugins设置项,点击右侧的“Browser..”按钮 在搜索栏里输入genymotio ...

  4. symfony2 controller

    1.基本概念 一次http请求    输入(Request):header信息.get信息.post数据等 输出(Response):symfony经过处理返回的信息,包括页面.json字符串.URL ...

  5. 自定义标签 与 JSTL(JSP Standard Tag Library)

    1.自定义标签 [理解]     [1]简介            > 在JSP2.0以后,在jsp页面中不建议使用脚本片段<% %>和JSP表达式<%= %>     ...

  6. js自执行函数的几种不同写法的比较

    经常需要一个函数自执行,可惜这一种写法是错的: function(){alert(1);}();  原因是前半段“function(){alert(1);}”被当成了函数声明,而不是一个函数表达式,从 ...

  7. css hover对其包含的元素进行样式设置

    <ul class="icon-down-single-arr-li"> <li> <a href="javascript:void(0)& ...

  8. yii2 输出xml格式数据

    作者:白狼 出处:http://www.manks.top/yii2_xml_response.html.html本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文 ...

  9. 持续集成 .Net手册--提升开发效率和质量

    参考:http://blog.csdn.net/chelsea/article/details/132525 持续集成 .Net手册 一.概念 Martin Fowler的文章:Continuous ...

  10. jquery.validate remote的用法

    1,远程返回数据时,一定要返回"true"或者"false",否则就是永远就是验证不通过. 2,remote有两种方式,如下就介绍remote与PHP间的验证( ...