public BLL.Veiculo PreencherPeliID(BLL.Veiculo ve) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT Id, Placa, Fabricante, Modelo FROM TBVeiculo WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", ve.Id); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); ve.Id = Convert.ToInt32(dr["Id"]); ve.Placa = dr["Placa"].ToString(); ve.Fabricante = dr["fabricante"].ToString(); ve.Modelo = dr["Modelo"].ToString(); dr.Close(); } else { ve.Id = 0; } con.Desconectar(); return(ve); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { gvListar.DataSource = veDAL.Listar(); gvListar.DataBind(); if (Request.QueryString["id"] != null) { if (Request.QueryString["id"].ToString() != "") { int idRecebido; int.TryParse(Request.QueryString["id"], out idRecebido); ve.Id = idRecebido; ve = veDAL.PreencherPeliID(ve); if (ve.Id != 0) { lblId.Text = ve.Id.ToString(); txtPlaca.Text = ve.Placa; txtFabricante.Text = ve.Fabricante; txtModelo.Text = ve.Modelo; Session.Add("ca", 1); } else { lblId.Text = "Id INVÁLIDO"; } } } } }
public void Excluir(BLL.Veiculo ve) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"DELETE FROM TBVeiculo WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", ve.Id); cmd.ExecuteNonQuery(); con.Desconectar(); }
public void Cadastrar(BLL.Veiculo ve) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"INSERT INTO TBVeiculo(Placa, Fabricante, Modelo) VALUES (@placa, @fabricante, @modelo)"; cmd.Parameters.AddWithValue("@placa", ve.Placa); cmd.Parameters.AddWithValue("@fabricante", ve.Fabricante); cmd.Parameters.AddWithValue("@modelo", ve.Modelo); cmd.ExecuteNonQuery(); con.Desconectar(); }
public void Atualizar(BLL.Veiculo ve) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"UPDATE TBVeiculo SET Placa = @placa, Fabricante = @fabricante, Modelo = @modelo WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", ve.Id); cmd.Parameters.AddWithValue("@placa", ve.Placa); cmd.Parameters.AddWithValue("@fabricante", ve.Fabricante); cmd.Parameters.AddWithValue("@modelo", ve.Modelo); cmd.ExecuteNonQuery(); con.Desconectar(); }
public DataTable Listar(BLL.Veiculo ve) { DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT Id, Placa, Fabricante, Modelo FROM TBVeiculo WHERE Placa LIKE @placa"; cmd.Parameters.AddWithValue("@placa", "%" + ve.Placa + "%"); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt); con.Desconectar(); return(dt); }