private void Txt_Search_TextChanged(object sender, EventArgs e) { //get the keyword from Cautare autoturisme searchbox string keyword = txt_Search.Text; //check if we value to txt_Search or not if (keyword == "") { // txt_AutoID.Text = ""; txt_Marca.Text = ""; txtModel.Text = ""; txtPret.Text = ""; txtAnFabricatie.Text = ""; txtCombustibil.Text = ""; return; } //Search the Autoturisme and display on respective textboxes Autoturisme a = autoturismeDA.GetAutoturismeForSales(keyword); //Set the values on textboxes bassed on a object // txt_AutoID.Text= a.Id_auto.ToString(); txt_Marca.Text = a.Marca; txtModel.Text = a.Model; txtPret.Text = a.Pret.ToString(); txtAnFabricatie.Text = a.An_fabricatie; txtCombustibil.Text = a.Combustibil; }
public bool Update(Autoturisme a) { bool succes = false; SqlConnection conn = new SqlConnection(CONNECTION_STRING); try { string sql = "Update autoturisme set marca= @marca, model= @model, pret= @pret, an_fabricatie=@an_fabricatie, culoare= @culoare, " + "combustibil= @combustibil, cai_putere= @cai_putere, stare_autoturism= @stare_autoturism WHERE id_Auto= @id_Auto"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@marca", a.Marca); cmd.Parameters.AddWithValue("@model", a.Model); cmd.Parameters.AddWithValue("@pret", a.Pret); cmd.Parameters.AddWithValue("@an_fabricatie", a.An_fabricatie); cmd.Parameters.AddWithValue("@culoare", a.Culoare); cmd.Parameters.AddWithValue("@combustibil", a.Combustibil); cmd.Parameters.AddWithValue("@cai_putere", a.Cai_putere); cmd.Parameters.AddWithValue("@stare_autoturism", a.Stare_Autoturism); cmd.Parameters.AddWithValue("@id_Auto", a.Id_auto); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //query succes succes = true; } else { //query failed succes = false; } } catch (Exception ex) { MessageBox.Show("Exceptie" + ex.Message); } finally { conn.Close(); } return(succes); }
public Autoturisme GetAutoturismeForSales(string keyWords) { //create an object for AutoturismeDataAcces and return it Autoturisme a = new Autoturisme(); //SqlConnection SqlConnection conn = new SqlConnection(CONNECTION_STRING); //Data tape to store data temporarily DataTable dt = new DataTable(); try { //QUERY String sql = "select marca, model, pret, an_fabricatie, combustibil from autoturisme Where id_Auto LIKE '%" + keyWords + "%' OR marca LIKE '%" + keyWords + "%' OR model LIKE '%" + keyWords + "%' OR pret LIKE '%" + keyWords + "%' OR an_fabricatie LIKE '%" + keyWords + "%' or combustibil LIKE '%" + keyWords + "%' "; //create sql data adapter to execute query SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, conn); //Open DataBase conn.Open(); //pass the value adapter from dt sqlDataAdapter.Fill(dt); //if we have any value on dt then set values to AutoturismeDataAcces if (dt.Rows.Count > 0) { // a.Id_auto=Convert.ToInt32(dt.Rows[0]["marca"].ToString()); a.Marca = dt.Rows[0]["marca"].ToString(); a.Model = dt.Rows[0]["model"].ToString(); a.Pret = Convert.ToInt32(dt.Rows[0]["pret"].ToString()); a.An_fabricatie = dt.Rows[0]["an_fabricatie"].ToString(); a.Combustibil = dt.Rows[0]["combustibil"].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(a); }
public bool Delete(Autoturisme a) { bool succes = false; SqlConnection conn = new SqlConnection(CONNECTION_STRING); try { string sql = "Delete from autoturisme WHERE id_Auto = @id_Auto"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id_Auto", a.Id_auto); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { succes = true; } else { succes = false; } } catch (Exception ex) { MessageBox.Show("Exceptie" + ex.Message); } finally { conn.Close(); } return(succes); }