如何将3层中的以下方法拆分为BOL / DAL / BLL [英] How do I Split the below method in 3-tier as BOL/DAL/BLL

查看:99
本文介绍了如何将3层中的以下方法拆分为BOL / DAL / BLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在正常的.net页面中写过以下方法。我需要在3层架构中使用相同的方法。我无法更改以下方法。请帮帮我。



在3层中拆分与BOL / DAL / BLL相同的方法。

I have written below method in normal .net page. I need the same method in 3-tier architecture. I’m unable to change the below method. Please help me on this.

Split the same method in 3-tier as BOL/DAL/BLL.

protected void CmdLogin_Click(object sender, EventArgs e)
        {

            _path = "LDAP://#";
            //lblerrormsg.Text = string.Empty;
            try
            {
                if (!IsAuthenticated(Convert.ToString(ConfigurationManager.AppSettings["domain"]), Login1.UserName, Login1.Password))
                {
                    return;
                }
                SqlCommand cmd = new SqlCommand("#");
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@UserID", SqlDbType.NVarChar, 50).Value = Login1.UserName;
                LMS dal = new LMS();
                DataSet ds = dal.DisconectedMethod(cmd);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    Session["Authorization"] = Convert.ToString(ds.Tables[0].Rows[0]["ROLE"]);
                    Session["UserID"] = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]);
                    Session["EMPLOYEE_NAME"] = Convert.ToString(ds.Tables[0].Rows[0]["EMPLOYEE_NAME"]);
                    Response.Redirect("index.aspx");
                }
            }
            catch (Exception ex)
            {
                Login1.FailureText = ex.Message;
            }

        }


        private bool IsAuthenticated(string domain, string username, string pwd)
        {
            string domainAndUsername = domain + @"\" + username;
            DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();

                if (null == result)
                {
                    return false;
                }

                //Update the new path to the user in the directory.
                _path = result.Path;
                _filterAttribute = (string)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                Login1.FailureText = ex.Message;
            }

            return true;
        }

推荐答案

将数据库访问代码放入DAL类(即AuthenticationDB)

Put在你身上验证BLL类(即AuthenticationManager)

创建具有UserId,Authorization和Employee名称属性的User类,从BLL返回



然后你的CmdLogin_Click看起来像这样



如果(!AuthenticationManager.IsAuthenticated){

员工e = AuthenticationManager.Login(用户名,密码)

if(e == null){//一些错误信息

}



{

会话[用户] = e;



}





在authenticationManager.Login(用户名,密码)中

你将调用

AuthenticationDB db = new AuthentiationDB(connectionString)

db。登录(用户名,密码),从返回的数据构造Employee对象并将对象返回到UI层。





如果这有助于花时间接受解决方案。谢谢。
Put database access code in your DAL class (i.e. AuthenticationDB)
Put IsAuthenticated in you BLL class (i.e. AuthenticationManager)
Create User class with properties UserId, Authorisation and Employee name, return that from BLL

Then your CmdLogin_Click look like this

If (!AuthenticationManager.IsAuthenticated){
Employee e = AuthenticationManager.Login(username, pwd)
if (e == null) { // some error message
}
else
{
Session["user"] = e;

}


In authenticationManager.Login(username, pwd)
you will call
AuthenticationDB db = new AuthentiationDB(connectionString)
db.Login(username, pwd), construct Employee object from the data returned and return the object to UI layer.


If this helpsplease take time to accept the solution. Thank you.


这篇关于如何将3层中的以下方法拆分为BOL / DAL / BLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