//guarda un artículo nuevo private void button1_Click(object sender, EventArgs e) { string marca = txtMarca.Text.Trim(); string producto= txtProducto.Text.Trim(); double capacidad= double.Parse(txtCapacidad.Text); artículo miArtículo = new artículo(marca, producto, capacidad); miArtículo.guardar(); }
public bool eliminarArtículo(artículo artículo_a_eliminar) { OleDbConnection cnn = new OleDbConnection(_rutaBD); try { cnn.Open(); string cadenaSQL = "Delete from Artículos where Id=" + artículo_a_eliminar.id; OleDbCommand cmd = new OleDbCommand(cadenaSQL, cnn); cmd.ExecuteNonQuery(); return true; } catch (Exception ex) { Debug.Print(ex.Message); return false; } finally { cnn.Close(); } }
private void cargarArtículoEnCombos(artículo miArtículo) { cmbCódigo.Text = miArtículo.id.ToString(); cmbMarca.Text = miArtículo.Marca; cmbProducto.Text = miArtículo.Producto; cmbCapacidad.Text = miArtículo.Capacidad.ToString(); }
public List<artículo> recuperarTodosLosArtículos() { List<artículo> misArtículos = new List<artículo>();// = new List<artículo>; OleDbConnection cnn = new OleDbConnection(_rutaBD); try { cnn.Open(); //quizás tire error el convertir idArtículo, que es un int, a string: OleDbCommand cmd = new OleDbCommand("Select id, marca, producto, capacidad from Artículos", cnn); OleDbDataReader miLector = cmd.ExecuteReader(); while (miLector.Read()) { artículo miArtículo = new artículo(); miArtículo.id = miLector.GetInt32(0); miArtículo.Marca = miLector.GetString(1); miArtículo.Producto = miLector.GetString(2); miArtículo.Capacidad = miLector.GetDouble(3); misArtículos.Add(miArtículo); } miLector.Close(); cnn.Close(); return misArtículos; } catch { return misArtículos; } }
public artículo recuperarArtículo(string marca, string producto, double capacidad) { artículo miArtículo = new artículo(); OleDbConnection cnn = new OleDbConnection(_rutaBD); try { cnn.Open(); //quizás tire error el convertir idArtículo, que es un int, a string: OleDbCommand cmd = new OleDbCommand("Select id from Artículos where marca = " + marca + " and producto = " + producto + " and capacidad = " + capacidad.ToString() + "" , cnn); OleDbDataReader miLector = cmd.ExecuteReader(); miLector.Read(); //while (miLector.Read()) //{ miArtículo.id = miLector.GetInt32(0); miArtículo.Marca = marca; miArtículo.Producto = producto; miArtículo.Capacidad = capacidad; //} miLector.Close(); cnn.Close(); return miArtículo; } catch { return miArtículo; } }
public artículo recuperarArtículo(int idArtículo) { artículo miArtículo = new artículo(); OleDbConnection cnn = new OleDbConnection(_rutaBD); try { cnn.Open(); //quizás tire error el convertir idArtículo, que es un int, a string: OleDbCommand cmd = new OleDbCommand("Select id, marca, producto, capacidad from Artículos where id = " + idArtículo.ToString() + "", cnn); OleDbDataReader miLector = cmd.ExecuteReader(); miLector.Read(); //while (miLector.Read()) //{ miArtículo.id = miLector.GetInt32(0); miArtículo.Marca = miLector.GetString(1); miArtículo.Producto = miLector.GetString(2); miArtículo.Capacidad = miLector.GetDouble (3); //} miLector.Close(); cnn.Close(); return miArtículo; } catch { return miArtículo; } }
public bool modificarArtículo(artículo artículo_a_modificar) { throw new System.NotImplementedException(); }
//private bool abrirBD(string ruta) //{ // try // { // cnn = new OleDbConnection(ruta); // cnn.Open(); // return true; // } // catch // { // return false; // } //} //private bool cerrarBD(OleDbConnection cnn) //{ // try { // if (cnn.State == ConnectionState.Open) cnn.Close(); // return true; // } // catch { return false; } //} ////guardar una fecha en el XML si es que ya no está guardada //private void guardarFecha(DateTime fecha) //{ // bool swYaEstá = false; // DataTable data = new DataTable(); // data.ReadXml("datos.xml"); // foreach (DataRow r in data.Rows) // { // if (string.Format("{0}", r.ItemArray[1]) == fecha.ToString()) // { // swYaEstá = true; // break; // } // } // if (swYaEstá == false) // { // DataRow fila = data.NewRow(); // fila["fecha"] = fecha; // data.Rows.Add(fila); // data.WriteXml("datos.xml", XmlWriteMode.WriteSchema); // } //} ////borrar una fecha del XML si es que está marcada //private void borrarFechaGuardada(DateTime fecha) //{ // DataTable data = new DataTable(); // data.ReadXml("datos.xml"); // //DataRow[] misFilas = data.Select(); // foreach (DataRow r in data.Rows) // { // if (string.Format("{0}", r.ItemArray[1]) == fecha.ToString()) // { // data.Rows.Remove(r); // break; // } // } // data.WriteXml("datos.xml", XmlWriteMode.WriteSchema); //} public bool guardarArtículo(artículo miArtículo) { OleDbConnection cnn = new OleDbConnection(_rutaBD); try { cnn.Open(); string comandoInsert = "'" + miArtículo.Marca + "', '" + miArtículo.Producto + "', '" + miArtículo.Capacidad + "'"; OleDbCommand cmd = new OleDbCommand("INSERT INTO Artículos (marca, producto, capacidad) VALUES (" + comandoInsert + ")", cnn); cmd.ExecuteNonQuery(); cnn.Close(); return true; } catch { return false; } }