Example #1
0
        //buscar
        public DataTable BuscarProducto(DProducto Producto)
        {
            DataTable     DtResultado = new DataTable("productos");
            SqlConnection SqlCon      = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "spbuscar_producto";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParTextoBuscar = new SqlParameter();
                ParTextoBuscar.ParameterName = "@textobuscar";
                ParTextoBuscar.SqlDbType     = SqlDbType.VarChar;
                ParTextoBuscar.Size          = 50;
                ParTextoBuscar.Value         = Producto.Textobuscar;
                SqlCmd.Parameters.Add(ParTextoBuscar);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);
            }
            catch (Exception ex)
            {
                DtResultado = null;
                string result = ex.ToString();
            }

            return(DtResultado);
        }
Example #2
0
        //metodo desactivar
        public string Desactivar(DProducto Producto)
        {
            string        respuesta = "";
            SqlConnection SqlCon    = new SqlConnection();

            try
            {
                //codigo
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCon.Open();
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "spdesactivar_producto";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParIdProducto = new SqlParameter();
                ParIdProducto.ParameterName = "@idproducto";
                ParIdProducto.SqlDbType     = SqlDbType.Int;
                ParIdProducto.Value         = Producto.Idproducto;
                SqlCmd.Parameters.Add(ParIdProducto);

                //Ejecutamos el comando
                respuesta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se Activó.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(respuesta);
        }
Example #3
0
        //metodo editar
        public string Editar(DProducto Producto)
        {
            string        respuesta = "";
            SqlConnection SqlCon    = new SqlConnection();

            try
            {
                //codigo
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCon.Open();
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "speditar_producto";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParIdProducto = new SqlParameter();
                ParIdProducto.ParameterName = "@idproducto";
                ParIdProducto.SqlDbType     = SqlDbType.Int;
                ParIdProducto.Value         = Producto.Idproducto;
                SqlCmd.Parameters.Add(ParIdProducto);

                SqlParameter ParCodigo = new SqlParameter();
                ParCodigo.ParameterName = "@codigo_producto";
                ParCodigo.SqlDbType     = SqlDbType.VarChar;
                ParCodigo.Size          = 100;
                ParCodigo.Value         = Producto.Codigo;
                SqlCmd.Parameters.Add(ParCodigo);

                SqlParameter ParNombre = new SqlParameter();
                ParNombre.ParameterName = "@nombre_producto";
                ParNombre.SqlDbType     = SqlDbType.VarChar;
                ParNombre.Size          = 100;
                ParNombre.Value         = Producto.Nombre;
                SqlCmd.Parameters.Add(ParNombre);

                SqlParameter ParDescripcion = new SqlParameter();
                ParDescripcion.ParameterName = "@descripcion_producto";
                ParDescripcion.SqlDbType     = SqlDbType.VarChar;
                ParDescripcion.Size          = 1024;
                ParDescripcion.Value         = Producto.Descripcion;
                SqlCmd.Parameters.Add(ParDescripcion);

                SqlParameter ParBusqueda = new SqlParameter();
                ParBusqueda.ParameterName = "@busqueda_producto";
                ParBusqueda.SqlDbType     = SqlDbType.NVarChar;
                ParBusqueda.Value         = Producto.Busqueda;
                SqlCmd.Parameters.Add(ParBusqueda);

                SqlParameter ParImagen = new SqlParameter();
                ParImagen.ParameterName = "@imagen_producto";
                ParImagen.SqlDbType     = SqlDbType.Image;
                ParImagen.Value         = Producto.Imagen;
                SqlCmd.Parameters.Add(ParImagen);

                SqlParameter ParActivo = new SqlParameter();
                ParActivo.ParameterName = "@activo_producto";
                ParActivo.SqlDbType     = SqlDbType.Int;
                ParActivo.Value         = Producto.Activo;
                SqlCmd.Parameters.Add(ParActivo);

                SqlParameter ParIdUnidad = new SqlParameter();
                ParIdUnidad.ParameterName = "@idunidad";
                ParIdUnidad.SqlDbType     = SqlDbType.Int;
                ParIdUnidad.Value         = Producto.Idunidad;
                SqlCmd.Parameters.Add(ParIdUnidad);

                SqlParameter ParIdCategoria = new SqlParameter();
                ParIdCategoria.ParameterName = "@idcategoria";
                ParIdCategoria.SqlDbType     = SqlDbType.Int;
                ParIdCategoria.Value         = Producto.Idcategoria;
                SqlCmd.Parameters.Add(ParIdCategoria);

                //Ejecutamos el comando
                respuesta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se Modificó el Registro.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(respuesta);
        }