private void btnAdVeiculo_Click(object sender, EventArgs e) { if (_IDCLIENTE == -1) { MessageBox.Show("Antes de adicionar o veículo é necessário gravar o cliente!", ConfigSistema1.Default.NomeEmpresa, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } else { if (ValidacoesVeiculos()) { try { //Grava itens de serviços VEICULOCLIENTEP.Save(Entity); Util.ExibirMSg(ConfigMessage.Default.MsgSave, "Blue"); Entity = null; } catch (Exception ex) { MessageBox.Show(ConfigMessage.Default.MsgSaveErro); MessageBox.Show("Erro técnico : " + ex.Message); } ListaVeiculoCliente(_IDCLIENTE); } } }
private static VEICULOCLIENTEEntity FillEntityObject(ref FbDataReader DataReader) { VEICULOCLIENTEEntity entity = new VEICULOCLIENTEEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDVEICULOCLIENTE = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDVEICULOCLIENTE")); entity.IDCLIENTE = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLIENTE")); entity.PLACA = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("PLACA")); entity.ANOFABR = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("ANOFABR")); entity.ANOMODELO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("ANOMODELO")); entity.IDCOR = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCOR")); entity.CHASSIS = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CHASSIS")); entity.MARCAMODELO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("MARCAMODELO")); return(entity); }
private void DSVeiculoCliente_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int rowindex = e.RowIndex; if (LIS_VEICULOCLIENTEColl.Count > 0 && rowindex > -1) { int ColumnSelecionada = e.ColumnIndex; int CodSelect = -1; if (ColumnSelecionada == 0)//Editar { CodSelect = Convert.ToInt32(LIS_VEICULOCLIENTEColl[rowindex].IDVEICULOCLIENTE); Entity = VEICULOCLIENTEP.Read(CodSelect); } else if (ColumnSelecionada == 1)//Excluir { DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete, ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { try { CodSelect = Convert.ToInt32(LIS_VEICULOCLIENTEColl[rowindex].IDVEICULOCLIENTE); VEICULOCLIENTEP.Delete(CodSelect); ListaVeiculoCliente(_IDCLIENTE); Entity = null; Util.ExibirMSg(ConfigMessage.Default.MsgDelete2, "Blue"); } catch (Exception) { MessageBox.Show(ConfigMessage.Default.MsgDeleteErro); } } } } }
public VEICULOCLIENTEEntity Read(int IDVEICULOCLIENTE) { 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_VEICULOCLIENTE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_VEICULOCLIENTE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDVEICULOCLIENTE", IDVEICULOCLIENTE); //PrimaryKey reader = dbCommand.ExecuteReader(); VEICULOCLIENTEEntity 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(VEICULOCLIENTEEntity 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_VEICULOCLIENTE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_VEICULOCLIENTE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; //PrimaryKey com valor igual a null, indica um novo registro, //o valor da chave será fornecido pelo banco. Qualquer outro valor indicará edição do registro. if (Entity.IDVEICULOCLIENTE == -1) { dbCommand.Parameters.AddWithValue("@IDVEICULOCLIENTE", DBNull.Value); } else { dbCommand.Parameters.AddWithValue("@IDVEICULOCLIENTE", Entity.IDVEICULOCLIENTE); } if (Entity.IDCLIENTE != null) { dbCommand.Parameters.AddWithValue("@IDCLIENTE", Entity.IDCLIENTE); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDCLIENTE", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@PLACA", Entity.PLACA); //Coluna dbCommand.Parameters.AddWithValue("@ANOFABR", Entity.ANOFABR); //Coluna dbCommand.Parameters.AddWithValue("@ANOMODELO", Entity.ANOMODELO); //Coluna if (Entity.IDCOR != null) { dbCommand.Parameters.AddWithValue("@IDCOR", Entity.IDCOR); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDCOR", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@CHASSIS", Entity.CHASSIS); //Coluna dbCommand.Parameters.AddWithValue("@MARCAMODELO", Entity.MARCAMODELO); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDVEICULOCLIENTE"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDVEICULOCLIENTE"].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); }