日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

机房收费系统重构(五)—登陆窗口完整版

發(fā)布時(shí)間:2025/3/19 windows 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 机房收费系统重构(五)—登陆窗口完整版 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

? ? ?在上上篇?!稒C(jī)房收費(fèi)系統(tǒng)重構(gòu)(3)》。中主要是介紹了自己關(guān)于DAL層,工廠層。以及接口層,還有實(shí)體層的理解。可是好多讀者再問我。你的代碼呢,我在這解釋一下。就是我僅僅是寫出關(guān)于那幾部分的理解,并沒有寫貼出代碼讓大家研究的??墒遣荒茼槕?yīng)民心的文章不是好文章,所以我在這篇文章中,將機(jī)房收費(fèi)登錄中七層中全部的代碼,貼出來供大家拍磚斧正。還有最后我在談?wù)勧槍?duì)BLL層和外觀層的理解。

? ? ?首先我所說的七層是針對(duì)UI層,外觀層,BLL層,DAL層,工廠層,實(shí)體層,接口層七層組成。

? ? ?實(shí)現(xiàn)登錄窗口,要明確。先要查詢用戶是否存在,然后將登錄信息寫入數(shù)據(jù)庫,這兩個(gè)主要步驟。

首先來看看我數(shù)據(jù)庫中用到的兩個(gè)表:

??

? ? 這樣能方便讀者更easy理解后面的代碼:

? ? 一.首先看看實(shí)體層的代碼吧

(1)用戶表實(shí)體層:

Public Class MO_LoginPrivate _userID As StringPrivate _level As StringPrivate _password As StringPrivate _userName As StringPrivate _computer As StringPublic Shared UserHead As String ' 設(shè)置全局變量Public Shared UserLevel As StringPublic Property UserID() As StringGetReturn _userIDEnd GetSet(value As String)_userID = valueEnd SetEnd PropertyPublic Property PassWord() As StringGetReturn _passwordEnd GetSet(value As String)_password = valueEnd SetEnd PropertyPublic Property level() As StringGetReturn _levelEnd GetSet(value As String)_level = valueEnd SetEnd PropertyPublic Property UserName() As StringGetReturn _userNameEnd GetSet(value As String)_userName = valueEnd SetEnd PropertyPublic Property Computer() As StringGetReturn _computerEnd GetSet(value As String)_computer = valueEnd SetEnd Property End Class(2)工作記錄實(shí)體層:

Public Class MO_WorklogPrivate _userID As StringPrivate _level As StringPrivate _loginDataTime As StringPrivate _computer As StringPrivate _status As StringPublic Shared Property Login_DataTime As StringPublic Property UserID() As StringGetReturn _userIDEnd GetSet(value As String)_userID = valueEnd SetEnd PropertyPublic Property level() As StringGetReturn _levelEnd GetSet(value As String)_level = valueEnd SetEnd PropertyPublic Property LoginDataTime() As StringGetReturn _loginDataTimeEnd GetSet(value As String)_loginDataTime = valueEnd SetEnd PropertyPublic Property Computer() As StringGetReturn _computerEnd GetSet(value As String)_computer = valueEnd SetEnd PropertyPublic Property Status() As StringGetReturn _statusEnd GetSet(value As String)_status = valueEnd SetEnd Property End Class? ?二.接著來看看UI層的吧:

Public Class frmLoginPrivate Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.ClickDim login As New Model.MO_LoginDim falogin As New Facade.FA_Login '實(shí)例化過程Dim strResult As Stringlogin.UserID = txtUserName.Text '賦值過程login.PassWord = txtPassWord.TextModel.MO_Login.UserHead = txtUserName.TextDim worklog As New Model.MO_Worklog '實(shí)例化工作記錄worklog.LoginDataTime = Date.Now.ToString("yyyy-mm-dd hh:mm:ss") '上機(jī)時(shí)間worklog.Status = "正在值班" '工作狀態(tài)worklog.UserID = Model.MO_Login.UserHeadworklog.Computer = System.Net.Dns.GetHostName().ToString() '本地計(jì)算機(jī)strResult = falogin.FLogin(login, worklog) '傳參返回過程Select Case strResult '推斷過程Case "輸入有誤"MsgBox("輸入有誤。請(qǐng)又一次輸入")Case "登錄成功"MsgBox("登錄成功")Model.MO_Worklog.Login_DataTime = worklog.LoginDataTimeMe.Hide()'frmMain.Show()End SelectEnd SubPrivate Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.ClickEndEnd Sub End Class ? ?三.外觀層代碼:

Imports BLL Public Class FA_LoginPublic Function FLogin(ByVal user As Model.MO_Login, worklog As Model.MO_Worklog) As StringDim UserBLL As New BLL.BL_LoginIf UserBLL.IsnotNull(user, worklog) = False ThenReturn "輸入有誤"ElseReturn "登錄成功"End IfEnd Function End Class ? ?四.BLL層代碼:<pre name="code" class="vb">Imports IDAL Public Class BL_LoginPublic Function IsnotNull(ByVal user As Model.MO_Login, ByVal worklog As Model.MO_Worklog) As BooleanDim IUser As IDAL.ILogin '注意接口類型不能實(shí)例化。Dim factory As New Factory.LoginFactory '實(shí)例化工廠Dim IWorklog As IDAL.IWorklogIUser = factory.CreateUserInfo() '工廠創(chuàng)建接口,DAL實(shí)現(xiàn)接口。BLL調(diào)用工廠IWorklog = factory.CreateWorklog()If IUser.User_Login(user).UserID = "" Then '假設(shè)為空Return False 'Boolean值為falseElseworklog.level = IUser.User_Login(user).level '傳參數(shù)。將查詢到的用戶類型傳給worklog實(shí)體層。在后面的增刪改中應(yīng)用。

