MiisApp: ViewSource_People.vb


Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class ViewSource_People
Inherits System.Windows.Forms.Form
Const MIIS_SERVER_NAME = “MIISSERVER”
Const DB_CONNECTION_STRING As String = “Database=MIISData;Data Source=MIISSERVER;Integrated Security=TRUE;;”
Const MIISDB_CONNECTION_STRING As String = “Database=MicrosoftIdentityIntegrationServer;Data Source=MIISSERVER;Integrated Security=TRUE;;”
Dim sqlQueryConnection As New SqlConnection(DB_CONNECTION_STRING)
Dim sqlMIISConnection As New SqlConnection(MIISDB_CONNECTION_STRING)
Dim searchUID As String = “”
Dim searchLBSNo As String = “”
#Region ” Windows Form Designer generated code “#End Region    Private Sub ViewSource_People_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txt_Output.Clear()

        Dim i As Int16
        Dim StaffID As String
        Dim fieldDesc As String
        Dim rowReader As SqlDataReader
        Dim peopleQueryString As String = “”
        Dim groupsQueryString As String = “”
        If rdo_uid.Checked AndAlso searchUID <> “” Then
            peopleQueryString = “select * from PeopleData_Snapshot where uid='” & searchUID & “‘”
        ElseIf rdo_staffid.Checked AndAlso searchStaffid <> “” Then
            peopleQueryString = “select * from PeopleData_Snapshot where staffid='” & searchStaffid & “‘”
        End If

        If peopleQueryString <> “” Then
            Dim sqlQuery As New SqlCommand(peopleQueryString, sqlQueryConnection)
            sqlQueryConnection.Open()
            rowReader = sqlQuery.ExecuteReader
            If rowReader.Read() Then
                StaffID = rowReader.GetString(0)
                For i = 0 To rowReader.FieldCount – 1
                    fieldDesc = rowReader.GetName(i) & “:”
                    fieldDesc = fieldDesc.PadRight(30)
                    Me.txt_Output.AppendText(fieldDesc)
                    Try
                        If Not rowReader.GetSqlValue(i).IsNull Then
                            Me.txt_Output.AppendText(rowReader.GetValue(i))
                        End If
                    Catch
                        Dim ex As InvalidCastException
                    End Try
                    Me.txt_Output.AppendText(vbCrLf)
                Next
                rowReader.Close()

                If Me.chk_showgroups.Checked Then
                    Me.txt_Output.AppendText(“Groups:” & vbCrLf)
                    groupQueryString = “select Name from admultivalue_snapshot where value='” & StaffID & “‘ and AttributeType = ‘member’ order by Name”
                    Dim memberQuery As New SqlCommand(groupQueryString, sqlQueryConnection)
                    rowReader = groupQuery.ExecuteReader
                    While rowReader.Read()
                        Me.txt_Output.AppendText(vbTab & vbTab & rowReader.GetString(0) & vbCrLf)
                    End While
                    rowReader.Close()
                End If

            Else
                Me.txt_Output.AppendText(“Not Found”)
            End If
            sqlQueryConnection.Close()
        End If
    End Sub

    Private Sub rdo_uid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdo_uid.CheckedChanged
        If rdo_uid.Checked Then
            Me.txt_uid.Focus()
        End If
    End Sub

    Private Sub rdo_lbsno_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdo_lbsno.CheckedChanged
        If rdo_lbsno.Checked Then
            Me.txt_lbsno.Focus()
        End If
    End Sub

    Private Sub txt_uid_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_uid.TextChanged
        rdo_uid.PerformClick()
        searchUID = Me.txt_uid.Text
    End Sub

    Private Sub txt_staffid_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_staffid.TextChanged
        rdo_staffid.PerformClick()
        searchStaffid = Me.txt_staffid.Text
    End Sub

End Class