207 lines
9.2 KiB
C#
207 lines
9.2 KiB
C#
using BLL;
|
|
using DAL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using MLL;
|
|
|
|
namespace UI
|
|
{
|
|
public class OrcaPadraoConsultaPanel : UserControl
|
|
{
|
|
// ── CORES (Identidade LevelOS) ──────────────────────────────────────────
|
|
private readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
|
|
private readonly Color TextDark = Color.FromArgb(30, 41, 59);
|
|
private readonly Color BorderColor = Color.FromArgb(226, 232, 240);
|
|
private readonly Color GreenColor = Color.FromArgb(34, 197, 94);
|
|
private readonly Color MutedGray = Color.FromArgb(148, 163, 184);
|
|
private readonly Color SurfaceColor = Color.FromArgb(248, 250, 252);
|
|
|
|
// ── CONTROLES ─────────────────────────────────────────────────────────
|
|
private Panel pnlToolbar = null!;
|
|
private Panel pnlFiltros = null!;
|
|
private Panel pnlRodape = null!;
|
|
private DataGridView dgvOrcas = null!;
|
|
private Label lblTotal = null!;
|
|
|
|
// ── FILTROS ───────────────────────────────────────────────────────────
|
|
private RoundTextBox txtFiltroNome = null!;
|
|
private RoundTextBox txtFiltroCodigo = null!;
|
|
private ComboBox cmbUsado = null!;
|
|
|
|
// ── DADOS ─────────────────────────────────────────────────────────────
|
|
private List<ModeloOrcaPadrao> _todos = new();
|
|
private List<ModeloOrcaPadrao> _filtrados = new();
|
|
private string _conexao = DadosDaConexao.ObterConexao();
|
|
|
|
public event Action<ModeloOrcaPadrao>? OnAbrirCadastro;
|
|
|
|
public OrcaPadraoConsultaPanel()
|
|
{
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
DoubleBuffered = true;
|
|
|
|
InitializeLayout();
|
|
CarregarDadosDoBanco();
|
|
AplicarFiltros();
|
|
}
|
|
|
|
private void InitializeLayout()
|
|
{
|
|
Controls.Clear();
|
|
|
|
// 1º GRID (Fill)
|
|
BuildGrid();
|
|
Controls.Add(dgvOrcas);
|
|
|
|
// 2º RODAPÉ (Bottom)
|
|
pnlRodape = new Panel { Dock = DockStyle.Bottom, Height = 30, BackColor = SurfaceColor };
|
|
lblTotal = new Label { AutoSize = true, Location = new Point(16, 7), Font = new Font("Segoe UI", 8.5f, FontStyle.Bold), ForeColor = MutedGray, Text = "0 modelos encontrados" };
|
|
pnlRodape.Controls.Add(lblTotal);
|
|
Controls.Add(pnlRodape);
|
|
|
|
// 3º FILTROS (Top)
|
|
pnlFiltros = new Panel { Dock = DockStyle.Top, Height = 65, BackColor = SurfaceColor, Padding = new Padding(16, 8, 16, 8) };
|
|
BuildFiltros();
|
|
Controls.Add(pnlFiltros);
|
|
|
|
// 4º TOOLBAR (Top)
|
|
pnlToolbar = new Panel { Dock = DockStyle.Top, Height = 55, BackColor = SurfaceColor };
|
|
var flow = new FlowLayoutPanel { Dock = DockStyle.Fill, Padding = new Padding(12, 10, 0, 0), BackColor = Color.Transparent };
|
|
|
|
var btnPesquisar = CreateToolbarButton("Pesquisar", AccentBlue);
|
|
var btnLimpar = CreateToolbarButton("Limpar", MutedGray);
|
|
var btnNovo = CreateToolbarButton("Novo Modelo", GreenColor);
|
|
var btnEditar = CreateToolbarButton("Editar", Color.FromArgb(99, 102, 241));
|
|
|
|
btnPesquisar.Click += (_, _) => AplicarFiltros();
|
|
btnLimpar.Click += (_, _) => LimparFiltros();
|
|
btnNovo.Click += (_, _) => OnAbrirCadastro?.Invoke(new ModeloOrcaPadrao());
|
|
btnEditar.Click += (_, _) => AbrirRegistroSelecionado();
|
|
|
|
flow.Controls.AddRange(new Control[] { btnPesquisar, btnLimpar, btnNovo, btnEditar });
|
|
pnlToolbar.Controls.Add(flow);
|
|
Controls.Add(pnlToolbar);
|
|
}
|
|
|
|
private void BuildFiltros()
|
|
{
|
|
txtFiltroCodigo = AddFiltroInput(pnlFiltros, "Código", 0, 8, 100);
|
|
txtFiltroNome = AddFiltroInput(pnlFiltros, "Nome do Modelo / Template", 110, 8, 300);
|
|
|
|
pnlFiltros.Controls.Add(new Label { Text = "Em Uso?", Location = new Point(420, 8), Font = new Font("Segoe UI", 7.5f, FontStyle.Bold), ForeColor = TextDark, AutoSize = true });
|
|
cmbUsado = new ComboBox { Location = new Point(420, 24), Size = new Size(100, 26), DropDownStyle = ComboBoxStyle.DropDownList, FlatStyle = FlatStyle.Flat };
|
|
cmbUsado.Items.AddRange(new object[] { "Todos", "Sim", "Não" });
|
|
cmbUsado.SelectedIndex = 0;
|
|
pnlFiltros.Controls.Add(cmbUsado);
|
|
|
|
txtFiltroNome.KeyDown += (_, e) => { if (e.KeyCode == Keys.Enter) AplicarFiltros(); };
|
|
}
|
|
|
|
private void BuildGrid()
|
|
{
|
|
dgvOrcas = new DataGridView
|
|
{
|
|
Dock = DockStyle.Fill,
|
|
BackgroundColor = Color.White,
|
|
BorderStyle = BorderStyle.None,
|
|
RowHeadersVisible = false,
|
|
AllowUserToAddRows = false,
|
|
ReadOnly = true,
|
|
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
|
|
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
|
|
RowTemplate = { Height = 32 }
|
|
};
|
|
|
|
dgvOrcas.Columns.AddRange(new DataGridViewColumn[]
|
|
{
|
|
new DataGridViewTextBoxColumn { Name = "colId", HeaderText = "ID", FillWeight = 10 },
|
|
new DataGridViewTextBoxColumn { Name = "colCodigo", HeaderText = "Código", FillWeight = 15 },
|
|
new DataGridViewTextBoxColumn { Name = "colNome", HeaderText = "Nome do Modelo", FillWeight = 45 },
|
|
new DataGridViewTextBoxColumn { Name = "colUsado", HeaderText = "Ativo", FillWeight = 10 },
|
|
new DataGridViewTextBoxColumn { Name = "colObs", HeaderText = "Observações", FillWeight = 20 }
|
|
});
|
|
|
|
dgvOrcas.CellDoubleClick += (_, e) => { if (e.RowIndex >= 0) AbrirRegistroSelecionado(); };
|
|
}
|
|
|
|
private void AplicarFiltros()
|
|
{
|
|
_filtrados = _todos.ToList();
|
|
|
|
var nome = txtFiltroNome.Text.Trim().ToLower();
|
|
if (!string.IsNullOrEmpty(nome))
|
|
_filtrados = _filtrados.Where(x => x.NOME.ToLower().Contains(nome)).ToList();
|
|
|
|
var cod = txtFiltroCodigo.Text.Trim().ToLower();
|
|
if (!string.IsNullOrEmpty(cod))
|
|
_filtrados = _filtrados.Where(x => x.CODIGO.ToLower().Contains(cod)).ToList();
|
|
|
|
var sit = cmbUsado.SelectedItem?.ToString();
|
|
if (sit == "Sim") _filtrados = _filtrados.Where(x => x.USADO?.ToUpper() == "S").ToList();
|
|
else if (sit == "Não") _filtrados = _filtrados.Where(x => x.USADO?.ToUpper() == "N").ToList();
|
|
|
|
PreencherGrid();
|
|
}
|
|
|
|
private void PreencherGrid()
|
|
{
|
|
dgvOrcas.Rows.Clear();
|
|
foreach (var item in _filtrados)
|
|
{
|
|
dgvOrcas.Rows.Add(
|
|
item.ID_ORCA_PADRAO,
|
|
item.CODIGO,
|
|
item.NOME,
|
|
item.USADO == "S" ? "Ativo" : "Inativo",
|
|
item.OBS.Length > 30 ? item.OBS.Substring(0, 30) + "..." : item.OBS
|
|
);
|
|
}
|
|
lblTotal.Text = $"{_filtrados.Count} modelos encontrados";
|
|
}
|
|
|
|
private void AbrirRegistroSelecionado()
|
|
{
|
|
if (dgvOrcas.SelectedRows.Count == 0) return;
|
|
var id = (int)dgvOrcas.SelectedRows[0].Cells["colId"].Value;
|
|
var selecionado = _filtrados.FirstOrDefault(x => x.ID_ORCA_PADRAO == id);
|
|
if (selecionado != null) OnAbrirCadastro?.Invoke(selecionado);
|
|
}
|
|
|
|
private void CarregarDadosDoBanco()
|
|
{
|
|
// BLLOrcaPadrao bll = new BLLOrcaPadrao(_conexao);
|
|
// _todos = bll.Listar();
|
|
}
|
|
|
|
private RoundTextBox AddFiltroInput(Control parent, string label, int x, int y, int width)
|
|
{
|
|
parent.Controls.Add(new Label { Text = label, Location = new Point(x, y), Font = new Font("Segoe UI", 7.5f, FontStyle.Bold), ForeColor = TextDark, AutoSize = true });
|
|
var txt = new RoundTextBox { Location = new Point(x, y + 16), Size = new Size(width, 26), Radius = 4, BorderColor = BorderColor, FocusColor = AccentBlue, BackColor = Color.White };
|
|
parent.Controls.Add(txt);
|
|
return txt;
|
|
}
|
|
|
|
private RoundButton CreateToolbarButton(string text, Color color) => new RoundButton
|
|
{
|
|
Text = text,
|
|
Size = new Size(110, 32),
|
|
BackColor = color,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 8.5f),
|
|
Margin = new Padding(0, 0, 6, 0),
|
|
Cursor = Cursors.Hand
|
|
};
|
|
|
|
private void LimparFiltros()
|
|
{
|
|
txtFiltroNome.Text = string.Empty;
|
|
txtFiltroCodigo.Text = string.Empty;
|
|
cmbUsado.SelectedIndex = 0;
|
|
AplicarFiltros();
|
|
}
|
|
}
|
|
} |