VB. NET data center charging system-logon to the seven fairies system and vb.net Charging System

Source: Internet
Author: User

VB. NET data center charging system-logon to the seven fairies system and vb.net Charging System
VB. NET, the first version of the data center charging system came to an end. During the acceptance, the problem was also a big problem. No design mode, no triggers, or stored procedures were used. Let's look at her friends, layer-7 login? What is that? compared to my three-tier architecture, I added another one by two times. I checked the information and read my blog. After several days, I finally got stuck, let's see a seven fairy-the seven-layer system login, seven daughters, performing their respective duties, perfect cooperation, derived from many beautiful stories.

From Layer 3 to Layer 7, there is a kind of feeling of traversing. To put it bluntly, there is no sense of escaping. But in the life of the world, some things cannot come with their own temper, if you like it, do it. If you don't like it, don't do it. If you don't have a solution, just keep holding on. Finally, the system logon is implemented. Next, let's summarize the knowledge about layer-7 system logon. As the saying goes, a picture can express the emotions and world that cannot be depicted in words. Now let's take a look at the package diagram of the data center charging system, as shown below:



First, let's analyze what we need to do to log on to the system, determine whether the user exists, and determine whether the user name and password are consistent. After the login is successful, we need to add a work record in the worklog table. This blog post provides a simple description of system logon, and adds work records. Next, the code implementation section:

Layer 1: IDAL-data interface access layer, where interface functions are placed.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> '************************************* * ******** 'file Name: IUser 'namespace: idal' internal capacity: interface implementation 'function: Create interface 'file relation:' OPERATOR: Ding Guohua 'small group: Baby scheduler' generation Date: 8:44:27 'version: V2.0' modify log: 'copyright description: '*************************************** * ***** Public Interface iuser' // <summary> '// depiction: <Select User> '// </summary>' // <param name = "<enUser>"> <user entity> </param> '// <returns> '// <returns a user Entity>' // </returns> Function SelectUser (ByVal enUser As Entity. userEntity) As List (Of Entity. userEntity) End Interface </span>

Layer 2: layer D-data access layer. You can add, delete, modify, query, and other functions by passing SQL statements to SqlHelper.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> '************************************* * ******** 'file Name: t_UserDAL 'namespace: DAL 'content: user name and password judgment' function: query whether the user name and password are correct 'file relationship:' OPERATOR: Ding Guohua 'small group: baby scheduler 'generated on: 9:03:17 'version: V2.0' modify log: 'copyright description: '*************************************** * ****** Imports System. data. sqlClientImports IDALPublic Class T_UserDAL: Implements iuser' // <summary> '// depiction: <query whether the user name and password are correct> '// </summary>' // <param name = "<enUser>"> <user entity> </param> '/ // <returns> '// <returns a collection of user entities>' // </returns> Public Function SelectUser (ByVal enUser As Entity. userEntity) As List (Of Entity. userEntity) Implements IUser. selectUser Dim strText As String = "select * from T_User where UserID = @ UserID and password = @ password" 'SQL statement Dim primitive type As CommandType = CommandType. text 'COMMAND type Dim Parameter As SqlParameter () 'Parameter = {New SqlParameter ("@ UserID", enUser. userID), New SqlParameter ("@ password", enUser. password)} Dim SqlHelper As New SqlHelper instantiate an object Of the SqlHelper class Dim dt As New DataTable Dim myList As List (Of Entity. userEntity) dt = SqlHelper. executeReaderTable (strText, primitive type, Parameter) 'calls the executereadertable method in sqlhelper myList = EntityHelper. convertToList (Of Entity. userEntity) (dt) Return myList End FunctionEnd Class </span>

The third layer: Factory-Factory layer. The Abstract Factory and configuration file are described in detail in the big talk design mode. If you do not understand it, You can query page 141st of "big talk design mode, the main role of the factory layer is to use configuration files and reflection to replace databases.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> '************************************* * ******** 'file Name: dataaccess' namespace: Factory 'content: Create interface' function: Create interface 'file relation: 'OPERATOR: Ding Guohua' small group: Baby scheduler 'generation Date: 8:41:23 'version: V2.0' modify log: 'copyright description: '*************************************** * ****** Imports System. reflectionPublic Class dataaccess' /// <summary> '// depiction: <create user interface> '// </summary>' // <param name = "<>"> </param> '// <returns>' /// <return IUserDAL> '// </returns> Public Function CreateIUser () as IDAL. IUser Return CType (Assembly. load ("DAL "). createInstance ("DAL. t_UserDAL "), IDAL. IUser) End FunctionEnd Class </span>

