public CategoriaWindow(object id) : base(Gtk.WindowType.Toplevel) { this.Build(); buttonOK.Clicked += (sender, e) => { string nombre = entryName.Text; IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); if (id is null) { dbCommand.CommandText = string.Format("insert into categoria(nombre) values(@nombre)"); DBCommmandHelper.AddParameter(dbCommand, "nombre", nombre); dbCommand.ExecuteNonQuery(); Destroy(); } else { dbCommand.CommandText = "update categoria set nombre = @nombre where id=@id"; DBCommmandHelper.AddParameter(dbCommand, "nombre", nombre); DBCommmandHelper.AddParameter(dbCommand, "id", id); dbCommand.ExecuteNonQuery(); } }; buttonCancel.Clicked += (sender, e) => Destroy(); }
private static void borrar() { IDbCommand dbCommand = dbConnection.CreateCommand(); obtion = 1; listar();//Aquí se muestra Console.WriteLine("Introduce el id del articulo que quieras borrar:"); string id = Console.ReadLine(); dbCommand.CommandText = "Delete from articulo where id = @id"; DBCommmandHelper.AddParameter(dbCommand, "id", id); dbCommand.ExecuteNonQuery(); }
private static Categoria Load(object id) { Categoria categoria = new Categoria(); IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand(); dbCommand.CommandText = select; DBCommmandHelper.AddParameter(dbCommand, "id", id); IDataReader dataReader = dbCommand.ExecuteReader(); dataReader.Read(); categoria.Id = (ulong)id; categoria.Nombre = (string)dataReader["nombre"]; dataReader.Close(); return(categoria); }
public static void InsertValue() { IDbCommand dbCommand = dbConnection.CreateCommand(); Console.WriteLine("Introduce el nombre de la categoria: "); string nombre = Console.ReadLine(); dbCommand.CommandText = string.Format("insert into categoria(nombre) values(@nombre)"); //IDataParameter dbDataParameter = dbCommand.CreateParameter(); //dbDataParameter.ParameterName = "nombre"; //dbDataParameter.Value = nombre; //dbCommand.Parameters.Add(dbDataParameter);//cat33 DBCommmandHelper.AddParameter(dbCommand, "nombre", nombre); dbCommand.ExecuteNonQuery(); }
private static void editar() { Console.WriteLine("Ha entrado en editar"); IDbCommand dbCommand = dbConnection.CreateCommand(); obtion = 1; listar();//Aquí se muestra //Console.WriteLine("Introduce el id del articulo que quieras editar:"); //DBCommmandHelper.AddParameter(dbCommand, "id", Console.ReadLine()); //Menu.Create("Menu editar") // .Add("1-Nombre", () => // { // Console.WriteLine("Introduce el nuevo nombre del articulo:"); // dbCommand.CommandText = "Update articulo set nombre = @nombre, " + // "where id= @id"; // DBCommmandHelper.AddParameter(dbCommand, "nombre", Console.ReadLine()); // }) //.Add("2-Precio", () => //{ // Console.WriteLine("Introduce el nuevo nombre del articulo:"); // dbCommand.CommandText = "Update articulo set precio = @precio, " + // "where id= @id"; // DBCommmandHelper.AddParameter(dbCommand, " precio ", Console.ReadLine()); //}) //.Add("3-Borrar", borrar); dbCommand.CommandText = "Update articulo set nombre = @nombre, " + "precio = @precio, categoria = @categoria " + "where id= @id"; Console.WriteLine("Introduce el id del articulo que quieras editar:"); DBCommmandHelper.AddParameter(dbCommand, "@id", Console.ReadLine()); Console.WriteLine("Introduce el nuevo nombre del articulo:"); DBCommmandHelper.AddParameter(dbCommand, "@nombre", Console.ReadLine()); Console.WriteLine("Introduce el nuevo precio del articulo:"); DBCommmandHelper.AddParameter(dbCommand, "@precio", float.Parse(Console.ReadLine())); Console.WriteLine("Introduce el nuevo categoria del articulo:"); DBCommmandHelper.AddParameter(dbCommand, "@categoria", int.Parse(Console.ReadLine())); dbCommand.ExecuteNonQuery(); }
private static void nuevo() { IDbCommand dbCommand = dbConnection.CreateCommand(); Console.WriteLine("Introduce el nombre del articulo: "); string nombre = Console.ReadLine(); Console.WriteLine("Introduce el precio del articulo: "); string precio = Console.ReadLine(); Console.WriteLine("Introduce el categoria del articulo: "); string categoria = Console.ReadLine(); dbCommand.CommandText = string.Format("insert into Articulo(nombre, precio, categoria) values(@nombre,@precio,@categoria)"); DBCommmandHelper.AddParameter(dbCommand, "nombre", nombre); DBCommmandHelper.AddParameter(dbCommand, "precio", precio); DBCommmandHelper.AddParameter(dbCommand, "categoria", categoria); dbCommand.ExecuteNonQuery(); }