-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form_WorkFlow.vb
294 lines (175 loc) · 8.4 KB
/
Form_WorkFlow.vb
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
Imports System.ComponentModel
Imports System.IO
Public Class Form_WorkFlow
Public Variables As List(Of Object)
Private Sub Add_Event_Click(sender As Object, e As EventArgs) Handles Add_Event.Click
Dim tmpStep = NewEvent()
FLP_Events.Controls.Add(tmpStep)
tmpStep.DG_Variables.ClearSelection()
SetupAnchors()
SetPrevious(tmpStep)
End Sub
Private Function NewEvent() As UC_WorkFlowEvent
Dim list = New List(Of EventVariable)
For Each tmpVar In Variables
If Not (tmpVar.IsReadOnly Or tmpVar.Formula <> "") Then
Dim tmpVariable As New EventVariable
tmpVariable.Check = True
tmpVariable.Name = tmpVar.DisplayName
tmpVariable.Value = Math.Round(UC_Slider.CadToValue(tmpVar.value, tmpVar.UnitsType), 2)
tmpVariable.objVar = tmpVar
list.Add(tmpVariable)
End If
Next
Dim bindingList = New BindingList(Of EventVariable)(list)
Dim source = New BindingSource(bindingList, Nothing)
Dim tmpStep As New UC_WorkFlowEvent
tmpStep.DG_Variables.Columns.Clear()
tmpStep.DG_Variables.AutoGenerateColumns = True
tmpStep.DG_Variables.DataSource = source
tmpStep.LB_SEQ.Text = FLP_Events.Controls.Count + 1
tmpStep.Height = 22 + tmpStep.DG_Variables.RowTemplate.Height * tmpStep.DG_Variables.Rows.Count
tmpStep.DG_Variables.Columns.Item("check").Visible = False
tmpStep.DG_Variables.Columns.Item("objVar").Visible = False
tmpStep.DG_Variables.Columns.Item("Value").Width = 80
tmpStep.DG_Variables.Columns.Item("Value").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
tmpStep.DG_Variables.Columns.Item("Value").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
tmpStep.DG_Variables.Columns.Item("Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
tmpStep.DG_Variables.Columns.Item("Name").ReadOnly = True
Return tmpStep
End Function
Private Sub SetPrevious(StepEvent As UC_WorkFlowEvent)
If FLP_Events.Controls.Count > 1 Then
Dim PreviousStep As UC_WorkFlowEvent = FLP_Events.Controls.Item(FLP_Events.Controls.Count - 2)
For Each tmpRow As DataGridViewRow In PreviousStep.DG_Variables.Rows
StepEvent.DG_Variables.Rows.Item(tmpRow.Index).Cells("Value").Value = tmpRow.Cells("Value").Value
Next
End If
End Sub
Private Sub SetupAnchors()
FLP_Events.SuspendLayout()
If FLP_Events.Controls.Count > 0 Then
For i = 0 To FLP_Events.Controls.Count - 1
Dim c As Control = FLP_Events.Controls(i)
If i = 0 Then
' Its the first control, all subsequent controls follow
' the anchor behavior of this control.
c.Width = FLP_Events.Width - 6
c.Anchor = AnchorStyles.Left + AnchorStyles.Top
If FLP_Events.VerticalScroll.Visible Then c.Width += -SystemInformation.VerticalScrollBarWidth + 0
Else
' It is not the first control. Set its anchor to
' copy the width of the first control in the list.
c.Anchor = AnchorStyles.Left + AnchorStyles.Right
End If
Next
End If
FLP_Events.ResumeLayout()
End Sub
Private Sub Form_WorkFlow_Resize(sender As Object, e As EventArgs) Handles Me.Resize
SetupAnchors()
End Sub
Private Sub BT_Play_Click(sender As Object, e As EventArgs) Handles BT_Play.Click
If FLP_Events.Controls.Count > 0 Then
For Each StepEvent As UC_WorkFlowEvent In FLP_Events.Controls
StepEvent.LB_SEQ.ForeColor = Color.DarkGreen
SetSteps(StepEvent)
For i = 1 To 20
Form_VarHandler.objDoc.Parent.DelayCompute = True
For Each tmpRow As DataGridViewRow In StepEvent.DG_Variables.Rows
Dim tmpVariable As Object = tmpRow.Cells("objVar").Value
tmpVariable.Value += UC_Slider.ValueToCad(tmpRow.Tag, tmpVariable.UnitsType)
Next
Form_VarHandler.objDoc.Parent.DelayCompute = False
Form_VarHandler.objDoc.Parent.DoIdle()
Next
StepEvent.LB_SEQ.ForeColor = Color.DarkGray
Next
End If
End Sub
Private Sub SetSteps(stepEvent As UC_WorkFlowEvent)
For Each tmpRow As DataGridViewRow In stepEvent.DG_Variables.Rows
Dim tmpVariable As Object = tmpRow.Cells("objVar").Value
Dim stepValue As Double = (CDbl(tmpRow.Cells("Value").Value) - UC_Slider.CadToValue(tmpVariable.Value, tmpVariable.UnitsType)) / 20
tmpRow.Tag = stepValue
Next
End Sub
Private Sub BT_Save_Click(sender As Object, e As EventArgs) Handles BT_Save.Click
If FLP_Events.Controls.Count > 0 Then
Dim tmpRighe As String = ""
For Each StepEvent As UC_WorkFlowEvent In FLP_Events.Controls
Dim tmpRiga As String = ""
For Each tmpRow As DataGridViewRow In StepEvent.DG_Variables.Rows
Dim tmpNome As String = tmpRow.Cells("Name").Value
Dim tmpValue As String = tmpRow.Cells("Value").Value
tmpRiga += (tmpNome & ":" & tmpValue & "|")
Next
tmpRiga = tmpRiga.Substring(0, tmpRiga.Length - 1)
tmpRighe += tmpRiga & vbCrLf
Next
tmpRighe = tmpRighe.TrimEnd
Dim tmpFileDialog As New SaveFileDialog
tmpFileDialog.Filter = "Text File|*.txt"
tmpFileDialog.Title = "Save a Text File"
tmpFileDialog.ShowDialog()
If tmpFileDialog.FileName <> "" Then
Dim sw As StreamWriter
sw = My.Computer.FileSystem.OpenTextFileWriter(tmpFileDialog.FileName, False)
sw.Write(tmpRighe)
sw.Close()
End If
End If
End Sub
Private Sub BT_Open_Click(sender As Object, e As EventArgs) Handles BT_Open.Click
Dim tmpFileDialog As New OpenFileDialog
tmpFileDialog.Filter = "Text File|*.txt"
tmpFileDialog.Title = "Save a Text File"
tmpFileDialog.ShowDialog()
If tmpFileDialog.FileName <> "" Then
Dim prg = My.Computer.FileSystem.ReadAllText(tmpFileDialog.FileName)
Dim righe = prg.Replace(vbCrLf, vbCr).Split(vbCrLf)
FLP_Events.SuspendLayout()
For i = 0 To righe.Count - 1
Dim tmpStep = NewEvent()
FLP_Events.Controls.Add(tmpStep)
tmpStep.DG_Variables.ClearSelection()
SetValues(tmpStep, righe(i))
Next
FLP_Events.ResumeLayout()
SetupAnchors()
End If
End Sub
Private Sub SetValues(tmpStep As UC_WorkFlowEvent, riga As String)
Dim variabili = Split(riga, "|")
For Each item In variabili
Dim valori = item.Split(":")
For Each tmpRow As DataGridViewRow In tmpStep.DG_Variables.Rows
If tmpRow.Cells.Item("Name").Value = valori(0) Then tmpRow.Cells.Item("Value").Value = valori(1)
Next
Next
End Sub
Private Sub BT_Close_Click(sender As Object, e As EventArgs) Handles BT_Close.Click
FLP_Events.Controls.Clear()
End Sub
Private Sub Form_WorkFlow_Load(sender As Object, e As EventArgs) Handles Me.Load
'################# Questo risolver il problema del bordo sgrazinato della ToolStrip
ToolStrip1.Renderer = New MySR()
'################# rif: https://stackoverflow.com/questions/1918247/how-to-disable-the-line-under-tool-strip-in-winform-c
End Sub
Friend Sub ReNumber()
FLP_Events.SuspendLayout()
Dim i = 1
For Each item As UC_WorkFlowEvent In FLP_Events.Controls
item.LB_SEQ.Text = i.ToString
i += 1
Next
SetupAnchors()
FLP_Events.ResumeLayout()
End Sub
End Class
Public Class EventVariable
Public Property Check As Boolean = True
Public Property Name As String = ""
Public Property Value As Double = 0
Public Property objVar As Object
End Class