A hierarchical small project (hospital information automation management system) ---- Data Part section (DataAccess)

xiaoxiao2021-04-07  283

Recently completed a small hospital information automation management system, I want to write a summary of this development. Because it was developed from the first time, some places wrote a little naive. If there is an incorrect place, please ask your high-end fingertips!

Let me talk about my overall development process.

1. According to the system's expected function, first create a good database. Now the entire project is completely completed, and the total feelings are very important for the database establishment.

2. Write a DataAccess (data layer). The code is accurate and can't bring trouble for later development.

3. Write the businessRules (Business Layer) based on the specific function. My idea is to return a DataSet from DataAccess, then accept this DataSet in the function block in the specific business layer, create a DataTable in BusinessRules, populate DataSet into the DataTable, and then return to DataTable. For Indicates the layer to use the DataTable it needs.

4. Return to the design on the interface based on the pre-thoughtable function. Since I am very poor, the interface is very general, just dragging the control.

The expected features are 3 parts, namely: outpatient management, hospital equipment management and pharmacy management.

From 3 to the functional requirements of the database: employees, patients, equipment, departments, department, ward, bed, outpatient business. Attributes and relational tables associated with these entities. Now the database is built! Then start writing the data layer (DataAccess), the program is as follows:

1. A class that gets the connection string.

Public Class Constr

Private constr as string

Public Sub New ()

Constr = "Server = localhost; database = The hospital message manager; user ID = sa; password =;"

End Sub

Public function getconstr () AS String

GetConstr = constr

END FUNCTION

END CLASS

2. A database operation class with returning plants, ie query.

Imports system.data.sqlclient

Public Class Querydata

'This function is an operation of the SQL statement.

Public Function QueryDataInsentence (Byval Sqlstr As String) AS Dataset

DIM Constr As New Constr

Dim Adpter AS New SqldataAdapter

DIM DS AS New DataSet

DIM COM AS New SQLCommand

DIM Con As New SqlConnection (Constr.getConstr)

Adpter.selectCommand = COM

Adpter.selectCommand.connection = con

Adpter.selectCommand.commandType = CommandType.Text

Adpter.selectCommand.comMandText = SQLSTR

Con.open ()

Try

Adpter.Fill (DS)

Return DS

Catch exception

MSGBOX (ex.Message)

Finally

Con. close ()

END TRY

END FUNCTION

'This function is a pair of stored procedures.

Public Function QueryDataInProc (Byval Sqlprocname As String) AS Dataset

DIM Constr As New Constr

Dim Adpter AS New SqldataAdapter

DIM DS AS New DataSet

DIM COM AS New SQLCommand

DIM Con As New SqlConnection (Constr.getConstr)

Adpter.selectCommand = COM

Adpter.selectCommand.connection = con

Adpter.selectcommand.commandtype = commandtype.storedProcedure

Adpter.selectCommand.commandtext = SQLPROCNAME

Con.open ()

Try

Adpter.Fill (DS)

Return DS

Catch exception

MSGBOX (ex.Message)

Finally

Con. close ()

END TRY

END FUNCTION

END CLASS

3. A data operation class that has not returned values, ie fills, deletes, and modifications. Because the needs of the program, the method in this class has a boolean return value.

Imports system.data.sqlclient

Public Class Unquerydata, PUBLIC CLASS UNQUERYDATA

'This function is an operation of the SQL statement.

Public Function Changeinsence (Byval Sqlstr As String) AS Boolean

DIM Constr As New Constr

DIM COM AS New SQLCommand

DIM Con As New SqlConnection (Constr.getConstr)

com.connection = con

com.CommandType = commandtype.text

com.commandtext = SQLSTR

Con.open ()

Try

com.executenonquery ()

Return True

Catch exception

Return False

MSGBOX (ex.Message)

Finally

Con. close ()

END TRY

END FUNCTION

'This function is a pair of stored procedures.

Public Function ChangeinProc (Byval SqlProcname As String) AS Boolean

DIM Constr As New Constr

DIM COM AS New SQLCommand

DIM Con As New SqlConnection

com.connection = con

com.commandtype = commandtype.storedProcedure

com.commandtext = SQLPROCNAME

Con.open ()

Try

com.executenonquery ()

Return True

Catch exception

Return False

MSGBOX (ex.Message)

Finally

Con. close ()

END TRY

END FUNCTION

END CLASS

The operation of the data layer mainly pays attention to the life cycle of each SqlClient object. In order not to enable the BusinessRules layer to access this layer, I will define the definition of no objects in the method, so that the life cycle of the object is very short.

转载请注明原文地址:https://www.9cbs.com/read-132634.html

New Post(0)