179 lines
8.1 KiB
C#
179 lines
8.1 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 OrcasConsultaPanel : UserControl
|
|
{
|
|
// ── DESIGN ──────────────────────────────────────────────────────────
|
|
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 SurfaceColor = Color.FromArgb(248, 250, 252);
|
|
private readonly Color OrangeColor = Color.FromArgb(249, 115, 22);
|
|
|
|
// ── CONTROLES ───────────────────────────────────────────────────────
|
|
private DataGridView dgvOrcas = null!;
|
|
private Label lblContador = null!;
|
|
private Label lblSomaTotal = null!;
|
|
|
|
private RoundTextBox txtFiltroCliente = null!;
|
|
private RoundTextBox txtFiltroCodigo = null!;
|
|
private ComboBox cmbSituacao = null!;
|
|
|
|
// ── DADOS ────────────────────────────────────────────────────────────
|
|
private List<ModeloOrcas> _todos = new();
|
|
private List<ModeloOrcas> _filtrados = new();
|
|
|
|
public event Action<ModeloOrcas>? OnEditarOrcamento;
|
|
public event Action? OnNovoOrcamento;
|
|
|
|
public OrcasConsultaPanel()
|
|
{
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
InitializeLayout();
|
|
// CarregarDados(); // Chamar BLL aqui
|
|
}
|
|
|
|
private void InitializeLayout()
|
|
{
|
|
Controls.Clear();
|
|
|
|
// 1. GRID
|
|
BuildGrid();
|
|
Controls.Add(dgvOrcas);
|
|
|
|
// 2. RODAPÉ (Resumo Financeiro)
|
|
var pnlRodape = new Panel { Dock = DockStyle.Bottom, Height = 50, BackColor = SurfaceColor, Padding = new Padding(16, 0, 16, 0) };
|
|
lblContador = new Label { Text = "0 Orçamentos", AutoSize = true, Location = new Point(16, 18), Font = new Font("Segoe UI", 9f, FontStyle.Bold), ForeColor = TextDark };
|
|
lblSomaTotal = new Label { Text = "Total Geral: R$ 0,00", AutoSize = false, Width = 300, Location = new Point(pnlRodape.Width - 320, 15), Anchor = AnchorStyles.Right, Font = new Font("Segoe UI", 11f, FontStyle.Bold), ForeColor = AccentBlue, TextAlign = ContentAlignment.MiddleRight };
|
|
pnlRodape.Controls.AddRange(new Control[] { lblContador, lblSomaTotal });
|
|
Controls.Add(pnlRodape);
|
|
|
|
// 3. FILTROS
|
|
var pnlFiltros = new Panel { Dock = DockStyle.Top, Height = 70, BackColor = SurfaceColor, Padding = new Padding(16, 10, 16, 10) };
|
|
txtFiltroCodigo = AddFiltroInput(pnlFiltros, "Cód/Nº", 16, 10, 80);
|
|
txtFiltroCliente = AddFiltroInput(pnlFiltros, "Cliente (Nome ou CPF/CNPJ)", 105, 10, 300);
|
|
|
|
pnlFiltros.Controls.Add(new Label { Text = "Situação", Location = new Point(415, 10), Font = new Font("Segoe UI", 8f, FontStyle.Bold), AutoSize = true });
|
|
cmbSituacao = new ComboBox { Location = new Point(415, 28), Size = new Size(130, 28), DropDownStyle = ComboBoxStyle.DropDownList, FlatStyle = FlatStyle.Flat };
|
|
cmbSituacao.Items.AddRange(new[] { "Todos", "Aberto", "Aprovado", "Cancelado", "Finalizado" });
|
|
cmbSituacao.SelectedIndex = 0;
|
|
pnlFiltros.Controls.Add(cmbSituacao);
|
|
|
|
Controls.Add(pnlFiltros);
|
|
|
|
// 4. TOOLBAR
|
|
var pnlToolbar = new Panel { Dock = DockStyle.Top, Height = 60, BackColor = Color.White };
|
|
var btnNovo = CreateButton("Novo Orçamento", GreenColor, 16);
|
|
btnNovo.Click += (s, e) => OnNovoOrcamento?.Invoke();
|
|
|
|
var btnFiltrar = CreateButton("Pesquisar", AccentBlue, 165);
|
|
btnFiltrar.Click += (s, e) => AplicarFiltros();
|
|
|
|
pnlToolbar.Controls.AddRange(new Control[] { btnNovo, btnFiltrar });
|
|
Controls.Add(pnlToolbar);
|
|
}
|
|
|
|
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 = 40 }
|
|
};
|
|
|
|
dgvOrcas.Columns.AddRange(new DataGridViewColumn[]
|
|
{
|
|
new DataGridViewTextBoxColumn { Name = "colCod", HeaderText = "Código", FillWeight = 20 },
|
|
new DataGridViewTextBoxColumn { Name = "colData", HeaderText = "Data", FillWeight = 20 },
|
|
new DataGridViewTextBoxColumn { Name = "colCliente", HeaderText = "Cliente", FillWeight = 60 },
|
|
new DataGridViewTextBoxColumn { Name = "colTotal", HeaderText = "Total Geral", FillWeight = 30 },
|
|
new DataGridViewTextBoxColumn { Name = "colStatus", HeaderText = "Situação", FillWeight = 25 }
|
|
});
|
|
|
|
dgvOrcas.CellFormatting += (s, e) => {
|
|
if (dgvOrcas.Columns[e.ColumnIndex].Name == "colStatus" && e.Value != null)
|
|
{
|
|
if (e.Value.ToString() == "Aprovado") e.CellStyle.ForeColor = GreenColor;
|
|
if (e.Value.ToString() == "Aberto") e.CellStyle.ForeColor = OrangeColor;
|
|
}
|
|
};
|
|
|
|
dgvOrcas.CellDoubleClick += (s, e) => {
|
|
if (e.RowIndex >= 0) AbrirEdicao();
|
|
};
|
|
}
|
|
|
|
private void AplicarFiltros()
|
|
{
|
|
_filtrados = _todos.ToList();
|
|
|
|
if (!string.IsNullOrEmpty(txtFiltroCliente.Text))
|
|
_filtrados = _filtrados.Where(x => x.CLIENTE_NOME.ToUpper().Contains(txtFiltroCliente.Text.ToUpper())).ToList();
|
|
|
|
if (cmbSituacao.SelectedIndex > 0)
|
|
_filtrados = _filtrados.Where(x => x.SITUACAO == cmbSituacao.SelectedItem.ToString()).ToList();
|
|
|
|
AtualizarGrid();
|
|
}
|
|
|
|
private void AtualizarGrid()
|
|
{
|
|
dgvOrcas.Rows.Clear();
|
|
decimal soma = 0;
|
|
|
|
foreach (var o in _filtrados)
|
|
{
|
|
dgvOrcas.Rows.Add(o.CODIGO, o.DIA, o.CLIENTE_NOME, o.TOTAL_GERAL, o.SITUACAO);
|
|
|
|
if (decimal.TryParse(o.TOTAL_GERAL, out decimal v)) soma += v;
|
|
}
|
|
|
|
lblContador.Text = $"{_filtrados.Count} Orçamentos encontrados";
|
|
lblSomaTotal.Text = $"Total Geral: {soma:C2}";
|
|
}
|
|
|
|
private void AbrirEdicao()
|
|
{
|
|
if (dgvOrcas.SelectedRows.Count == 0) return;
|
|
string cod = dgvOrcas.SelectedRows[0].Cells["colCod"].Value.ToString();
|
|
var orca = _filtrados.FirstOrDefault(x => x.CODIGO == cod);
|
|
if (orca != null) OnEditarOrcamento?.Invoke(orca);
|
|
}
|
|
|
|
private RoundTextBox AddFiltroInput(Control parent, string label, int x, int y, int w)
|
|
{
|
|
parent.Controls.Add(new Label { Text = label, Location = new Point(x, y), Font = new Font("Segoe UI", 8f, FontStyle.Bold), AutoSize = true });
|
|
var txt = new RoundTextBox { Location = new Point(x, y + 18), Size = new Size(w, 30), Radius = 5, BorderColor = BorderColor };
|
|
parent.Controls.Add(txt);
|
|
return txt;
|
|
}
|
|
|
|
private RoundButton CreateButton(string text, Color color, int x) => new RoundButton
|
|
{
|
|
Text = text,
|
|
Size = new Size(140, 35),
|
|
Location = new Point(x, 12),
|
|
BackColor = color,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 9f),
|
|
Cursor = Cursors.Hand
|
|
};
|
|
}
|
|
} |