private static MENSAGEMNFEEntity FillEntityObject(ref FbDataReader DataReader) { MENSAGEMNFEEntity entity = new MENSAGEMNFEEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDMENSAGEMNFE = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDMENSAGEMNFE")); entity.MENSAGEM = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("MENSAGEM")); entity.NOME = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOME")); return(entity); }
private void GetDropMensagem() { MENSAGEMNFEProvider MENSAGEMNFEP = new MENSAGEMNFEProvider(); MENSAGEMNFEColl = MENSAGEMNFEP.ReadCollectionByParameter(null); cbMensagem.DisplayMember = "NOME"; cbMensagem.ValueMember = "IDMENSAGEMNFE"; MENSAGEMNFEEntity MENSAGEMNFETy = new MENSAGEMNFEEntity(); MENSAGEMNFETy.NOME = ConfigMessage.Default.MsgDrop; MENSAGEMNFETy.IDMENSAGEMNFE = -1; MENSAGEMNFEColl.Add(MENSAGEMNFETy); Phydeaux.Utilities.DynamicComparer <MENSAGEMNFEEntity> comparer = new Phydeaux.Utilities.DynamicComparer <MENSAGEMNFEEntity>(cbMensagem.DisplayMember); MENSAGEMNFEColl.Sort(comparer.Comparer); cbMensagem.DataSource = MENSAGEMNFEColl; // cbMensagem.SelectedIndex = 0; }
public MENSAGEMNFEEntity Read(int IDMENSAGEMNFE) { FbDataReader reader = null; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_MENSAGEMNFE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_MENSAGEMNFE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDMENSAGEMNFE", IDMENSAGEMNFE); //PrimaryKey reader = dbCommand.ExecuteReader(); MENSAGEMNFEEntity entity = null; if (reader.HasRows) { while (reader.Read()) { entity = FillEntityObject(ref reader); } } // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } // Fecha conexão if (dbTransaction == null) { dbCommand.Transaction.Commit(); if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } return(entity); } catch (Exception ex) { // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
public int Save(MENSAGEMNFEEntity Entity) { int result = 0; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_MENSAGEMNFE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_MENSAGEMNFE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; if (Entity.IDMENSAGEMNFE != -1) { dbCommand.Parameters.AddWithValue("@IDMENSAGEMNFE", Entity.IDMENSAGEMNFE); //PrimaryKey } else { dbCommand.Parameters.AddWithValue("@IDMENSAGEMNFE", DBNull.Value); //PrimaryKey } dbCommand.Parameters.AddWithValue("@MENSAGEM", Entity.MENSAGEM); //Coluna dbCommand.Parameters.AddWithValue("@NOME", Entity.NOME); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDMENSAGEMNFE"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDMENSAGEMNFE"].Value.ToString()); if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } } catch (Exception ex) { if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } return(result); }