机房重构
来源:互联网 发布:去哪里学java 编辑:程序博客网 时间:2024/05/06 16:09
三层登陆完事就是七层,三层当时就是照着敲,基本上没遇到什么问题,总以为七层还是能在网上找到现成的代码,庆幸的是找到了,也照着敲了,但是运行不起来,看来欠的总是要还的,自己搜的代码里好多命名都给弄混了,研究了一周终于明白点了。
UI层
- private void btnOK_Click(object sender, EventArgs e)
- {
-
- string UserName = txtUserName.Text.Trim();
- string Password = txtPassword.Text;
- if (txtUserName .Text ==string .Empty )
- {
- MessageBox.Show("请输入用户名!", "登录");
- }
- if (txtPassword.Text ==string .Empty )
- {
- MessageBox.Show("请输入密码!", "登录");
- }
-
- JF.Facade.LoginFacade FLogin = new JF.Facade.LoginFacade();
- JF.Entity.LoginEntity user = FLogin.SelectUser(UserName, Password);
-
- if (user!=null )
- {
- MessageBox.Show("登陆成功!");
- this.Hide ();
- this.DialogResult =System .Windows .Forms .DialogResult .OK ;
- frmMain frmMain=new frmMain ();
- frmMain.Show();
- }
- else
- {
- MessageBox .Show("密码或者用户名错误");
- }
- }
Facade层
- public JF .Entity .LoginEntity SelectUser(string UserName,string Password)
- {
- JF.Entity.LoginEntity user = new JF.Entity.LoginEntity();
- JF.BLL.LoginBLL loginBll = new JF.BLL.LoginBLL();
- user = loginBll.SelectUser(UserName, Password);
- return user;
- }
BLL层
- public JF.Entity.LoginEntity SelectUser(string UserName,string Password)
- {
- JF.Entity.LoginEntity user = new JF.Entity.LoginEntity();
- JF.Factory.LoginFactory Datacess = new JF.Factory.LoginFactory();
- JF.IDAL.LoginIDAL ILogin;
- ILogin = Datacess.SelectUser();
- user = ILogin.GetUser(UserName, Password);
- return user;
- }
Factory层
- public static readonly string strDB = System.Configuration.ConfigurationManager.AppSettings ["DBString"];
- public JF.IDAL .LoginIDAL SelectUser()
- {
- return (JF.IDAL.LoginIDAL)Assembly.Load(strDB).CreateInstance("JF.DAL.LoginDAO");
- }
IDAL层
- JF.Entity.LoginEntity GetUser(string UserName, string Password);
DAL层
- public JF.Entity.LoginEntity GetUser(string UserName, string Password)
- {
- using (SqlConnection conn = new SqlConnection(DBUtil.conString))
- {
- SqlCommand cmd = conn.CreateCommand();
-
- cmd.CommandText = @"select * from JFUser_Info where UserID=@UserName and Pwd=@Password";
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.Add(new SqlParameter("@UserName", Password));
- cmd.Parameters.Add(new SqlParameter("@Password", UserName));
- conn.Open();
- SqlDataReader reader = cmd.ExecuteReader();
-
- JF.Entity .LoginEntity user = null;
- while (reader.Read())
- {
- if (user == null)
- {
- user = new JF.Entity.LoginEntity();
-
- }
-
- user.UserName = reader.GetString(1);
- user.Pwd = reader.GetString(2);
- }
- return user;
- }
- }
Entity层
- public class LoginEntity
- {
- private static string _userid;
- public static string UserID
- {
- get { return _userid; }
- set { _userid = value; }
- }
- private string _level;
- public string Level
- {
- get { return _level; }
- set { _level = value; }
- }
- private string _head;
- public string Head
- {
- get { return _head; }
- set { _head = value; }
- }
- private string _username;
- public string UserName
- {
- get { return _username; }
- set { _username = value; }
- }
- private string _pwd;
- public string Pwd
- {
- get { return _pwd; }
- set { _pwd = value; }
- }
- }