Example #1
0
        private void excluirItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_CUPOMELETRONICOID != -1)
            {
                using (FrmItensVenda frm = new FrmItensVenda())
                {
                    try
                    {
                        frm.CUPOMELETRONICOID = _CUPOMELETRONICOID;
                        frm.ShowDialog();
                        ExibirDadosCupom(_CUPOMELETRONICOID);
                        txtTotalVenda.Text = TotalCupom(_CUPOMELETRONICOID).ToString("n2");

                        CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                        CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(_CUPOMELETRONICOID);

                        if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4) //Aberto
                        {
                            CUPOMELETRONICOP.Save(Entity);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erro técnico: " + ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Cupom não selecionado!");
            }
        }
Example #2
0
        private void VerificaSituacaodoArquivo(string NumeroNota, int CUPOMELETRONICOID)
        {
            try
            {
                Application.DoEvents();
                this.Text = "Aguarde.. processando...";

                string arquivo = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Processados\NFCe_" + NumeroNota + ".txt";

                //100 Autorizado o uso da NF-e
                //101 Cancelamento de NF-e homologado
                //102 Inutilização de número homologado
                //103 Lote recebido com sucesso
                //104 Lote processado
                //105 Lote em processamento
                //106 Lote não localizado
                //107 Serviço em Operação
                //108 Serviço Paralisado Momentaneamente (curto prazo)
                //109 Serviço Paralisado sem Previsão
                //110 Uso Denegado
                //111 Consulta cadastro com uma ocorrência
                //112 Consulta cadastro com mais de uma ocorrência

                //usando a instrução using os recursos são liberados após a conclusão da operação

                if (File.Exists(arquivo))
                {
                    using (StreamReader sr = new StreamReader(arquivo))
                    {
                        String linha;
                        // Lê linha por linha até o final do arquivo
                        while ((linha = sr.ReadLine()) != null)
                        {
                            if (linha.IndexOf("|100|") != -1)//Autorizado
                            {
                                CUPOMELETRONICOEntity CUPOMELETRONICOTy_2 = new CUPOMELETRONICOEntity();
                                CUPOMELETRONICOTy_2 = CUPOMELETRONICOP.Read(CUPOMELETRONICOID);
                                CUPOMELETRONICOTy_2.IDSTATUSNFCE = 1;//Enviado
                                CUPOMELETRONICOTy_2.PROTOCOLO    = linha.Substring(3, 15);
                                CUPOMELETRONICOP.Save(CUPOMELETRONICOTy_2);
                            }
                        }
                    }
                }
                else
                {
                    Application.DoEvents();
                    this.Text = "Fechar Venda";
                }
            }
            catch (Exception ex)
            {
                Application.DoEvents();
                this.Text = "Fechar Venda";

                MessageBox.Show("Erro técnico: " + ex.Message);
            };
        }
Example #3
0
        private void cupomEletrônicoNFCeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_CUPOMELETRONICOID != -1)
            {
                CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(_CUPOMELETRONICOID);

                if (CUPOMELETRONICOTy.IDSTATUSNFCE == 1) //Enviado
                {
                    string strQrcode = CUPOMELETRONICOTy.STRQRCODE;

                    System.Threading.Thread.Sleep(100);
                    var    nfce          = new Nfce();
                    bool   isCtng        = false;
                    string edNomeArquivo = BmsSoftware.ConfigSistema1.Default.PathInstall + @"\\XMLGerado\NF_NFCe_" + CUPOMELETRONICOTy.NUMERONFCE + ".xml";

                    if (File.Exists(edNomeArquivo))
                    {
                        string htmlFile = nfce.Run(edNomeArquivo, isCtng);

                        /*
                         * O componente WebBrowser usado neste exemplo, infelizmente não processa imagens ou recursos não identificados,
                         * logo, necessita inserir o caminho completo (URI) para rodar, no Browser IE ou Chrome abre sem problemas,
                         * pois tem a referência do caminho e diretórios, mas neste caso, será inserido o path completo já que não existe
                         * a URI identificando o recurso, pois resolvemos retornar o HTML em vez de arquivo...
                         * Você pode resolver usando o protocolo res: [http://msdn.microsoft.com/en-us/library/aa767740.aspx], mas para
                         * demonstração, não foi considerado...
                         */
                        string path = ObterNomePathNfceXslt();
                        path     = path.Replace("\\", "/");
                        htmlFile = htmlFile.Replace("<img src=\"images/logoMarcaNFC.PNG\" alt=\"NFC-e\" width=\"80", "<img src=\"" + path + "/images/logoMarcaNFC.PNG\" alt=\"NFC-e\" width=\"80");
                        htmlFile = htmlFile.Replace("<img src=\"images/qrcode.png\" alt=\"QRCode", "<img src=\"" + path + "/images/qrcode.png\" alt=\"QRCode");
                        htmlFile = htmlFile.Replace("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/sefaz_nfce.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + path + "/css/sefaz_nfce.css");
                        //  webBrowser.DocumentText = htmlFile;

                        FrmExibirNFce Frm = new FrmExibirNFce();
                        Frm.CaminhoNFCe = htmlFile;
                        Frm.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Arquivo: " + edNomeArquivo + " não localizado!");
                    }
                }
            }
            else
            {
                MessageBox.Show("Cupom Eletrônico não foi enviado!");
            }
        }
