Ejemplo n.º 1
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!");
            }
        }
Ejemplo n.º 2
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!");
                    }
                }
            }
        }