516 lines
20 KiB
C#
516 lines
20 KiB
C#
using CPM;
|
|
using DAL;
|
|
using MLL;
|
|
using BLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public class CheguesCadastroPanel : FormularioModelo
|
|
{
|
|
// ── CAMPOS DO FORMULÁRIO ──────────────────────────────────────────────
|
|
private LV_TEXTBOX1 txtId = null!;
|
|
private LV_TEXTBOX1 txtCodigo = null!;
|
|
private LV_COMBOBOXCUSTOM cmbTipo = null!;
|
|
|
|
// Banco
|
|
private LV_TEXTBOX1 txtBanco = null!;
|
|
private LV_TEXTBOX1 txtAgencia = null!;
|
|
private LV_TEXTBOX1 txtConta = null!;
|
|
private LV_TEXTBOX1 txtNumero = null!;
|
|
private LV_TEXTBOX1 txtValor = null!;
|
|
|
|
// Cliente + Fornecedor — busca
|
|
private LV_TEXTBOX1 txtCliente = null!;
|
|
private Button btnBuscarCliente = null!;
|
|
private LV_TEXTBOX1 txtFornecedor = null!;
|
|
private Button btnBuscarFornecedor = null!;
|
|
private LV_TEXTBOX1 txtEmitente = null!;
|
|
|
|
// Datas e compensação
|
|
private LV_TEXTBOX1 txtEmitido = null!;
|
|
private LV_TEXTBOX1 txtCompensar = null!;
|
|
private LV_TEXTBOX1 txtCodConta = null!;
|
|
private CheckBox chkOk = null!;
|
|
|
|
// Observações
|
|
private LV_TEXTBOX1 txtObs = null!;
|
|
|
|
// ── ESTADO ────────────────────────────────────────────────────────────
|
|
private enum ModoFormulario { Visualizacao, Novo, Edicao }
|
|
private ModoFormulario _modo = ModoFormulario.Visualizacao;
|
|
private int _idAtual = 0;
|
|
|
|
// ── BLL ───────────────────────────────────────────────────────────────
|
|
// private ChegueBLL _bll = null!;
|
|
|
|
// ── CONSTRUTOR ────────────────────────────────────────────────────────
|
|
public CheguesCadastroPanel()
|
|
{
|
|
Titulo = "Cadastro de Cheques";
|
|
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;
|
|
|
|
// Tipo
|
|
var lblTipo = new Label
|
|
{
|
|
Text = "Tipo",
|
|
Location = new Point(300, 58),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
cmbTipo = new LV_COMBOBOXCUSTOM
|
|
{
|
|
Location = new Point(300, 74),
|
|
Size = new Size(180, 32),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
BorderColor = BorderColor,
|
|
BackColor = Color.White,
|
|
ListBackColor = Color.White,
|
|
ListTextColor = TextDark,
|
|
IconColor = AccentBlue,
|
|
Font = new Font("Segoe UI", 9f)
|
|
};
|
|
cmbTipo.Items.Add("Recebido");
|
|
cmbTipo.Items.Add("Emitido");
|
|
cmbTipo.Items.Add("Devolvido");
|
|
cmbTipo.Items.Add("Cancelado");
|
|
cmbTipo.SelectedIndex = 0;
|
|
content.Controls.Add(lblTipo);
|
|
content.Controls.Add(cmbTipo);
|
|
|
|
// ── SEÇÃO: DADOS BANCÁRIOS ────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Dados Bancários", 128));
|
|
|
|
txtBanco = AddInput(content, "Banco", 20, 166, 220, 32);
|
|
txtBanco.MaxLength = 100;
|
|
|
|
txtAgencia = AddInput(content, "Agência", 260, 166, 140, 32);
|
|
txtAgencia.MaxLength = 20;
|
|
|
|
txtConta = AddInput(content, "Conta", 420, 166, 140, 32);
|
|
txtConta.MaxLength = 30;
|
|
|
|
txtNumero = AddInput(content, "Número", 580, 166, 120, 32);
|
|
txtNumero.MaxLength = 20;
|
|
|
|
txtValor = AddInput(content, "Valor", 20, 228, 160, 32);
|
|
txtValor.MaxLength = 20;
|
|
|
|
txtEmitido = AddInput(content, "Data Emissão", 200, 228, 160, 32);
|
|
txtEmitido.MaxLength = 20;
|
|
|
|
txtCompensar = AddInput(content, "Data Compensação", 380, 228, 160, 32);
|
|
txtCompensar.MaxLength = 20;
|
|
|
|
// CheckBox OK — compensado
|
|
chkOk = CreateCheckBox("Compensado (OK)", 560, 238);
|
|
content.Controls.Add(chkOk);
|
|
|
|
// ── SEÇÃO: PARTES ENVOLVIDAS ──────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Partes Envolvidas", 290));
|
|
|
|
// Cliente + botão buscar
|
|
var lblCliente = new Label
|
|
{
|
|
Text = "Cliente",
|
|
Location = new Point(20, 328),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtCliente = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 344),
|
|
Size = new Size(220, 32),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true,
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
btnBuscarCliente = new Button
|
|
{
|
|
Text = "🔍 Buscar",
|
|
Location = new Point(248, 344),
|
|
Size = new Size(90, 32),
|
|
BackColor = AccentBlue,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 8.5f),
|
|
Cursor = Cursors.Hand,
|
|
FlatStyle = FlatStyle.Flat,
|
|
Enabled = false
|
|
};
|
|
btnBuscarCliente.FlatAppearance.BorderSize = 0;
|
|
btnBuscarCliente.Click += BtnBuscarCliente_Click;
|
|
content.Controls.Add(lblCliente);
|
|
content.Controls.Add(txtCliente);
|
|
content.Controls.Add(btnBuscarCliente);
|
|
|
|
// Fornecedor + botão buscar
|
|
var lblFornecedor = new Label
|
|
{
|
|
Text = "Fornecedor",
|
|
Location = new Point(360, 328),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtFornecedor = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(360, 344),
|
|
Size = new Size(220, 32),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true,
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
btnBuscarFornecedor = new Button
|
|
{
|
|
Text = "🔍 Buscar",
|
|
Location = new Point(588, 344),
|
|
Size = new Size(90, 32),
|
|
BackColor = AccentBlue,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 8.5f),
|
|
Cursor = Cursors.Hand,
|
|
FlatStyle = FlatStyle.Flat,
|
|
Enabled = false
|
|
};
|
|
btnBuscarFornecedor.FlatAppearance.BorderSize = 0;
|
|
btnBuscarFornecedor.Click += BtnBuscarFornecedor_Click;
|
|
content.Controls.Add(lblFornecedor);
|
|
content.Controls.Add(txtFornecedor);
|
|
content.Controls.Add(btnBuscarFornecedor);
|
|
|
|
txtEmitente = AddInput(content, "Emitente", 20, 396, 340, 32);
|
|
txtEmitente.MaxLength = 150;
|
|
|
|
txtCodConta = AddInput(content, "Cód. Conta", 380, 396, 160, 32);
|
|
txtCodConta.MaxLength = 50;
|
|
|
|
// ── SEÇÃO: OBSERVAÇÕES ────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Observações", 450));
|
|
|
|
var lblObs = new Label
|
|
{
|
|
Text = "Observações",
|
|
Location = new Point(20, 488),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtObs = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 504),
|
|
Size = new Size(680, 70),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
Multiline = true,
|
|
MaxLength = 500
|
|
};
|
|
content.Controls.Add(lblObs);
|
|
content.Controls.Add(txtObs);
|
|
|
|
content.Height = 610;
|
|
}
|
|
|
|
// ── CAMPOS EDITÁVEIS ──────────────────────────────────────────────────
|
|
private LV_TEXTBOX1[] CamposEditaveis() => new[]
|
|
{
|
|
txtCodigo, txtBanco, txtAgencia, txtConta, txtNumero,
|
|
txtValor, txtEmitido, txtCompensar, txtEmitente, txtCodConta, txtObs
|
|
};
|
|
|
|
// ── 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;
|
|
}
|
|
|
|
cmbTipo.Enabled = editando;
|
|
cmbTipo.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
cmbTipo.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
|
|
chkOk.Enabled = editando;
|
|
|
|
btnBuscarCliente.Enabled = editando;
|
|
btnBuscarFornecedor.Enabled = editando;
|
|
|
|
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();
|
|
}
|
|
|
|
// ── BUSCA DE CLIENTE ──────────────────────────────────────────────────
|
|
private void BtnBuscarCliente_Click(object? sender, EventArgs e)
|
|
{
|
|
// TODO: abrir formulário de busca de clientes
|
|
// var frm = new FormularioBuscarCliente();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// txtCliente.Text = frm.ClienteSelecionado.CODIGO;
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de clientes.",
|
|
"Buscar Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
// ── BUSCA DE FORNECEDOR ───────────────────────────────────────────────
|
|
private void BtnBuscarFornecedor_Click(object? sender, EventArgs e)
|
|
{
|
|
// TODO: abrir formulário de busca de fornecedores
|
|
// var frm = new FormularioBuscarFornecedor();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// txtFornecedor.Text = frm.FornecedorSelecionado.CODIGO;
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de fornecedores.",
|
|
"Buscar Fornecedor", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
// ── POPULAR / LIMPAR ──────────────────────────────────────────────────
|
|
private void PopularCampos(ModeloChegues m)
|
|
{
|
|
_idAtual = m.ID_CHEGUES;
|
|
|
|
txtId.Text = m.ID_CHEGUES.ToString();
|
|
txtCodigo.Text = m.CODIGO;
|
|
txtBanco.Text = m.BANCO;
|
|
txtAgencia.Text = m.AGENCIA;
|
|
txtConta.Text = m.CONTA;
|
|
txtNumero.Text = m.NUMERO;
|
|
txtValor.Text = m.VALOR;
|
|
txtCliente.Text = m.CLIENTE;
|
|
txtFornecedor.Text = m.FORNECEDOR;
|
|
txtEmitente.Text = m.EMITENTE;
|
|
txtEmitido.Text = m.EMITIDO;
|
|
txtCompensar.Text = m.COMPENSAR;
|
|
txtCodConta.Text = m.COD_CONTA;
|
|
txtObs.Text = m.OBS;
|
|
chkOk.Checked = m.OK == "S" || m.OK == "1" || m.OK?.ToLower() == "true";
|
|
|
|
SelecionarCombo(cmbTipo, m.TIPO);
|
|
}
|
|
|
|
private void LimparCampos()
|
|
{
|
|
_idAtual = 0;
|
|
|
|
txtId.Text = string.Empty;
|
|
txtCodigo.Text = string.Empty;
|
|
txtBanco.Text = string.Empty;
|
|
txtAgencia.Text = string.Empty;
|
|
txtConta.Text = string.Empty;
|
|
txtNumero.Text = string.Empty;
|
|
txtValor.Text = string.Empty;
|
|
txtCliente.Text = string.Empty;
|
|
txtFornecedor.Text = string.Empty;
|
|
txtEmitente.Text = string.Empty;
|
|
txtEmitido.Text = string.Empty;
|
|
txtCompensar.Text = string.Empty;
|
|
txtCodConta.Text = string.Empty;
|
|
txtObs.Text = string.Empty;
|
|
chkOk.Checked = false;
|
|
cmbTipo.SelectedIndex = 0;
|
|
}
|
|
|
|
// ── HELPER COMBOBOX ───────────────────────────────────────────────────
|
|
private static void SelecionarCombo(LV_COMBOBOXCUSTOM cmb, string valor)
|
|
{
|
|
for (int i = 0; i < cmb.Items.Count; i++)
|
|
{
|
|
if (cmb.Items[i]?.ToString() == valor)
|
|
{
|
|
cmb.SelectedIndex = i;
|
|
return;
|
|
}
|
|
}
|
|
cmb.SelectedIndex = 0;
|
|
}
|
|
|
|
// ── VALIDAÇÃO ─────────────────────────────────────────────────────────
|
|
private bool Validar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtCodigo.Text))
|
|
{
|
|
MessageBox.Show("Informe o código do cheque.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtCodigo.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtBanco.Text))
|
|
{
|
|
MessageBox.Show("Informe o banco.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtBanco.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtNumero.Text))
|
|
{
|
|
MessageBox.Show("Informe o número do cheque.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtNumero.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtValor.Text))
|
|
{
|
|
MessageBox.Show("Informe o valor do cheque.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtValor.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtEmitido.Text))
|
|
{
|
|
MessageBox.Show("Informe a data de emissão.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtEmitido.Focus();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// ── MONTAR MODELO ─────────────────────────────────────────────────────
|
|
private ModeloChegues MontarModelo() => new ModeloChegues(
|
|
_idAtual,
|
|
txtCodigo.Text.Trim(),
|
|
txtBanco.Text.Trim(),
|
|
txtAgencia.Text.Trim(),
|
|
txtValor.Text.Trim(),
|
|
txtCliente.Text.Trim(),
|
|
txtFornecedor.Text.Trim(),
|
|
txtEmitido.Text.Trim(),
|
|
txtCompensar.Text.Trim(),
|
|
chkOk.Checked ? "S" : "N",
|
|
cmbTipo.SelectedItem?.ToString() ?? string.Empty,
|
|
txtConta.Text.Trim(),
|
|
txtNumero.Text.Trim(),
|
|
txtObs.Text.Trim(),
|
|
txtCodConta.Text.Trim(),
|
|
txtEmitente.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 cheque \"{txtNumero.Text}\"?",
|
|
"Confirmar exclusão",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
|
|
if (confirm != DialogResult.Yes) return;
|
|
|
|
try
|
|
{
|
|
// TODO: _bll.Excluir(_idAtual);
|
|
MessageBox.Show("Cheque 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 cheques
|
|
// var frm = new FormularioBuscarCheques();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// PopularCampos(frm.ChequeSelecionado);
|
|
// AplicarModo(ModoFormulario.Visualizacao);
|
|
// }
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de cheques.",
|
|
"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("Cheque cadastrado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
// TODO: _bll.Atualizar(modelo);
|
|
MessageBox.Show("Cheque 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);
|
|
}
|
|
}
|
|
} |