LoadPage

From FeMR Wiki
Jump to navigation Jump to search

The following statements call the relevant table data based on the needs of the ASP page and can be used in combination of two or more.

Dim dsPatientData As New DataSet
dsPatientData = GetTable("tblPatientMaster", "Patient", "")

Dim dsAssailantsData As New DataSet
dsAssailantsData = GetTable("tblAssailants", "Assailants", "")

Dim dsExamData As New DataSet
dsExamData = GetTable("tblExam", "Exam", "")

Dim dsEvidenceData As New DataSet
dsEvidenceData = GetTable("tblEvidence", "Evidence", "")

Dim dsAftercareData As New DataSet
dsAftercareData = GetTable("tblAftercare", "Aftercare", "")

Dim dsInjuryLogData As New DataSet
dsInjuryLogData = GetTable("tblInjuryLog", "InjuryLog", "")

Dim dsInjuryLog2Data As New DataSet
dsInjuryLog2Data = GetTable("tblInjuryLog2", "InjuryLog2", "")

Dim dsCOCData As New DataSet
dsCOCData = GetTable("tblCOC", "COC", "")

These statements replace several lines of code in the LoadPage sub. For example:

    Protected Sub LoadPage()
        Dim con As New SqlConnection
        Dim strErrLocation As String
        Dim strSQL1 As String
        Dim strSQL2 As String
        Dim strRecordTest As String


        strSQL1 = "select * from tblPatientMaster"
        strSQL2 = " where varMedicalRecordNumber = '" & Session("sesCurrentMedicalRecordNumber") & "'"


        On Error GoTo ErrHandler
        strErrLocation = "Connection String"

        Dim strConnectionString As String
        con.ConnectionString = GetConnectionString()
        Dim cmdSel As New SqlCommand(strSQL1 & strSQL2, con)
        Dim daPatientData As New SqlDataAdapter(cmdSel)
        Dim dsPatientData As New DataSet

        strErrLocation = "DB Open"
        con.Open()

        strErrLocation = "DB Read"
        cmdSel.ExecuteNonQuery()

        strErrLocation = "DB Close"
        con.Close()


        daPatientData.Fill(dsPatientData, "Patient")

        strRecordTest = dsPatientData.Tables("Patient").Rows(0).Item("varMedicalRecordNumber")
        If strRecordTest = Session("sesCurrentMedicalRecordNumber") Then 'record exists


            'Load




        Else

            'No record - Do not load

        End If


        GoTo GoodEnd

ErrHandler:
        Session("sesCriticalError") = "Error Loading SAAP3 LoadPage from DB at " & strErrLocation & " Error=" & Err.Description
        Server.Transfer("FEMRError.aspx", True)


GoodEnd:
    End Sub
 

May be reduced to: (note this example allows for the loading of data from two tables)

    Protected Sub LoadPage()
        Dim strErrLocation As String
        On Error GoTo ErrHandler

        'DataSet
        Dim dsPatientData As New DataSet
        Dim dsEvidenceData As New DataSet

        'Table
        dsPatientData = GetTable("tblPatientMaster", "Patient", "")
        dsEvidenceData = GetTable("tblEvidence", "Evidence", "")

        'Load 


        GoTo GoodEnd

ErrHandler:
        Session("sesCriticalError") = "Error Loading SAAP1 LoadPage from DB at " & strErrLocation & " Error=" & Err.Description
        Server.Transfer("FEMRError.aspx", True)


GoodEnd:
    End Sub
 

Or in cases where there is a drop down box on a page, the following can be used:

    Protected Sub LoadPage()
        Dim strErrLocation As String
        On Error GoTo ErrHandler
        Dim strFacility As String
        Dim strLEAgency As String


        'DataSet
        Dim dsPatientData As New DataSet
        Dim dsAssailantsData As New DataSet

        'Table
        dsPatientData = GetTable("tblPatientMaster", "Patient", "")
        dsAssailantsData = GetTable("tblAssailants", "Assailants", "")

        'Load LE Agency Datasource
        cmbLEAgency.DataSourceID = "SqlDataSourceLEAgency"
        cmbLEAgency.DataBind()


        'Load Facility Datasource
        cmbFacility.DataSourceID = "SqlDataSourceFacility"
        cmbFacility.DataBind()

        'Combo box Load data here
        cmbFacility.Text = dsPatientData.Tables("Patient").Rows(0).Item("varFacility")
        strFacility = dsPatientData.Tables("Patient").Rows(0).Item("varFacility")
        If Not cmbFacility.Items.Contains(New ListItem(strFacility)) Then
            cmbFacility.Items.Add(strFacility)
            cmbFacility.Text = strFacility
        End If

        cmbLEAgency.Text = dsPatientData.Tables("Patient").Rows(0).Item("varLEAgency")
        strLEAgency = dsPatientData.Tables("Patient").Rows(0).Item("varLEAgency")
        If Not cmbLEAgency.Items.Contains(New ListItem(strLEAgency)) Then
            cmbLEAgency.Items.Add(strLEAgency)
            cmbLEAgency.Text = strLEAgency
        End If



        'Load






        GoTo GoodEnd

ErrHandler:
        Session("sesCriticalError") = "Error Loading SAAP90 LoadPage from DB at " & strErrLocation & " Error=" & Err.Description
        Server.Transfer("FEMRError.aspx", True)


GoodEnd:
    End Sub