Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Imports Microsoft.Win32
Imports System.IO
Imports LFSO83Lib
Imports System.Configuration


Public Class NewConfig
    Private Sub NewConfig_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim keypath As String = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
        Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey(keypath, True)

        'Dim keypath As String = ConfigurationManager.AppSettings("RegistryKeyPath")
        'Dim regKey As RegistryKey = ReadRegistry()
        Dim sSource As String

        Try
            For Each sSource In regKey.GetValueNames
                BoxODBCSource.Items.Add(sSource)
                BoxLFDSN.Items.Add(sSource)
            Next sSource
        Catch ex As Exception
        End Try



        Dim app As LFApplication = New LFApplication
        Dim dbs As ILFCollection
        Dim db As LFDatabase


        Try
            dbs = app.GetAllDatabases(True)
            For i As Integer = 1 To dbs.Count()
                db = dbs.Item(i)
                BoxLFServer.Items.Add(db.Server.Name())
            Next
        Catch ex As Exception
        End Try
    End Sub

    Private Sub ButtonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
        SaveConfig.ShowDialog()
    End Sub
    'ODBC Subs
    Private Sub ODBCValidate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ODBCValidate.Click
        Dim conn As Odbc.OdbcConnection
        Dim sConnString As String = _
                  "DSN=" & BoxODBCSource.Text & ";uid=" & BoxODBCUser.Text & ";pwd=" & BoxODBCPass.Text & ";dbq=tmax"
        conn = New Odbc.OdbcConnection(sConnString)
        conn.Open()


        Dim Tables As DataTable = conn.GetSchema("tables")

        BoxTableSource.Items.Clear()
        BoxTableSource.Text = ""
        For i As Integer = 0 To Tables.Rows.Count - 1
            BoxTableSource.Items.Add(Tables.Rows.Item(i).Item(2))
        Next

        conn.Close()
    End Sub

    Private Sub BoxTableSource_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BoxTableSource.SelectedValueChanged
        Dim conn As Odbc.OdbcConnection
        Dim sConnString As String = _
                  "DSN=" & BoxODBCSource.Text & ";uid=" & BoxODBCUser.Text & ";pwd=" & BoxODBCPass.Text & ";dbq=tmax"
        conn = New Odbc.OdbcConnection(sConnString)
        conn.Open()

        Dim cmd As New Odbc.OdbcCommand("SELECT * FROM " & BoxTableSource.Text, conn)
        Dim dr As Odbc.OdbcDataReader

        dr = cmd.ExecuteReader

        BoxColumnSource.Items.Clear()
        BoxColumnSource.Text = ""
        For i As Integer = 0 To dr.FieldCount - 1
            BoxColumnSource.Items.Add(dr.GetName(i))
        Next

        conn.Close()
    End Sub

    'Laserfiche Subs
    Private Sub BoxLFServer_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BoxLFServer.SelectedValueChanged
        Dim app As LFApplication = New LFApplication
        Dim dbs As ILFCollection
        Dim server As LFServer = app.GetServerByName(BoxLFServer.Text)
        Dim rep As LFDatabase

        Try
            dbs = server.GetAllDatabases()
            For i As Integer = 1 To dbs.Count()
                rep = dbs.Item(i)
                BoxLFRep.Items.Add(rep.Name())
            Next
        Catch ex As Exception
        End Try

    End Sub

    Private Sub ButtonValidate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonValidate.Click
        Dim app As LFApplication = New LFApplication
        Dim serv As LFServer = app.GetServerByName(BoxLFServer.Text)
        Dim db As LFDatabase = serv.GetDatabaseByName(BoxLFRep.SelectedItem)
        Dim conn As New LFConnection
        conn.UserName = BoxUser.Text
        conn.Password = BoxPass.Text




        Try
            conn.Create(db)
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

        Dim AllTemps As ILFCollection = db.GetAllTemplates()

        BoxTemplate.Items.Clear()
        BoxTemplate.Text = ""
        For i As Integer = 1 To AllTemps.Count
            Dim Template As LFTemplate = AllTemps.Item(i)
            BoxTemplate.Items.Add(Template.Name)
        Next

        conn.Terminate()
    End Sub

    Private Sub BoxTemplate_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BoxTemplate.SelectedValueChanged
        Dim app As LFApplication = New LFApplication
        Dim serv As LFServer = app.GetServerByName(BoxLFServer.Text)
        Dim db As LFDatabase = serv.GetDatabaseByName(BoxLFRep.SelectedItem)
        Dim conn As New LFConnection
        conn.UserName = BoxUser.Text
        conn.Password = BoxPass.Text

        Try
            conn.Create(db)
        Catch ex As Exception
        End Try

        Dim Template As LFTemplate = db.GetTemplateByName(BoxTemplate.Text)

        BoxField.Items.Clear()
        BoxField.Text = ""

        Try
            For i As Integer = 1 To Template.Count()
                Dim Field As LFTemplateField = Template.Item(i)
                BoxField.Items.Add(Field.Name)
            Next
        Catch ex As Exception
        End Try


        conn.Terminate()
    End Sub

    Private Sub SaveConfig_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveConfig.FileOk

        Dim oWrite As StreamWriter
        oWrite = File.CreateText(SaveConfig.FileName)

        oWrite.WriteLine("<ODBC>")
        oWrite.WriteLine("DSN: " & BoxODBCSource.Text & ";")
        oWrite.WriteLine("User: " & BoxODBCUser.Text & ";")
        oWrite.WriteLine("Pass: " & BoxODBCPass.Text & ";")
        oWrite.WriteLine("Table: " & BoxTableSource.Text & ";")
        oWrite.WriteLine("Column: " & BoxColumnSource.Text & ";")
        oWrite.WriteLine("</ODBC>")
        oWrite.WriteLine()
        oWrite.WriteLine("<Laserfiche>")
        oWrite.WriteLine("Server: " & BoxLFServer.Text & ";")
        oWrite.WriteLine("Repository: " & BoxLFRep.Text & ";")
        oWrite.WriteLine("User: " & BoxUser.Text & ";")
        oWrite.WriteLine("Pass: " & BoxPass.Text & ";")
        oWrite.WriteLine("Template: " & BoxTemplate.Text & ";")
        oWrite.WriteLine("Field: " & BoxField.Text & ";")
        oWrite.WriteLine("DSN: " & BoxLFDSN.Text & ";")
        oWrite.WriteLine("DSN User: " & BoxLFDSNUser.Text & ";")
        oWrite.WriteLine("DSN Pass: " & BoxLFDSNPass.Text & ";")
        oWrite.Write("</Laserfiche>")

        oWrite.Close()
        Me.Close()
    End Sub

    'Private Function ReadRegistry() As RegistryKey

    '    'Dim localKey32 As RegistryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32)
    '    'localKey32 = localKey32.OpenSubKey(ConfigurationManager.AppSettings("RegistryKeyPath"), True)
    '    'If (localKey32 IsNot Nothing) Then
    '    '    If (localKey32.GetValueNames IsNot Nothing And localKey32.GetValueNames.Length > 0) Then
    '    '        MessageBox.Show("32 bit key values exist")
    '    '        Return localKey32
    '    '    End If
    '    'End If

    '    Dim localKey As RegistryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
    '    localKey = localKey.OpenSubKey(ConfigurationManager.AppSettings("RegistryKeyPath"), True)
    '    If (localKey IsNot Nothing) Then
    '        MessageBox.Show("64 bit key values exist")
    '        Return localKey
    '    End If

    '    Return Nothing
    'End Function

End Class

Commits for ChrisCompleteCodeTrunk/ATC LaserficheFieldUpdater/LaserficheFieldUpdater/NewConfig.vb

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000