392 lines
16 KiB
C#
392 lines
16 KiB
C#
using CPM;
|
|
using DAL;
|
|
using MLL;
|
|
using BLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public class CartoesCadastroPanel : FormularioModelo
|
|
{
|
|
// ── CAMPOS DO FORMULÁRIO ──────────────────────────────────────────────
|
|
private LV_TEXTBOX1 txtId = null!;
|
|
private LV_TEXTBOX1 txtCodigo = null!;
|
|
private LV_COMBOBOXCUSTOM cmbBandeira = null!;
|
|
private LV_TEXTBOX1 txtNumCartao = null!;
|
|
private LV_TEXTBOX1 txtNome = null!;
|
|
private LV_TEXTBOX1 txtValidade = null!;
|
|
private LV_TEXTBOX1 txtAutorizacao = null!;
|
|
private LV_TEXTBOX1 txtParcelas = null!;
|
|
private LV_TEXTBOX1 txtValor = null!;
|
|
private LV_TEXTBOX1 txtCodCliente = null!;
|
|
private LV_TEXTBOX1 txtResumo = null!;
|
|
private LV_TEXTBOX1 txtDebito = null!;
|
|
private LV_TEXTBOX1 txtCodConta = null!;
|
|
private LV_TEXTBOX1 txtDia = null!;
|
|
private LV_TEXTBOX1 txtCompensado = null!;
|
|
private LV_TEXTBOX1 txtObsComp = null!;
|
|
|
|
// ── ESTADO ────────────────────────────────────────────────────────────
|
|
private enum ModoFormulario { Visualizacao, Novo, Edicao }
|
|
private ModoFormulario _modo = ModoFormulario.Visualizacao;
|
|
private int _idAtual = 0;
|
|
|
|
// ── BLL ───────────────────────────────────────────────────────────────
|
|
// private CartoesBLL _bll = null!;
|
|
|
|
// ── CONSTRUTOR ────────────────────────────────────────────────────────
|
|
public CartoesCadastroPanel()
|
|
{
|
|
Titulo = "Cadastro de Cartões";
|
|
BuildForm();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
|
|
// ── CONSTRUÇÃO DOS CAMPOS ─────────────────────────────────────────────
|
|
private void BuildForm()
|
|
{
|
|
// ── SEÇÃO: IDENTIFICAÇÃO ──────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Identificação", 20));
|
|
|
|
txtId = AddInput(content, "ID", 20, 58, 80, 32, readOnly: true);
|
|
txtCodigo = AddInput(content, "Código", 120, 58, 160, 32);
|
|
txtCodigo.MaxLength = 50;
|
|
|
|
// ── SEÇÃO: DADOS DO CARTÃO ────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Dados do Cartão", 110));
|
|
|
|
// Bandeira — LV_COMBOBOXCUSTOM
|
|
var lblBandeira = new Label
|
|
{
|
|
Text = "Bandeira",
|
|
Location = new Point(20, 148),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
cmbBandeira = new LV_COMBOBOXCUSTOM
|
|
{
|
|
Location = new Point(20, 164),
|
|
Size = new Size(160, 32),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
BorderColor = BorderColor,
|
|
BackColor = Color.White,
|
|
ListBackColor = Color.White,
|
|
ListTextColor = TextDark,
|
|
IconColor = AccentBlue,
|
|
Font = new Font("Segoe UI", 9f)
|
|
};
|
|
cmbBandeira.Items.Add("Visa");
|
|
cmbBandeira.Items.Add("Mastercard");
|
|
cmbBandeira.Items.Add("Elo");
|
|
cmbBandeira.Items.Add("American Express");
|
|
cmbBandeira.Items.Add("Hipercard");
|
|
cmbBandeira.Items.Add("PayPal");
|
|
cmbBandeira.Items.Add("Outro");
|
|
cmbBandeira.SelectedIndex = 0;
|
|
content.Controls.Add(lblBandeira);
|
|
content.Controls.Add(cmbBandeira);
|
|
|
|
txtNumCartao = AddInput(content, "Número do Cartão", 200, 148, 220, 32);
|
|
txtNumCartao.MaxLength = 20;
|
|
|
|
txtNome = AddInput(content, "Nome no Cartão", 440, 148, 260, 32);
|
|
txtNome.MaxLength = 100;
|
|
|
|
txtValidade = AddInput(content, "Validade", 20, 228, 120, 32);
|
|
txtValidade.MaxLength = 10;
|
|
|
|
txtAutorizacao = AddInput(content, "Autorização", 160, 228, 180, 32);
|
|
txtAutorizacao.MaxLength = 50;
|
|
|
|
txtParcelas = AddInput(content, "Parcelas", 360, 228, 100, 32);
|
|
txtParcelas.MaxLength = 10;
|
|
|
|
txtValor = AddInput(content, "Valor", 480, 228, 140, 32);
|
|
txtValor.MaxLength = 20;
|
|
|
|
// ── SEÇÃO: CLIENTE E CONTA ────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Cliente e Conta", 290));
|
|
|
|
txtCodCliente = AddInput(content, "Cód. Cliente", 20, 328, 160, 32);
|
|
txtCodCliente.MaxLength = 50;
|
|
|
|
txtCodConta = AddInput(content, "Cód. Conta", 200, 328, 160, 32);
|
|
txtCodConta.MaxLength = 50;
|
|
|
|
txtDia = AddInput(content, "Dia", 380, 328, 80, 32);
|
|
txtDia.MaxLength = 5;
|
|
|
|
txtDebito = AddInput(content, "Débito", 480, 328, 140, 32);
|
|
txtDebito.MaxLength = 20;
|
|
|
|
// ── SEÇÃO: COMPENSAÇÃO ────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Compensação", 390));
|
|
|
|
txtResumo = AddInput(content, "Resumo", 20, 428, 300, 32);
|
|
txtResumo.MaxLength = 255;
|
|
|
|
txtCompensado = AddInput(content, "Compensado", 340, 428, 120, 32);
|
|
txtCompensado.MaxLength = 20;
|
|
|
|
// Observações da compensação — multiline
|
|
var lblObsComp = new Label
|
|
{
|
|
Text = "Obs. Compensação",
|
|
Location = new Point(20, 490),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtObsComp = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 506),
|
|
Size = new Size(700, 70),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
Multiline = true,
|
|
MaxLength = 255
|
|
};
|
|
content.Controls.Add(lblObsComp);
|
|
content.Controls.Add(txtObsComp);
|
|
|
|
content.Height = 610;
|
|
}
|
|
|
|
// ── CAMPOS EDITÁVEIS — lista para evitar repetição ────────────────────
|
|
private LV_TEXTBOX1[] CamposEditaveis() => new[]
|
|
{
|
|
txtCodigo, txtNumCartao, txtNome, txtValidade, txtAutorizacao,
|
|
txtParcelas, txtValor, txtCodCliente, txtResumo, txtDebito,
|
|
txtCodConta, txtDia, txtCompensado, txtObsComp
|
|
};
|
|
|
|
// ── MODOS DO FORMULÁRIO ───────────────────────────────────────────────
|
|
private void AplicarModo(ModoFormulario modo)
|
|
{
|
|
_modo = modo;
|
|
|
|
bool editando = modo == ModoFormulario.Novo || modo == ModoFormulario.Edicao;
|
|
|
|
foreach (var txt in CamposEditaveis())
|
|
{
|
|
txt.ReadOnly = !editando;
|
|
txt.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
txt.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
}
|
|
|
|
cmbBandeira.Enabled = editando;
|
|
cmbBandeira.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
cmbBandeira.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
|
|
btnNovo.Enabled = !editando;
|
|
btnAlterar.Enabled = !editando && _idAtual > 0;
|
|
btnExcluir.Enabled = !editando && _idAtual > 0;
|
|
btnLocalizar.Enabled = !editando;
|
|
btnSalvar.Enabled = editando;
|
|
btnCancelar.Enabled = editando;
|
|
|
|
if (modo == ModoFormulario.Novo) LimparCampos();
|
|
}
|
|
|
|
// ── POPULAR / LIMPAR ──────────────────────────────────────────────────
|
|
private void PopularCampos(ModeloCartoes m)
|
|
{
|
|
_idAtual = m.ID_COD_CARTAO;
|
|
|
|
txtId.Text = m.ID_COD_CARTAO.ToString();
|
|
txtCodigo.Text = m.CODIGO;
|
|
txtNumCartao.Text = m.NUM_CARTAO;
|
|
txtNome.Text = m.NOME;
|
|
txtValidade.Text = m.VALIDADE;
|
|
txtAutorizacao.Text = m.AUTORIZACAO;
|
|
txtParcelas.Text = m.PARCELAS;
|
|
txtValor.Text = m.VALOR;
|
|
txtCodCliente.Text = m.COD_CLIENTE;
|
|
txtResumo.Text = m.RESUMO;
|
|
txtDebito.Text = m.DEBITO;
|
|
txtCodConta.Text = m.COD_CONTA;
|
|
txtDia.Text = m.DIA;
|
|
txtCompensado.Text = m.COMPENSADO;
|
|
txtObsComp.Text = m.OBS_COMP;
|
|
|
|
// Seleciona bandeira no ComboBox
|
|
for (int i = 0; i < cmbBandeira.Items.Count; i++)
|
|
{
|
|
if (cmbBandeira.Items[i]?.ToString() == m.BANDEIRA)
|
|
{
|
|
cmbBandeira.SelectedIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LimparCampos()
|
|
{
|
|
_idAtual = 0;
|
|
txtId.Text = string.Empty;
|
|
txtCodigo.Text = string.Empty;
|
|
txtNumCartao.Text = string.Empty;
|
|
txtNome.Text = string.Empty;
|
|
txtValidade.Text = string.Empty;
|
|
txtAutorizacao.Text = string.Empty;
|
|
txtParcelas.Text = string.Empty;
|
|
txtValor.Text = string.Empty;
|
|
txtCodCliente.Text = string.Empty;
|
|
txtResumo.Text = string.Empty;
|
|
txtDebito.Text = string.Empty;
|
|
txtCodConta.Text = string.Empty;
|
|
txtDia.Text = string.Empty;
|
|
txtCompensado.Text = string.Empty;
|
|
txtObsComp.Text = string.Empty;
|
|
cmbBandeira.SelectedIndex = 0;
|
|
}
|
|
|
|
// ── VALIDAÇÃO ─────────────────────────────────────────────────────────
|
|
private bool Validar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtCodigo.Text))
|
|
{
|
|
MessageBox.Show("Informe o código do cartão.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtCodigo.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtNumCartao.Text))
|
|
{
|
|
MessageBox.Show("Informe o número do cartão.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtNumCartao.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtValor.Text))
|
|
{
|
|
MessageBox.Show("Informe o valor.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtValor.Focus();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// ── MONTAR MODELO ─────────────────────────────────────────────────────
|
|
private ModeloCartoes MontarModelo() => new ModeloCartoes(
|
|
_idAtual,
|
|
txtCodigo.Text.Trim(),
|
|
cmbBandeira.SelectedItem?.ToString() ?? string.Empty,
|
|
txtNumCartao.Text.Trim(),
|
|
txtNome.Text.Trim(),
|
|
txtValidade.Text.Trim(),
|
|
txtAutorizacao.Text.Trim(),
|
|
txtParcelas.Text.Trim(),
|
|
txtValor.Text.Trim(),
|
|
txtCodCliente.Text.Trim(),
|
|
txtResumo.Text.Trim(),
|
|
txtDebito.Text.Trim(),
|
|
txtCodConta.Text.Trim(),
|
|
txtDia.Text.Trim(),
|
|
txtCompensado.Text.Trim(),
|
|
txtObsComp.Text.Trim()
|
|
);
|
|
|
|
// ── EVENTOS ABSTRATOS ─────────────────────────────────────────────────
|
|
protected override void OnNovo()
|
|
{
|
|
AplicarModo(ModoFormulario.Novo);
|
|
txtCodigo.Focus();
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
AplicarModo(ModoFormulario.Edicao);
|
|
txtCodigo.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
|
|
var confirm = MessageBox.Show(
|
|
$"Deseja realmente excluir o cartão \"{txtNumCartao.Text}\"?",
|
|
"Confirmar exclusão",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
|
|
if (confirm != DialogResult.Yes) return;
|
|
|
|
try
|
|
{
|
|
// TODO: _bll.Excluir(_idAtual);
|
|
MessageBox.Show("Cartão excluído com sucesso.", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
LimparCampos();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Erro ao excluir:\n{ex.Message}", "Erro",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
protected override void OnLocalizar()
|
|
{
|
|
// TODO: abrir formulário de busca de cartões
|
|
// var frm = new FormularioBuscarCartoes();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// PopularCampos(frm.CartaoSelecionado);
|
|
// AplicarModo(ModoFormulario.Visualizacao);
|
|
// }
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de cartões.",
|
|
"Localizar", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
if (!Validar()) return;
|
|
|
|
var modelo = MontarModelo();
|
|
|
|
try
|
|
{
|
|
if (_modo == ModoFormulario.Novo)
|
|
{
|
|
// TODO: _bll.Criar(modelo);
|
|
MessageBox.Show("Cartão cadastrado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
// TODO: _bll.Atualizar(modelo);
|
|
MessageBox.Show("Cartão atualizado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Erro ao salvar:\n{ex.Message}", "Erro",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
protected override void OnCancelar()
|
|
{
|
|
if (_idAtual > 0)
|
|
{
|
|
// TODO: recarregar do banco se necessário
|
|
}
|
|
LimparCampos();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
}
|
|
} |