273 lines
8.9 KiB
C#
273 lines
8.9 KiB
C#
using CPM;
|
|
using DAL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public abstract class FormularioModelo : UserControl
|
|
{
|
|
protected string _cx = DadosDaConexao.ObterConexao();
|
|
|
|
protected readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
|
|
protected readonly Color TextDark = Color.FromArgb(30, 41, 59);
|
|
protected readonly Color BorderColor = Color.FromArgb(226, 232, 240);
|
|
protected readonly Color BgLight = Color.FromArgb(248, 250, 252);
|
|
protected readonly Color ReadOnlyBg = Color.FromArgb(241, 245, 249);
|
|
protected readonly Color ReadOnlyBorder = Color.FromArgb(203, 213, 225);
|
|
|
|
protected Panel pnlToolbar = null!;
|
|
protected Panel pnlTitulo = null!;
|
|
protected Panel mainScroll = null!;
|
|
protected Panel content = null!;
|
|
|
|
protected Button btnNovo = null!;
|
|
protected Button btnAlterar = null!;
|
|
protected Button btnExcluir = null!;
|
|
protected Button btnLocalizar = null!;
|
|
protected Button btnSalvar = null!;
|
|
protected Button btnCancelar = null!;
|
|
protected Button btnFechar = null!; // ✅ NOVO
|
|
|
|
private Label lblTitulo = null!;
|
|
|
|
public string Titulo
|
|
{
|
|
get => lblTitulo.Text;
|
|
set => lblTitulo.Text = value;
|
|
}
|
|
|
|
protected FormularioModelo()
|
|
{
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
DoubleBuffered = true;
|
|
|
|
BuildToolbar();
|
|
BuildTitulo();
|
|
BuildScrollArea();
|
|
|
|
btnNovo.Click += (s, e) => OnNovo();
|
|
btnAlterar.Click += (s, e) => OnAlterar();
|
|
btnExcluir.Click += (s, e) => OnExcluir();
|
|
btnLocalizar.Click += (s, e) => OnLocalizar();
|
|
btnSalvar.Click += (s, e) => OnSalvar();
|
|
btnCancelar.Click += (s, e) => OnCancelar();
|
|
|
|
// ✅ Fechar: remove o UserControl do pai
|
|
btnFechar.Click += (s, e) =>
|
|
{
|
|
var pai = this.Parent;
|
|
if (pai != null)
|
|
{
|
|
pai.Controls.Remove(this);
|
|
this.Dispose();
|
|
}
|
|
};
|
|
}
|
|
|
|
private void BuildToolbar()
|
|
{
|
|
pnlToolbar = new Panel
|
|
{
|
|
Dock = DockStyle.Top,
|
|
Height = 55,
|
|
BackColor = Color.FromArgb(248, 250, 252)
|
|
};
|
|
|
|
var flow = new FlowLayoutPanel
|
|
{
|
|
Dock = DockStyle.Fill,
|
|
Padding = new Padding(12, 10, 0, 0),
|
|
BackColor = Color.Transparent
|
|
};
|
|
|
|
btnNovo = CreateToolbarButton("Novo", Color.FromArgb(34, 197, 94));
|
|
btnAlterar = CreateToolbarButton("Alterar", Color.FromArgb(245, 158, 11));
|
|
btnExcluir = CreateToolbarButton("Excluir", Color.FromArgb(239, 68, 68));
|
|
btnLocalizar = CreateToolbarButton("Localizar", AccentBlue);
|
|
btnSalvar = CreateToolbarButton("Salvar", AccentBlue);
|
|
btnCancelar = CreateToolbarButton("Cancelar", Color.FromArgb(148, 163, 184));
|
|
btnFechar = CreateToolbarButton("Fechar", Color.FromArgb(100, 116, 139)); // ✅ NOVO
|
|
|
|
flow.Controls.AddRange(new Control[]
|
|
{ btnNovo, btnAlterar, btnExcluir, btnLocalizar, btnSalvar, btnCancelar, btnFechar });
|
|
|
|
pnlToolbar.Controls.Add(flow);
|
|
this.Controls.Add(pnlToolbar);
|
|
}
|
|
|
|
private void BuildTitulo()
|
|
{
|
|
pnlTitulo = new Panel
|
|
{
|
|
Dock = DockStyle.Top,
|
|
Height = 42,
|
|
BackColor = Color.White
|
|
};
|
|
|
|
var linha = new Panel
|
|
{
|
|
Dock = DockStyle.Top,
|
|
Height = 1,
|
|
BackColor = BorderColor
|
|
};
|
|
|
|
lblTitulo = new Label
|
|
{
|
|
Dock = DockStyle.Fill,
|
|
Text = "Título do Formulário",
|
|
Font = new Font("Segoe UI", 13f, FontStyle.Bold),
|
|
ForeColor = AccentBlue,
|
|
TextAlign = ContentAlignment.MiddleLeft,
|
|
Padding = new Padding(16, 0, 0, 0)
|
|
};
|
|
|
|
pnlTitulo.Controls.Add(lblTitulo);
|
|
pnlTitulo.Controls.Add(linha);
|
|
this.Controls.Add(pnlTitulo);
|
|
}
|
|
|
|
private void BuildScrollArea()
|
|
{
|
|
mainScroll = new Panel
|
|
{
|
|
Dock = DockStyle.Fill,
|
|
AutoScroll = true,
|
|
BackColor = Color.White
|
|
};
|
|
|
|
content = new Panel
|
|
{
|
|
Width = 1100,
|
|
Height = 900,
|
|
Location = new Point(0, 0),
|
|
BackColor = Color.White
|
|
};
|
|
|
|
mainScroll.Controls.Add(content);
|
|
this.Controls.Add(mainScroll);
|
|
mainScroll.BringToFront();
|
|
}
|
|
|
|
protected Panel CreateSectionHeader(string title, int y)
|
|
{
|
|
var pnl = new Panel { Location = new Point(20, y), Width = 1000, Height = 26 };
|
|
|
|
var lbl = new Label
|
|
{
|
|
Text = title,
|
|
Font = new Font("Segoe UI", 8.5f, FontStyle.Bold),
|
|
ForeColor = AccentBlue,
|
|
AutoSize = true,
|
|
Location = new Point(0, 0)
|
|
};
|
|
|
|
var line = new Panel
|
|
{
|
|
BackColor = BorderColor,
|
|
Height = 1,
|
|
Width = 980,
|
|
Location = new Point(0, 20)
|
|
};
|
|
|
|
pnl.Controls.Add(lbl);
|
|
pnl.Controls.Add(line);
|
|
return pnl;
|
|
}
|
|
|
|
protected LV_TEXTBOX1 AddInput(Control parent, string label,
|
|
int x, int y, int width, int height,
|
|
bool readOnly = false)
|
|
{
|
|
var lbl = new Label
|
|
{
|
|
Text = label,
|
|
Location = new Point(x, y),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = readOnly ? Color.Gray : TextDark,
|
|
AutoSize = true
|
|
};
|
|
|
|
var txt = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(x, y + 16), // ← input sempre 16px abaixo do label
|
|
Size = new Size(width, height),
|
|
BorderColor = readOnly ? ReadOnlyBorder : BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = readOnly,
|
|
BackColor = readOnly ? ReadOnlyBg : Color.White
|
|
};
|
|
|
|
parent.Controls.Add(lbl);
|
|
parent.Controls.Add(txt);
|
|
return txt;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cria um label + ComboBox seguindo o mesmo padrão visual do AddInput.
|
|
/// ✅ Resolve o bug do label sendo coberto pelo ComboBox.
|
|
/// </summary>
|
|
protected ComboBox AddComboBox(Control parent, string label,
|
|
int x, int y, int width)
|
|
{
|
|
var lbl = new Label
|
|
{
|
|
Text = label,
|
|
Location = new Point(x, y),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
|
|
var cb = new ComboBox
|
|
{
|
|
Location = new Point(x, y + 16), // ← mesmo padrão do AddInput
|
|
Size = new Size(width, 26),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
FlatStyle = FlatStyle.Flat,
|
|
Font = new Font("Segoe UI", 9f)
|
|
};
|
|
|
|
parent.Controls.Add(lbl);
|
|
parent.Controls.Add(cb);
|
|
return cb;
|
|
}
|
|
|
|
protected CheckBox CreateCheckBox(string text, int x, int y) => new CheckBox
|
|
{
|
|
Text = text,
|
|
Location = new Point(x, y),
|
|
Font = new Font("Segoe UI", 8.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
|
|
protected Button CreateToolbarButton(string text, Color color) => new Button
|
|
{
|
|
Text = text,
|
|
Size = new Size(95, 32),
|
|
BackColor = color,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 8.5f),
|
|
Margin = new Padding(0, 0, 6, 0),
|
|
Cursor = Cursors.Hand,
|
|
FlatStyle = FlatStyle.Flat,
|
|
FlatAppearance = { BorderSize = 0 }
|
|
};
|
|
|
|
protected void AddToolbarButton(Button btn)
|
|
{
|
|
var flow = pnlToolbar.Controls[0] as FlowLayoutPanel;
|
|
flow?.Controls.Add(btn);
|
|
}
|
|
|
|
protected abstract void OnNovo();
|
|
protected abstract void OnAlterar();
|
|
protected abstract void OnExcluir();
|
|
protected abstract void OnLocalizar();
|
|
protected abstract void OnSalvar();
|
|
protected abstract void OnCancelar();
|
|
}
|
|
} |