夹竹桃ppt,怪兽电力公司中文版,四子王旗百兴网
经过不懈的努力,我的vb.net 版的三层登陆终于实现了。下面将我的成果向大家展示一下。
'定义一个共有的类,用于传递用户的基本信息 public class user '这里分别定义user的三个属性,id、name和password private user_id as string private user_name as string private user_password as string '传入和传出用户的属性值 public property userid() as string get return user_id end get set(byval value as string) user_id = value end set end property public property username() as string get return user_name end get set(byval value as string) user_name = value end set end property public property userpassword() as string get return user_password end get set(value as string) user_password = value end set end property end class
'用于存放链接数据库的字符串 public shared function connstring() as string connstring = server=你数据库的名称;database=login;uid=sa;pwd=你数据库的密码 end function在知道了数据库这个大仓库的位置后,我们对仓库要进行什么操作呢?比如说,我们可能是要看看仓库中都有什么,进行一下查询,也有可能是把仓库中的某条数据复制出来,还有可能是将仓库中的某条数据删除掉。这些都是有可能的。那么我们怎么样才能明确的把我们的命令传到仓库,并且得到我们想要的东西呢? 下面的 userlogin将告诉我们答案:
'引用有关于数据库连接的dll imports system.data.sqlclient imports system.data public class userlogindal '用一个函数调用user将得到的数据传入数据库中,通过数据取出相应的数据 function userselect(byval user as entity.user) as entity.user '定义一个链接数据库的对象 dim cnn as sqlconnection '定义一个输入命令的对象 dim comd as sqlcommand comd = new sqlcommand '将数据库的链接路径赋值给数据链接对象 cnn = new sqlconnection(dal.dbconnstring.connstring()) '为comd绑定链接数据库的路径 comd.connection = cnn '将实体中的数据传入命令对象,用于取得相应的数据 comd.commandtext = select * from users where password= 'a' comd.parameters.add(new sqlparameter(@username, user.username)) comd.parameters.add(new sqlparameter(@userpassword, user.userpassword)) '选择命令输入类型,这里选择的是输入文本格式的数据 comd.commandtype = commandtype.text '打开数据库 cnn.open() dim mrc as sqlclient.sqldatareader mrc = comd.executereader dim selectuser as entity.user selectuser = new entity.user '将取出的临时表中的数据赋值给selectuser对象,这个赋值本来应该由b层来完成,这里为了便于理解就放在这里了 while (mrc.read()) selectuser.userid = mrc.getstring(mrc.getordinal(id)) selectuser.username = mrc.getstring(mrc.getordinal(username)) selectuser.userpassword = mrc.getstring(mrc.getordinal(password)) end while cnn.close() return selectuser end function end class
public class loginbll public function usertest(byval user as entity.user) as entity.user '定义一个usertest,接受从u层和d层传过来的数据 dim testuser as entity.user '将d层的类实例化 dim usedal as dal.userlogindal usedal = new dal.userlogindal testuser = new entity.user '将从u层传来的数据传入d层,然后通过d层从数据库中取得相应的数据 testuser.userid = user.userid testuser.username = user.username testuser.userpassword = user.userpassword testuser = usedal.userselect(testuser) '对从d层取出来的数据进行判断并将判断结果反馈给u层 if testuser is nothing then msgbox(登陆失败) testuser = nothing end if return testuser end function end class
private sub btnlogin_click(sender as object, e as eventargs) handles btnlogin.click '定义一个loginuser用于存储用户输入的信息 dim loginuser as new entity.user '调用bll层的类进行逻辑判断,这里将b层的类先实例化一下,不然没法应用 dim usebll as new bll.loginbll '将用户输入的数据存入loginuser中 loginuser.username = txtusername.text loginuser.userpassword = txtpassword.text '进行逻辑判断 loginuser = usebll.usertest(loginuser) '根据判断的结果来给用户一个反馈,是否验证成功,本来应该传回一个true 或者是fals的值的,考虑到理解的困难程度,这里就不写成那样了 if loginuser is nothing then end else msgbox(登陆成功!) end if end sub
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论