using CPM; using MLL; using System; using System.Drawing; using System.Windows.Forms; using UI; namespace UI { public partial class NotasComprasDFEPanel : FormularioModelo { private ModeloNotasComprasDFE _dfe = new ModeloNotasComprasDFE(); // Controles de UI private LV_TEXTBOX1 txtId, txtCodigo, txtChave; private ComboBox cbManifesto; private Label lblStatusSefaz; public NotasComprasDFEPanel() { this.Titulo = "Monitoramento de Notas da SEFAZ (DF-e)"; MontarInterface(); } private void MontarInterface() { // --- Área de Dados --- content.Controls.Add(CreateSectionHeader("DADOS DO DOCUMENTO LOCALIZADO", 20)); txtId = AddInput(content, "ID", 20, 50, 60, 30, true); txtCodigo = AddInput(content, "CÓDIGO INTERNO", 90, 50, 150, 30); txtChave = AddInput(content, "CHAVE DE ACESSO (44 DÍGITOS)", 20, 110, 540, 30); txtChave.ForeColor = Color.DarkBlue; // --- Status da Manifestação --- content.Controls.Add(CreateSectionHeader("AÇÃO DE MANIFESTAÇÃO", 175)); cbManifesto = new ComboBox { Location = new Point(25, 205), Size = new Size(300, 30), DropDownStyle = ComboBoxStyle.DropDownList, Font = new Font("Segoe UI", 10) }; cbManifesto.Items.AddRange(new object[] { "0 - Sem Manifestação", "1 - Ciência da Operação", "2 - Confirmação da Operação", "3 - Desconhecimento da Operação", "4 - Operação não Realizada" }); content.Controls.Add(cbManifesto); lblStatusSefaz = new Label { Text = "● Aguardando interação com SEFAZ", Location = new Point(340, 210), AutoSize = true, ForeColor = Color.Gray, Font = new Font("Segoe UI", 9, FontStyle.Bold) }; content.Controls.Add(lblStatusSefaz); content.Height = 280; } private void PreencherModel() { _dfe.CODIGO = txtCodigo.Text; _dfe.CHAVE = txtChave.Text; _dfe.MANIFESTADO = cbManifesto.SelectedIndex.ToString(); } private void MapModelParaTela(ModeloNotasComprasDFE model) { txtId.Text = model.ID_NOTAS_COMPRAS_DFE.ToString(); txtCodigo.Text = model.CODIGO; txtChave.Text = model.CHAVE; int index; if (int.TryParse(model.MANIFESTADO, out index) && index < cbManifesto.Items.Count) cbManifesto.SelectedIndex = index; else cbManifesto.SelectedIndex = 0; } // --- MÉTODOS OBRIGATÓRIOS DA CLASSE FormularioModelo --- protected override void OnNovo() { _dfe = new ModeloNotasComprasDFE(); txtId.Text = "0"; txtCodigo.Text = ""; txtChave.Text = ""; cbManifesto.SelectedIndex = 0; txtChave.Focus(); } protected override void OnSalvar() { if (txtChave.Text.Length < 44) { MessageBox.Show("A chave de acesso deve conter 44 caracteres.", "Erro de Validação"); return; } PreencherModel(); // Aqui entraria a chamada para a DLL de transmissão (ex: ACBr ou Zeus) lblStatusSefaz.Text = "● Manifesto enviado com sucesso!"; lblStatusSefaz.ForeColor = Color.Green; MessageBox.Show("Evento registrado no banco e enviado para a SEFAZ.", "LevelOS Fiscal"); } protected override void OnAlterar() { if (string.IsNullOrEmpty(txtId.Text) || txtId.Text == "0") { MessageBox.Show("Localize uma nota antes de tentar alterar."); return; } PreencherModel(); MessageBox.Show("Registro de manifesto atualizado."); } protected override void OnExcluir() { if (MessageBox.Show("Deseja remover este registro de DF-e local?", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { OnNovo(); } } protected override void OnLocalizar() { // Simulação de busca na tabela de documentos baixados MessageBox.Show("Abrindo lista de notas detectadas via Certificado Digital..."); } protected override void OnCancelar() { } } }