public static Articulo Load(object id) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "select * from articulo where id = @id"; DbCommandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); if (!dataReader.Read()) { string excep = "ERROR"; Console.Write(excep); dataReader.Close(); } objeto.Nombre = (String)dataReader ["nombre"]; objeto.Categoria = dataReader ["categoria"]; if (objeto.Categoria is DBNull) { objeto.Categoria = null; } objeto.Precio = (decimal)dataReader ["precio"]; dataReader.Close(); //entry1.Text = nombre; //TODO posicionarnos en el comboboxCategoria //spinbutton1.Value = Convert.ToDouble (precio); return(objeto); }
private void load() { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "select * from articulo where id = @id"; DbCommandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); if (!dataReader.Read()) { //TODO throw exception return; } nombre = (string)dataReader ["nombre"]; categoria = dataReader ["categoria"]; if (categoria is DBNull) { categoria = null; } decimal precio = (decimal)dataReader ["precio"]; dataReader.Close(); entryNombre.Text = nombre; //TODO posicionamos en el comboBoxCategoria spinButtonPrecio.Value = Convert.ToDouble(precio); }
// CARGA LOS DATOS DE LA BD DEL ARTICULO SELECCIONADO public static Articulo Load(object id) { Articulo articulo = new Articulo(); articulo.Id = id; IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "select * from articulo where id = @id"; DbCommandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); if (!dataReader.Read()) { //TODO return(null); } articulo.Nombre = (string)dataReader ["nombre"]; articulo.Categoria = get(dataReader ["categoria"], null); articulo.Precio = (decimal)get(dataReader["precio"], decimal.Zero); dataReader.Close(); return(articulo); }
public static void Insert(Articulo articulo) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "insert into articulo (nombre, categoria, precio) " + "values(@nombre,@categoria,@Precio)"; DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", articulo.Categoria); DbCommandHelper.AddParameter(dbCommand, "precio", articulo.Precio); dbCommand.ExecuteNonQuery(); }
public static int Update(Articulo articulo) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); string update = "update articulo set nombre=@nombre, categoria=@categoria, precio=@precio where id = {0}"; dbCommand.CommandText = string.Format(update, articulo.Id); DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", articulo.Categoria); DbCommandHelper.AddParameter(dbCommand, "precio", articulo.Precio); return(dbCommand.ExecuteNonQuery()); }
private static void addParameters(IDbCommand dbCommand, object obj) { Type type = obj.GetType(); PropertyInfo[] propertyInfos = type.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { if (!propertyInfo.Name.Equals("Id")) { string name = propertyInfo.Name.ToLower(); object value = propertyInfo.GetValue(obj, null); DbCommandHelper.AddParameter(dbCommand, name, value); } } }
private void update(object id) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "UPDATE articulo SET nombre=@nombre, categoria=@categoria, precio=@precio WHERE id=" + id; string nombre = entryNombre.Text; object categoria = ComboBoxHelper.GetId(comboBoxCategoria); decimal precio = Convert.ToDecimal(spinButtonPrecio.Value); DbCommandHelper.AddParameter(dbCommand, "nombre", nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", categoria); DbCommandHelper.AddParameter(dbCommand, "precio", precio); dbCommand.ExecuteNonQuery(); Destroy(); }
private void save() { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "insert into articulo (nombre, categoria, precio) " + "values (@nombre, @categoria, @precio)"; string nombre = entryNombre.Text; object categoria = ComboBoxHelper.GetId(comboBoxCategoria); decimal precio = Convert.ToDecimal(spinButtonPrecio.Value); DbCommandHelper.AddParameter(dbCommand, "nombre", nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", categoria); DbCommandHelper.AddParameter(dbCommand, "precio", precio); dbCommand.ExecuteNonQuery(); }
public static void Update(Articulo articulo) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "update articulo set nombre=@nombre, categoria=@categoria, precio=@precio where id=@id"; id = articulo.Id; nombre = articulo.Nombre; categoria = articulo.Categoria; precio = articulo.Precio; DbCommandHelper.AddParameter(dbCommand, "nombre", nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", categoria); DbCommandHelper.AddParameter(dbCommand, "precio", precio); DbCommandHelper.AddParameter(dbCommand, "id", id); dbCommand.ExecuteNonQuery(); }
private void updateArt(object id) { Console.Write(this.id); Console.Write(id); IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "update articulo set nombre=@nombre, categoria=@categoria, precio=@precio" + " where id=@id"; string nombre = entryNombre.Text; object categoria = ComboBoxHelper.GetId(comboBoxCategoria); decimal precio = Convert.ToDecimal(spinButtonPrecio.Value); DbCommandHelper.AddParameter(dbCommand, "id", id); DbCommandHelper.AddParameter(dbCommand, "nombre", nombre); DbCommandHelper.AddParameter(dbCommand, "categoria", categoria); DbCommandHelper.AddParameter(dbCommand, "precio", precio); dbCommand.ExecuteNonQuery(); Destroy(); }
private void load() { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "select * from articulo where id = @id"; DbCommandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); if (!dataReader.Read()) { //TODO throw exception return; } nombre = (string)dataReader ["nombre"]; categoria = dataReader ["categoria"]; if (categoria is DBNull) { categoria = null; } precio = (decimal)dataReader ["precio"]; dataReader.Close(); }
public static Articulo load(object id) { IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = "select * from articulo where id = @id"; DbCommandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); if (!dataReader.Read()) { //TODO throw exception return(artiuclo); } Articulo.nombre = (string)dataReader ["nombre"]; Articulo.categoria = dataReader ["categoria"]; if (Articulo.categoria is DBNull) { Articulo.categoria = null; } Articulo.precio = (decimal)dataReader ["precio"]; dataReader.Close(); }