private void dtgItensCupom_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int rowindex = e.RowIndex; if (LIS_PRODUTONFCEColl.Count > 0 && rowindex > -1) { int ColumnSelecionada = e.ColumnIndex; int CodSelect = -1; if (ColumnSelecionada == 0)//Editar { try { if (LIS_PRODUTONFCEColl[rowindex].IDSTATUSNFCE == 4) // Aberto { CodSelect = Convert.ToInt32(LIS_PRODUTONFCEColl[rowindex].PRODUTONFCEID); PRODUTONFCETy = PRODUTONFCEP.Read(CodSelect); txtQuant.Text = Convert.ToDecimal(PRODUTONFCETy.QUANTIDADE).ToString("n2"); cbProduto.SelectedValue = PRODUTONFCETy.IDPRODUTO; txtvalorunit.Text = Convert.ToDecimal(PRODUTONFCETy.VALORUNITARIO).ToString("n2"); txtVlTotal.Text = Convert.ToDecimal(PRODUTONFCETy.VALORTOTAL).ToString("n2"); } else { MessageBox.Show("Cupom Já Emitido, Não é Possível Alterar!"); } } catch (Exception ex) { MessageBox.Show("Erro técnico: " + ex.Message); } } else if (ColumnSelecionada == 1) //Excluir { if (LIS_PRODUTONFCEColl[rowindex].IDSTATUSNFCE == 4) // Aberto { DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete, ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { try { CodSelect = Convert.ToInt32(LIS_PRODUTONFCEColl[rowindex].PRODUTONFCEID); PRODUTONFCEP.Delete(CodSelect); ExibirDadosCupom(CUPOMELETRONICOID); MessageBox.Show(ConfigMessage.Default.MsgDelete2); } catch (Exception ex) { MessageBox.Show(ConfigMessage.Default.MsgDeleteErro); MessageBox.Show("Erro técnico: " + ex.Message); } } } else { MessageBox.Show("Cupom Já Emitido, Não é Possível Excluir!"); } } } }
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(); } } } }