示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        // 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);
        }
示例#4
0
        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();
        }
示例#5
0
        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());
        }
示例#6
0
        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);
                }
            }
        }
示例#7
0
        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();
        }
示例#8
0
        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();
        }
示例#9
0
        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();
        }
示例#10
0
        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();
        }
示例#11
0
        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();
        }
示例#12
0
        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();
        }