237 lines
9.6 KiB
C#
237 lines
9.6 KiB
C#
using BLL;
|
|
using MLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public class OrcasCadastroPanel : UserControl
|
|
{
|
|
// ── DESIGN ──────────────────────────────────────────────────────────
|
|
private readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
|
|
private readonly Color GreenColor = Color.FromArgb(34, 197, 94);
|
|
private readonly Color TextDark = Color.FromArgb(30, 41, 59);
|
|
private readonly Color BorderColor = Color.FromArgb(226, 232, 240);
|
|
|
|
// ── CONTROLES ───────────────────────────────────────────────────────
|
|
private RoundTextBox txtCodigo = null!, txtCliente = null!, txtDesconto = null!;
|
|
private Label lblTotalGeral = null!, lblTotalServicos = null!, lblTotalPecas = null!;
|
|
private ComboBox cmbSituacao = null!;
|
|
private TextBox txtObs = null!;
|
|
private DataGridView dgvItens = null!;
|
|
|
|
private ModeloOrcas _orca = null!;
|
|
public event Action? OnVoltar;
|
|
|
|
// ── CONSTRUTORES ─────────────────────────────────────────────────────
|
|
|
|
// Construtor Vazio (Resolve o erro da sua variável global)
|
|
public OrcasCadastroPanel()
|
|
{
|
|
_orca = new ModeloOrcas(); // Inicializa um modelo limpo
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
InitializeComponent();
|
|
}
|
|
|
|
// Construtor com parâmetro (Para abrir direto na edição)
|
|
public OrcasCadastroPanel(ModeloOrcas orca)
|
|
{
|
|
_orca = orca;
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
InitializeComponent();
|
|
PreencherCampos();
|
|
}
|
|
|
|
// ── MÉTODOS PÚBLICOS ────────────────────────────────────────────────
|
|
|
|
// Método para carregar um orçamento quando o painel já está instanciado
|
|
public void CarregarOrcamento(ModeloOrcas orca)
|
|
{
|
|
_orca = orca;
|
|
PreencherCampos();
|
|
}
|
|
|
|
// ── UI LOGIC ────────────────────────────────────────────────────────
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
// HEADER
|
|
var pnlHeader = new Panel { Dock = DockStyle.Top, Height = 60, BackColor = Color.FromArgb(248, 250, 252) };
|
|
|
|
// Título dinâmico (se ID for 0 é novo)
|
|
var lblTitulo = new Label
|
|
{
|
|
Text = "Cadastro de Orçamento",
|
|
Font = new Font("Segoe UI", 12f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
Location = new Point(20, 18),
|
|
AutoSize = true
|
|
};
|
|
|
|
var btnSalvar = CreateHeaderButton("Gravar Orçamento", AccentBlue, Width - 160);
|
|
btnSalvar.Click += (s, e) => Salvar();
|
|
|
|
var btnImportar = CreateHeaderButton("Importar Padrão", GreenColor, Width - 320);
|
|
btnImportar.Click += (s, e) => ImportarModeloPadrao();
|
|
|
|
var btnVoltar = CreateHeaderButton("Voltar", Color.FromArgb(203, 213, 225), Width - 410, 80);
|
|
btnVoltar.ForeColor = TextDark;
|
|
btnVoltar.Click += (s, e) => OnVoltar?.Invoke();
|
|
|
|
pnlHeader.Controls.AddRange(new Control[] { lblTitulo, btnSalvar, btnImportar, btnVoltar });
|
|
Controls.Add(pnlHeader);
|
|
|
|
// CAMPOS PRINCIPAIS
|
|
txtCodigo = AddCampo("Nº Orçamento", 20, 80, 120);
|
|
txtCliente = AddCampo("Cliente (F2 para buscar)", 150, 80, 430);
|
|
|
|
AddLabel("Situação", 590, 60);
|
|
cmbSituacao = new ComboBox
|
|
{
|
|
Location = new Point(590, 80),
|
|
Size = new Size(150, 30),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
FlatStyle = FlatStyle.Flat
|
|
};
|
|
cmbSituacao.Items.AddRange(new[] { "Aberto", "Aprovado", "Cancelado", "Finalizado" });
|
|
cmbSituacao.SelectedIndex = 0;
|
|
Controls.Add(cmbSituacao);
|
|
|
|
// GRID DE ITENS
|
|
AddLabel("Itens do Orçamento (Produtos e Serviços)", 20, 130);
|
|
BuildGrid();
|
|
|
|
// PAINEL LATERAL DE TOTAIS
|
|
var pnlTotais = new Panel
|
|
{
|
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
|
Size = new Size(300, 180),
|
|
Location = new Point(Width - 320, Height - 190),
|
|
BackColor = Color.FromArgb(241, 245, 249)
|
|
};
|
|
BuildTotais(pnlTotais);
|
|
Controls.Add(pnlTotais);
|
|
|
|
// OBSERVAÇÕES
|
|
AddLabel("Observações do Orçamento", 20, Height - 190);
|
|
txtObs = new TextBox
|
|
{
|
|
Location = new Point(20, Height - 170),
|
|
Size = new Size(Width - 350, 150),
|
|
Multiline = true,
|
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
|
|
BorderStyle = BorderStyle.FixedSingle
|
|
};
|
|
Controls.Add(txtObs);
|
|
}
|
|
|
|
private void BuildGrid()
|
|
{
|
|
dgvItens = new DataGridView
|
|
{
|
|
Location = new Point(20, 150),
|
|
Size = new Size(Width - 40, Height - 360),
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
|
|
BackgroundColor = Color.White,
|
|
BorderStyle = BorderStyle.None,
|
|
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
|
|
RowTemplate = { Height = 35 }
|
|
};
|
|
|
|
dgvItens.Columns.Add("colTipo", "Tipo (P/S)");
|
|
dgvItens.Columns.Add("colCod", "Cód. Item");
|
|
dgvItens.Columns.Add("colDesc", "Descrição");
|
|
dgvItens.Columns.Add("colQtd", "Qtd");
|
|
dgvItens.Columns.Add("colVunit", "V. Unit");
|
|
dgvItens.Columns.Add("colTotal", "Total");
|
|
|
|
dgvItens.CellValueChanged += (s, e) => CalcularTotais();
|
|
Controls.Add(dgvItens);
|
|
}
|
|
|
|
private void BuildTotais(Panel p)
|
|
{
|
|
lblTotalServicos = AddLabelTotal(p, "Total Serviços: R$ 0,00", 15, 20);
|
|
lblTotalPecas = AddLabelTotal(p, "Total Peças: R$ 0,00", 15, 50);
|
|
|
|
var lblDesc = new Label { Text = "Desconto R$:", Location = new Point(15, 85), AutoSize = true, Font = new Font("Segoe UI", 9f, FontStyle.Bold) };
|
|
txtDesconto = new RoundTextBox { Location = new Point(120, 80), Size = new Size(150, 25), Radius = 2 };
|
|
txtDesconto.TextChanged += (s, e) => CalcularTotais();
|
|
|
|
lblTotalGeral = new Label
|
|
{
|
|
Text = "TOTAL: R$ 0,00",
|
|
Location = new Point(15, 130),
|
|
Size = new Size(270, 30),
|
|
Font = new Font("Segoe UI", 14f, FontStyle.Bold),
|
|
ForeColor = AccentBlue,
|
|
TextAlign = ContentAlignment.MiddleRight
|
|
};
|
|
|
|
p.Controls.AddRange(new Control[] { lblTotalServicos, lblTotalPecas, lblTotalGeral, lblDesc, txtDesconto });
|
|
}
|
|
|
|
private void CalcularTotais()
|
|
{
|
|
// Lógica de soma simplificada para exemplo
|
|
lblTotalGeral.Text = "TOTAL: R$ 0,00";
|
|
}
|
|
|
|
private void PreencherCampos()
|
|
{
|
|
if (_orca == null) return;
|
|
|
|
txtCodigo.Text = _orca.CODIGO;
|
|
txtCliente.Text = _orca.CLIENTE_NOME;
|
|
txtObs.Text = _orca.OBS;
|
|
cmbSituacao.SelectedItem = _orca.SITUACAO ?? "Aberto";
|
|
txtDesconto.Text = _orca.DESCONTO;
|
|
}
|
|
|
|
private void ImportarModeloPadrao() { /* Lógica de Importação */ }
|
|
|
|
private void Salvar()
|
|
{
|
|
MessageBox.Show("Orçamento salvo com sucesso!");
|
|
OnVoltar?.Invoke();
|
|
}
|
|
|
|
// ── AUXILIARES DE DESIGN ─────────────────────────────────────────────
|
|
|
|
private RoundTextBox AddCampo(string label, int x, int y, int w)
|
|
{
|
|
AddLabel(label, x, y - 20);
|
|
var txt = new RoundTextBox { Location = new Point(x, y), Size = new Size(w, 30), Radius = 5, BorderColor = BorderColor };
|
|
Controls.Add(txt);
|
|
return txt;
|
|
}
|
|
|
|
private void AddLabel(string texto, int x, int y)
|
|
{
|
|
Controls.Add(new Label { Text = texto, Location = new Point(x, y), AutoSize = true, Font = new Font("Segoe UI", 8.5f, FontStyle.Bold), ForeColor = TextDark });
|
|
}
|
|
|
|
private Label AddLabelTotal(Panel p, string texto, int x, int y)
|
|
{
|
|
var lbl = new Label { Text = texto, Location = new Point(x, y), AutoSize = true, Font = new Font("Segoe UI", 9f) };
|
|
p.Controls.Add(lbl);
|
|
return lbl;
|
|
}
|
|
|
|
private RoundButton CreateHeaderButton(string text, Color color, int x, int w = 130) => new RoundButton
|
|
{
|
|
Text = text,
|
|
Size = new Size(w, 35),
|
|
Location = new Point(x, 12),
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Right,
|
|
BackColor = color,
|
|
ForeColor = Color.White,
|
|
Cursor = Cursors.Hand
|
|
};
|
|
}
|
|
} |