Imports Ultra_file.Form1
Public Class frmAdd
Public MyMode As String
Public Data() As String
Public Sub New(Optional ByVal Obj As Object = Nothing)
Me.InitializeComponent()
Dim y As UInt16 = 16
Dim x As UInt16 = 0
Dim Counter As UInt16 = 0
Dim L As Label
Dim T As TextBox
Dim C As ComboBox
For Each S() As String In FieldTable
L = New Label
L.Text = S(0) + ":"
L.Location = New Point(16, y)
x = L.Width + 16
If S.Length > 1 Then
C = New ComboBox
C.Name = "field" & Counter
C.Location = New Point(x, y - 2)
C.Width = 336 - L.Width
For i As UInt16 = 1 To UBound(S)
C.Items.Add(S(i))
Next
Me.Controls.Add(C)
Else
T = New TextBox
T.Name = "field" & Counter
T.Location = New Point(x, y - 2)
T.Width = 336 - L.Width
Me.Controls.Add(T)
End If
Counter += 1
y += 32
Me.Controls.Add(L)
Next
Me.Height = y + 80
If Not TypeOf Obj Is String() Then
MyMode = "ADD"
Else
MyMode = "MOD"
Data = Obj
End If
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Dim Obj(FieldNumber) As String
Dim Index As UInt16 = 0
For Each C As Control In Me.Controls
'Se è un pulsante o una label, salta
If TypeOf C Is Button Or TypeOf C Is Label Then
Continue For
End If
Index = C.Name.Remove(0, C.Name.Length - 1)
If TypeOf C Is TextBox Then
Obj(Index) = C.Text
Else
Dim Cb As ComboBox = C
Obj(Index) = Cb.SelectedItem
End If
Next
If MyMode = "ADD" Then
AddObject(Obj(0), Obj)
Else
ModObject(Obj(0), Obj)
End If
Me.Close()
End Sub
Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If MyMode = "ADD" Then
Me.Text = "Ultra File - Aggiungi"
Else
Me.Text = "Ultra File - Modifica"
Dim Index As UInt16 = 0
For Each C As Control In Me.Controls
'Se è un pulsante o una label, salta
If TypeOf C Is Button Or TypeOf C Is Label Then
Continue For
End If
Index = C.Name.Remove(0, C.Name.Length - 1)
If TypeOf C Is TextBox Then
C.Text = Data(Index)
Else
Dim Cb As ComboBox = C
Cb.SelectedItem = Data(Index)
End If
Next
End If
End Sub
End Class