using CPM; using MLL; using System; using System.Drawing; using System.Windows.Forms; namespace UI { public class SatFiscalConsumidorFormasPanel : FormularioModelo { // Mapeamento absoluto de todas as propriedades do ModeloSatFiscalConsumidorFormas private LV_TEXTBOX1 txtIdSatFiscalConsFormas; private LV_TEXTBOX1 txtCodigo; private LV_TEXTBOX1 txtCodNfce; private LV_TEXTBOX1 txtForma; private LV_TEXTBOX1 txtValor; private LV_TEXTBOX1 txtDataCadastro; private LV_TEXTBOX1 txtCnpjOperadora; private LV_TEXTBOX1 txtTBand; public SatFiscalConsumidorFormasPanel() { this.Titulo = "DETALHAMENTO DE FORMAS DE PAGAMENTO (NFC-E / SAT)"; MontarInterfaceCompleta(); } private void MontarInterfaceCompleta() { // --- SEÇÃO 1: VÍNCULOS DA OPERAÇÃO --- content.Controls.Add(CreateSectionHeader("Vínculos Fiscais e Código da Transação", 20)); txtIdSatFiscalConsFormas = AddInput(content, "ID REGISTRO", 20, 55, 110, 28, true); txtCodigo = AddInput(content, "CÓDIGO INTERNO", 145, 55, 140, 28); txtCodNfce = AddInput(content, "CÓD. VÍNCULO NFC-E / SAT", 300, 55, 200, 28); txtDataCadastro = AddInput(content, "DATA DO LANÇAMENTO", 515, 55, 180, 28, true); // --- SEÇÃO 2: DETALHES DO PAGAMENTO --- content.Controls.Add(CreateSectionHeader("Valores e Regras do Meio de Pagamento (SEFAZ)", 115)); txtForma = AddInput(content, "FORMA (EX: 01-DINHEIRO, 03-CARTÃO CRÉDITO)", 20, 150, 320, 28); txtValor = AddInput(content, "VALOR INTEGRADO (R$)", 355, 150, 150, 28); // --- SEÇÃO 3: DADOS DE CARTÃO / TEF --- content.Controls.Add(CreateSectionHeader("Identificação de Operações com Cartão (Crédito/Débito)", 210)); txtCnpjOperadora = AddInput(content, "CNPJ DA OPERADORA DO CARTÃO (ADQUIRENTE)", 20, 245, 320, 28); txtTBand = AddInput(content, "CÓDIGO BANDEIRA (TBAND: 01-VISA, 02-MASTER)", 355, 245, 340, 28); } // --- MÉTODOS OBRIGATÓRIOS DO FORMULÁRIO MODELO --- protected override void OnNovo() { // Varre e limpa os inputs de forma segura foreach (Control c in content.Controls) { if (c is LV_TEXTBOX1 txt && !txt.ReadOnly) { txt.Text = string.Empty; } } txtIdSatFiscalConsFormas.Text = "0"; txtDataCadastro.Text = DateTime.Now.ToString("g"); txtCodNfce.Focus(); } protected override void OnSalvar() { // Validações básicas de negócio para evitar faturamento incompleto if (string.IsNullOrWhiteSpace(txtCodNfce.Text)) { MessageBox.Show("O código de vínculo da NFC-e é obrigatório.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtCodNfce.Focus(); return; } if (string.IsNullOrWhiteSpace(txtForma.Text)) { MessageBox.Show("A forma de pagamento é obrigatória.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtForma.Focus(); return; } // Mapeamento absoluto, limpo e direto de todas as propriedades da classe var formaPagamento = new ModeloSatFiscalConsumidorFormas { ID_SAT_FISCAL_CONS_FORMAS = string.IsNullOrEmpty(txtIdSatFiscalConsFormas.Text) ? 0 : Convert.ToInt32(txtIdSatFiscalConsFormas.Text), CODIGO = txtCodigo.Text, COD_NFCE = txtCodNfce.Text, FORMA = txtForma.Text, VALOR = txtValor.Text, DATA_CADASTRO = txtDataCadastro.Text, CNPJ_OPERADORA = txtCnpjOperadora.Text, TBand = txtTBand.Text }; // Envio do objeto preenchido para sua BLL / DAL para inserção ou update no SQL Server MessageBox.Show("Forma de pagamento registrada com sucesso para o cupom fiscal!", "LevelOS", MessageBoxButtons.OK, MessageBoxIcon.Information); } protected override void OnAlterar() { txtForma.Focus(); } protected override void OnExcluir() { if (MessageBox.Show("Deseja remover esta forma de pagamento? Isso alterará o balanço de fechamento do cupom fiscal.", "LevelOS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { // Processa a exclusão física... OnNovo(); } } protected override void OnLocalizar() { // Abre o Grid para consultar as formas cadastradas neste cupom } protected override void OnCancelar() { OnNovo(); } } }