-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormBackend.vb
More file actions
755 lines (652 loc) · 31.6 KB
/
Copy pathFormBackend.vb
File metadata and controls
755 lines (652 loc) · 31.6 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
''' <summary>
''' FormBackend.vb - Finestra Backend / Gestione Dati
''' Permette agli operatori di selezionare le code e inserire i tempi di attesa.
''' Mostra anche lo storico delle misurazioni e statistiche per ogni coda.
''' </summary>
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
'Namespace QueueMonitor
''' <summary>
''' Form backend per la gestione manuale dei dati di coda.
''' Funzionalità: selezione coda, inserimento tempo attesa, storico, statistiche,
''' aggiunta/rimozione code, attivazione/disattivazione monitoraggio.
''' </summary>
Public Class FormBackend
Inherits Form
' ─── Controlli UI ─────────────────────────────────────────
Private _splitMain As SplitContainer
Private _panelQueueList As Panel
Private _lstQueues As ListView
Private _btnAddQueue As Button
Private _btnRemoveQueue As Button
Private _btnToggleActive As Button
' Pannello destra: dettaglio coda
Private _panelDetail As Panel
Private _lblQueueName As Label
Private _lblQueueStatus As Label
Private _panelMini As Panel ' mini-gauge preview
Private _miniGauge As GaugeControl
' Input tempo attesa
Private _nudWaitTime As NumericUpDown
Private _lblCurrentWait As Label
Private _btnSetWait As Button
Private _btnQuickSet As Button()
Private _sliderWait As TrackBar
' Gestione coda
Private _txtQueueName As TextBox
Private _txtDescription As TextBox
Private _chkActive As CheckBox
' Storico
Private _lstHistory As ListView
Private _btnClearHistory As Button
' Statistiche
Private _lblAvgWait As Label
Private _lblMaxWaitSeen As Label
Private _lblMinWaitSeen As Label
Private _lblTotalSamples As Label
' Stato interno
Private _selectedQueue As QueueModel
' ─── Costruttore ─────────────────────────────────────────
Public Sub New(Optional selectedQueueId As String = Nothing)
InitializeComponent()
LoadQueueList()
' Seleziona coda specifica se richiesto
If selectedQueueId IsNot Nothing Then
SelectQueue(selectedQueueId)
ElseIf _lstQueues.Items.Count > 0 Then
_lstQueues.Items(0).Selected = True
End If
End Sub
' ─── Inizializzazione UI ──────────────────────────────────
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.Text = "📊 Backend Dati — Queue Monitor Pro"
Me.Size = New Size(1020, 680)
Me.MinimumSize = New Size(800, 550)
Me.BackColor = Color.FromArgb(22, 27, 38)
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 = 56,
.BackColor = Color.FromArgb(28, 44, 38)
}
Dim lblHeader = New Label With {
.Text = "📊 Backend — Gestione Code e Tempi di Attesa",
.Font = New Font("Segoe UI", 13, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 220, 140),
.Location = New Point(16, 16),
.AutoSize = True
}
headerPanel.Controls.Add(lblHeader)
' ── Split ───────────────────────────────────────────
_splitMain = New SplitContainer With {
.Dock = DockStyle.Fill,
.BackColor = Color.FromArgb(22, 27, 38)
}
BuildQueueListPanel()
BuildDetailPanel()
Me.Controls.Add(_splitMain)
Me.Controls.Add(headerPanel)
Me.ResumeLayout(False)
End Sub
' ── Pannello lista code ───────────────────────────────────
Private Sub BuildQueueListPanel()
_panelQueueList = _splitMain.Panel1
_panelQueueList.BackColor = Color.FromArgb(24, 29, 42)
Dim lblTitle = New Label With {
.Text = "ELENCO CODE",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 200, 120),
.Location = New Point(10, 12),
.AutoSize = True
}
' ListView con colonne: Nome, Attesa, Stato
_lstQueues = New ListView With {
.Location = New Point(10, 34),
.Size = New Size(295, 480),
.View = View.Details,
.FullRowSelect = True,
.GridLines = False,
.BackColor = Color.FromArgb(28, 34, 50),
.ForeColor = Color.FromArgb(200, 215, 235),
.BorderStyle = BorderStyle.None,
.HideSelection = False,
.Font = New Font("Segoe UI", 9.5F)
}
_lstQueues.Columns.Add("Nome Coda", 140)
_lstQueues.Columns.Add("Attesa", 70)
_lstQueues.Columns.Add("Stato", 70)
_lstQueues.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
AddHandler _lstQueues.SelectedIndexChanged, AddressOf OnQueueSelected
' Imposta la proprietà correttamente
_lstQueues.OwnerDraw = True
' Se vuoi che la lista si veda correttamente anche se OwnerDraw è True,
' devi aggiungere questo AddHandler per il disegno standard:
AddHandler _lstQueues.DrawColumnHeader, Sub(sender, e) e.DrawDefault = True
AddHandler _lstQueues.DrawItem, Sub(sender, e) e.DrawDefault = True
AddHandler _lstQueues.DrawSubItem, Sub(sender, e) e.DrawDefault = True
' Bottoni gestione
_btnAddQueue = CreateMgmtButton("+ Aggiungi", Color.FromArgb(30, 80, 50), 10, 520)
_btnRemoveQueue = CreateMgmtButton("− Rimuovi", Color.FromArgb(80, 30, 30), 110, 520)
_btnToggleActive = CreateMgmtButton("◉ Attiva/Pausa", Color.FromArgb(40, 55, 85), 10, 555)
AddHandler _btnAddQueue.Click, AddressOf OnAddQueueClick
AddHandler _btnRemoveQueue.Click, AddressOf OnRemoveQueueClick
AddHandler _btnToggleActive.Click, AddressOf OnToggleActiveClick
_panelQueueList.Controls.AddRange({lblTitle, _lstQueues, _btnAddQueue, _btnRemoveQueue, _btnToggleActive})
End Sub
' ── Pannello dettaglio coda ───────────────────────────────
Private Sub BuildDetailPanel()
_panelDetail = _splitMain.Panel2
_panelDetail.BackColor = Color.FromArgb(22, 27, 38)
' ─ Header dettaglio
_lblQueueName = New Label With {
.Text = "Seleziona una coda →",
.Font = New Font("Segoe UI", 16, FontStyle.Bold),
.ForeColor = Color.White,
.Location = New Point(16, 14),
.Size = New Size(400, 32)
}
_lblQueueStatus = New Label With {
.Text = "",
.Font = New Font("Segoe UI", 9.5F),
.ForeColor = Color.FromArgb(140, 160, 190),
.Location = New Point(16, 48),
.Size = New Size(400, 20)
}
' ─ Mini gauge preview
_panelMini = New Panel With {
.Location = New Point(520, 10),
.Size = New Size(160, 160),
.BackColor = Color.FromArgb(28, 33, 48)
}
' ─ Sezione inserimento tempo
Dim lblInputTitle = New Label With {
.Text = "IMPOSTA TEMPO DI ATTESA",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 200, 140),
.Location = New Point(16, 82),
.AutoSize = True
}
_lblCurrentWait = New Label With {
.Text = "Valore corrente: — min",
.Font = New Font("Segoe UI", 11, FontStyle.Bold),
.ForeColor = Color.FromArgb(100, 200, 255),
.Location = New Point(16, 104),
.Size = New Size(360, 26)
}
' Slider
_sliderWait = New TrackBar With {
.Location = New Point(16, 136),
.Size = New Size(460, 40),
.Minimum = 0,
.Maximum = 120,
.TickFrequency = 10,
.LargeChange = 5,
.BackColor = Color.FromArgb(22, 27, 38)
}
AddHandler _sliderWait.ValueChanged, Sub(s, e)
_nudWaitTime.Value = _sliderWait.Value
End Sub
' NumericUpDown
Dim lblNud = New Label With {
.Text = "Minuti:",
.Location = New Point(16, 186),
.AutoSize = True,
.ForeColor = Color.FromArgb(160, 180, 210)
}
_nudWaitTime = New NumericUpDown With {
.Location = New Point(70, 182),
.Size = New Size(100, 30),
.Minimum = 0,
.Maximum = 1440,
.Value = 0,
.BackColor = Color.FromArgb(38, 44, 62),
.ForeColor = Color.FromArgb(200, 215, 235),
.Font = New Font("Segoe UI", 12, FontStyle.Bold),
.BorderStyle = BorderStyle.FixedSingle
}
AddHandler _nudWaitTime.ValueChanged, Sub(s, e)
If _sliderWait.Value <> CInt(_nudWaitTime.Value) Then
_sliderWait.Value = Math.Min(CInt(_nudWaitTime.Value), _sliderWait.Maximum)
End If
End Sub
_btnSetWait = New Button With {
.Text = "✓ AGGIORNA ATTESA",
.Location = New Point(186, 182),
.Size = New Size(200, 34),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(20, 120, 70),
.ForeColor = Color.White,
.Font = New Font("Segoe UI", 10, FontStyle.Bold),
.Cursor = Cursors.Hand
}
_btnSetWait.FlatAppearance.BorderColor = Color.FromArgb(40, 160, 100)
AddHandler _btnSetWait.Click, AddressOf OnSetWaitClick
' Bottoni preset rapidi
Dim lblPresets = New Label With {
.Text = "Inserimento rapido:",
.Location = New Point(16, 228),
.AutoSize = True,
.Font = New Font("Segoe UI", 8.5F),
.ForeColor = Color.FromArgb(110, 130, 160)
}
Dim presets = {0, 5, 10, 15, 20, 30, 45, 60, 90}
_btnQuickSet = New Button(presets.Length - 1) {}
Dim qx = 16
For i = 0 To presets.Length - 1
Dim presetVal = presets(i)
_btnQuickSet(i) = New Button With {
.Text = If(presetVal = 0, "0", $"{presetVal}m"),
.Location = New Point(qx, 248),
.Size = New Size(50, 28),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(40, 50, 70),
.ForeColor = Color.FromArgb(180, 200, 230),
.Font = New Font("Segoe UI", 8.5F, FontStyle.Bold),
.Cursor = Cursors.Hand
}
_btnQuickSet(i).FlatAppearance.BorderColor = Color.FromArgb(60, 75, 100)
AddHandler _btnQuickSet(i).Click, Sub(s, e)
Dim btn = CType(s, Button)
Dim txt = btn.Text.Replace("m", "")
Dim val As Integer
If Integer.TryParse(txt, val) Then
_nudWaitTime.Value = val
OnSetWaitClick(s, e)
End If
End Sub
qx += 54
Next
' ─ Modifica info coda
Dim lblEditTitle = New Label With {
.Text = "INFORMAZIONI CODA",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 200, 140),
.Location = New Point(16, 292),
.AutoSize = True
}
Dim lblNameEdit = New Label With {
.Text = "Nome:",
.Location = New Point(16, 316),
.AutoSize = True,
.ForeColor = Color.FromArgb(160, 180, 210)
}
_txtQueueName = New TextBox With {
.Location = New Point(80, 312),
.Size = New Size(260, 26),
.BackColor = Color.FromArgb(38, 44, 62),
.ForeColor = Color.FromArgb(200, 215, 235),
.BorderStyle = BorderStyle.FixedSingle,
.Font = New Font("Segoe UI", 9.5F)
}
Dim lblDescEdit = New Label With {
.Text = "Note:",
.Location = New Point(16, 348),
.AutoSize = True,
.ForeColor = Color.FromArgb(160, 180, 210)
}
_txtDescription = New TextBox With {
.Location = New Point(80, 344),
.Size = New Size(260, 26),
.BackColor = Color.FromArgb(38, 44, 62),
.ForeColor = Color.FromArgb(200, 215, 235),
.BorderStyle = BorderStyle.FixedSingle,
.Font = New Font("Segoe UI", 9.5F)
}
_chkActive = New CheckBox With {
.Text = "Coda attiva (monitorata nella dashboard)",
.Location = New Point(16, 380),
.AutoSize = True,
.ForeColor = Color.FromArgb(200, 215, 235)
}
Dim btnSaveInfo = New Button With {
.Text = "💾 Salva Info",
.Location = New Point(16, 410),
.Size = New Size(140, 32),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(40, 60, 100),
.ForeColor = Color.White,
.Font = New Font("Segoe UI", 9.5F, FontStyle.Bold),
.Cursor = Cursors.Hand
}
btnSaveInfo.FlatAppearance.BorderColor = Color.FromArgb(60, 90, 150)
AddHandler btnSaveInfo.Click, AddressOf OnSaveInfoClick
' ─ Storico misurazioni
Dim lblHistTitle = New Label With {
.Text = "STORICO MISURAZIONI",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 200, 140),
.Location = New Point(16, 456),
.AutoSize = True
}
_lstHistory = New ListView With {
.Location = New Point(16, 476),
.Size = New Size(560, 100),
.View = View.Details,
.BackColor = Color.FromArgb(28, 34, 50),
.ForeColor = Color.FromArgb(180, 200, 225),
.BorderStyle = BorderStyle.None,
.Font = New Font("Segoe UI", 8.5F),
.FullRowSelect = True,
.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
}
_lstHistory.Columns.Add("Data/Ora", 130)
_lstHistory.Columns.Add("Attesa (min)", 100)
_lstHistory.Columns.Add("Stato", 100)
_btnClearHistory = New Button With {
.Text = "Svuota storico",
.Location = New Point(16, 580),
.Size = New Size(140, 28),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(60, 35, 35),
.ForeColor = Color.FromArgb(220, 150, 150),
.Font = New Font("Segoe UI", 8.5F),
.Cursor = Cursors.Hand,
.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
}
_btnClearHistory.FlatAppearance.BorderColor = Color.FromArgb(100, 50, 50)
AddHandler _btnClearHistory.Click, Sub(s, e)
_selectedQueue?.History.Clear()
RefreshHistory()
End Sub
' ─ Statistiche
Dim lblStatsTitle = New Label With {
.Text = "STATISTICHE",
.Font = New Font("Segoe UI", 8, FontStyle.Bold),
.ForeColor = Color.FromArgb(80, 200, 140),
.Location = New Point(420, 456),
.AutoSize = True
}
_lblAvgWait = CreateStatLabel("Media: —", 420, 476)
_lblMaxWaitSeen = CreateStatLabel("Massimo: —", 420, 498)
_lblMinWaitSeen = CreateStatLabel("Minimo: —", 420, 520)
_lblTotalSamples = CreateStatLabel("Campioni: 0", 420, 542)
' Assembla pannello destra
_panelDetail.Controls.AddRange({
_lblQueueName, _lblQueueStatus, _panelMini,
lblInputTitle, _lblCurrentWait,
_sliderWait, lblNud, _nudWaitTime, _btnSetWait,
lblPresets,
lblEditTitle, lblNameEdit, _txtQueueName,
lblDescEdit, _txtDescription,
_chkActive, btnSaveInfo,
lblHistTitle, _lstHistory, _btnClearHistory,
lblStatsTitle, _lblAvgWait, _lblMaxWaitSeen, _lblMinWaitSeen, _lblTotalSamples
})
For Each b In _btnQuickSet
_panelDetail.Controls.Add(b)
Next
End Sub
Private Function CreateStatLabel(text As String, x As Integer, y As Integer) As Label
Return New Label With {
.Text = text,
.Location = New Point(x, y),
.Size = New Size(180, 18),
.Font = New Font("Segoe UI", 8.5F),
.ForeColor = Color.FromArgb(150, 175, 210)
}
End Function
Private Function CreateMgmtButton(text As String, bgColor As Color, x As Integer, y As Integer) As Button
Dim btn = New Button With {
.Text = text,
.Location = New Point(x, y),
.Size = New Size(95, 30),
.FlatStyle = FlatStyle.Flat,
.BackColor = bgColor,
.ForeColor = Color.White,
.Font = New Font("Segoe UI", 8.5F, FontStyle.Bold),
.Cursor = Cursors.Hand,
.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
}
btn.FlatAppearance.BorderColor = Color.FromArgb(70, 85, 120)
Return btn
End Function
' ─── Caricamento dati ─────────────────────────────────────
Private Sub LoadQueueList()
_lstQueues.Items.Clear()
For Each q In AppState.Instance.Config.Queues
AddQueueToList(q)
Next
End Sub
Private Sub AddQueueToList(q As QueueModel)
Dim item = New ListViewItem(q.Name)
item.SubItems.Add(q.WaitTimeFormatted)
item.SubItems.Add(q.Status.ToString())
item.Tag = q.Id
' Colore per stato
Select Case q.Status
Case QueueStatus.Normal : item.ForeColor = Color.FromArgb(100, 220, 130)
Case QueueStatus.Warning : item.ForeColor = Color.FromArgb(255, 180, 60)
Case QueueStatus.Critical : item.ForeColor = Color.FromArgb(255, 90, 90)
Case QueueStatus.Offline : item.ForeColor = Color.FromArgb(100, 110, 130)
End Select
_lstQueues.Items.Add(item)
End Sub
''' <summary>Seleziona una coda nella lista per ID</summary>
Public Sub SelectQueue(queueId As String)
For Each item As ListViewItem In _lstQueues.Items
If item.Tag?.ToString() = queueId Then
item.Selected = True
item.EnsureVisible()
Return
End If
Next
End Sub
Private Sub LoadQueueDetail(q As QueueModel)
_selectedQueue = q
_lblQueueName.Text = q.Name
_lblQueueStatus.Text = $"Stato: {q.Status} | Attesa corrente: {q.WaitTimeFormatted} | Aggiornato: {q.LastUpdated:HH:mm:ss}"
_nudWaitTime.Value = Math.Min(1440, CDec(q.CurrentWaitTime))
_sliderWait.Maximum = CInt(Math.Min(120, q.MaxWaitTime))
_sliderWait.Value = Math.Min(_sliderWait.Maximum, CInt(q.CurrentWaitTime))
_lblCurrentWait.Text = $"Valore corrente: {q.WaitTimeFormatted} (soglia warn: {q.WarningThreshold}m | critica: {q.CriticalThreshold}m)"
_txtQueueName.Text = q.Name
_txtDescription.Text = q.Description
_chkActive.Checked = q.IsActive
' Mini gauge
_panelMini.Controls.Clear()
Dim gc = AppState.Instance.Config.GetGaugeConfig(q.Id)
Dim miniG = New GaugeControl(q, gc) With {.Dock = DockStyle.Fill}
_panelMini.Controls.Add(miniG)
RefreshHistory()
RefreshStats()
End Sub
Private Sub RefreshHistory()
_lstHistory.Items.Clear()
If _selectedQueue Is Nothing Then Return
' Mostra ultimi 20 campioni (più recenti prima)
Dim items = _selectedQueue.History.AsEnumerable().Reverse().Take(20)
For Each entry In items
Dim itm = New ListViewItem(entry.Timestamp.ToString("dd/MM HH:mm:ss"))
itm.SubItems.Add(entry.WaitTime.ToString("F1"))
Dim status = If(entry.WaitTime >= _selectedQueue.CriticalThreshold, "Critico",
If(entry.WaitTime >= _selectedQueue.WarningThreshold, "Attenzione", "Normale"))
itm.SubItems.Add(status)
Select Case status
Case "Critico" : itm.ForeColor = Color.FromArgb(255, 90, 90)
Case "Attenzione" : itm.ForeColor = Color.FromArgb(255, 180, 60)
Case Else : itm.ForeColor = Color.FromArgb(100, 220, 130)
End Select
_lstHistory.Items.Add(itm)
Next
End Sub
Private Sub RefreshStats()
If _selectedQueue Is Nothing OrElse _selectedQueue.History.Count = 0 Then
_lblAvgWait.Text = "Media: —"
_lblMaxWaitSeen.Text = "Massimo: —"
_lblMinWaitSeen.Text = "Minimo: —"
_lblTotalSamples.Text = "Campioni: 0"
Return
End If
Dim hist = _selectedQueue.History
Dim avg = hist.Average(Function(h) h.WaitTime)
Dim max = hist.Max(Function(h) h.WaitTime)
Dim min = hist.Min(Function(h) h.WaitTime)
_lblAvgWait.Text = $"Media: {avg:F1} min"
_lblMaxWaitSeen.Text = $"Massimo: {max:F1} min"
_lblMinWaitSeen.Text = $"Minimo: {min:F1} min"
_lblTotalSamples.Text = $"Campioni: {hist.Count}"
End Sub
' ─── Gestione eventi ──────────────────────────────────────
Private Sub OnQueueSelected(sender As Object, e As EventArgs)
If _lstQueues.SelectedItems.Count = 0 Then Return
Dim queueId = _lstQueues.SelectedItems(0).Tag?.ToString()
Dim q = AppState.Instance.Config.Queues.FirstOrDefault(Function(x) x.Id = queueId)
If q IsNot Nothing Then LoadQueueDetail(q)
End Sub
''' <summary>Applica il tempo di attesa impostato alla coda selezionata</summary>
Private Sub OnSetWaitClick(sender As Object, e As EventArgs)
If _selectedQueue Is Nothing Then
System.Windows.Forms.MessageBox.Show("Seleziona prima una coda dalla lista.", "Attenzione",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning)
Return
End If
Dim newWait = CDbl(_nudWaitTime.Value)
_selectedQueue.CurrentWaitTime = newWait
' Aggiorna UI locale
_lblCurrentWait.Text = $"Valore corrente: {_selectedQueue.WaitTimeFormatted} (warn: {_selectedQueue.WarningThreshold}m | crit: {_selectedQueue.CriticalThreshold}m)"
_lblQueueStatus.Text = $"Stato: {_selectedQueue.Status} | Attesa: {_selectedQueue.WaitTimeFormatted} | Aggiornato: {DateTime.Now:HH:mm:ss}"
' Aggiorna mini gauge
_panelMini.Controls.OfType(Of GaugeControl).FirstOrDefault()?.RefreshData()
' Aggiorna voce nella lista
For Each item As ListViewItem In _lstQueues.Items
If item.Tag?.ToString() = _selectedQueue.Id Then
item.SubItems(1).Text = _selectedQueue.WaitTimeFormatted
item.SubItems(2).Text = _selectedQueue.Status.ToString()
Exit For
End If
Next
RefreshHistory()
RefreshStats()
' Propaga aggiornamento alla dashboard
AppState.Instance.SaveAndNotify()
End Sub
''' <summary>Salva le informazioni base della coda (nome, descrizione, attiva)</summary>
Private Sub OnSaveInfoClick(sender As Object, e As EventArgs)
If _selectedQueue Is Nothing Then Return
_selectedQueue.Name = _txtQueueName.Text.Trim()
_selectedQueue.Description = _txtDescription.Text.Trim()
_selectedQueue.IsActive = _chkActive.Checked
' Aggiorna lista
For Each item As ListViewItem In _lstQueues.Items
If item.Tag?.ToString() = _selectedQueue.Id Then
item.Text = _selectedQueue.Name
Exit For
End If
Next
_lblQueueName.Text = _selectedQueue.Name
AppState.Instance.SaveAndNotify()
System.Windows.Forms.MessageBox.Show("Informazioni coda salvate.", "✓ Salvato",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
End Sub
''' <summary>Aggiunge una nuova coda vuota</summary>
Private Sub OnAddQueueClick(sender As Object, e As EventArgs)
Dim nameDlg = New InputDialog("Nuova Coda", "Nome della nuova coda:", "Nuova Coda")
If nameDlg.ShowDialog() = DialogResult.OK AndAlso Not String.IsNullOrWhiteSpace(nameDlg.InputValue) Then
Dim newQ = New QueueModel With {
.Name = nameDlg.InputValue.Trim(),
.Description = "",
.CurrentWaitTime = 0,
.MaxWaitTime = 60,
.WarningThreshold = 20,
.CriticalThreshold = 40,
.IsActive = True
}
AppState.Instance.Config.Queues.Add(newQ)
AppState.Instance.Config.GaugeConfigs(newQ.Id) = New GaugeConfig With {.QueueId = newQ.Id}
LoadQueueList()
AppState.Instance.SaveAndNotify()
End If
End Sub
''' <summary>Rimuove la coda selezionata</summary>
Private Sub OnRemoveQueueClick(sender As Object, e As EventArgs)
If _selectedQueue Is Nothing Then Return
Dim res = System.Windows.Forms.MessageBox.Show(
$"Eliminare la coda '{_selectedQueue.Name}'?",
"Conferma eliminazione",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning)
If res = DialogResult.Yes Then
AppState.Instance.Config.Queues.Remove(_selectedQueue)
AppState.Instance.Config.GaugeConfigs.Remove(_selectedQueue.Id)
_selectedQueue = Nothing
LoadQueueList()
AppState.Instance.SaveAndNotify()
End If
End Sub
''' <summary>Attiva/disattiva il monitoraggio della coda selezionata</summary>
Private Sub OnToggleActiveClick(sender As Object, e As EventArgs)
If _selectedQueue Is Nothing Then Return
_selectedQueue.IsActive = Not _selectedQueue.IsActive
_chkActive.Checked = _selectedQueue.IsActive
LoadQueueList()
AppState.Instance.SaveAndNotify()
End Sub
End Class
' ═══════════════════════════════════════════════════════════
' DIALOG INPUT NOME
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Dialog semplice per l'inserimento di un testo (es. nome coda)
''' </summary>
Public Class InputDialog
Inherits Form
Private _inputValue As String = ""
''' <summary>Valore inserito dall'utente</summary>
Public ReadOnly Property InputValue As String
Get
Return _inputValue
End Get
End Property
Public Sub New(title As String, prompt As String, defaultValue As String)
Me.Text = title
Me.Size = New Size(380, 150)
Me.BackColor = Color.FromArgb(30, 36, 52)
Me.ForeColor = Color.White
Me.FormBorderStyle = FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.StartPosition = FormStartPosition.CenterParent
Me.Font = New Font("Segoe UI", 9.5F)
Dim lbl = New Label With {.Text = prompt, .Location = New Point(12, 12), .AutoSize = True, .ForeColor = Color.FromArgb(180, 200, 225)}
Dim txt = New TextBox With {
.Location = New Point(12, 36),
.Size = New Size(340, 26),
.Text = defaultValue,
.BackColor = Color.FromArgb(44, 52, 72),
.ForeColor = Color.White,
.BorderStyle = BorderStyle.FixedSingle
}
Dim btnOk = New Button With {
.Text = "OK",
.Location = New Point(180, 72),
.Size = New Size(80, 30),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(30, 100, 60),
.ForeColor = Color.White,
.DialogResult = DialogResult.OK
}
Dim btnCancel = New Button With {
.Text = "Annulla",
.Location = New Point(272, 72),
.Size = New Size(80, 30),
.FlatStyle = FlatStyle.Flat,
.BackColor = Color.FromArgb(70, 40, 40),
.ForeColor = Color.White,
.DialogResult = DialogResult.Cancel
}
AddHandler btnOk.Click, Sub(s, e)
_inputValue = txt.Text
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
Me.Controls.AddRange({lbl, txt, btnOk, btnCancel})
Me.AcceptButton = btnOk
Me.CancelButton = btnCancel
End Sub
End Class
'End Namespace