求助:三层架构登录系统功能

createdatabase 发布于 2011/01/19 14:08
阅读 749
收藏 2

1.Model库类,新建一个userModel.代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class userModel
    {
       string _name;
       string _pwd;

        public string UserName {
            get {
                return this._name;
            }
            set {
                this._name = value;
            }
        }

        public string UserPwd {
            get {
                return this._pwd;
            }
            set {
                this._pwd = value;
            }
        }

      

    }
}

2.配置文件的代码如下:

</configSections>
    <appSettings>
        <add key="strconnection" value="server=(local);database=user_db;uid=sa;pwd=;"/>
    </appSettings>
    <connectionStrings/>

 

3.BLL库类,创建一个userBll.代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dll;
using Model;

namespace BLL
{
    public class userBLL
    {
        Dll.userDll dl = new Dll.userDll();
        public bool login(Model.userModel user)
        {
          
            return dl.login(user);
           
        }
    }
}

 

4.DLL库类,创建一个userDll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Model;


namespace Dll
{
    public class userDll
    {
        string conning = ConfigurationManager.AppSettings["strconnection"];

        public bool login(Model.userModel user) {
            SqlConnection con = new SqlConnection(conning);
            con.Open();
          
            string strcom = "select * from login_tb where userName='" +user.UserName+ "' and userPwd='" +user.UserPwd + "';";
            SqlCommand com = new SqlCommand(strcom, con);
            SqlDataReader sdr = com.ExecuteReader();
            if(sdr.Read())
            {
                return true;
            }
            else {
                return false;
            }            
        }

    }
}

5.

UI层的代码如下:

 protected void btnLogin_Click(object sender, EventArgs e)
    {
        Model.userModel M = new userModel();
        M.UserName = this.userName.ToString();
        M.UserPwd = this.userPwd.ToString(); ;
        BLL.userBLL bll = new userBLL();
        try
        {
            bll.login(M);
           
            Response.Write("成功");
        }
        catch {
            Response.Write("失败");
        }

6.数据库表login_tb

    userName varchar(20),

    userPwd varchar(20)

 

 

出现的问题:不管是输入正确的账号和密码都提示成功!

请各位高手帮帮忙,看下上面的代码,帮我解决这个问题,小弟不甚感激

加载中
0
默默无蚊
默默无蚊

bll.login(M);     //这里应该判断一下在做下面的输出吧?
            
Response.Write("成功");

0
默默无蚊
默默无蚊
            try
            {
                if (bll.login(M))
                {

                    Response.Write("登录成功");
                }
                else
                {
                    Response.Write("登录失败");
                }
            }
            catch
            {
                Response.Write("错误提示");
            }
返回顶部
顶部