三层架构求教!!! 哪位大虾跟小弟我讲一下c#三层架构???? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据数据访问层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; } } }} 你们说的都是逻辑上的三层,只是将代码分开来写而已,这就是所谓的三层(DAL,BLL,UI)?有没有想过物理上面的三层呢? Model DAL BLL三层,即model层来封装实体对象、DAL完成业务逻辑处理、BLL又来传值, aspx充当view层。但我们通常将Model和DAL层和为一层,摒弃BLL层 数据访问层——业务逻辑层——表现层,业务逻辑层调用数据访问层,表现层调用业务逻辑层,三层架构中层的耦合度较高,你可以学习一下MVC http://download.csdn.net/detail/swarb/3851428这有个demo ,自己看下吧 MVC就是典型的三层架构Model、View、Controller 求正则表达式 help me.....很无奈呀. 我的listview有2列,三行, 通过按钮调用本机的exe文件(是一个加密的录像),调用时需要输入密码,现在我想在程序里把密码写上去,点按钮的时候直接播放~请问怎么弄~ 能告诉我这段pdf文件代码的意思吗?? 在c#中,如何实现就象.net编译环境中那样切换属性窗口和类视图? 关于替换的正则表达式。 本来想做软件开发,却一直没做成。 C# timer的不同的intervals如何操作 我用wcf写了一个文件上传的程序,提示被占用 有用过Ranorex测试 软件的没? .net速成有没有什么要诀
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; }
}
}
}
Model、View、Controller