Example #4
0
        private void FrmAlteraNFCe_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.FixedDialog;

            GetDropStatus();

            if (_CUPOMELETRONICOID != -1)
            {
                CUPOMELETRONICOTy      = CUPOMELETRONICOP.Read(_CUPOMELETRONICOID);
                lblNotaFiscal.Text     = CUPOMELETRONICOTy.NUMERONFCE.ToString().Trim();
                cbStatus.SelectedValue = CUPOMELETRONICOTy.IDSTATUSNFCE;
                txtChave.Text          = CUPOMELETRONICOTy.CHAVEACESSO.Trim();
                txtProtocolo.Text      = CUPOMELETRONICOTy.PROTOCOLO.Trim();
            }

            btnSair.Image = Util.GetAddressImage(21);
        }
Example #5
0
        private void fecharVendaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VerificaExisteNFCeContigencia();

            using (FrmFecharVenda frm = new FrmFecharVenda())
            {
                if (_CUPOMELETRONICOID != -1)
                {
                    frm.CUPOMELETRONICOID = _CUPOMELETRONICOID;
                    frm.ShowDialog();

                    if (frm.CUPOMELETRONICOID == -1)
                    {
                        novaVendaToolStripMenuItem_Click(null, null);
                    }
                    else
                    {
                        if (frm.CUPOMELETRONICOID != -1)
                        {
                            CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                            CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(frm.CUPOMELETRONICOID);

                            if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4) //Aberto
                            {
                                txtQuant.Enabled       = true;
                                txtValorUnit.Enabled   = true;
                                txtDescProduto.Enabled = true;
                            }
                            else
                            {
                                txtQuant.Enabled       = false;
                                txtValorUnit.Enabled   = false;
                                txtDescProduto.Text    = string.Empty;
                                txtDescProduto.Enabled = false;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Venda não selecionada!");
                }
            }
        }
Example #6
0
        private void FrmItensVenda_Load(object sender, EventArgs e)
        {
            try
            {
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                AddItemProdutosNFCe(CUPOMELETRONICOID);
                ExibirDadosCupom(CUPOMELETRONICOID);
                GetDropProdutos();

                btnSair.Image   = Util.GetAddressImage(21);
                btnSalvar.Image = Util.GetAddressImage(15);
                btnLimpar.Image = Util.GetAddressImage(16);

                CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(CUPOMELETRONICOID);

                if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4)// Aberto
                {
                    dtgItensCupom.Enabled = true;
                    cbProduto.Enabled     = true;
                    txtQuant.Enabled      = true;
                    txtvalorunit.Enabled  = true;
                    btnSalvar.Enabled     = true;
                    btnLimpar.Enabled     = true;
                }
                else
                {
                    dtgItensCupom.Enabled = false;
                    cbProduto.Enabled     = false;
                    txtQuant.Enabled      = false;
                    txtvalorunit.Enabled  = false;
                    btnSalvar.Enabled     = false;
                    btnLimpar.Enabled     = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }
Example #7
0
        private void PreencheGrid()
        {
            ValotTotalGeral = 0;

            CreaterCursor Cr = new CreaterCursor();

            this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

            DataGriewDados.Rows.Clear();
            CUPOMELETRONICOProvider CUPOMELETRONICOP = new CUPOMELETRONICOProvider();

            foreach (var LIS_PRODUTONFCETy in LIS_PRODUTONFCEColl)
            {
                CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(Convert.ToInt32(LIS_PRODUTONFCETy.CUPOMELETRONICOID));
                string NumCupom   = CUPOMELETRONICOTy.NUMERONFCE.ToString();
                string Data       = Convert.ToDateTime(CUPOMELETRONICOTy.DTEMISSAO).ToString("dd/MM/yyyy");
                string Produto    = LIS_PRODUTONFCETy.NOMEPRODUTO;
                string Quantidade = Convert.ToDecimal(LIS_PRODUTONFCETy.QUANTIDADE).ToString("n3");
                string VlUnit     = Convert.ToDecimal(LIS_PRODUTONFCETy.VALORUNITARIO).ToString("n3");
                string VlTotal    = Convert.ToDecimal(LIS_PRODUTONFCETy.VALORTOTAL).ToString("n2");

                ValotTotalGeral += Convert.ToDecimal(LIS_PRODUTONFCETy.VALORTOTAL);

                DataGridViewRow row2 = new DataGridViewRow();
                row2.CreateCells(DataGriewDados, NumCupom, Data, Produto, Quantidade, VlUnit, VlTotal);
                row2.DefaultCellStyle.Font = new Font("Arial", 8);
                DataGriewDados.Rows.Add(row2);
            }

            DataGridViewRow rowLinha = new DataGridViewRow();

            rowLinha.CreateCells(DataGriewDados, "", "", "", "", "Total Geral: ", ValotTotalGeral.ToString("n2"));
            rowLinha.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
            DataGriewDados.Rows.Add(rowLinha);

            this.Cursor = Cursors.Default;
        }
Example #8
0
        private void pesquisaToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            using (FrmPesquisaNFCe frm = new FrmPesquisaNFCe())
            {
                frm.ShowDialog();

                if (frm.Result > 0)
                {
                    ExibirDadosCupom(frm.Result);
                    txtTotalVenda.Text = Convert.ToDecimal(TotalCupom(frm.Result)).ToString("n2");

                    if (frm.Result != -1)
                    {
                        CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                        CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(frm.Result);

                        if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4) //Aberto
                        {
                            txtQuant.Enabled        = true;
                            txtValorUnit.Enabled    = true;
                            txtDescProduto.Enabled  = true;
                            txtTotalProduto.Enabled = true;
                            txtTotalProduto.Enabled = true;
                        }
                        else
                        {
                            txtQuant.Enabled        = false;
                            txtValorUnit.Enabled    = false;
                            txtDescProduto.Text     = string.Empty;
                            txtDescProduto.Enabled  = false;
                            txtTotalProduto.Enabled = false;
                            txtTotalProduto.Enabled = false;
                        }
                    }
                }
            }
        }
