@@ -382,7 +382,7 @@ private void BtnInsucessoEntrega_Click(object sender, RoutedEventArgs e)
382
382
}
383
383
}
384
384
385
- private void BtnCancInsucessoEntrega_Click ( object sender , RoutedEventArgs e )
385
+ private void BtnCancInsucessoEntrega_Click ( object sender , RoutedEventArgs e )
386
386
{
387
387
const string titulo = "Cancelar Insucesso Entrega NFe" ;
388
388
@@ -435,6 +435,143 @@ private void BtnCancInsucessoEntrega_Click(object sender, RoutedEventArgs e)
435
435
}
436
436
}
437
437
438
+ private void BtnComprovanteEntrega_Click ( object sender , RoutedEventArgs e )
439
+ {
440
+ const string titulo = "Comprovante Entrega NFe" ;
441
+
442
+ try
443
+ {
444
+ #region Comprovante Entrega NFe
445
+
446
+ var idlote = Funcoes . InpuBox ( this , titulo , "Identificador de controle do Lote de envio:" , "1" ) ;
447
+ if ( string . IsNullOrEmpty ( idlote ) ) throw new Exception ( "A Id do Lote deve ser informada!" ) ;
448
+
449
+ var sequenciaEvento = Funcoes . InpuBox ( this , titulo , "Número sequencial do evento:" , "1" ) ;
450
+ if ( string . IsNullOrEmpty ( sequenciaEvento ) )
451
+ throw new Exception ( "O número sequencial deve ser informado!" ) ;
452
+
453
+ var chave = Funcoes . InpuBox ( this , titulo , "Chave da NFe:" , "35240311656919000154550750000008281647961399" ) ;
454
+ if ( string . IsNullOrEmpty ( chave ) ) throw new Exception ( "A Chave deve ser informada!" ) ;
455
+ if ( chave . Length != 44 ) throw new Exception ( "Chave deve conter 44 caracteres!" ) ;
456
+
457
+ var dhEntregaStr = Funcoes . InpuBox ( this , titulo , "Data da entrega da NFe" , DateTimeOffset . Now . ToString ( "dd/MM/yyyy" ) ) ;
458
+ if ( string . IsNullOrEmpty ( dhEntregaStr ) ) throw new Exception ( "A Data deve ser informada!" ) ;
459
+
460
+ if ( ! DateTimeOffset . TryParse ( dhEntregaStr , out DateTimeOffset dhEntrega ) )
461
+ throw new Exception ( "Data inválida!" ) ;
462
+
463
+ var nDoc = Funcoes . InpuBox ( this , titulo , "Documento da Pessoa:" , "1234" ) ;
464
+ if ( string . IsNullOrEmpty ( nDoc ) ) throw new Exception ( "Número do documento deve ser informado!" ) ;
465
+
466
+ var xNome = Funcoes . InpuBox ( this , titulo , "Nome da Pessoa:" , "José da Silva" ) ;
467
+ if ( string . IsNullOrEmpty ( xNome ) ) throw new Exception ( "Nome da Pessoa deve ser informado!" ) ;
468
+
469
+ var imagemExemploBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADUlEQVR42gECAP3/AP8BAQEATamDVwAAAABJRU5ErkJggg==" ;
470
+ var concatenacao = chave + imagemExemploBase64 ;
471
+
472
+ var hashComprovante = string . Empty ;
473
+ using ( SHA1 sha1 = SHA1 . Create ( ) )
474
+ {
475
+ byte [ ] inputBytes = Encoding . UTF8 . GetBytes ( concatenacao ) ;
476
+ byte [ ] hashBytes = sha1 . ComputeHash ( inputBytes ) ;
477
+ // O hash SHA-1 terá 20 bytes
478
+ hashComprovante = Convert . ToBase64String ( hashBytes ) . Trim ( ) ;
479
+ }
480
+
481
+ DateTimeOffset ? dhHashComprovante = null ;
482
+ var dhHashComprovanteStr = Funcoes . InpuBox ( this , titulo , "Data geração do Hash Tentativa na Entrega:" , DateTimeOffset . Now . ToString ( "dd/MM/yyyy" ) ) ;
483
+ if ( ! string . IsNullOrEmpty ( dhHashComprovanteStr ) ) dhHashComprovante = Convert . ToDateTime ( dhHashComprovanteStr ) ;
484
+
485
+ decimal ? latGps = null ;
486
+ var latGpsStr = Funcoes . InpuBox ( this , titulo , "Latitude GPS:" ) ;
487
+ if ( ! string . IsNullOrEmpty ( latGpsStr ) ) latGps = Convert . ToDecimal ( latGpsStr ) ;
488
+
489
+ decimal ? longGps = null ;
490
+ var longGpsStr = Funcoes . InpuBox ( this , titulo , "Latitude GPS:" ) ;
491
+ if ( ! string . IsNullOrEmpty ( longGpsStr ) ) longGps = Convert . ToDecimal ( longGpsStr ) ;
492
+
493
+
494
+ var servicoNFe = new ServicosNFe ( _configuracoes . CfgServico ) ;
495
+ var cpfcnpj = string . IsNullOrEmpty ( _configuracoes . Emitente . CNPJ )
496
+ ? _configuracoes . Emitente . CPF
497
+ : _configuracoes . Emitente . CNPJ ;
498
+
499
+ var retornoComprovante = servicoNFe . RecepcaoEventoComprovanteEntrega ( Convert . ToInt32 ( idlote ) ,
500
+ Convert . ToInt16 ( sequenciaEvento ) , cpfcnpj , chave , dhEntrega , nDoc , xNome , hashComprovante ,
501
+ dhHashComprovante , latGps , longGps , DFe . Classes . Entidades . Estado . SP ) ;
502
+
503
+ TrataRetorno ( retornoComprovante ) ;
504
+
505
+ #endregion
506
+ }
507
+ catch ( ComunicacaoException ex )
508
+ {
509
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
510
+ }
511
+ catch ( ValidacaoSchemaException ex )
512
+ {
513
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
514
+ }
515
+ catch ( Exception ex )
516
+ {
517
+ if ( ! string . IsNullOrEmpty ( ex . Message ) )
518
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
519
+ }
520
+ }
521
+
522
+ private void BtnCancComprovanteEntrega_Click ( object sender , RoutedEventArgs e )
523
+ {
524
+ const string titulo = "Cancelar Comprovante Entrega NFe" ;
525
+
526
+ try
527
+ {
528
+ #region Cancelar Comprovante Entrega NFe
529
+
530
+ var idlote = Funcoes . InpuBox ( this , titulo , "Identificador de controle do Lote de envio:" , "1" ) ;
531
+ if ( string . IsNullOrEmpty ( idlote ) ) throw new Exception ( "A Id do Lote deve ser informada!" ) ;
532
+
533
+ var sequenciaEvento = Funcoes . InpuBox ( this , titulo , "Número sequencial do evento:" , "1" ) ;
534
+ if ( string . IsNullOrEmpty ( sequenciaEvento ) )
535
+ throw new Exception ( "O número sequencial deve ser informado!" ) ;
536
+
537
+ var chave = Funcoes . InpuBox ( this , titulo , "Chave da NFe:" , "35240311656919000154550750000008281647961399" ) ;
538
+ if ( string . IsNullOrEmpty ( chave ) ) throw new Exception ( "A Chave deve ser informada!" ) ;
539
+ if ( chave . Length != 44 ) throw new Exception ( "Chave deve conter 44 caracteres!" ) ;
540
+
541
+ var nProtEvento = Funcoes . InpuBox ( this , titulo , "Nº Prot Evento:" ) ;
542
+
543
+ if ( string . IsNullOrEmpty ( nProtEvento ) )
544
+ throw new Exception ( "O nº Prot Evento deve ser informado!" ) ;
545
+
546
+
547
+
548
+ var servicoNFe = new ServicosNFe ( _configuracoes . CfgServico ) ;
549
+ var cpfcnpj = string . IsNullOrEmpty ( _configuracoes . Emitente . CNPJ )
550
+ ? _configuracoes . Emitente . CPF
551
+ : _configuracoes . Emitente . CNPJ ;
552
+
553
+ var retornoComprovante = servicoNFe . RecepcaoEventoCancComprovanteEntrega ( Convert . ToInt32 ( idlote ) ,
554
+ Convert . ToInt16 ( sequenciaEvento ) , cpfcnpj , chave , nProtEvento ) ;
555
+
556
+ TrataRetorno ( retornoComprovante ) ;
557
+
558
+ #endregion
559
+ }
560
+ catch ( ComunicacaoException ex )
561
+ {
562
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
563
+ }
564
+ catch ( ValidacaoSchemaException ex )
565
+ {
566
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
567
+ }
568
+ catch ( Exception ex )
569
+ {
570
+ if ( ! string . IsNullOrEmpty ( ex . Message ) )
571
+ Funcoes . Mensagem ( ex . Message , "Erro" , MessageBoxButton . OK ) ;
572
+ }
573
+ }
574
+
438
575
private void BtnConsultaXml_Click ( object sender , RoutedEventArgs e )
439
576
{
440
577
try
0 commit comments