Layer 4: BLL-business logic layer. Check whether the user name and password are correct, instantiate the factory, define interface variables, call methods in the factory, and return a collection of user entities.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> Imports IDAL '*********************************** * ********** 'file Name: t_UserBLL 'namespace: bll' internal volume: business logic level' function: query whether the user name and password are correct 'file relationship:' OPERATOR: Ding Guohua 'small group: baby scheduler 'generated on: 9:02:30 'version: V2.0' modify log: 'copyright description: '*************************************** * ***** Public Class T_UserBLL '// <summary>' // depiction: <query whether the user name and password are correct> '// </summary>' // <param name = "<enUser>"> <user entity> </param> '/ // <returns> '// <returns a collection of user entities>' // </returns> Public Function SelectUser (ByVal enUser As Entity. userEntity) As List (Of Entity. userEntity) Dim factory As New Factory. dataAccess Dim IUser As IDAL. IUser Dim myList As List (Of Entity. userEntity) IUser = factory. createIUser () myList = IUser. selectUser (enUser) Return myList End FunctionEnd Class </span>

Layer 5: Facade-appearance layer, detailed description on page one hundred and three of "big talk design mode.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px; "> '************************************* * ******** 'file Name: loginFacade 'namespace: Facade' internal volume: 'function:' file relation: 'OPERATOR: Ding Guohua' group: Baby scheduler 'generation Date: 8:41:05' version: v2.0 'modify log: 'copyright description: '*************************************** * ****** Public Class LoginFacade '// <summary>' // depiction: <Select User> '// </summary>' // <param name = "<enUser>"> <user entity> </param> '// <returns> '// <returns a collection of user entities>' // </returns> Public Function SelectUser (ByVal enUser As Entity. userEntity) As List (Of Entity. userEntity) Dim userBLL As New BLL. t_UserBLL Dim myList As List (Of Entity. userEntity) myList = userBLL. selectUser (enUser) If myList. count = 0 Then Throw New Exception ("Incorrect username or password") Else Return myList End If End FunctionEnd Class </span>

Layer 6: UI Layer-User display layer. The U layer is responsible for data input and output. The Fa C ade layer is called to verify the user-class query method to check whether the user exists, finally, log on by calling the Fa C ade layer method.

<Span style = "font-size: 18px;"> <span style = "font-size: 18px;"> Imports System. windows. forms '************************************** * ******* 'file Name: frmLogin 'namespace: Ui' content: User display lay' function: confirm whether the user has a 'file relation: 'OPERATOR: Ding Guohua' group: Baby scheduler 'generation Date: 17:51:07 'version: V2.0' modify log: 'copyright description: '*************************************** * ***** Public Class frmLogin Public Shared enLogin As New Entity. userEntity '// <summary>' // depiction: <confirm whether the user exists> '// </summary>' // <param name = "<>"> </param> '// <returns> '// <logon Failure prompt, log on to the main page and go to '// </returns> Private Sub btnConfirm_Click (sender As Object, e As EventArgs) Handles btnConfirm. click Dim facade As New Facade. loginFacade Dim myList As New List (Of Entity. userEntity) Dim enUser As New Entity. userEntity 'encapsulate entity Dim flag As Boolean Try enUser. userID = txtUserName. text. trim () enUser. password = txtPassword. text. trim () myList = facade. selectUser (enUser) If myList. count> 0 Then MsgBox ("Logon successful") Dim enWorklog As New Entity. worklogEntity enWorklog. userID = txtUserName. text. trim () enWorklog. loginDate = CStr (Format (Now (), "yyyy-MM-dd") enWorklog. loginTime = CStr (Format (Now (), "HH: mm: ss") enWorklog. status = "on duty" enWorklog. computer = Environment. getEnvironmentVariable ("USERNAME") flag = facade. insertWorklog (enWorklog) enLogin. userID = myList. item (0 ). userID enLogin. level = myList. item (0 ). level End If Catch ex As Exception MessageBox. show (ex. message. toString () txtUserName. focus () txtUserName. selectAll () txtPassword. text = "" End Try End Sub Private Sub btnCancel_Click (sender As Object, e As EventArgs) Handles btnCancel. click Me. close () End SubEnd Class </span>

Layer 7: SqlHelper. The previous blog post has related introductions. Here, we will not discuss them one by one. Since then, a small login function has been implemented. When the layer-7 login is not yet formed, there are various kinds of confusions, various don't want to do, and there is a feeling that it is approaching the critical point, but after walking through, I found that, this critical point is to open the three realms, and then discover the world is so beautiful and colorful. Like the story of the seven fairies, our layer-7 logins also perform their respective duties and fulfill their duties in their jobs.

Fee System for the second version of the IDC, not complete, to be continued ......




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.