-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormConfig.vb
More file actions
844 lines (712 loc) · 34.9 KB
/
Copy pathFormConfig.vb
File metadata and controls
844 lines (712 loc) · 34.9 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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
''' <summary>
''' FormConfig.vb - Finestra di Configurazione
''' Permette di personalizzare ogni gauge: stile, colori, soglie, layout.
''' Separata dalla dashboard per uso amministrativo.
''' </summary>
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
'Namespace QueueMonitor
''' <summary>
''' Form di configurazione dell'applicazione e dei gauge.
''' Permette di: gestire lo stile gauge per ogni coda, impostare soglie,
''' configurare l'auto-refresh, modificare il layout della dashboard.
''' </summary>
Public Class FormConfig
Inherits Form
' ─── Controlli UI ─────────────────────────────────────────
Private _splitMain As SplitContainer
Private _lstQueues As ListBox
Private _lblQueueListTitle As Label
Private _panelRight As Panel
Private _tabControl As TabControl
' Tab Gauge
Private _cmbStyle As ComboBox
Private _cmbColorScheme As ComboBox
Private _chkShowValue As CheckBox
Private _chkShowName As CheckBox
Private _chkShowLabels As CheckBox
Private _chkAnimate As CheckBox
Private _chkShowGrid As CheckBox
Private _nudArcWidth As NumericUpDown
Private _previewPanel As Panel
Private _previewGauge As GaugeControl
' Tab Soglie
Private _nudMaxWait As NumericUpDown
Private _nudWarnThreshold As NumericUpDown
Private _nudCritThreshold As NumericUpDown
' Tab Globale
Private _nudColumns As NumericUpDown
Private _nudAutoRefresh As NumericUpDown
Private _nudFontSize As NumericUpDown
Private _chkStatusBar As CheckBox
Private _chkDarkTheme As CheckBox
' Colori personalizzati
Private _btnColorNormal As Button
Private _btnColorWarning As Button
Private _btnColorCritical As Button
Private _cmbCustomColorLabel As Label
' Footer
Private _btnSave As Button
Private _btnCancel As Button
Private _btnResetDefaults As Button
Private _btnAddQueue As Button
Private _btnRemoveQueue As Button
' Stato interno
Private _selectedQueueId As String = ""
Private _isLoading As Boolean = False
' ─── Costruttore ─────────────────────────────────────────
Public Sub New()
InitializeComponent()
PopulateQueueList()
LoadGlobalSettings()
' Seleziona prima coda se disponibile
If _lstQueues.Items.Count > 0 Then
_lstQueues.SelectedIndex = 0
End If
End Sub
' ─── Inizializzazione UI ──────────────────────────────────
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.Text = "⚙ Configurazione — Queue Monitor Pro"
Me.Size = New Size(840, 660)
Me.MinimumSize = New Size(700, 560)
Me.BackColor = Color.FromArgb(28, 33, 48)
Me.ForeColor = Color.FromArgb(200, 215, 235)
Me.StartPosition = FormStartPosition.CenterScreen
Me.Font = New Font("Segoe UI", 9.5F)
' ── Header ──────────────────────────────────────────
Dim headerPanel = New Panel With {
.Dock = DockStyle.Top,
.Height = 52,
.BackColor = Color.FromArgb(38, 44, 62)
}
Dim lblHeader = New Label With {
.Text = "⚙ Configurazione Gauge e Sistema",
.Font = New Font("Segoe UI", 13, FontStyle.Bold),
.ForeColor = Color.FromArgb(100, 180, 255),
.Location = New Point(16, 14),
.AutoSize = True
}
headerPanel.Controls.Add(lblHeader)
' ── Split: Lista code | Pannello config ─────────────
_splitMain = New SplitContainer With {
.Dock = DockStyle.Fill,
.BackColor = Color.FromArgb(22, 27, 38)
}
' Pannello sinistro: lista code
BuildQueueListPanel()
' Pannello destro: tab configurazione
BuildConfigTabs()
' ── Footer ──────────────────────────────────────────
Dim footerPanel = New Panel With {
.Dock = DockStyle.Bottom,
.Height = 52,
.BackColor = Color.FromArgb(22, 27, 38),
.Padding = New Padding(12, 8, 12, 8)
}
_btnSave = CreateFooterButton("💾 Salva Configurazione", Color.FromArgb(30, 100, 60), True)
_btnCancel = CreateFooterButton("✕ Annulla", Color.FromArgb(70, 40, 40), False)
_btnResetDefaults = CreateFooterButton("↺ Ripristina Default", Color.FromArgb(50, 50, 70), False)
_btnAddQueue = CreateFooterButton("Crea Nuova Coda", Color.FromArgb(30, 100, 60), True)
_btnRemoveQueue = CreateFooterButton("Elimina Coda", Color.FromArgb(30, 100, 60), True)
_btnSave.Location = New Point(12, 10)
_btnCancel.Location = New Point(210, 10)
_btnResetDefaults.Location = New Point(370, 10)
_btnAddQueue.Location = New Point(550, 10)
_btnRemoveQueue.Location = New Point(700, 10)
AddHandler _btnSave.Click, AddressOf OnSaveClick
AddHandler _btnCancel.Click, Sub(s, e) Me.Close()
AddHandler _btnResetDefaults.Click, AddressOf OnResetClick
AddHandler _btnAddQueue.Click, AddressOf AddQueue
AddHandler _btnRemoveQueue.Click, AddressOf OnRemoveQueue
footerPanel.Controls.AddRange({_btnSave, _btnCancel, _btnResetDefaults, _btnAddQueue, _btnRemoveQueue})
Me.Controls.Add(_splitMain)
Me.Controls.Add(headerPanel)
Me.Controls.Add(footerPanel)
Me.ResumeLayout(False)
End Sub
Private Sub BuildQueueListPanel()
Dim panel = _splitMain.Panel1
panel.BackColor = Color.FromArgb(24, 29, 42)
_lblQueueListTitle = New Label With {
.Text = "CODE CONFIGURATE",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(100, 120, 160),
.Location = New Point(10, 12),
.AutoSize = True
}
_lstQueues = New ListBox With {
.Location = New Point(10, 35),
.Size = New Size(190, 500),
.BackColor = Color.FromArgb(30, 36, 52),
.ForeColor = Color.FromArgb(200, 215, 235),
.BorderStyle = BorderStyle.None,
.Font = New Font("Segoe UI", 9.5F),
.DrawMode = DrawMode.OwnerDrawFixed,
.ItemHeight = 48,
.SelectionMode = SelectionMode.One
}
_lstQueues.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
AddHandler _lstQueues.DrawItem, AddressOf OnDrawQueueItem
AddHandler _lstQueues.SelectedIndexChanged, AddressOf OnQueueSelected
panel.Controls.AddRange({_lblQueueListTitle, _lstQueues})
End Sub
''' <summary>Disegna un item della listbox con nome, stato e colore</summary>
Private Sub OnDrawQueueItem(sender As Object, e As DrawItemEventArgs)
If e.Index < 0 Then Return
Dim item = TryCast(_lstQueues.Items(e.Index), QueueListItem)
If item Is Nothing Then Return
Dim isSelected = (e.State And DrawItemState.Selected) <> 0
Dim bgColor = If(isSelected, Color.FromArgb(45, 60, 90), Color.FromArgb(30, 36, 52))
e.Graphics.FillRectangle(New SolidBrush(bgColor), e.Bounds)
' Pallino stato
Dim stateColor = GetStatusColor(item.Queue)
e.Graphics.FillEllipse(New SolidBrush(stateColor),
e.Bounds.X + 10, e.Bounds.Y + 17, 10, 10)
' Nome
Dim nameFont = New Font("Segoe UI", 9.5F, If(isSelected, FontStyle.Bold, FontStyle.Regular))
e.Graphics.DrawString(item.Queue.Name, nameFont, Brushes.White,
e.Bounds.X + 28, e.Bounds.Y + 10)
nameFont.Dispose()
' Stato
Dim statusText = $"{item.Queue.WaitTimeFormatted} — {item.Queue.Status}"
e.Graphics.DrawString(statusText, New Font("Segoe UI", 7.5F), New SolidBrush(stateColor),
e.Bounds.X + 28, e.Bounds.Y + 30)
' Separatore
e.Graphics.DrawLine(New Pen(Color.FromArgb(40, 50, 70)),
e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
End Sub
Private Function GetStatusColor(q As QueueModel) As Color
Select Case q.Status
Case QueueStatus.Normal : Return Color.FromArgb(0, 200, 81)
Case QueueStatus.Warning : Return Color.FromArgb(255, 165, 0)
Case QueueStatus.Critical : Return Color.FromArgb(220, 50, 50)
Case Else : Return Color.FromArgb(100, 100, 120)
End Select
End Function
Private Sub BuildConfigTabs()
Dim panel = _splitMain.Panel2
panel.BackColor = Color.FromArgb(28, 33, 48)
_tabControl = New TabControl With {
.Dock = DockStyle.Fill,
.Padding = New Point(12, 6),
.Font = New Font("Segoe UI", 9.5F)
}
_tabControl.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler _tabControl.DrawItem, AddressOf OnDrawTab
_tabControl.TabPages.Add(BuildGaugeTab())
_tabControl.TabPages.Add(BuildThresholdsTab())
_tabControl.TabPages.Add(BuildGlobalTab())
panel.Controls.Add(_tabControl)
End Sub
''' <summary>Disegna tab con sfondo scuro</summary>
Private Sub OnDrawTab(sender As Object, e As DrawItemEventArgs)
Dim tab = _tabControl.TabPages(e.Index)
Dim isSelected = (e.Index = _tabControl.SelectedIndex)
Dim bgColor = If(isSelected, Color.FromArgb(38, 44, 62), Color.FromArgb(28, 33, 48))
e.Graphics.FillRectangle(New SolidBrush(bgColor), e.Bounds)
Dim textColor = If(isSelected, Color.FromArgb(130, 190, 255), Color.FromArgb(140, 160, 190))
Dim font = New Font("Segoe UI", 9.5F, If(isSelected, FontStyle.Bold, FontStyle.Regular))
Dim sz = e.Graphics.MeasureString(tab.Text, font)
e.Graphics.DrawString(tab.Text, font, New SolidBrush(textColor),
e.Bounds.X + (e.Bounds.Width - sz.Width) / 2,
e.Bounds.Y + (e.Bounds.Height - sz.Height) / 2)
font.Dispose()
If isSelected Then
e.Graphics.DrawLine(New Pen(Color.FromArgb(100, 180, 255), 2),
e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
End If
End Sub
' ── Tab Gauge ────────────────────────────────────────────
Private Function BuildGaugeTab() As TabPage
Dim tab = New TabPage(" 🎛 Stile Gauge ") With {
.BackColor = Color.FromArgb(28, 33, 48),
.ForeColor = Color.FromArgb(200, 215, 235),
.Padding = New Padding(10)
}
Dim panel = New Panel With {
.Location = New Point(10, 10),
.Size = New Size(360, 470),
.BackColor = Color.FromArgb(28, 33, 48)
}
Dim y = 10
' Stile gauge
panel.Controls.Add(CreateSectionLabel("STILE GAUGE", 0, y)) : y += 24
_cmbStyle = CreateComboBox(panel, y)
_cmbStyle.Items.AddRange({"Arco 270°", "Semicerchio", "Barra Orizzontale", "Barra Verticale"})
AddHandler _cmbStyle.SelectedIndexChanged, AddressOf OnGaugeConfigChanged
y += 36
' Schema colori
panel.Controls.Add(CreateSectionLabel("SCHEMA COLORI", 0, y)) : y += 24
_cmbColorScheme = CreateComboBox(panel, y)
_cmbColorScheme.Items.AddRange({"Semaforo (default)", "Oceano", "Tramonto", "Monocromatico", "Personalizzato"})
AddHandler _cmbColorScheme.SelectedIndexChanged, AddressOf OnColorSchemeChanged
y += 36
' Colori personalizzati
_cmbCustomColorLabel = CreateSectionLabel("COLORI PERSONALIZZATI", 0, y)
panel.Controls.Add(_cmbCustomColorLabel) : y += 24
_btnColorNormal = CreateColorButton("Normale", Color.FromArgb(0, 200, 81), panel, y)
_btnColorWarning = CreateColorButton("Attenzione", Color.FromArgb(255, 165, 0), panel, y + 36)
_btnColorCritical = CreateColorButton("Critico", Color.FromArgb(220, 50, 50), panel, y + 72)
y += 120
' Larghezza arco
panel.Controls.Add(CreateSectionLabel("LARGHEZZA ARCO / BARRA", 0, y)) : y += 24
_nudArcWidth = CreateNumericUpDown(panel, y, 4, 40, 18)
AddHandler _nudArcWidth.ValueChanged, AddressOf OnGaugeConfigChanged
y += 36
' Checkbox opzioni
panel.Controls.Add(CreateSectionLabel("OPZIONI VISUALIZZAZIONE", 0, y)) : y += 24
_chkShowValue = CreateCheckBox(panel, "Mostra valore numerico", y) : y += 28
_chkShowName = CreateCheckBox(panel, "Mostra nome coda", y) : y += 28
_chkShowLabels = CreateCheckBox(panel, "Mostra etichette min/max", y) : y += 28
_chkAnimate = CreateCheckBox(panel, "Animazioni di transizione", y) : y += 28
_chkShowGrid = CreateCheckBox(panel, "Mostra griglia (barre)", y) : y += 28
AddHandler _chkShowValue.CheckedChanged, AddressOf OnGaugeConfigChanged
AddHandler _chkShowName.CheckedChanged, AddressOf OnGaugeConfigChanged
AddHandler _chkShowLabels.CheckedChanged, AddressOf OnGaugeConfigChanged
AddHandler _chkAnimate.CheckedChanged, AddressOf OnGaugeConfigChanged
AddHandler _chkShowGrid.CheckedChanged, AddressOf OnGaugeConfigChanged
tab.Controls.Add(panel)
' Preview
Dim previewLabel = New Label With {
.Text = "ANTEPRIMA",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(100, 120, 160),
.Location = New Point(390, 10),
.AutoSize = True
}
tab.Controls.Add(previewLabel)
_previewPanel = New Panel With {
.Location = New Point(385, 32),
.Size = New Size(200, 200),
.BackColor = Color.FromArgb(22, 27, 38)
}
tab.Controls.Add(_previewPanel)
Return tab
End Function
' ── Tab Soglie ───────────────────────────────────────────
Private Function BuildThresholdsTab() As TabPage
Dim tab = New TabPage(" ⚠ Soglie ") With {
.BackColor = Color.FromArgb(28, 33, 48),
.ForeColor = Color.FromArgb(200, 215, 235),
.Padding = New Padding(16)
}
Dim y = 20
' Descrizione
Dim lblDesc = New Label With {
.Text = "Configura i tempi di attesa soglia per la coda selezionata." & Environment.NewLine &
"Il gauge cambierà colore quando il tempo supera ciascuna soglia.",
.Location = New Point(16, y),
.Size = New Size(500, 44),
.Font = New Font("Segoe UI", 9),
.ForeColor = Color.FromArgb(140, 160, 190)
}
tab.Controls.Add(lblDesc) : y += 60
' Max wait
tab.Controls.Add(CreateSectionLabel("TEMPO MASSIMO (minuti)", 16, y)) : y += 22
Dim lblMaxDesc = New Label With {
.Text = "Valore a cui il gauge mostra 100%",
.Location = New Point(16, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 8),
.ForeColor = Color.FromArgb(110, 130, 160)
}
tab.Controls.Add(lblMaxDesc) : y += 22
_nudMaxWait = CreateNumericUpDown(tab, y, 5, 480, 60, 16)
y += 46
' Warning threshold
tab.Controls.Add(CreateSectionLabel("SOGLIA ATTENZIONE (minuti) — Giallo", 16, y)) : y += 22
Dim lblWarnDesc = New Label With {
.Text = "Il gauge diventa giallo/arancio oltre questa soglia",
.Location = New Point(16, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 8),
.ForeColor = Color.FromArgb(255, 165, 0)
}
tab.Controls.Add(lblWarnDesc) : y += 22
_nudWarnThreshold = CreateNumericUpDown(tab, y, 1, 480, 20, 16)
y += 46
' Critical threshold
tab.Controls.Add(CreateSectionLabel("SOGLIA CRITICA (minuti) — Rosso", 16, y)) : y += 22
Dim lblCritDesc = New Label With {
.Text = "Il gauge diventa rosso e lampeggia oltre questa soglia",
.Location = New Point(16, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 8),
.ForeColor = Color.FromArgb(220, 80, 80)
}
tab.Controls.Add(lblCritDesc) : y += 22
_nudCritThreshold = CreateNumericUpDown(tab, y, 1, 480, 40, 16)
y += 60
' Visualizzazione grafica soglie
Dim thresholdViz = New Panel With {
.Location = New Point(16, y),
.Size = New Size(500, 60),
.BackColor = Color.FromArgb(22, 27, 38)
}
AddHandler thresholdViz.Paint, AddressOf OnDrawThresholdViz
tab.Controls.Add(thresholdViz)
AddHandler _nudMaxWait.ValueChanged, Sub(s, e)
thresholdViz.Invalidate()
End Sub
AddHandler _nudWarnThreshold.ValueChanged, Sub(s, e)
thresholdViz.Invalidate()
End Sub
AddHandler _nudCritThreshold.ValueChanged, Sub(s, e)
thresholdViz.Invalidate()
End Sub
Return tab
End Function
''' <summary>Disegna la visualizzazione grafica delle soglie</summary>
Private Sub OnDrawThresholdViz(sender As Object, e As PaintEventArgs)
Dim panel = CType(sender, Panel)
Dim g = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.FromArgb(22, 27, 38))
Dim maxVal = CDbl(_nudMaxWait?.Value)
Dim warnVal = CDbl(_nudWarnThreshold?.Value)
Dim critVal = CDbl(_nudCritThreshold?.Value)
If maxVal = 0 Then Return
Dim barRect = New Rectangle(10, 20, panel.Width - 20, 24)
' Sfondo bar
Using bgBrush As New SolidBrush(Color.FromArgb(40, 48, 65))
g.FillRectangle(bgBrush, barRect)
End Using
' Zona verde (0 → warn)
Dim warnX = CInt(barRect.Width * warnVal / maxVal)
Using greenBrush As New SolidBrush(Color.FromArgb(0, 160, 60))
g.FillRectangle(greenBrush, New Rectangle(barRect.X, barRect.Y, warnX, barRect.Height))
End Using
' Zona gialla (warn → crit)
Dim critX = CInt(barRect.Width * critVal / maxVal)
If critX > warnX Then
Using yellowBrush As New SolidBrush(Color.FromArgb(220, 140, 0))
g.FillRectangle(yellowBrush, New Rectangle(barRect.X + warnX, barRect.Y, critX - warnX, barRect.Height))
End Using
End If
' Zona rossa (crit → max)
If critX < barRect.Width Then
Using redBrush As New SolidBrush(Color.FromArgb(180, 40, 40))
g.FillRectangle(redBrush, New Rectangle(barRect.X + critX, barRect.Y, barRect.Width - critX, barRect.Height))
End Using
End If
' Labels
Dim font = New Font("Segoe UI", 7.5F)
g.DrawString("0", font, Brushes.White, barRect.X, barRect.Bottom + 2)
If warnX > 30 Then g.DrawString($"{CInt(warnVal)}m ⚠", font, New SolidBrush(Color.FromArgb(255, 200, 0)), barRect.X + warnX - 20, barRect.Bottom + 2)
If critX - warnX > 30 Then g.DrawString($"{CInt(critVal)}m ✖", font, New SolidBrush(Color.FromArgb(255, 100, 100)), barRect.X + critX - 20, barRect.Bottom + 2)
Dim maxStr = $"{CInt(maxVal)}m"
Dim maxSz = g.MeasureString(maxStr, font)
g.DrawString(maxStr, font, New SolidBrush(Color.FromArgb(160, 175, 200)), barRect.Right - maxSz.Width, barRect.Bottom + 2)
font.Dispose()
End Sub
' ── Tab Globale ──────────────────────────────────────────
Private Function BuildGlobalTab() As TabPage
Dim tab = New TabPage(" 🌐 Globale ") With {
.BackColor = Color.FromArgb(28, 33, 48),
.ForeColor = Color.FromArgb(200, 215, 235)
}
Dim y = 20
tab.Controls.Add(CreateSectionLabel("LAYOUT DASHBOARD", 16, y)) : y += 22
tab.Controls.Add(New Label With {
.Text = "Numero di colonne nella griglia",
.Location = New Point(16, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 8.5F),
.ForeColor = Color.FromArgb(140, 160, 190)
}) : y += 20
_nudColumns = CreateNumericUpDown(tab, y, 1, 8, 3, 16)
y += 46
tab.Controls.Add(CreateSectionLabel("AUTO-REFRESH", 16, y)) : y += 22
tab.Controls.Add(New Label With {
.Text = "Secondi tra un aggiornamento e l'altro (0 = disabilitato)",
.Location = New Point(16, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 8.5F),
.ForeColor = Color.FromArgb(140, 160, 190)
}) : y += 20
_nudAutoRefresh = CreateNumericUpDown(tab, y, 0, 3600, 30, 16)
y += 46
tab.Controls.Add(CreateSectionLabel("DIMENSIONE FONT GAUGE", 16, y)) : y += 22
_nudFontSize = CreateNumericUpDown(tab, y, 8, 36, 18, 16)
y += 46
tab.Controls.Add(CreateSectionLabel("OPZIONI INTERFACCIA", 16, y)) : y += 22
_chkStatusBar = CreateCheckBox(tab, "Mostra barra di stato", y, 16) : y += 28
_chkDarkTheme = CreateCheckBox(tab, "Tema scuro (consigliato)", y, 16)
Return tab
End Function
' ─── Helpers UI Factory ──────────────────────────────────
Private Function CreateSectionLabel(text As String, x As Integer, y As Integer) As Label
Return New Label With {
.Text = text,
.Location = New Point(x, y),
.AutoSize = True,
.Font = New Font("Segoe UI", 7.5F, FontStyle.Bold),
.ForeColor = Color.FromArgb(100, 125, 165)
}
End Function
Private Function CreateComboBox(parent As Control, y As Integer) As ComboBox
Dim cmb = New ComboBox With {
.Location = New Point(0, y),
.Size = New Size(320, 28),
.DropDownStyle = ComboBoxStyle.DropDownList,
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(38, 44, 62),
.ForeColor = Color.FromArgb(200, 215, 235)
}
parent.Controls.Add(cmb)
Return cmb
End Function
Private Function CreateNumericUpDown(parent As Control, y As Integer,
min As Decimal, max As Decimal,
defaultVal As Decimal,
Optional x As Integer = 0) As NumericUpDown
Dim nud = New NumericUpDown With {
.Location = New Point(x, y),
.Size = New Size(160, 28),
.Minimum = min,
.Maximum = max,
.Value = defaultVal,
.BackColor = Color.FromArgb(38, 44, 62),
.ForeColor = Color.FromArgb(200, 215, 235),
.BorderStyle = BorderStyle.FixedSingle
}
parent.Controls.Add(nud)
Return nud
End Function
Private Function CreateCheckBox(parent As Control, text As String, y As Integer,
Optional x As Integer = 0) As CheckBox
Dim chk = New CheckBox With {
.Text = text,
.Location = New Point(x, y),
.AutoSize = True,
.ForeColor = Color.FromArgb(200, 215, 235),
.BackColor = Color.Transparent
}
parent.Controls.Add(chk)
Return chk
End Function
Private Function CreateColorButton(text As String, color As Color, parent As Panel, y As Integer) As Button
Dim btn = New Button With {
.Text = $"■ {text}",
.Location = New Point(0, y),
.Size = New Size(200, 30),
.FlatStyle = FlatStyle.Flat,
.BackColor = color,
.ForeColor = Color.White,
.Font = New Font("Segoe UI", 9, FontStyle.Bold),
.Tag = color
}
btn.FlatAppearance.BorderColor = Color.FromArgb(80, 90, 110)
AddHandler btn.Click, Sub(s, e)
Dim b = CType(s, Button)
Dim dlg = New ColorDialog With {.Color = CType(b.Tag, Color)}
If dlg.ShowDialog() = DialogResult.OK Then
b.BackColor = dlg.Color
b.Tag = dlg.Color
OnGaugeConfigChanged(s, e)
End If
End Sub
parent.Controls.Add(btn)
Return btn
End Function
Private Function CreateFooterButton(text As String, bgColor As Color, isPrimary As Boolean) As Button
Dim btn = New Button With {
.Text = text,
.Size = New Size(185, 34),
.FlatStyle = FlatStyle.Flat,
.BackColor = bgColor,
.ForeColor = Color.White,
.Font = New Font("Segoe UI", 9.5F, If(isPrimary, FontStyle.Bold, FontStyle.Regular)),
.Cursor = Cursors.Hand
}
btn.FlatAppearance.BorderColor = Color.FromArgb(70, 85, 120)
Return btn
End Function
' ─── Caricamento dati ─────────────────────────────────────
Private Sub PopulateQueueList()
_lstQueues.Items.Clear()
For Each q In AppState.Instance.Config.Queues
_lstQueues.Items.Add(New QueueListItem(q))
Next
End Sub
Private Sub LoadGlobalSettings()
_isLoading = True
Dim cfg = AppState.Instance.Config
_nudColumns.Value = cfg.DashboardColumns
_nudAutoRefresh.Value = cfg.AutoRefreshSeconds
_nudFontSize.Value = CInt(cfg.GaugeValueFontSize)
_chkStatusBar.Checked = cfg.ShowStatusBar
_chkDarkTheme.Checked = cfg.DarkTheme
_isLoading = False
End Sub
Private Sub LoadQueueGaugeConfig(queueId As String)
_isLoading = True
_selectedQueueId = queueId
Dim q = AppState.Instance.Config.Queues.FirstOrDefault(Function(x) x.Id = queueId)
Dim gc = AppState.Instance.Config.GetGaugeConfig(queueId)
If q IsNot Nothing Then
_nudMaxWait.Value = CDec(q.MaxWaitTime)
_nudWarnThreshold.Value = CDec(q.WarningThreshold)
_nudCritThreshold.Value = CDec(q.CriticalThreshold)
End If
_cmbStyle.SelectedIndex = CInt(gc.Style)
_cmbColorScheme.SelectedIndex = CInt(gc.ColorScheme)
_chkShowValue.Checked = gc.ShowValue
_chkShowName.Checked = gc.ShowName
_chkShowLabels.Checked = gc.ShowLabels
_chkAnimate.Checked = gc.AnimateTransitions
_chkShowGrid.Checked = gc.ShowGrid
_nudArcWidth.Value = gc.ArcWidth
Try
_btnColorNormal.BackColor = ColorTranslator.FromHtml(gc.CustomColorNormal)
_btnColorNormal.Tag = _btnColorNormal.BackColor
_btnColorWarning.BackColor = ColorTranslator.FromHtml(gc.CustomColorWarning)
_btnColorWarning.Tag = _btnColorWarning.BackColor
_btnColorCritical.BackColor = ColorTranslator.FromHtml(gc.CustomColorCritical)
_btnColorCritical.Tag = _btnColorCritical.BackColor
Catch : End Try
UpdateColorCustomVisibility()
UpdatePreview(q, gc)
_isLoading = False
End Sub
Private Sub UpdateColorCustomVisibility()
Dim isCustom = (_cmbColorScheme.SelectedIndex = CInt(GaugeColorScheme.Custom))
_cmbCustomColorLabel.Visible = isCustom
_btnColorNormal.Visible = isCustom
_btnColorWarning.Visible = isCustom
_btnColorCritical.Visible = isCustom
End Sub
Private Sub UpdatePreview(queue As QueueModel, gc As GaugeConfig)
_previewPanel.Controls.Clear()
_previewGauge?.Dispose()
If queue Is Nothing OrElse gc Is Nothing Then Return
_previewGauge = New GaugeControl(queue, gc) With {
.Dock = DockStyle.Fill,
.BackColor = Color.FromArgb(22, 27, 38)
}
_previewPanel.Controls.Add(_previewGauge)
End Sub
' ─── Gestione eventi ──────────────────────────────────────
Private Sub OnQueueSelected(sender As Object, e As EventArgs)
Dim item = TryCast(_lstQueues.SelectedItem, QueueListItem)
If item IsNot Nothing Then
LoadQueueGaugeConfig(item.Queue.Id)
End If
End Sub
Private Sub OnGaugeConfigChanged(sender As Object, e As EventArgs)
If _isLoading OrElse String.IsNullOrEmpty(_selectedQueueId) Then Return
' Aggiorna preview live
Dim gc = AppState.Instance.Config.GetGaugeConfig(_selectedQueueId)
gc.Style = CType(_cmbStyle.SelectedIndex, GaugeStyle)
gc.ColorScheme = CType(_cmbColorScheme.SelectedIndex, GaugeColorScheme)
gc.ShowValue = _chkShowValue.Checked
gc.ShowName = _chkShowName.Checked
gc.ShowLabels = _chkShowLabels.Checked
gc.AnimateTransitions = _chkAnimate.Checked
gc.ShowGrid = _chkShowGrid.Checked
gc.ArcWidth = CInt(_nudArcWidth.Value)
gc.CustomColorNormal = ColorTranslator.ToHtml(CType(_btnColorNormal.Tag, Color))
gc.CustomColorWarning = ColorTranslator.ToHtml(CType(_btnColorWarning.Tag, Color))
gc.CustomColorCritical = ColorTranslator.ToHtml(CType(_btnColorCritical.Tag, Color))
Dim q = AppState.Instance.Config.Queues.FirstOrDefault(Function(x) x.Id = _selectedQueueId)
UpdatePreview(q, gc)
End Sub
Private Sub OnColorSchemeChanged(sender As Object, e As EventArgs)
UpdateColorCustomVisibility()
OnGaugeConfigChanged(sender, e)
End Sub
Private Sub OnSaveClick(sender As Object, e As EventArgs)
' Salva config globale
Dim cfg = AppState.Instance.Config
cfg.DashboardColumns = CInt(_nudColumns.Value)
cfg.AutoRefreshSeconds = CInt(_nudAutoRefresh.Value)
cfg.GaugeValueFontSize = CSng(_nudFontSize.Value)
cfg.ShowStatusBar = _chkStatusBar.Checked
cfg.DarkTheme = _chkDarkTheme.Checked
' Salva soglie per la coda selezionata
If Not String.IsNullOrEmpty(_selectedQueueId) Then
Dim q = cfg.Queues.FirstOrDefault(Function(x) x.Id = _selectedQueueId)
If q IsNot Nothing Then
q.MaxWaitTime = CDbl(_nudMaxWait.Value)
q.WarningThreshold = CDbl(_nudWarnThreshold.Value)
q.CriticalThreshold = CDbl(_nudCritThreshold.Value)
End If
End If
AppState.Instance.SaveAndNotify()
System.Windows.Forms.MessageBox.Show("Configurazione salvata con successo!", "✓ Salvato",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
End Sub
Private Sub OnResetClick(sender As Object, e As EventArgs)
Dim res = System.Windows.Forms.MessageBox.Show(
"Ripristinare tutte le impostazioni ai valori predefiniti?",
"Conferma Reset",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question)
If res = DialogResult.Yes Then
AppState.Instance.Config = ConfigService.CreateDefault()
AppState.Instance.SaveAndNotify()
PopulateQueueList()
LoadGlobalSettings()
If _lstQueues.Items.Count > 0 Then _lstQueues.SelectedIndex = 0
End If
End Sub
Private Sub AddQueue(sender As Object, e As EventArgs)
Dim nuovaCoda As New QueueModel With {
.Name = "Nuova Coda",
.MaxWaitTime = 60,
.WarningThreshold = 20,
.CriticalThreshold = 40,
.IsActive = True
}
AppState.Instance.Config.Queues.Add(nuovaCoda)
Dim nuovaGaugeConfig = AppState.Instance.Config.GetGaugeConfig(nuovaCoda.Id)
nuovaGaugeConfig.Style = GaugeStyle.Arc270
AppState.Instance.SaveAndNotify()
MsgBox("Coda aggiunta con successo!")
End Sub
Private Sub OnRemoveQueue(sender As Object, e As EventArgs)
' 2. Chiedi conferma all'utente
Dim res = System.Windows.Forms.MessageBox.Show(
"Sei sicuro di voler eliminare definitivamente questa coda?",
"Conferma Eliminazione",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning)
If res = DialogResult.Yes Then
Dim cfg = AppState.Instance.Config
' 3. Trova la coda nella lista
Dim q = cfg.Queues.FirstOrDefault(Function(x) x.Id = _selectedQueueId)
If q IsNot Nothing Then
' 4. Rimuovi la coda e la sua configurazione grafica
cfg.Queues.Remove(q)
If cfg.GaugeConfigs.ContainsKey(_selectedQueueId) Then
cfg.GaugeConfigs.Remove(_selectedQueueId)
End If
' 5. Salva i cambiamenti e notifica le altre finestre (Dashboard)
AppState.Instance.SaveAndNotify()
' 6. Aggiorna l'interfaccia locale del Backend
PopulateQueueList() ' Ricarica la lista nomi
' Se la lista non è vuota, seleziona il primo elemento, altrimenti resetta l'ID
If _lstQueues.Items.Count > 0 Then
_lstQueues.SelectedIndex = 0
Else
_selectedQueueId = Nothing
End If
System.Windows.Forms.MessageBox.Show("Coda rimossa con successo!", "✓ Eliminato",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
End If
End If
End Sub
End Class
''' <summary>Item wrapper per la listbox code (permette custom draw)</summary>
Friend Class QueueListItem
Public ReadOnly Property Queue As QueueModel
Public Sub New(q As QueueModel)
Queue = q
End Sub
Public Overrides Function ToString() As String
Return Queue.Name
End Function
End Class
'End Namespace