Example #9
0
        private void cancelarCupomEletrônicoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreaterCursor Cr = new CreaterCursor();

            this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

            NFCeService     ws        = NewWebService();
            retStatus       ret       = null;
            EMPRESAEntity   EMPRESATy = new EMPRESAEntity();
            EMPRESAProvider EMPRESAP  = new EMPRESAProvider();

            try
            {
                CUPOMELETRONICOEntity CUPOMELETRONICOTy = new CUPOMELETRONICOEntity();
                CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(_CUPOMELETRONICOID);

                if (CUPOMELETRONICOTy != null)
                {
                    DialogResult dr = MessageBox.Show("Deseja realmente cancelar o Cupom Eletrônico?",
                                                      ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo);
                    {
                        string justificativa = InputBox("Justificativa de Cancelamento da NFCe", ConfigSistema1.Default.NomeEmpresa, "");

                        if (justificativa.Trim() == string.Empty)
                        {
                            MessageBox.Show("Campo de Justificativa não poderá ser vazio!");
                        }
                        else if (justificativa.Trim().Length < 15)
                        {
                            MessageBox.Show("Campo de Justificativa deverá conter igual ou superior a 15 caracteres!");
                        }
                        else
                        {
                            EMPRESATy = EMPRESAP.Read(1);
                            ret       = ws.Cancela(Util.RetiraLetras(EMPRESATy.CNPJCPF), CUPOMELETRONICOTy.CHAVEACESSO, justificativa);

                            if (ret != null)
                            {
                                int resultCancel = ret.detalheCancelamento.ToString().IndexOf("135");  //135 : CANCELAMENTO -
                                if (resultCancel != -1)
                                {
                                    CUPOMELETRONICOTy.IDSTATUSNFCE = 2; // cancelamento

                                    char[]   split               = new char[] { '/', ',' };
                                    string[] detalheAut          = ret.detalheCancelamento.Split(split);
                                    string   DetalheCancelamento = string.Empty;
                                    foreach (var s in detalheAut)
                                    {
                                        DetalheCancelamento = @"  ==> " + s.Trim() + Environment.NewLine;
                                        if (DetalheCancelamento.ToString().IndexOf("nProt") != -1)
                                        {
                                            CUPOMELETRONICOTy.PROTOCOLOCANCEL = Util.RetiraLetras(DetalheCancelamento).Trim();
                                        }
                                    }

                                    CUPOMELETRONICOP.Save(CUPOMELETRONICOTy);
                                    MessageBox.Show(ret.detalheCancelamento);
                                }
                            }
                        }
                    }

                    this.Cursor = Cursors.Default;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("Cupom não selecionado!");
                }
            }
            catch (Exception exception)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show(exception.Message);
                Log.Debug(exception.Message);
            }
        }
