三層架構資料傳遞

2021-06-16 08:40:40 字數 4053 閱讀 1765

說三層先說乙個小故事。

從前有三家鄰居,一家姓張,一家姓李,一家姓王,姓張的和姓李的兩家人各有乙個兒子,而姓李的家是乙個女孩,長得特別的漂亮,於是其他兩家的的都想追求這個女孩,兩個人人誰也不服誰,於是在那一天,兩個人相聚到小樹林,打了起來,打得是不相上下,後來兩家人因為這個鬧得很是不痛快!!這件事情讓女孩子知道了,他覺得這兩個人不該這樣,於是女孩子就去勸說他們兩個,而是找到了乙個男孩,對他說,我們以前多麼的好,現在不該因為我變成這樣,在女孩子的勸說之下其中乙個男孩子開始有了悔意,於是就說,你幫我傳遞乙個話吧,說我晚上要請客,你可以幫我告訴他嗎?女孩子很高興的將這件事情告訴了另乙個男孩子那個男孩子一聽覺得自己也有不對的地方,於是讓女孩子把他心裡面想說讓女孩高數那個要請客的男孩子於是兩個人又和好了。

女孩是就是實體類,也就是看成了乙個整體的慘數,在兩個男孩之間進行傳遞話,從而使兩方面的關係變好了。

用乙個三層的登陸的小例子來說明吧!

實體類  也就是那個女孩的角色:

public classe_userinfo

private e_username as string

public property username as string

getreturn e_username

end get

set(byval value as string)

e_username = value

end set

end property

private e_password as string

public property password as string

getreturn e_password

end get

set(byval value as string)

e_password = value

end set

end property

end class

//ui層判讀層,在這裡面定義了乙個實體類(女孩進行資料的傳遞)用於判斷

private sub btnok_click(byval sender as system.object, byval e as system.eventargs) handles btnok.click

dim loginuser as new loginentity.e_userinfo     '定義乙個實體類物件loginentity.e_userinfo

dim bcheck as new loginbll.loginmanager         '定義乙個loginbll.loginmanager物件

if trim(txtusername.text) = "" then

msgbox("姓名不能空")

exit sub

elseif trim(txtpassword.text) = "" then

msgbox("密碼不能為空")

exit sub

else

loginuser.username = txtusername.text()

loginuser.password = txtpassword.text()

end if

'採集使用者資訊,展現登入結果

if bcheck.selectuiandentity(loginuser) = true then//將資料傳遞

msgbox("登入成功!")

else

msgbox("登入失敗!")

end if

end sub

//b層的**進行資料的判斷

imports loginentity

imports logindal.userdao

'b層業務處理(邏輯),做判斷

public class loginmanager

function selectuiandentity(byval user as loginentity.e_userinfo) as boolean

dim daluser as new logindal.userdao 'd

dim entityuser as new loginentity.e_userinfo 'e//定義乙個實體類進行將資料從ui層的傳遞b層

entityuser.username = user.username

entityuser = daluser.selectuserinfoformuserinfotable(entityuser)  // 將資料傳遞給d層進行查詢

'判斷操作

if entityuser.password = user.password then

return true

else

return false

end if

end function

end class

imports system.data.sqlclient

imports loginentity

//d層的**    

public class userdao

'連線資料庫

dim sqlconnectstr as string = "server=lizhihua-pc;database=charge_sys;uid=sa;pwd=123456;"

dim sqlconnection1 as sqlconnection = new sqlconnection(sqlconnectstr)

'自定義檢查引數

function selectuserinfoformuserinfotable(byval user asloginentity.e_userinfo) as loginentity.e_userinfo//將實體類傳遞到d層進行查詢

dim sql as string = "select * from user_info where username='" & user.username & "'"      'sql語句

dim cmd as sqlcommand = new sqlcommand(sql, sqlconnection1)     '定義sqlcommand物件

dim read as sqldatareader       '定義sqldatareader物件

dim userdatatable as new datatable    '定義乙個datatable物件

dim user1 as new loginentity.e_userinfo

trysqlconnection1.open()

read = cmd.executereader()

userdatatable.load(read)

user1.username = trim(userdatatable.rows(0).item("username"))        

user1.password = trim(userdatatable.rows(0).item("pwd"))

'label1.caption = (trim(userdatatable.rows(0).item("pwd")))

'print(trim(userdatatable.rows(0).item("pwd")))

return user1

catch ex as exception

user1.password = ""

return user1

finally

if not isnothing(sqlconnection1) then

sqlconnection1.close()

end if

end try

end function

end class

三層都有實體類,也就是乙個引數 ,這個引數從u層的輸入到 b層進行 ,再由b層傳到d層進行查詢,將查詢結果返回到b層進行判斷,最後回到ui層顯示出來,也就相當於連個男孩子在女孩子的幫助下和好了。

三層架構中的引數傳遞

三層架構中的引數傳遞 三層架構中的引數傳遞情況很多 也很重要 不過引數傳遞又分很多的情況 雖然情況眾多 不多按照形式來分 一般都是用傳值和傳遞實體 下面就來稍微介紹一些情況 做機房收費系統的時候有這麼一種情況 那就是當管理員登陸了以後 管理員的 id需要多次被不同的窗體用到 而管理員的 id則需要被...

c mysql三層架構例項 三層架構例項

一 概要 這篇部落格,準備用乙個小demo來介紹應該實現三層架構。三層架構只是分層的一種經典形式,到底分幾層,要依具體情況而定,考慮到系統的複雜程度,和後期的可維護性,完全可以分四層,五層,甚至六層,七層。二 demo 1 實現語言 vb.net 2 需求 學校機房收費系統 中的乙個功能 操作員為學...

軟體架構 三層架構

三層系統的分層式結構 三層架構 3 tier architecture 通常意義上的三層架構就是將整個業務應用劃分為 區分層次的目的即為了 高內聚,低耦合 的思想。表現層 ui 通俗講就是展現給使用者的介面,即使用者在使用乙個系統的時候他的所見所得。業務邏輯層 bll 針對具體問題的操作,也可以說是...