-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGravarAtributosForm.cs
More file actions
1115 lines (971 loc) · 44.8 KB
/
Copy pathGravarAtributosForm.cs
File metadata and controls
1115 lines (971 loc) · 44.8 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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace AutisAnalytics.NavisworksAtributos
{
/// <summary>
/// Formulário moderno para gravação de atributos customizados.
///
/// Layout:
/// ┌──────────────────┬───────────────────────────────────┐
/// │ Header (info) │ │
/// ├──────────────────┼───────────────────────────────────┤
/// │ Pesquisar... │ Categoria: [___________] │
/// │ ┌────────────┐ │ ┌───────────────────────────┐ │
/// │ │ Categorias │ │ │ Nome │ Valor │ Tipo │ ✕ │ │
/// │ │ existentes │ │ │ │ │ │ │ │
/// │ │ (clique p/ │ │ └───────────────────────────┘ │
/// │ │ importar) │ │ [+ Adicionar] [- Remover] │
/// │ └────────────┘ │ │
/// │ │ [Cancelar] [Gravar] │
/// └──────────────────┴───────────────────────────────────┘
/// </summary>
public class GravarAtributosForm : Form
{
private const string CATEGORIA_FIXA = AutisSchema.CategoriaPrincipal;
public class SetResumo
{
public string Nome { get; }
public int ItensSelecionados { get; }
public SetResumo(string nome, int itensSelecionados)
{
Nome = nome;
ItensSelecionados = itensSelecionados;
}
}
// ── Cores do tema ──────────────────────────────────────────────
private static readonly Color CorFundo = Color.FromArgb(245, 246, 250);
private static readonly Color CorPainel = Color.White;
private static readonly Color CorHeader = Color.FromArgb(44, 62, 80);
private static readonly Color CorAccent = Color.FromArgb(0, 120, 215);
private static readonly Color CorAccentHover = Color.FromArgb(0, 100, 190);
private static readonly Color CorTexto = Color.FromArgb(50, 50, 50);
private static readonly Color CorTextoClaro = Color.FromArgb(130, 130, 130);
private static readonly Color CorBorda = Color.FromArgb(220, 222, 228);
private static readonly Color CorGridHeader = Color.FromArgb(248, 249, 252);
private static readonly Color CorGridAlt = Color.FromArgb(250, 251, 254);
private static readonly Color CorPerigo = Color.FromArgb(220, 53, 69);
private static readonly Color CorOk = Color.FromArgb(0, 150, 70);
private static readonly Font FonteNormal = new Font("Segoe UI", 9.5f);
private static readonly Font FonteSemibold = new Font("Segoe UI Semibold", 9.5f);
private static readonly Font FonteTitulo = new Font("Segoe UI Semibold", 11f);
private static readonly Font FonteHeader = new Font("Segoe UI", 13f, FontStyle.Bold);
private static readonly Font FontePequena = new Font("Segoe UI", 8.5f);
private static readonly Font FonteGrid = new Font("Segoe UI", 9f);
// ── Controles ──────────────────────────────────────────────────
private Panel pnlHeader;
private Panel pnlEsquerdo;
private Panel pnlDireito;
private TextBox txtPesquisa;
private ListView lvCategorias;
private TextBox txtCategoria;
private DataGridView grid;
private Label lblSubHeader;
private Label lblResumoSets;
private Label lblSelecaoSets;
// ── Dados ──────────────────────────────────────────────────────
private readonly List<SetResumo> _setsExistentes;
private readonly HashSet<string> _setsSelecionados;
private readonly int _qtdSelecionados;
private bool _atualizandoListaSets;
public string NomeCategoria { get; private set; }
public List<AtributoCustom> Atributos { get; private set; }
public List<string> NomesSetsSelecionados { get; private set; }
public bool SolicitarExclusao { get; private set; }
private string _nomeSetDetectado;
public GravarAtributosForm(int qtdSelecionados, List<SetResumo> setsExistentes,
string nomeSetDetectado = null,
IEnumerable<string> setsInicialmenteSelecionados = null)
{
Atributos = new List<AtributoCustom>();
_setsExistentes = setsExistentes ?? new List<SetResumo>();
var selecaoInicial = (setsInicialmenteSelecionados ?? Enumerable.Empty<string>())
.Where(nome => !string.IsNullOrWhiteSpace(nome))
.Select(nome => nome.Trim())
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
_setsSelecionados = selecaoInicial.Count > 0
? new HashSet<string>(selecaoInicial, StringComparer.OrdinalIgnoreCase)
: new HashSet<string>(
_setsExistentes
.Where(s => !string.IsNullOrWhiteSpace(s?.Nome))
.Select(s => s.Nome),
StringComparer.OrdinalIgnoreCase);
NomesSetsSelecionados = new List<string>();
_qtdSelecionados = qtdSelecionados;
_nomeSetDetectado = nomeSetDetectado;
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
Montar(qtdSelecionados);
}
// ────────────────────────────────────────────────────────────────
// MONTAGEM DO LAYOUT
// ────────────────────────────────────────────────────────────────
private void Montar(int qtdSelecionados)
{
Text = "Autis Analytics";
Size = new Size(920, 600);
MinimumSize = new Size(780, 500);
StartPosition = FormStartPosition.CenterScreen;
BackColor = CorFundo;
Font = FonteNormal;
// ── Header ─────────────────────────────────────────────────
pnlHeader = new Panel
{
Dock = DockStyle.Top,
Height = 64,
BackColor = CorHeader,
Padding = new Padding(20, 0, 20, 0)
};
var lblTitulo = new Label
{
Text = "Write Properties",
Font = FonteHeader,
ForeColor = Color.White,
AutoSize = true,
Location = new Point(20, 8)
};
pnlHeader.Controls.Add(lblTitulo);
lblSubHeader = new Label
{
Font = FonteNormal,
ForeColor = Color.FromArgb(180, 200, 220),
AutoSize = true,
Location = new Point(20, 38)
};
pnlHeader.Controls.Add(lblSubHeader);
AtualizarResumoSetsUI();
Controls.Add(pnlHeader);
// ── Container principal ────────────────────────────────────
var pnlBody = new Panel
{
Dock = DockStyle.Fill,
Padding = new Padding(16, 12, 16, 12)
};
Controls.Add(pnlBody);
pnlBody.BringToFront();
// ── Splitter esquerdo / direito ────────────────────────────
var splitter = new SplitContainer
{
Dock = DockStyle.Fill,
SplitterWidth = 8,
BackColor = CorFundo,
BorderStyle = BorderStyle.None
};
splitter.Panel1.BackColor = CorFundo;
splitter.Panel2.BackColor = CorFundo;
pnlBody.Controls.Add(splitter);
// Centralizar 50/50 após o layout estar pronto
splitter.SplitterDistance = splitter.Width / 2;
pnlBody.Resize += (s, e) => splitter.SplitterDistance = splitter.Width / 2;
MontarPainelEsquerdo(splitter.Panel1);
MontarPainelDireito(splitter.Panel2);
// ── Footer ─────────────────────────────────────────────────
var pnlFooter = new Panel
{
Dock = DockStyle.Bottom,
Height = 56,
BackColor = CorFundo,
Padding = new Padding(16, 8, 16, 8)
};
var btnCancelar = CriarBotao("Cancel", CorPainel, CorTexto, CorBorda);
btnCancelar.DialogResult = DialogResult.Cancel;
btnCancelar.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
btnCancelar.Location = new Point(pnlFooter.Width - 342, 10);
pnlFooter.Controls.Add(btnCancelar);
var btnExcluir = CriarBotao("Delete Created", CorPerigo, Color.White, CorPerigo);
btnExcluir.Font = FonteSemibold;
btnExcluir.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
btnExcluir.Location = new Point(pnlFooter.Width - 230, 10);
btnExcluir.Click += BtnExcluir_Click;
pnlFooter.Controls.Add(btnExcluir);
var btnGravar = CriarBotao("Save", CorAccent, Color.White, CorAccent);
btnGravar.Font = FonteSemibold;
btnGravar.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
btnGravar.Location = new Point(pnlFooter.Width - 118, 10);
btnGravar.Click += BtnGravar_Click;
pnlFooter.Controls.Add(btnGravar);
// Reposicionar ao redimensionar
pnlFooter.Resize += (s, e) =>
{
btnGravar.Location = new Point(pnlFooter.Width - 118, 10);
btnExcluir.Location = new Point(pnlFooter.Width - 230, 10);
btnCancelar.Location = new Point(pnlFooter.Width - 342, 10);
};
Controls.Add(pnlFooter);
pnlFooter.BringToFront();
AcceptButton = btnGravar;
CancelButton = btnCancelar;
}
// ────────────────────────────────────────────────────────────────
// PAINEL ESQUERDO — Categoria fixa + Sets detectados
// ────────────────────────────────────────────────────────────────
private TextBox txtNovaCategoria;
private void MontarPainelEsquerdo(Control parent)
{
pnlEsquerdo = CriarPainelCard();
pnlEsquerdo.Dock = DockStyle.Fill;
parent.Padding = new Padding(0, 0, 4, 0);
parent.Controls.Add(pnlEsquerdo);
// ── Seção: Criar Nova Categoria ──────────────────────────────
var lblCriar = new Label
{
Text = "Storage Category",
Font = FonteTitulo,
ForeColor = CorTexto,
Dock = DockStyle.Top,
Height = 28,
Padding = new Padding(0, 2, 0, 0)
};
pnlEsquerdo.Controls.Add(lblCriar);
var lblDicaCriar = new Label
{
Text = "All created attributes are stored under this fixed category",
Font = FontePequena,
ForeColor = CorTextoClaro,
Dock = DockStyle.Top,
Height = 18
};
pnlEsquerdo.Controls.Add(lblDicaCriar);
lblDicaCriar.BringToFront();
// Campo + botão criar
var pnlCriar = new Panel
{
Dock = DockStyle.Top,
Height = 36,
Padding = new Padding(0, 4, 0, 4)
};
var btnCriar = CriarBotaoPequeno("Reset", CorAccent);
btnCriar.Size = new Size(70, 26);
btnCriar.Dock = DockStyle.Right;
btnCriar.Click += BtnCriarCategoria_Click;
pnlCriar.Controls.Add(btnCriar);
txtNovaCategoria = new TextBox
{
Dock = DockStyle.Fill,
Font = FonteNormal,
ForeColor = CorTexto,
Text = CATEGORIA_FIXA,
BorderStyle = BorderStyle.FixedSingle,
ReadOnly = true
};
pnlCriar.Controls.Add(txtNovaCategoria);
pnlEsquerdo.Controls.Add(pnlCriar);
pnlCriar.BringToFront();
// Separador visual
var separador = new Panel
{
Dock = DockStyle.Top,
Height = 1,
BackColor = CorBorda,
Margin = new Padding(0, 6, 0, 6)
};
pnlEsquerdo.Controls.Add(separador);
separador.BringToFront();
// Espaçador
var espaco = new Panel { Dock = DockStyle.Top, Height = 8 };
pnlEsquerdo.Controls.Add(espaco);
espaco.BringToFront();
// ── Seção: Sets Detectados ──────────────────────────────────
var lblExistentes = new Label
{
Text = "Detected Sets",
Font = FonteSemibold,
ForeColor = CorTexto,
Dock = DockStyle.Top,
Height = 24
};
pnlEsquerdo.Controls.Add(lblExistentes);
lblExistentes.BringToFront();
var lblDica = new Label
{
Text = $"Check the set names you want to include in the fixed {AutisSchema.PropriedadeSets} field",
Font = FontePequena,
ForeColor = CorTextoClaro,
Dock = DockStyle.Top,
Height = 18
};
pnlEsquerdo.Controls.Add(lblDica);
lblDica.BringToFront();
var pnlResumoSets = new Panel
{
Dock = DockStyle.Top,
Height = 54,
BackColor = Color.FromArgb(238, 245, 255),
Padding = new Padding(10, 6, 10, 6)
};
pnlResumoSets.Paint += (s, e) =>
{
var rect = new Rectangle(0, 0, pnlResumoSets.Width - 1, pnlResumoSets.Height - 1);
using (var pen = new Pen(Color.FromArgb(206, 223, 248)))
e.Graphics.DrawRectangle(pen, rect);
};
lblResumoSets = new Label
{
Dock = DockStyle.Fill,
Font = FontePequena,
ForeColor = Color.FromArgb(36, 76, 126),
Text = ObterTextoResumoSets()
};
pnlResumoSets.Controls.Add(lblResumoSets);
pnlEsquerdo.Controls.Add(pnlResumoSets);
pnlResumoSets.BringToFront();
var pnlSelecaoSets = new Panel
{
Dock = DockStyle.Top,
Height = 34,
Padding = new Padding(0, 4, 0, 2)
};
var btnLimparSets = CriarBotaoPequeno("Clear", CorTextoClaro);
btnLimparSets.Size = new Size(66, 26);
btnLimparSets.Dock = DockStyle.Right;
btnLimparSets.Click += (s, e) => DefinirSelecaoSets(false);
pnlSelecaoSets.Controls.Add(btnLimparSets);
var btnSelecionarTodos = CriarBotaoPequeno("Select All", CorAccent);
btnSelecionarTodos.Size = new Size(84, 26);
btnSelecionarTodos.Dock = DockStyle.Right;
btnSelecionarTodos.Margin = new Padding(0, 0, 8, 0);
btnSelecionarTodos.Click += (s, e) => DefinirSelecaoSets(true);
pnlSelecaoSets.Controls.Add(btnSelecionarTodos);
lblSelecaoSets = new Label
{
Dock = DockStyle.Fill,
Font = FontePequena,
ForeColor = CorTextoClaro,
TextAlign = ContentAlignment.MiddleLeft
};
pnlSelecaoSets.Controls.Add(lblSelecaoSets);
pnlEsquerdo.Controls.Add(pnlSelecaoSets);
pnlSelecaoSets.BringToFront();
// Pesquisa
var pnlPesquisa = new Panel
{
Dock = DockStyle.Top,
Height = 36,
Padding = new Padding(0, 4, 0, 4)
};
txtPesquisa = new TextBox
{
Dock = DockStyle.Fill,
Font = FonteNormal,
ForeColor = CorTextoClaro,
Text = "Search sets...",
BorderStyle = BorderStyle.FixedSingle
};
txtPesquisa.GotFocus += (s, e) =>
{
if (txtPesquisa.ForeColor == CorTextoClaro)
{
txtPesquisa.Text = "";
txtPesquisa.ForeColor = CorTexto;
}
};
txtPesquisa.LostFocus += (s, e) =>
{
if (string.IsNullOrWhiteSpace(txtPesquisa.Text))
{
txtPesquisa.Text = "Search sets...";
txtPesquisa.ForeColor = CorTextoClaro;
}
};
txtPesquisa.TextChanged += (s, e) => FiltrarSets();
pnlPesquisa.Controls.Add(txtPesquisa);
pnlEsquerdo.Controls.Add(pnlPesquisa);
pnlPesquisa.BringToFront();
// Lista de categorias
lvCategorias = new ListView
{
Dock = DockStyle.Fill,
View = View.Details,
FullRowSelect = true,
CheckBoxes = true,
HeaderStyle = ColumnHeaderStyle.Nonclickable,
BorderStyle = BorderStyle.None,
Font = FonteGrid,
GridLines = false,
MultiSelect = false,
ShowItemToolTips = true,
HotTracking = true,
Activation = ItemActivation.OneClick
};
lvCategorias.Columns.Add("Set", 220);
lvCategorias.Columns.Add("Items", 60, HorizontalAlignment.Center);
lvCategorias.ItemChecked += LvCategorias_ItemChecked;
pnlEsquerdo.Controls.Add(lvCategorias);
lvCategorias.BringToFront();
PreencherSets();
}
// ── Criar nova categoria ─────────────────────────────────────────
private void BtnCriarCategoria_Click(object sender, EventArgs e)
{
// Setar categoria no painel direito e limpar grid para novas propriedades
AplicarCategoriaFixa();
SolicitarExclusao = false;
grid.Rows.Clear();
AdicionarLinhaGrid("", "", "string");
// Focar no grid para o usuário começar a preencher
grid.Focus();
if (grid.Rows.Count > 0)
grid.CurrentCell = grid.Rows[0].Cells["Nome"];
}
// ── Preencher / filtrar lista ────────────────────────────────────
private void PreencherSets()
{
_atualizandoListaSets = true;
lvCategorias.Items.Clear();
var filtro = "";
if (txtPesquisa != null && txtPesquisa.ForeColor != CorTextoClaro)
filtro = txtPesquisa.Text.Trim().ToLower();
foreach (var setInfo in _setsExistentes.OrderBy(s => s.Nome))
{
if (!string.IsNullOrEmpty(filtro) &&
!setInfo.Nome.ToLower().Contains(filtro))
continue;
var item = new ListViewItem(setInfo.Nome);
item.SubItems.Add(setInfo.ItensSelecionados.ToString());
item.Tag = setInfo.Nome;
item.ToolTipText = $"{setInfo.ItensSelecionados} selected item(s) will receive this set name.";
item.Checked = _setsSelecionados.Contains(setInfo.Nome);
lvCategorias.Items.Add(item);
}
// Auto-resize
if (lvCategorias.Columns.Count >= 2)
{
lvCategorias.Columns[0].Width = -2;
lvCategorias.Columns[1].Width = 56;
}
_atualizandoListaSets = false;
AtualizarResumoSetsUI();
}
private void FiltrarSets()
{
if (txtPesquisa.ForeColor == CorTextoClaro) return;
PreencherSets();
}
private void LvCategorias_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (_atualizandoListaSets || !(e.Item.Tag is string nomeSet)) return;
if (e.Item.Checked)
_setsSelecionados.Add(nomeSet);
else
_setsSelecionados.Remove(nomeSet);
AtualizarResumoSetsUI();
}
private void DefinirSelecaoSets(bool selecionarTodos)
{
if (selecionarTodos)
{
_setsSelecionados.Clear();
foreach (var setInfo in _setsExistentes)
{
if (!string.IsNullOrWhiteSpace(setInfo?.Nome))
_setsSelecionados.Add(setInfo.Nome);
}
}
else
{
_setsSelecionados.Clear();
}
PreencherSets();
}
// ────────────────────────────────────────────────────────────────
// PAINEL DIREITO — Edição de atributos
// ────────────────────────────────────────────────────────────────
private void MontarPainelDireito(Control parent)
{
pnlDireito = CriarPainelCard();
pnlDireito.Dock = DockStyle.Fill;
parent.Padding = new Padding(4, 0, 0, 0);
parent.Controls.Add(pnlDireito);
// Título
var lblTitulo = new Label
{
Text = "Custom Attributes",
Font = FonteTitulo,
ForeColor = CorTexto,
Dock = DockStyle.Top,
Height = 30,
Padding = new Padding(0, 2, 0, 0)
};
pnlDireito.Controls.Add(lblTitulo);
// ── Linha da categoria ─────────────────────────────────────
var pnlCat = new Panel
{
Dock = DockStyle.Top,
Height = 32,
Padding = new Padding(0, 2, 0, 2)
};
var lblCat = new Label
{
Text = "Category:",
Font = FonteSemibold,
ForeColor = CorTexto,
AutoSize = true,
Location = new Point(0, 7)
};
pnlCat.Controls.Add(lblCat);
int catLabelW = TextRenderer.MeasureText("Category:", FonteSemibold).Width + 4;
txtCategoria = new TextBox
{
Text = CATEGORIA_FIXA,
Font = FonteNormal,
BorderStyle = BorderStyle.FixedSingle,
ReadOnly = true,
BackColor = CorGridAlt,
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
Location = new Point(catLabelW, 3),
Size = new Size(pnlCat.Width - catLabelW - 2, 24)
};
pnlCat.Controls.Add(txtCategoria);
pnlCat.Resize += (s, e) => txtCategoria.Width = pnlCat.Width - catLabelW - 2;
pnlDireito.Controls.Add(pnlCat);
pnlCat.BringToFront();
var pnlAjuda = new Panel
{
Dock = DockStyle.Top,
Height = 50,
BackColor = Color.FromArgb(242, 247, 252),
Padding = new Padding(12, 8, 12, 8)
};
pnlAjuda.Paint += (s, e) =>
{
var rect = new Rectangle(0, 0, pnlAjuda.Width - 1, pnlAjuda.Height - 1);
using (var pen = new Pen(Color.FromArgb(220, 230, 240)))
e.Graphics.DrawRectangle(pen, rect);
};
var lblAjuda = new Label
{
Dock = DockStyle.Fill,
Font = FontePequena,
ForeColor = Color.FromArgb(86, 96, 106),
Text = $"Checked set names are saved in the {AutisSchema.PropriedadeSets} field under {CATEGORIA_FIXA}. Use the table below only for extra custom attributes."
};
pnlAjuda.Controls.Add(lblAjuda);
pnlDireito.Controls.Add(pnlAjuda);
pnlAjuda.BringToFront();
// ── Botões acima do grid ───────────────────────────────────
var pnlBtns = new Panel
{
Dock = DockStyle.Top,
Height = 38,
Padding = new Padding(0, 2, 0, 4)
};
var btnAdd = CriarBotaoPequeno("+ Add Row", CorAccent);
btnAdd.Size = new Size(104, 28);
btnAdd.Location = new Point(0, 3);
btnAdd.Click += (s, e) => AdicionarLinhaGrid("", "", "string");
pnlBtns.Controls.Add(btnAdd);
var btnRemove = CriarBotaoPequeno("- Remove", CorPerigo);
btnRemove.Size = new Size(92, 28);
btnRemove.Location = new Point(110, 3);
btnRemove.Click += (s, e) =>
{
if (grid.SelectedRows.Count > 0 && grid.Rows.Count > 0)
grid.Rows.RemoveAt(grid.SelectedRows[0].Index);
};
pnlBtns.Controls.Add(btnRemove);
var btnLimpar = CriarBotaoPequeno("Clear Grid", CorTextoClaro);
btnLimpar.Size = new Size(82, 28);
btnLimpar.Location = new Point(208, 3);
btnLimpar.Click += (s, e) => grid.Rows.Clear();
pnlBtns.Controls.Add(btnLimpar);
var corExport = Color.FromArgb(108, 117, 125);
var btnExportar = CriarBotaoPequeno("Export", corExport);
btnExportar.Size = new Size(80, 28);
btnExportar.Location = new Point(296, 3);
btnExportar.Click += BtnExportar_Click;
pnlBtns.Controls.Add(btnExportar);
var btnImportar = CriarBotaoPequeno("Import", corExport);
btnImportar.Size = new Size(80, 28);
btnImportar.Location = new Point(382, 3);
btnImportar.Click += BtnImportar_Click;
pnlBtns.Controls.Add(btnImportar);
pnlDireito.Controls.Add(pnlBtns);
pnlBtns.BringToFront();
// ── Grid ───────────────────────────────────────────────────
grid = new DataGridView
{
Dock = DockStyle.Fill,
Font = FonteGrid,
AllowUserToAddRows = false,
AllowUserToDeleteRows = false,
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
RowHeadersVisible = false,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
BackgroundColor = CorPainel,
GridColor = CorBorda,
BorderStyle = BorderStyle.None,
CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal,
ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None,
EnableHeadersVisualStyles = false,
RowTemplate = { Height = 32 },
ColumnHeadersHeight = 36,
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
};
// Estilo do header
grid.ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle
{
BackColor = CorGridHeader,
ForeColor = CorTexto,
Font = FonteSemibold,
Alignment = DataGridViewContentAlignment.MiddleLeft,
Padding = new Padding(8, 0, 0, 0),
SelectionBackColor = CorGridHeader,
SelectionForeColor = CorTexto
};
// Estilo das células
grid.DefaultCellStyle = new DataGridViewCellStyle
{
BackColor = CorPainel,
ForeColor = CorTexto,
SelectionBackColor = Color.FromArgb(230, 240, 255),
SelectionForeColor = CorTexto,
Padding = new Padding(8, 0, 0, 0)
};
grid.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle
{
BackColor = CorGridAlt,
ForeColor = CorTexto,
SelectionBackColor = Color.FromArgb(230, 240, 255),
SelectionForeColor = CorTexto,
Padding = new Padding(8, 0, 0, 0)
};
// Colunas
grid.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "Nome",
HeaderText = "Name",
FillWeight = 35
});
grid.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "Valor",
HeaderText = "Value",
FillWeight = 40
});
var colTipo = new DataGridViewComboBoxColumn
{
Name = "Tipo",
HeaderText = "Type",
FillWeight = 25,
FlatStyle = FlatStyle.Flat,
DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
};
colTipo.Items.AddRange("string", "double", "int", "bool");
grid.Columns.Add(colTipo);
pnlDireito.Controls.Add(grid);
grid.BringToFront();
// Primeira linha inicia vazia para evitar preenchimento implícito
AdicionarLinhaGrid("", "", "string");
}
// ────────────────────────────────────────────────────────────────
// HELPERS
// ────────────────────────────────────────────────────────────────
private void AdicionarLinhaGrid(string nome, string valor, string tipo)
{
int idx = grid.Rows.Add();
grid.Rows[idx].Cells["Nome"].Value = nome;
grid.Rows[idx].Cells["Valor"].Value = valor;
grid.Rows[idx].Cells["Tipo"].Value = tipo;
}
private void AplicarCategoriaFixa()
{
if (txtCategoria != null)
txtCategoria.Text = CATEGORIA_FIXA;
}
private string ObterTextoResumoSets()
{
if (_setsExistentes.Count == 0)
return "No sets were detected for the current selection. You can still save extra custom attributes below.";
return $"{_setsSelecionados.Count} of {_setsExistentes.Count} detected set name(s) selected for the fixed {AutisSchema.PropriedadeSets} field.";
}
private string ObterTextoSubHeader()
{
int totalSetsDetectados = _setsExistentes.Count;
int totalSetsSelecionados = _setsSelecionados.Count;
if (totalSetsDetectados > 0 && !string.IsNullOrWhiteSpace(_nomeSetDetectado))
return $"{_qtdSelecionados} element(s) — {totalSetsSelecionados}/{totalSetsDetectados} set name(s) selected — First: {_nomeSetDetectado}";
if (totalSetsDetectados > 0)
return $"{_qtdSelecionados} element(s) — {totalSetsSelecionados}/{totalSetsDetectados} set name(s) selected";
return $"{_qtdSelecionados} element(s) selected";
}
private void AtualizarResumoSetsUI()
{
if (lblSubHeader != null)
lblSubHeader.Text = ObterTextoSubHeader();
if (lblResumoSets != null)
lblResumoSets.Text = ObterTextoResumoSets();
if (lblSelecaoSets != null)
lblSelecaoSets.Text = $"{_setsSelecionados.Count} selected";
}
private Panel CriarPainelCard()
{
var pnl = new Panel
{
BackColor = CorPainel,
Padding = new Padding(14)
};
pnl.Paint += (s, e) =>
{
var rect = new Rectangle(0, 0, pnl.Width - 1, pnl.Height - 1);
using (var pen = new Pen(CorBorda))
using (var path = CriarRoundedRect(rect, 6))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawPath(pen, path);
}
};
return pnl;
}
private Button CriarBotao(string texto, Color fundo, Color textoColor, Color borda)
{
var btn = new Button
{
Text = texto,
Size = new Size(105, 36),
Font = FonteNormal,
BackColor = fundo,
ForeColor = textoColor,
FlatStyle = FlatStyle.Flat,
Cursor = Cursors.Hand
};
btn.FlatAppearance.BorderColor = borda;
btn.FlatAppearance.BorderSize = 1;
btn.FlatAppearance.MouseOverBackColor = fundo == CorAccent
? CorAccentHover
: fundo == CorPerigo
? Color.FromArgb(190, 40, 55)
: Color.FromArgb(240, 240, 245);
return btn;
}
private Button CriarBotaoPequeno(string texto, Color cor)
{
var btn = new Button
{
Text = texto,
Size = new Size(92, 26),
Font = FontePequena,
ForeColor = cor,
BackColor = CorPainel,
FlatStyle = FlatStyle.Flat,
Cursor = Cursors.Hand
};
btn.FlatAppearance.BorderColor = cor;
btn.FlatAppearance.BorderSize = 1;
btn.FlatAppearance.MouseOverBackColor = Color.FromArgb(245, 245, 250);
return btn;
}
private static GraphicsPath CriarRoundedRect(Rectangle rect, int raio)
{
var path = new GraphicsPath();
int d = raio * 2;
path.AddArc(rect.X, rect.Y, d, d, 180, 90);
path.AddArc(rect.Right - d, rect.Y, d, d, 270, 90);
path.AddArc(rect.Right - d, rect.Bottom - d, d, d, 0, 90);
path.AddArc(rect.X, rect.Bottom - d, d, d, 90, 90);
path.CloseFigure();
return path;
}
// ────────────────────────────────────────────────────────────────
// EXPORTAR / IMPORTAR
// ────────────────────────────────────────────────────────────────
private void BtnExportar_Click(object sender, EventArgs e)
{
if (grid.Rows.Count == 0)
{
MessageBox.Show("No attributes to export.",
"AWP Autis", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
using (var dlg = new SaveFileDialog
{
Filter = "CSV (*.csv)|*.csv|XML (*.xml)|*.xml",
Title = "Export Attributes",
DefaultExt = "csv"
})
{
if (dlg.ShowDialog() != DialogResult.OK) return;
if (dlg.FileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
ExportarXml(dlg.FileName);
else
ExportarCsv(dlg.FileName);
MessageBox.Show("Exported successfully!",
"AWP Autis", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void BtnImportar_Click(object sender, EventArgs e)
{
using (var dlg = new OpenFileDialog
{
Filter = "CSV (*.csv)|*.csv|XML (*.xml)|*.xml",
Title = "Import Attributes"
})
{
if (dlg.ShowDialog() != DialogResult.OK) return;
try
{
if (dlg.FileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
ImportarXml(dlg.FileName);
else
ImportarCsv(dlg.FileName);
MessageBox.Show($"Imported {grid.Rows.Count} attribute(s).",
"AWP Autis", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao importar: {ex.Message}",
"AWP Autis", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ExportarCsv(string path)
{
var sb = new StringBuilder();
sb.AppendLine("Categoria,Nome,Valor,Tipo");
var cat = CATEGORIA_FIXA;
for (int i = 0; i < grid.Rows.Count; i++)
{
var nome = Escapar(grid.Rows[i].Cells["Nome"].Value?.ToString() ?? "");
var valor = Escapar(grid.Rows[i].Cells["Valor"].Value?.ToString() ?? "");
var tipo = grid.Rows[i].Cells["Tipo"].Value?.ToString() ?? "string";
sb.AppendLine($"{Escapar(cat)},{nome},{valor},{tipo}");
}
File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
}
private void ExportarXml(string path)
{
var ds = new DataSet("AutisAtributos");
var dt = new DataTable("Atributo");
dt.Columns.Add("Categoria", typeof(string));
dt.Columns.Add("Nome", typeof(string));
dt.Columns.Add("Valor", typeof(string));
dt.Columns.Add("Tipo", typeof(string));
var cat = CATEGORIA_FIXA;
for (int i = 0; i < grid.Rows.Count; i++)
{
var row = dt.NewRow();
row["Categoria"] = cat;
row["Nome"] = grid.Rows[i].Cells["Nome"].Value?.ToString() ?? "";
row["Valor"] = grid.Rows[i].Cells["Valor"].Value?.ToString() ?? "";
row["Tipo"] = grid.Rows[i].Cells["Tipo"].Value?.ToString() ?? "string";
dt.Rows.Add(row);
}
ds.Tables.Add(dt);
var settings = new XmlWriterSettings { Indent = true };
using (var writer = XmlWriter.Create(path, settings))
ds.WriteXml(writer);
}
private void ImportarCsv(string path)
{
var lines = File.ReadAllLines(path, Encoding.UTF8);
if (lines.Length < 2) return;
grid.Rows.Clear();
// Pular header
for (int i = 1; i < lines.Length; i++)
{
var parts = ParseCsvLine(lines[i]);
if (parts.Count < 4) continue;