Example #10
0
        private void DataGriewDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;

            if (LIS_CUPOMELETRONICOColl.Count > 0 && rowindex > -1)
            {
                int ColumnSelecionada = e.ColumnIndex;
                int CodSelect         = -1;

                if (ColumnSelecionada == 0)
                {
                    CodSelect = Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID);
                    Result    = CodSelect;
                    this.Close();
                }
                else if (ColumnSelecionada == 1)
                {
                    DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete,
                                                      ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo);

                    if (dr == DialogResult.Yes)
                    {
                        try
                        {
                            CodSelect         = Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID);
                            CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(CodSelect);

                            if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4)
                            {
                                CUPOMELETRONICOP.Delete(CodSelect);
                                btnPesquisa_Click(null, null);
                                Util.ExibirMSg(ConfigMessage.Default.MsgDelete2, "Blue");
                            }
                            else
                            {
                                MessageBox.Show("Não é possível excluir este Cupom Eletrônico!");
                            }
                        }
                        catch (Exception ex)
                        {
                            Util.ExibirMSg(ConfigMessage.Default.MsgDeleteErro, "Red");
                            MessageBox.Show("Erro técnico: " + ex.Message);
                        }
                    }
                }
                else if (ColumnSelecionada == 2)
                {
                    CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID));

                    if (CUPOMELETRONICOTy.IDSTATUSNFCE == 1)
                    {
                        if (BmsSoftware.ConfigNFCe.Default.EmpresaIntegra == "0") //0 - Benefix / 1 News Systems
                        {
                            CreaterCursor Cr = new CreaterCursor();
                            this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

                            string strQrcode = CUPOMELETRONICOTy.STRQRCODE;

                            System.Threading.Thread.Sleep(100);
                            var    nfce          = new Nfce();
                            bool   isCtng        = false;
                            string edNomeArquivo = BmsSoftware.ConfigSistema1.Default.PathInstall + @"\\XMLGerado\NF_NFCe_" + CUPOMELETRONICOTy.NUMERONFCE + ".xml";

                            if (File.Exists(edNomeArquivo))
                            {
                                string htmlFile = nfce.Run(edNomeArquivo, isCtng);

                                /*
                                 * O componente WebBrowser usado neste exemplo, infelizmente não processa imagens ou recursos não identificados,
                                 * logo, necessita inserir o caminho completo (URI) para rodar, no Browser IE ou Chrome abre sem problemas,
                                 * pois tem a referência do caminho e diretórios, mas neste caso, será inserido o path completo já que não existe
                                 * a URI identificando o recurso, pois resolvemos retornar o HTML em vez de arquivo...
                                 * Você pode resolver usando o protocolo res: [http://msdn.microsoft.com/en-us/library/aa767740.aspx], mas para
                                 * demonstração, não foi considerado...
                                 */
                                string path = ObterNomePathNfceXslt();
                                path     = path.Replace("\\", "/");
                                htmlFile = htmlFile.Replace("<img src=\"images/logoMarcaNFC.PNG\" alt=\"NFC-e\" width=\"80", "<img src=\"" + path + "/images/logoMarcaNFC.PNG\" alt=\"NFC-e\" width=\"80");
                                htmlFile = htmlFile.Replace("<img src=\"images/qrcode.png\" alt=\"QRCode", "<img src=\"" + path + "/images/qrcode.png\" alt=\"QRCode");
                                htmlFile = htmlFile.Replace("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/sefaz_nfce.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + path + "/css/sefaz_nfce.css");
                                //  webBrowser.DocumentText = htmlFile;

                                if (BmsSoftware.ConfigNFCe.Default.TipoImpressao == "1")              //Termica
                                {
                                    if (BmsSoftware.ConfigNFCe.Default.NomeFabImpressora == "Daruma") //Daruma
                                    {
                                        ImprimirDaruma(strQrcode, edNomeArquivo, edNomeArquivo);
                                    }
                                }
                                else if (BmsSoftware.ConfigNFCe.Default.TipoImpressao == "2") //Lajer/Jato de Tinta
                                {
                                    FrmExibirNFce Frm = new FrmExibirNFce();
                                    Frm.CaminhoNFCe = htmlFile;
                                    Frm.ShowDialog();
                                }

                                this.Cursor = Cursors.Default;
                            }
                            else
                            {
                                MessageBox.Show("Arquivo: " + edNomeArquivo + " não localizado!");
                            }
                        }
                        else // 1 News Systems
                        {
                            string       arquivo  = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Remessas\REIMP_NFE_" + CUPOMELETRONICOTy.NUMERONFCE + ".txt";
                            StreamWriter escrever = new StreamWriter(arquivo, false, Encoding.GetEncoding(1252));

                            try
                            {
                                escrever.WriteLine("REIMPRIME|1|");
                                escrever.WriteLine("A|" + CUPOMELETRONICOTy.CHAVEACESSO);
                                escrever.Close();
                            }
                            catch (Exception ex)
                            {
                                escrever.Close();
                                MessageBox.Show("Erro técnico: " + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Esta Nota Fiscal não foi enviada!");
                    }
                }
                else if (ColumnSelecionada == 3) //Cancelar NFCe
                {
                    CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID));

                    if (CUPOMELETRONICOTy.IDSTATUSNFCE == 1)                                                                      //Enviada
                    {
                        string xJust = InputBox("Justificativa de Cancelamento da NFCe", ConfigSistema1.Default.NomeEmpresa, ""); //Motivo do Cancelamento da Nfe

                        if (xJust.Length > 15)
                        {
                            string       arquivo  = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Remessas\NFCe_Canc_" + CUPOMELETRONICOTy.NUMERONFCE + ".txt";
                            StreamWriter escrever = new StreamWriter(arquivo, false, Encoding.GetEncoding(1252));

                            try
                            {
                                this.Text = "Aguarde Processando...";
                                Application.DoEvents();

                                EMPRESAEntity   EMPRESATy = new EMPRESAEntity();
                                EMPRESAProvider EMPRESAP  = new EMPRESAProvider();
                                EMPRESATy = EMPRESAP.Read(1);

                                //Cancelamento de NFC-e - Via Evento
                                //Identificação do Tipo de Comando
                                escrever.WriteLine("EVENTO|1|");

                                //Atributos da Cancelamento
                                string versao = "1.00";         // ; Versão do leiaute
                                string Id     = "CANCELAMENTO"; // ; Identificador do tipo de evento
                                escrever.WriteLine("A|" + versao + "|" + Id + "|");

                                //Identificadores do Cancelamento
                                string cUF = BuscaCodigoUF(EMPRESATy.UF).ToString(); //1 - Código da UF do emitente do Documento Fiscal

                                string tpAmb = "1";                                  //2 - Identificação do Ambiente //1 - Produção/ 2 - Homologação
                                if (BmsSoftware.ConfigNFCe.Default.IdentificacaoAmbiente == "P")
                                {
                                    tpAmb = "1";
                                }
                                else if (BmsSoftware.ConfigNFCe.Default.IdentificacaoAmbiente == "H")
                                {
                                    tpAmb = "2";
                                }

                                string ChNFe      = CUPOMELETRONICOTy.CHAVEACESSO;                                     //3 - Chave de acesso da NF-e a ser corrigida
                                string dEmi       = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); // 4 - Data de Emissão do Evento de Cancelamento
                                string hEmi       = DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture);   //54 - Hora de Emissão do Evento de Cancelamento
                                string TZD        = BmsSoftware.ConfigNFCe.Default.DiferencaFuxoHorario;               // UTC  TZD (UTC - Universal Coordinated Time,onde TZD pode ser -02:00 (Fernando de Noronha), -03:00(Brasília) ou -04:00 (Manaus), no horário de verão serão -01:00, -02:00 e -03:00. Ex.: 2010-08-19T13:00:15-03:00.
                                string tpEvento   = "110111";                                                          //Tipo de Evento da Nfe //Código do de evento = 110111 Código do Evento de Cancelamento
                                string nSeqEvento = "1";                                                               //Numero Sequencial do Evento //Seqüencial do evento para o mesmo tipo de evento. Parao evento de cancelamento será 1

                                escrever.WriteLine("B|" + cUF + "|" + Id + "|" + tpAmb + "|" + ChNFe + "|" + dEmi + "|" + hEmi + "|" + TZD + "|" + tpEvento + "|" + nSeqEvento +
                                                   "|");

                                //Emitente
                                string CNPJ = Util.RetiraLetras(EMPRESATy.CNPJCPF);
                                escrever.WriteLine("C02|" + CNPJ + "|");

                                //Dados do Cancelamento
                                string descEvento = "Cancelamento";              //Descrição do Evento
                                string nProt      = CUPOMELETRONICOTy.PROTOCOLO; //Numero Protocolo da NF-e Informar o número do Protocolo de Autorização da NF-e a ser Cancelada

                                escrever.WriteLine("E|" + descEvento + "|" + nProt + "|" + xJust + "|");
                                escrever.Close();

                                this.Text = "Fechar Venda";
                                Application.DoEvents();

                                VerificaSituacaodoArquivoCancelado(CUPOMELETRONICOTy.NUMERONFCE.ToString());

                                btnPesquisa_Click(null, null);
                            }
                            catch (Exception ex)
                            {
                                escrever.Close();
                                MessageBox.Show("Erro técnico: " + ex.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Campo de Justificativa deverá conter igual ou superior a 15 caracteres!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Cupom Eletrônico não enviado!");
                    }
                }
            }
        }
