-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNuForm.vb
More file actions
138 lines (132 loc) · 4.69 KB
/
NuForm.vb
File metadata and controls
138 lines (132 loc) · 4.69 KB
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
Imports System.Windows.Forms
Imports System.Drawing
Public Class NuForm
Public action As String = "VIEW"
Public crud As NuCRUD
Public mPanel As New TableLayoutPanel()
Public dataPanel As New TableLayoutPanel()
Private Sub NuForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AutoSize = True
Select Case action
Case "VIEW"
Me.Text = crud.table.title
Case "ADD"
Me.Text = "Tambah " & crud.table.title
Case "EDIT"
Me.Text = "Edit " & crud.table.title
End Select
addTable()
End Sub
Public Overloads Function ShowDialog(Optional act As String = "VIEW", Optional ByRef nuCrud As NuCRUD = Nothing) As DialogResult
action = act
crud = nuCrud
Return MyBase.ShowDialog()
End Function
Private Sub addTable()
mPanel.AutoSize = True
mPanel.Dock = DockStyle.Fill
mPanel.Controls.Clear()
mPanel.ColumnStyles.Clear()
mPanel.RowStyles.Clear()
mPanel.ColumnCount = 1
mPanel.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100))
mPanel.RowCount = 2
mPanel.RowStyles.Add(New System.Windows.Forms.RowStyle(SizeType.Percent, 100))
mPanel.RowStyles.Add(New System.Windows.Forms.RowStyle(SizeType.Absolute, 60))
mPanel.BackColor = Color.Transparent
' mainPanel.RowStyles.Add(New System.Windows.Forms.RowStyle(SizeType.Absolute, 30))
'mainPanel.BackColor = Color.Aqua
mPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble
Me.Controls.Add(mPanel)
addData()
End Sub
Private Sub addData()
dataPanel.AutoSize = True
dataPanel.Dock = DockStyle.Fill
dataPanel.Controls.Clear()
dataPanel.ColumnStyles.Clear()
dataPanel.RowStyles.Clear()
dataPanel.ColumnCount = 3
dataPanel.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30))
dataPanel.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 70))
Dim fields = getFields()
For Each nf As NuField In fields
dataPanel.RowStyles.Add(New RowStyle(SizeType.AutoSize))
dataPanel.RowCount += 1
Dim lbl As New Label()
lbl.Text = If(nf.title Is Nothing, nf.name, nf.title)
lbl.Dock = DockStyle.Fill
dataPanel.Controls.Add(lbl, 0, dataPanel.RowCount - 1)
addControl(nf)
Next
mPanel.Controls.Add(dataPanel)
End Sub
Private Sub addControl(nf As NuField)
Dim txt
Select Case nf.type
Case "date"
txt = addDate(nf)
Case "options"
txt = addOptions(nf)
Case "textarea"
txt = addTextArea(nf)
Case Else
txt = addText(nf)
End Select
dataPanel.Controls.Add(txt, 1, dataPanel.RowCount - 1)
End Sub
Private Function addDate(nf As NuField)
Dim txt As New DateTimePicker()
txt.Name = nf.name
txt.Dock = DockStyle.Fill
Return txt
End Function
Private Function addOptions(nf As NuField)
Dim txt As New ComboBox()
txt.DataSource = nf.options
txt.DisplayMember = "Value"
txt.ValueMember = "Key"
txt.Dock = DockStyle.Fill
Return txt
End Function
Private Function addText(nf)
Dim txt As New TextBox()
txt.Name = nf.name
txt.Text = ""
txt.Dock = DockStyle.Fill
Return txt
End Function
Private Function addTextArea(nf)
Dim txt As New TextBox()
txt.Name = nf.name
txt.Text = ""
txt.Multiline = True
txt.Height = txt.Height * 2
txt.Dock = DockStyle.Fill
Return txt
End Function
Private Function getFields() As List(Of NuField)
Dim dbfields As New List(Of NuField)
Select Case action
Case "VIEW"
For Each nf As NuField In crud.table.fields
If nf.read Then
dbfields.Add(nf)
End If
Next
Case "ADD"
For Each nf As NuField In crud.table.fields
If nf.create Then
dbfields.Add(nf)
End If
Next
Case "EDIT"
For Each nf As NuField In crud.table.fields
If nf.update Then
dbfields.Add(nf)
End If
Next
End Select
Return dbfields
End Function
End Class