If IWorklog.SaveWorkLog(worklog) Then '假設(shè)查詢到用戶存在,就開始將登錄信息寫入數(shù)據(jù)庫中。

Return True End If Return True End If End Function End Class

? 五.工廠層代碼:

Imports System.Reflection '加入反射的引用 Imports System.Configuration '加入配置文件的引用 Imports IDAL Public Class LoginFactory'利用反射+配置文件+抽象工廠Dim strDB As String = System.Configuration.ConfigurationSettings.AppSettings("strSqlConnection")'表示讀取配置文件。假設(shè)配置文件里是SQLserver數(shù)據(jù)庫就訪問,假設(shè)是別的就放訪問別的,不須要更改代碼'Dim strQueryWorkLog As String = System.Configuration.ConfigurationSettings.AppSettings("strSqlConnection")'創(chuàng)建用戶表工廠Public Function CreateUserInfo() As ILoginReturn CType(Assembly.Load("DAL").CreateInstance("DAL" & "." & "DA_Login"), ILogin)End FunctionPublic Function CreateWorklog() As IWorklogReturn CType(Assembly.Load("DAL").CreateInstance("DAL" & "." & "DA_Worklog"), IWorklog)End FunctionEnd Class? 六.接口層代碼:

(1)用戶查詢接口

Public Interface ILoginFunction User_Login(ByVal user As Model.MO_Login) As Model.MO_Login End Interface(2)將操作記錄寫入數(shù)據(jù)庫代碼:

Public Interface IWorklogFunction SaveWorkLog(ByVal worklog As Model.MO_Worklog) As Boolean End Interface? 七.最后是DAL層代碼:

(1)用戶查詢DAL

Imports System.Data.SqlClient Imports System.Data Imports IDAL Public Class DA_Login : Implements IDAL.ILoginPublic Function User_Login(user As Model.MO_Login) As Model.MO_Login Implements IDAL.ILogin.User_LoginDim sqlparams As SqlParameter() = {New SqlParameter("@UserID", user.UserID), New SqlParameter("@Password", user.PassWord)} '傳遞參數(shù)過程Dim cmdText As String = "select * from T_UserInfo where UserName =@UserID and PassWord =@Password" '查詢數(shù)據(jù)庫Dim aUser As New Model.MO_Login '實(shí)例化過程Dim helper As New SqlHelperDim cmdType As CommandType = New CommandType()cmdType = CommandType.Text '定義命令類型為存儲(chǔ)過程Dim table As DataTable '實(shí)例化一個(gè)過程'在這里想解釋一個(gè),因?yàn)楹瘮?shù)返回參數(shù)是實(shí)體層??墒沁@里定義的table是一個(gè)Datable類型。所以系統(tǒng)無法進(jìn)行轉(zhuǎn)換。

所以我定義了一個(gè)aUser進(jìn)行中轉(zhuǎn)。 table = helper.ExecuteQuery(cmdText, cmdType, sqlparams) '定義返回值 If table.Rows.Count <> 0 Then aUser.UserID = table.Rows(0).Item("UserID") aUser.PassWord = table.Rows(0).Item("PassWord") aUser.level = table.Rows(0).Item("level") aUser.UserName = table.Rows(0).Item("UserName") End If Return aUser End Function End Class

(2)操作記錄寫入代碼DAL

Imports System.Data.SqlClient Imports System.Data Imports IDAL Public Class DA_Worklog : Implements IDAL.IWorklogPublic Function SaveWorkLog(worklog As Model.MO_Worklog) As Boolean Implements IWorklog.SaveWorkLogDim strText As String = "INSERT INTO T_WorkLog(UserID,level,LoginDateTime,Computer,Status)VALUES (@UserID,@level,@LoginDateTime,@Computer,@Status)"Dim sqlparams As SqlParameter() = {New SqlParameter("@UserID", worklog.UserID), New SqlParameter("@level", worklog.level), New SqlParameter("@LoginDateTime", worklog.LoginDataTime), New SqlParameter("@Computer", worklog.Computer), New SqlParameter("@Status", worklog.Status)}Dim cmdType As CommandType = CommandType.TextDim helper As New SqlHelperReturn helper.ExecuteNonQuery(strText, cmdType, sqlparams)End Function End Class ? ? ??事實(shí)上這些代碼也不全。少了關(guān)于工廠反射的配置部分的內(nèi)容,還有就是SqlHelper。

SqlHelper,在我《機(jī)房收費(fèi)重構(gòu)(4)》中有非常具體的介紹。

在這就不寫了。


? ? 最后說一下關(guān)于BLL和外觀層的理解吧。從代碼看。仿佛感覺外觀層沒有什么作用,是的,關(guān)于登錄窗口小功能的實(shí)現(xiàn),沒有太大的必要用外觀層,可是以后要敲一個(gè)龐大的窗口時(shí),我們須要將U層和B層解耦,那么外觀層的作用就彰顯出來了。關(guān)于BLL和外觀事實(shí)上沒有什么想說的。最想說的是數(shù)據(jù)類型的轉(zhuǎn)換,由于層與層之間傳遞參數(shù)和返回參數(shù)的過程須要用到相同類型的數(shù)據(jù),可是將數(shù)據(jù)類型都設(shè)置為Datatable和string或者實(shí)體類型是不可能。希望大家在今后寫程序過程中注意就能夠了。

? ?本片文章代碼較多。希望大家拍磚斧正。。

總結(jié)

以上是生活随笔為你收集整理的机房收费系统重构(五)—登陆窗口完整版的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。