Example #11
0
        private void DataGriewDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;

            if (LIS_CUPOMELETRONICOColl.Count > 0 && rowindex > -1)
            {
                int ColumnSelecionada = e.ColumnIndex;
                int CodSelect         = -1;

                if (ColumnSelecionada == 0) //editar
                {
                    if (LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID > 0)
                    {
                        CodSelect = Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID);
                        Result    = CodSelect;
                        this.Close();
                    }
                }
                else if (ColumnSelecionada == 1)//Excluir
                {
                    DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete,
                                                      ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo);

                    if (dr == DialogResult.Yes)
                    {
                        try
                        {
                            if (LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID > 0)
                            {
                                CodSelect         = Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID);
                                CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(CodSelect);

                                if (CUPOMELETRONICOTy.IDSTATUSNFCE == 4)
                                {
                                    //Apaga os produtos do cupom
                                    RowRelatorio.Clear();
                                    RowRelatorio.Add(new RowsFiltro("CUPOMELETRONICOID", "System.Int32", "=", CodSelect.ToString()));
                                    PRODUTONFCECollection PRODUTONFCEColl = new PRODUTONFCECollection();
                                    PRODUTONFCEProvider   PRODUTONFCEP    = new PRODUTONFCEProvider();
                                    PRODUTONFCEColl = PRODUTONFCEP.ReadCollectionByParameter(RowRelatorio);
                                    foreach (PRODUTONFCEEntity item in PRODUTONFCEColl)
                                    {
                                        PRODUTONFCEP.Delete(item.PRODUTONFCEID);
                                    }

                                    CUPOMELETRONICOP.Delete(CodSelect);
                                    btnPesquisa_Click(null, null);
                                    Util.ExibirMSg(ConfigMessage.Default.MsgDelete2, "Blue");
                                }
                                else
                                {
                                    MessageBox.Show("Não é possível excluir este Cupom Eletrônico!");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Util.ExibirMSg(ConfigMessage.Default.MsgDeleteErro, "Red");
                            MessageBox.Show("Erro técnico: " + ex.Message);
                        }
                    }
                }
                else if (ColumnSelecionada == 2)//Imprimir
                {
                    CreaterCursor Cr = new CreaterCursor();
                    this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

                    if (LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID > 0)
                    {
                        CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID));
                    }

                    if (CUPOMELETRONICOTy.CHAVEACESSO != string.Empty)
                    {
                        string       arquivo  = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Remessas\REIMP_NFE_" + CUPOMELETRONICOTy.NUMERONFCE + ".txt";
                        StreamWriter escrever = new StreamWriter(arquivo, false, Encoding.GetEncoding(1252));

                        try
                        {
                            this.Cursor = Cursors.Default;
                            escrever.WriteLine("REIMPRIME|1|");
                            escrever.WriteLine("A|" + Util.RetiraLetras(CUPOMELETRONICOTy.CHAVEACESSO) + "|");
                            escrever.Close();
                        }
                        catch (Exception ex)
                        {
                            this.Cursor = Cursors.Default;
                            escrever.Close();
                            MessageBox.Show("Erro técnico: " + ex.Message);
                        }

                        this.Cursor = Cursors.Default;
                    }
                    else
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("Esta Nota Fiscal não foi enviada!");
                    }
                }
                else if (ColumnSelecionada == 3) //Cancelar NFCe
                {
                    if (LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID > 0)
                    {
                        CUPOMELETRONICOTy = CUPOMELETRONICOP.Read(Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID));
                    }

                    if (CUPOMELETRONICOTy != null && CUPOMELETRONICOTy.IDSTATUSNFCE == 1)                                         //Enviada
                    {
                        string xJust = InputBox("Justificativa de Cancelamento da NFCe", ConfigSistema1.Default.NomeEmpresa, ""); //Motivo do Cancelamento da Nfe

                        if (xJust.Length > 15)
                        {
                            string       arquivo  = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Remessas\NFCe_Canc_" + CUPOMELETRONICOTy.NUMERONFCE + ".txt";
                            StreamWriter escrever = new StreamWriter(arquivo, false, Encoding.GetEncoding(1252));

                            try
                            {
                                this.Text = "Aguarde Processando...";
                                Application.DoEvents();

                                EMPRESAEntity   EMPRESATy = new EMPRESAEntity();
                                EMPRESAProvider EMPRESAP  = new EMPRESAProvider();
                                EMPRESATy = EMPRESAP.Read(1);

                                //Cancelamento de NFC-e - Via Evento
                                //Identificação do Tipo de Comando
                                escrever.WriteLine("EVENTO|1|");

                                //Atributos da Cancelamento
                                string versao = "1.00";         // ; Versão do leiaute
                                string Id     = "CANCELAMENTO"; // ; Identificador do tipo de evento
                                escrever.WriteLine("A|" + versao + "|" + Id + "|");

                                //Identificadores do Cancelamento
                                string cUF = BuscaCodigoUF(EMPRESATy.UF).ToString(); //1 - Código da UF do emitente do Documento Fiscal

                                string tpAmb = "1";                                  //2 - Identificação do Ambiente //1 - Produção/ 2 - Homologação
                                if (BmsSoftware.ConfigNFCe.Default.IdentificacaoAmbiente == "P")
                                {
                                    tpAmb = "1";
                                }
                                else if (BmsSoftware.ConfigNFCe.Default.IdentificacaoAmbiente == "H")
                                {
                                    tpAmb = "2";
                                }

                                string ChNFe      = CUPOMELETRONICOTy.CHAVEACESSO;                                     //3 - Chave de acesso da NF-e a ser corrigida
                                string dEmi       = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); // 4 - Data de Emissão do Evento de Cancelamento
                                string hEmi       = DateTime.Now.ToString("hh:mm:ss", CultureInfo.InvariantCulture);   //54 - Hora de Emissão do Evento de Cancelamento
                                string TZD        = BmsSoftware.ConfigNFCe.Default.DiferencaFuxoHorario;               // UTC  TZD (UTC - Universal Coordinated Time,onde TZD pode ser -02:00 (Fernando de Noronha), -03:00(Brasília) ou -04:00 (Manaus), no horário de verão serão -01:00, -02:00 e -03:00. Ex.: 2010-08-19T13:00:15-03:00.
                                string tpEvento   = "110111";                                                          //Tipo de Evento da Nfe //Código do de evento = 110111 Código do Evento de Cancelamento
                                string nSeqEvento = "1";                                                               //Numero Sequencial do Evento //Seqüencial do evento para o mesmo tipo de evento. Parao evento de cancelamento será 1

                                escrever.WriteLine("B|" + cUF + "|" + Id + "|" + tpAmb + "|" + ChNFe + "|" + dEmi + "|" + hEmi + "|" + TZD + "|" + tpEvento + "|" + nSeqEvento +
                                                   "|");

                                //Emitente
                                string CNPJ = Util.RetiraLetras(EMPRESATy.CNPJCPF);
                                escrever.WriteLine("C02|" + CNPJ + "|");

                                //Dados do Cancelamento
                                string descEvento = "Cancelamento";              //Descrição do Evento
                                string nProt      = CUPOMELETRONICOTy.PROTOCOLO; //Numero Protocolo da NF-e Informar o número do Protocolo de Autorização da NF-e a ser Cancelada

                                escrever.WriteLine("E|" + descEvento + "|" + nProt + "|" + xJust + "|");
                                escrever.Close();

                                this.Text = "Pesquisa Cupom NFCe";
                                Application.DoEvents();

                                VerificaSituacaodoArquivoCancelado(CUPOMELETRONICOTy.NUMERONFCE.ToString());

                                btnPesquisa_Click(null, null);
                            }
                            catch (Exception ex)
                            {
                                escrever.Close();
                                MessageBox.Show("Erro técnico: " + ex.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Campo de Justificativa deverá conter igual ou superior a 15 caracteres!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Cupom Eletrônico não enviado!");
                    }
                }
                else if (ColumnSelecionada == 4) //editar
                {
                    if (LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID > 0)
                    {
                        CodSelect = Convert.ToInt32(LIS_CUPOMELETRONICOColl[rowindex].CUPOMELETRONICOID);

                        FrmAlteraNFCe Frm = new FrmAlteraNFCe();
                        Frm._CUPOMELETRONICOID = CodSelect;
                        Frm.ShowDialog();
                    }
                }
            }
        }
