Imports System.Web.Services

Imports System.Data.OleDb

Imports System.IO

 

 

<WebService(Namespace:="http://tempuri.org/")> _

Public Class SendReceiveData

    Inherits System.Web.Services.WebService

 

#Region " Web Services Designer Generated Code "

 

    Public Sub New()

        MyBase.New()

 

        'This call is required by the Web Services Designer.

        InitializeComponent()

 

        'Add your own initialization code after the InitializeComponent() call

 

    End Sub

 

    'Required by the Web Services Designer

    Private components As System.ComponentModel.IContainer

 

    'NOTE: The following procedure is required by the Web Services Designer

    'It can be modified using the Web Services Designer. 

    'Do not modify it using the code editor.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        components = New System.ComponentModel.Container()

    End Sub

 

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

        'CODEGEN: This procedure is required by the Web Services Designer

        'Do not modify it using the code editor.

        If disposing Then

            If Not (components Is Nothing) Then

                components.Dispose()

            End If

        End If

        MyBase.Dispose(disposing)

    End Sub

 

#End Region

 

    <WebMethod()> Public Function DownLoadBinary(ByVal PathToFile As String, ByVal PassWord As String) As Byte()

        'This Web Service Returns A Binary Object In An Array, b.

 

        'If you don't know the password, then send back NOTHING!!!

        If PassWord <> "DaisyBean" Then

            Dim BadPassWord() As Byte

            Return BadPassWord

        End If

        '*********************************************************

 

        Try

            Dim fs As New System.IO.FileStream(PathToFile, IO.FileMode.Open, IO.FileAccess.Read)

            Dim b(fs.Length() - 1) As Byte

            fs.Read(b, 0, b.Length)

            fs.Close()

            Return b

        Catch

            Dim b() As Byte

            Return b

        End Try

 

        'USAGE...Found in c:\inetpub\wwwroot\SendReceiveDataVBClient.vbproj....

        'Dim objPassBinary As New localhost.SendReceiveData()

        'Dim b() As Byte

        'b = objPassBinary.DownLoadBinary("c:\Inetpub\wwwroot\PassBinary\Blob.doc")

        'Dim fs2 As New System.IO.FileStream("c:\Blob.Doc", IO.FileMode.Create, IO.FileAccess.Write)

        'fs2.Write(b, 0, b.Length)

        'fs2.Close()

        'MsgBox("C:\Blob.Doc Was Downloaded")

    End Function

 

    <WebMethod()> Public Function UpLoadBinary(ByVal PathToSaveFileOnServer As String, ByVal b() As Byte, ByVal PassWord As String) As Boolean

        'This code will take a binary array  and save it to another binary file on the Server's C: Drive.

 

        'If you don't know the password, then send back NOTHING!!!

        If PassWord <> "DaisyBean" Then

            Return False

        End If

        '*********************************************************

 

 

        MakeFolder(PathToSaveFileOnServer)

 

        Dim fs2 As New System.IO.FileStream(PathToSaveFileOnServer, IO.FileMode.Create, IO.FileAccess.Write)

        fs2.Write(b, 0, b.Length)

        fs2.Close()

        Return True

 

        'USAGE...Found in c:\inetpub\wwwroot\SendReceiveDAtaVBClient.vbproj....

        '    Dim objPassBinary As New localhost.SendReceiveData()

        '    Dim FileToUpload As String

        '    FileToUpload = "C:\blob.doc" 'File on client pc to upload

        '    Dim UploadedFileNameOnServer As String

        '    UploadedFileNameOnServer = "C:\NewBlob.doc" 'after we upload the file, save it as this path & name

 

        'Read the file into an array - b

        ' Dim fs As New System.IO.FileStream(FileToUpload, IO.FileMode.Open, IO.FileAccess.Read)

        ' Dim b(fs.Length() - 1) As Byte

        ' fs.Read(b, 0, b.Length)

        ' fs.Close()

        'Pass the upload function the binary array of the file, b, and what you want to call it on the server...

        ' objPassBinary.UpLoadBinary(UploadedFileNameOnServer, b)

        'MsgBox(FileToUpload & " was saved On server Pc as " & UploadedFileNameOnServer)

        '************************************************************************************

    End Function

 

    <WebMethod()> Public Function GetDataSet(ByVal strPathToMDB As String, ByVal strSQL As String, ByVal strDSTableName As String) As DataSet

        Dim objConn As New OleDbConnection()

        objConn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathToMDB)

        objConn.Open()

        Dim objDA As New OleDbDataAdapter(strSQL, objConn)

 

        Dim dataset As New DataSet()

        objDA.Fill(dataset, strDSTableName)

        Return dataset

 

        ' USAGE...Found in c:\inetpub\wwwroot\SendReceiveDataClientVB....

        'Dim objSendReceiveData As New com.LocalHost.SendReceiveData()

        'Dim ds As DataSet

        'ds = objSendReceiveData.GetDataSet("c:\inetpub\wwwroot\cp\cp.mdb", "Select * From Candidate", "Candidate")

        'MsgBox(ds.Tables("candidate").Rows(0).Item("Lname"))

 

    End Function

 

    <WebMethod()> Public Function UpDateFields(ByVal strPathToMDB As String, ByVal strSQLStatement As String)

        Dim objConnection As New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathToMDB)

        Dim objcommand As New OleDbCommand()

        objcommand = New OleDbCommand(strSQLStatement, objConnection)

        objConnection.Open()

        objcommand.ExecuteNonQuery()

        objConnection.Close()

 

        ' USAGE...Found in c:\inetpub\wwwroot\SendReceiveDataClientVB...

        'Dim objSendReceiveData As New com.LocalHost.SendReceiveData()

        'objSendReceiveData.UpDateFields("c:\inetpub\wwwroot\cp\cp.mdb", "UPDATE DISTINCTROW Candidate SET Candidate.FNAME = 'BustaRhymes' WHERE ((Candidate.SSN='21625'));")

        'MsgBox("Table Updated")

 

    End Function

 

    <WebMethod()> Public Function AddRecord(ByVal strPathToMDB As String, ByVal strSQLStatement As String)

        Dim objConn As New OleDbConnection()

        Dim objCommand As New OleDbCommand()

        objConn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathToMDB)

        objCommand = New OleDbCommand(strSQLStatement, objConn)

        objConn.Open()

        objCommand.ExecuteNonQuery()

        objConn.Close()

 

        ' USAGE...Found in c:\inetpub\wwwroot\SendReceiveDataClientVB...

        'Dim v1 As String = "'" & txtSsn.Text & "'"

        'Dim v2 As String = "'" & txtFname.Text & "'"

        'Dim v3 As String = "'" & txtLname.Text & "'"

 

        'Windows/Web Form Fields...

        'Dim strValues As String = v1 & "," & v2 & "," & v3

        'Database Fields...

        'Dim strFields As String = "Ssn,Fname,Lname"

        'Dim vSQL As String

        'vSQL = "INSERT INTO Candidate (" & strFields & ") VALUES (" & strValues & ")"

        'objSendReceiveData.AddRecord("C:\inetpub\wwwroot\SendReceiveData\cp.mdb", vSQL)

        'MsgBox("Record Added!")

 

    End Function

 

    <WebMethod()> Public Function WSGetFiles(ByVal strPath As String) As String()

        'Returns a list of files on the server

        Return Directory.GetFiles(strPath)

    End Function

 

    <WebMethod()> Public Function WSGetDirectories(ByVal strPath As String) As String()

        'Returns a list of directories on the server

        Return Directory.GetDirectories(strPath)

    End Function

 

 

    <WebMethod()> Public Function Login(ByVal vLogin As String, ByVal vPassWord As String) As String

        'Returns a string with True or False (login passed or Failed), LoginInfoString

        Dim objDs As New DataSet()

        Dim objDaTable1 As New OleDb.OleDbDataAdapter()

        Dim objConn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Login.mdb"))

        Dim objCommand As New OleDb.OleDbCommand()

        objCommand = New OleDbCommand("Select * From Login Where Login ='" & vLogin & "'", objConn)

        objDaTable1.SelectCommand = objCommand

        objDaTable1.Fill(objDs, "Login")

 

        If objDs.Tables("Login").Rows.Count = 0 Then

            'Login Not Found

            Return "False,Login Not Found"

            Exit Function

        End If

 

        If UCase(vPassWord.Trim) <> UCase(objDs.Tables("Login").Rows(0).Item("Password")) Then

            'PassWord Incorrect

            Return "False,PassWord Incorrect"

            Exit Function

        Else

            Return "True," & objDs.Tables("Login").Rows(0).Item("Info")

        End If

    End Function

 

 

    Sub MakeFolder(ByVal PathToFile As String)

        Dim aPath() As String

        aPath = Split(PathToFile, "\")

        Dim i As Integer

        i = UBound(aPath)

        Dim c As Integer

        Dim MPath As String

        Dim Slash As String

        For c = 0 To i - 1

            If c <> i - 1 Then

                Slash = "\"

            Else

                Slash = ""

            End If

            MPath = MPath & aPath(c) & Slash

        Next

 

        Try

            MkDir(MPath)

        Catch

            'do nothing, the folder already exists...

        End Try

    End Sub

 

End Class