private static PRODUTONFCECollection ExecuteReader(ref PRODUTONFCECollection collection, ref FbDataReader dataReader, FbCommand dbCommand) { using (dataReader = dbCommand.ExecuteReader()) { collection = new PRODUTONFCECollection(); if (dataReader.HasRows) { while (dataReader.Read()) { collection.Add(FillEntityObject(ref dataReader)); } } if (!(dataReader.IsClosed)) { dataReader.Close(); } dataReader.Dispose(); } return(collection); }
public PRODUTONFCECollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder) { FbDataReader dataReader = null; PRODUTONFCECollection collection = null; string strSqlCommand = String.Empty; try { if (RowsFiltro != null) { if (RowsFiltro.Count > 0) { strSqlCommand = "SELECT * FROM PRODUTONFCE WHERE ("; ArrayList _rowsFiltro = new ArrayList(); RowsFiltro.ForEach(delegate(RowsFiltro i) { string[] item = { i.Condicao.ToString(), i.Campo.ToString(), i.Tipo.ToString(), i.Operador.ToString(), i.Valor.ToString() }; _rowsFiltro.Add(item); }); int _count = 1; foreach (string[] item in _rowsFiltro) { strSqlCommand += "(" + item[1] + " " + item[3]; switch (item[2]) { case ("System.String"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int16"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int32"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int64"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Double"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Decimal"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Float"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Byte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.SByte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.Char"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.DateTime"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Guid"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Boolean"): strSqlCommand += " " + item[4] + ")"; break; } if (_rowsFiltro.Count > 1) { if (_count < _rowsFiltro.Count) { strSqlCommand += " " + item[0] + " "; } _count++; } } strSqlCommand += ") order by " + FieldOrder; } else { strSqlCommand = "SELECT * FROM PRODUTONFCE order by " + FieldOrder; } } else { strSqlCommand = "SELECT * FROM PRODUTONFCE order by " + FieldOrder; } //Verificando a existência de um transação if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = new FbConnection(connectionString); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } collection = ExecuteReader(ref collection, ref dataReader, dbCommand); if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } return(collection); } catch (Exception ex) { // Deleta reader if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
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(); } } } }