Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Ultra File - frmAdd.vb

frmAdd.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports Ultra_file.Form1
  2. Public Class frmAdd
  3.     Public MyMode As String
  4.     Public Data() As String
  5.     Public Sub New(Optional ByVal Obj As Object = Nothing)
  6.         Me.InitializeComponent()
  7.         Dim y As UInt16 = 16
  8.         Dim x As UInt16 = 0
  9.         Dim Counter As UInt16 = 0
  10.         Dim L As Label
  11.         Dim T As TextBox
  12.         Dim C As ComboBox
  13.  
  14.         For Each S() As String In FieldTable
  15.             L = New Label
  16.             L.Text = S(0) + ":"
  17.             L.Location = New Point(16, y)
  18.             x = L.Width + 16
  19.             If S.Length > 1 Then
  20.                 C = New ComboBox
  21.                 C.Name = "field" & Counter
  22.                 C.Location = New Point(x, y - 2)
  23.                 C.Width = 336 - L.Width
  24.                 For i As UInt16 = 1 To UBound(S)
  25.                     C.Items.Add(S(i))
  26.                 Next
  27.                 Me.Controls.Add(C)
  28.             Else
  29.                 T = New TextBox
  30.                 T.Name = "field" & Counter
  31.                 T.Location = New Point(x, y - 2)
  32.                 T.Width = 336 - L.Width
  33.                 Me.Controls.Add(T)
  34.             End If
  35.             Counter += 1
  36.             y += 32
  37.             Me.Controls.Add(L)
  38.         Next
  39.  
  40.         Me.Height = y + 80
  41.  
  42.         If Not TypeOf Obj Is String() Then
  43.             MyMode = "ADD"
  44.         Else
  45.             MyMode = "MOD"
  46.             Data = Obj
  47.         End If
  48.     End Sub
  49.     Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
  50.         Dim Obj(FieldNumber) As String
  51.         Dim Index As UInt16 = 0
  52.  
  53.         For Each C As Control In Me.Controls
  54.             'Se è un pulsante o una label, salta
  55.             If TypeOf C Is Button Or TypeOf C Is Label Then
  56.                 Continue For
  57.             End If
  58.  
  59.             Index = C.Name.Remove(0, C.Name.Length - 1)
  60.             If TypeOf C Is TextBox Then
  61.                 Obj(Index) = C.Text
  62.             Else
  63.                 Dim Cb As ComboBox = C
  64.                 Obj(Index) = Cb.SelectedItem
  65.             End If
  66.         Next
  67.  
  68.         If MyMode = "ADD" Then
  69.             AddObject(Obj(0), Obj)
  70.         Else
  71.             ModObject(Obj(0), Obj)
  72.         End If
  73.         Me.Close()
  74.     End Sub
  75.     Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  76.         If MyMode = "ADD" Then
  77.             Me.Text = "Ultra File - Aggiungi"
  78.         Else
  79.             Me.Text = "Ultra File - Modifica"
  80.             Dim Index As UInt16 = 0
  81.  
  82.             For Each C As Control In Me.Controls
  83.                 'Se è un pulsante o una label, salta
  84.                 If TypeOf C Is Button Or TypeOf C Is Label Then
  85.                     Continue For
  86.                 End If
  87.  
  88.                 Index = C.Name.Remove(0, C.Name.Length - 1)
  89.                 If TypeOf C Is TextBox Then
  90.                     C.Text = Data(Index)
  91.                 Else
  92.                     Dim Cb As ComboBox = C
  93.                     Cb.SelectedItem = Data(Index)
  94.                 End If
  95.             Next
  96.         End If
  97.     End Sub
  98. End Class