Example #12
0
        private void VerificaArquivoContingencia(string NumeroNota, int CUPOMELETRONICOID)
        {
            CreaterCursor Cr = new CreaterCursor();

            this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

            try
            {
                string arquivo = BmsSoftware.ConfigNFCe.Default.LocalInstalacaoNewSystems + @"\Processados\nsConcluido\contingencia_ret.txt";

                Application.DoEvents();
                this.Text = "Aguarde.. processando...";

                //100 Autorizado o uso da NF-e
                //101 Cancelamento de NF-e homologado
                //102 Inutilização de número homologado
                //103 Lote recebido com sucesso
                //104 Lote processado
                //105 Lote em processamento
                //106 Lote não localizado
                //107 Serviço em Operação
                //108 Serviço Paralisado Momentaneamente (curto prazo)
                //109 Serviço Paralisado sem Previsão
                //110 Uso Denegado
                //111 Consulta cadastro com uma ocorrência
                //112 Consulta cadastro com mais de uma ocorrência

                //usando a instrução using os recursos são liberados após a conclusão da operação

                if (File.Exists(arquivo))
                {
                    CUPOMELETRONICOEntity CUPOMELETRONICOTy_2 = new CUPOMELETRONICOEntity();
                    CUPOMELETRONICOTy_2 = CUPOMELETRONICOP.Read(CUPOMELETRONICOID);

                    using (StreamReader sr = new StreamReader(arquivo))
                    {
                        String linha;
                        // Lê linha por linha até o final do arquivo
                        while ((linha = sr.ReadLine()) != null)
                        {
                            if (Util.RetiraLetras(CUPOMELETRONICOTy_2.CHAVEACESSO) != string.Empty)
                            {
                                if (linha.IndexOf(Util.RetiraLetras(CUPOMELETRONICOTy_2.CHAVEACESSO)) != -1) //Chave de acesso na linha
                                {
                                    if (linha.IndexOf("Autorizado") != -1)                                   //Autorizado
                                    {
                                        CUPOMELETRONICOTy_2.IDSTATUSNFCE = 1;                                //Enviado
                                        CUPOMELETRONICOTy_2.PROTOCOLO    = Util.RetiraLetras(linha.Substring(3, 16));
                                        CUPOMELETRONICOP.Save(CUPOMELETRONICOTy_2);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Application.DoEvents();
                }

                this.Cursor = Cursors.Default;
                this.Text   = "  IMEX Sistemas - NFCe Nota Fiscal de Consumidor Eletrônica";
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                this.Text   = "  IMEX Sistemas - NFCe Nota Fiscal de Consumidor Eletrônica";
                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }