欢迎光临
我们一直在努力

分层体系结构(MVC)三-.NET教程,评论及其它

建站超值云服务器,限时71元/月

 

三、business层

business层主要完成一些对于业务逻辑的处理,以及参数传递的工作。

对于每一个功能,通常是一个form 要对应一个business下的子层,例如处理用户登录的功能,就在business下,添加一个login文件夹,文件夹中包括两个文件,userlimits和userparameter,userlimits主要用来业务逻辑处理,以及调用entityclass层中相应对数据库操作的函数;userparameter主要完成参数传递。

userparameter的代码如下:

namespace business.login
    public class userparameter

        private _id as string
        private _username as string
        private _password as string
        _id 的set和get方法
        public function set_id(byval m_id as string) as string
            me._id = m_id
        end function
        public function get_id() as string
            return (me._id)
        end function
        _username的set和get 方法
        public function set_username(byval m_username as string) as string
            me._username = m_username
        end function
        public function get_username() as string
            return (me._username)
        end function
        _password的set和get 方法
        public function set_password(byval m_password as string) as string
            me._password = m_password
        end function
        public function get_password() as string
            return (me._password)
        end function

        public function chacklogin(byval user as integer, byval pass as integer) as integer

            dim up as integer = 0
            if up.equals(0) then
                if user.equals(pass) then
                    return 1
                else
                    return 0
                end if
            end if

        end function
    end class
end namespace
可以看到,只是包括对应数据库中表的字段的属性,以及对其的set和get方法。

userlimits的代码如下:

imports system
imports system.data
imports system.web
namespace business.login

    public class userlimits
        private user as new entityclass.s_user

        public sub new()

            todo: 在此处添加构造函数逻辑
            me.user = new entityclass.s_user
        end sub
        public function getuserobj(byval username as string, byval password as string) as userparameter
            msgbox(1)
            if (me.user.getuser(username, password) > 0) then
                msgbox(2)
                dim up as userparameter = new userparameter
                up.set_id(me.user.id_i)
                up.set_username(me.user.username_s)
                up.set_password(me.user.password_s)

                return up

            else
                dim up1 as new userparameter
                return up1
                return nothing
            end if

        end function
        按id得到纪录
        public function getuserbyid(byval myid as string) as userparameter
            me.user.id_i = myid
            if (me.user.load() > 0) then
                msgbox(2)
                dim up as userparameter = new userparameter
                up.set_id(me.user.id_i)
                up.set_username(me.user.username_s)
                up.set_password(me.user.password_s)

                return up

            else
                dim up1 as new userparameter
                return up1
                return nothing
            end if
        end function
        增加用户
        public function adduserobj(byval adduser as userparameter)
            me.user.username_s = adduser.get_username
            me.user.password_s = adduser.get_password
            me.user.setentity(adduser)
            me.user.setdynamiccoloum()
            try
                me.user.creatuser()
            catch ex as exception

            end try

        end function
        更新用户
        public function updateuserobj(byval adduser as userparameter)
            me.user.username_s = adduser.get_username
            me.user.password_s = adduser.get_password
            me.user.setentity(adduser)
            try
                me.user.updata()
            catch ex as exception

            end try

        end function
        删除用户
        public function deluserobj(byval adduser as userparameter)
            me.user.username_s = adduser.get_username
            me.user.password_s = adduser.get_password
            try
                me.user.delete()
            catch ex as exception

            end try

        end function
        得到所有用户列表
        public function getalluser(byref dataset as dataset)
            me.user.loadusers(dataset)
        end function
        根据sql查询语句查询
        public function getobjbyqry(byval str as string) as userparameter()
            dim objlen as integer
            dim m_i as integer
            dim mp(objlen – 1) as userparameter
            objlen = me.user.getobjbyqry(str, mp)

          
            return mp
        end function
    end class
end namespace
可以看到,主要是做业务逻辑的处理。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 分层体系结构(MVC)三-.NET教程,评论及其它
分享到: 更多 (0)

相关推荐

  • 暂无文章