| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 
 |  
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System
Imports System.Web
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports AjaxControlToolkit
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.DirectoryServices
 
 
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
 
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class cascad
 
    Inherits System.Web.Services.WebService
 
 
 
    <WebMethod()> _
    Public Function GetBuilding(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
 
 
 
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("IT_Rent_connection").ConnectionString
        Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
        Dim UserID as string 
        UserID = TBUserID.Text 
        Dim LDAP As New DirectoryEntry("LDAP://************")
        Dim searcher As DirectorySearcher = New DirectorySearcher(LDAP)
        searcher.PropertiesToLoad.Add("SAMAccountName")
        searcher.PropertiesToLoad.Add("co")
        searcher.Filter = "(&(SAMAccountName=" & UserID & ")(objectCategory=user))"
 
        'Looking for the countryname of the user
        Dim results As System.DirectoryServices.SearchResultCollection
        Try
            results = searcher.FindAll()
        Catch ex As Exception
 
        End Try
 
        Dim result As System.DirectoryServices.SearchResult
        Dim country As String = ""
        For Each result In results
            country = Trim(CStr(result.Properties("co")(0)))
        Next
 
        textbox_test.test()
 
        MsgBox(country)
 
        'Looking for the IdCountry
        country = "'" & country & "'"
        Dim strCountryQuery As String = "SELECT * FROM COUNTRY WHERE CountryName=" & country
        ' MsgBox(strCountryQuery)
        Dim cmdFetchCountry As SqlCommand = New SqlCommand(strCountryQuery, sqlConn)
        Dim dtrCountry As SqlDataReader
        Dim IdCountry As String = ""
        sqlConn.Open()
        dtrCountry = cmdFetchCountry.ExecuteReader
        While dtrCountry.Read()
            Dim strCountryName As String = dtrCountry("CountryName").ToString
            Dim strCountryId As String = dtrCountry("IdCountry").ToString
            IdCountry = strCountryId
        End While
        sqlConn.Close()
 
 
        'Looking for IDCountry with Country of the user 
 
        Dim strBuildingQuery As String = "SELECT * FROM BUILDING WHERE IdCountry=" & IdCountry
 
        Dim cmdFetchBuilding As SqlCommand = New SqlCommand(strBuildingQuery, sqlConn)
 
        Dim dtrBuilding As SqlDataReader
        Dim kvBuilding As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
        sqlConn.Open()
        Dim myBuilding As New List(Of CascadingDropDownNameValue)
        dtrBuilding = cmdFetchBuilding.ExecuteReader
 
        While dtrBuilding.Read()
            Dim strBuildingName As String = dtrBuilding("BuildingName").ToString
            Dim strBuildingId As String = dtrBuilding("IdBuilding").ToString
 
            myBuilding.Add(New CascadingDropDownNameValue(strBuildingName, strBuildingId))
        End While
 
        Return myBuilding.ToArray
    End Function
 
 
    <WebMethod()> _
    Public Function GetMaterial(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("IT_Rent_connection").ConnectionString
        Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
        Dim strTeamQuery As String = "SELECT DISTINCT HardWareType.IdType,  HardWareType.HardwareName from country, building,	material,	HardWareType where	building.IdBuilding = @confid	and	country.IdCountry = building.IdCountry	and	building.IdBuilding = material.IdBuilding	and 	material.IdType = HardWareType.IdType"
 
        Dim cmdFetchTeam As SqlCommand = New SqlCommand(strTeamQuery, sqlConn)
 
        Dim dtrTeam As SqlDataReader
        Dim kvTeam As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
        'MsgBox(knownCategoryValues)
        Dim intConfId As Integer
 
        If Not kvTeam.ContainsKey("IdBuilding") Or Not Int32.TryParse(kvTeam("IdBuilding"), intConfId) Then
 
            Return Nothing
        End If
 
        cmdFetchTeam.Parameters.AddWithValue("@confid", intConfId)
        Dim myTeams As New List(Of CascadingDropDownNameValue)
 
        sqlConn.Open()
        dtrTeam = cmdFetchTeam.ExecuteReader
 
        While dtrTeam.Read()
            Dim strTeamName As String = dtrTeam("HardwareName").ToString
            Dim strTeamId As String = dtrTeam("IdType").ToString
 
            myTeams.Add(New CascadingDropDownNameValue(strTeamName, strTeamId))
        End While
 
        Return myTeams.ToArray
 
 
 
 
 
    End Function
 
End Class | 
Partager