哪位大虾跟小弟我讲一下c#三层架构????

解决方案 »

  1.   

    数据数据访问层
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;namespace Employee
    {
        class EmployeeDAO
        {
            static private string GetConnectionString()
            {
                // To avoid storing the connection string in your code, 
                // you can retrieve it from a configuration file.
                return "Data Source=localhost;Initial Catalog=employee;Persist Security Info=True;User ID=sa;Password=111111";
            }
            static public void InsertEmployee(Employee employee)
            {            string connectionString = GetConnectionString();
                string queryString =
                    "insert into employee (name,sex,salary) values('"+employee.Name+"','"+employee.Sex+"',"+employee.Salary+")";
                SqlConnection connection =
                       new SqlConnection(connectionString);            SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;            try
                {
                    connection.Open();                command.ExecuteNonQuery();
                    connection.Close();            }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }        static public List<Employee> GetAll()
            {
                List<Employee> employeeList = new List<Employee>();
                string connectionString = GetConnectionString();
                string queryString =
                    "select * from employee";
                SqlConnection connection =
                       new SqlConnection(connectionString);            SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;            try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();                while (reader.Read())
                    {
                        Employee employee = new Employee();
                        employee.Name = reader["name"].ToString();
                        employee.Id = reader["id"].ToString();
                        employee.Sex = reader["sex"].ToString();
                        employeeList.Add(employee);
                    }
                    reader.Close();            }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return employeeList;
            }
        }
    }业务逻辑层
    using System;
    using System.Collections.Generic;
    using System.Text;namespace Employee
    {
        class EmployeeBLL
        {
            static public List<Employee> GetAll()
            {
                List<Employee> empList = new List<Employee>();
                empList = EmployeeDAO.GetAll();            return empList;
            }        static public void insertEmployee(String name, String sex)
            {
                Employee employee = new Employee();
                employee.Name = name;
                employee.Sex = sex;            EmployeeDAO.InsertEmployee(employee);
            }
            //
            static public float getSalary(Employee emp)
            {
                float salary=0;
                return salary;        }
        }
    }表示层
    using System;
    using System.Collections.Generic;
    using System.Text;namespace Employee
    {
        class Employee
        {
            private String name;        public String Name
            {
                get { return name; }
                set { name = value; }
            }
            private String id;        public String Id
            {
                get { return id; }
                set { id = value; }
            }        private String sex;        public String Sex
            {
                get { return sex; }
                set { sex = value; }
            }        private float salary;        public float Salary
            {
                get { return salary; }
                set { salary = value; }
            }
        }
    }
      

  2.   

    你们说的都是逻辑上的三层,只是将代码分开来写而已,这就是所谓的三层(DAL,BLL,UI)?有没有想过物理上面的三层呢?
      

  3.   

    Model DAL BLL三层,即model层来封装实体对象、DAL完成业务逻辑处理、BLL又来传值, aspx充当view层。但我们通常将Model和DAL层和为一层,摒弃BLL层
      

  4.   

    数据访问层——业务逻辑层——表现层,业务逻辑层调用数据访问层,表现层调用业务逻辑层,三层架构中层的耦合度较高,你可以学习一下MVC
      

  5.   

    http://download.csdn.net/detail/swarb/3851428这有个demo ,自己看下吧
      

  6.   

    MVC就是典型的三层架构
    Model、View、Controller