示例#1
0
        // GET ID
        public DataTable GetArticleId(DB_articulos ArticuloId)
        {
            string        respuesta    = "";
            DataTable     AllArticulos = new DataTable("articulos");
            SqlConnection SQL          = new SqlConnection();

            try
            {
                SQL.ConnectionString = ConexionDB.StringConection;
                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection = SQL;

                SQL_comando.CommandText = "GET_ID_articulos";
                SQL_comando.CommandType = CommandType.StoredProcedure;

                SqlParameter ID = new SqlParameter();
                ID.ParameterName = "@idarticulo";
                ID.SqlDbType     = SqlDbType.Int;
                ID.Size          = 256;
                ID.Value         = ArticuloId.Articulo_id;
                SQL_comando.Parameters.Add(ID);

                SqlDataAdapter RespuestaSQL = new SqlDataAdapter(SQL_comando);
                RespuestaSQL.Fill(AllArticulos);
            }
            catch (Exception error)
            {
                respuesta    = error.Message;
                AllArticulos = null;
                throw;
            }
            finally
            {
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(AllArticulos);
        }
示例#2
0
        // GET SEARCH
        public DataTable GetSearch(DB_articulos ArticulosSearch)
        {
            string        respuesta    = "";
            DataTable     AllArticulos = new DataTable("articulos");
            SqlConnection SQL          = new SqlConnection();

            try
            {
                SQL.ConnectionString = ConexionDB.StringConection;
                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection = SQL;

                SQL_comando.CommandText = "GET_SEARCH_articulos";
                SQL_comando.CommandType = CommandType.StoredProcedure;

                SqlParameter Search = new SqlParameter();
                Search.ParameterName = "@search";
                Search.SqlDbType     = SqlDbType.VarChar;
                Search.Size          = 256;
                Search.Value         = ArticulosSearch.Search_value;
                SQL_comando.Parameters.Add(Search);

                SqlDataAdapter RespuestaSQL = new SqlDataAdapter(SQL_comando);
                RespuestaSQL.Fill(AllArticulos);
            }
            catch (Exception error)
            {
                respuesta    = error.Message;
                AllArticulos = null;
                throw;
            }
            finally
            {
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(AllArticulos);
        }
示例#3
0
        // DELETE
        public string Delete(DB_articulos ArticuloDelete)
        {
            string        respuesta = "";
            SqlConnection SQL       = new SqlConnection();

            try
            {
                SQL.ConnectionString = ConexionDB.StringConection;
                SQL.Open();

                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection  = SQL;
                SQL_comando.CommandText = "DELETEarticulos";
                SQL_comando.CommandType = CommandType.StoredProcedure;

                SqlParameter ID = new SqlParameter();
                ID.ParameterName = "@idarticulo";
                ID.SqlDbType     = SqlDbType.Int;
                ID.Size          = 250;
                ID.Value         = ArticuloDelete.Articulo_id;
                SQL_comando.Parameters.Add(ID);

                respuesta = SQL_comando.ExecuteNonQuery() == 1 || true ? "Realizado Exitosamente" : "Error al eliminar articulo del stock";
            }
            catch (Exception error)
            {
                respuesta = error.Message;
                throw;
            }
            finally
            {
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(respuesta);
        }
示例#4
0
        // EDIT
        public string Edit(DB_articulos ArticuloEdit)
        {
            string        respuesta = "";
            SqlConnection SQL       = new SqlConnection();

            try
            {
                SQL.ConnectionString = ConexionDB.StringConection;
                SQL.Open();

                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection  = SQL;
                SQL_comando.CommandText = "PUTarticulos";
                SQL_comando.CommandType = CommandType.StoredProcedure;

                SqlParameter ID = new SqlParameter();
                ID.ParameterName = "@idarticulo";
                ID.SqlDbType     = SqlDbType.Int;
                ID.Size          = 250;
                ID.Value         = ArticuloEdit.Articulo_id;
                SQL_comando.Parameters.Add(ID);

                SqlParameter CATEGORIA = new SqlParameter(); // instanciamos
                CATEGORIA.ParameterName = "@categoria_id";   // nombre de variable
                CATEGORIA.SqlDbType     = SqlDbType.Int;     // tipo de variable
                CATEGORIA.Size          = 256;
                CATEGORIA.Value         = ArticuloEdit.Categoria_id;
                SQL_comando.Parameters.Add(CATEGORIA);           // Añadimos al comando

                SqlParameter PRESENTACION = new SqlParameter();  // instanciamos
                PRESENTACION.ParameterName = "@presentacion_id"; // nombre de variable
                PRESENTACION.SqlDbType     = SqlDbType.Int;      // tipo de variable
                PRESENTACION.Size          = 256;
                PRESENTACION.Value         = ArticuloEdit.Presentacion_id;
                SQL_comando.Parameters.Add(PRESENTACION);                       // Añadimos al comando

                SqlParameter NOMBRE = new SqlParameter();                       // instanciamos
                NOMBRE.ParameterName = "@articulo_nombre";                      // nombre de variable
                NOMBRE.SqlDbType     = SqlDbType.VarBinary;                     // tipo de variable
                NOMBRE.Size          = 256;
                NOMBRE.Value         = ArticuloEdit.Articulo_nombre;            // valor de la variable
                SQL_comando.Parameters.Add(NOMBRE);                             // Añadimos al comando

                SqlParameter CODIGOBARRA = new SqlParameter();                  // instanciamos
                CODIGOBARRA.ParameterName = "@articulo_codigo_barra";           // nombre de variable
                CODIGOBARRA.SqlDbType     = SqlDbType.VarBinary;                // tipo de variable
                CODIGOBARRA.Size          = 256;
                CODIGOBARRA.Value         = ArticuloEdit.Articulo_codigo_barra; // valor de la variable
                SQL_comando.Parameters.Add(CODIGOBARRA);                        // Añadimos al comando

                SqlParameter DESCRIPCION = new SqlParameter();                  // instanciamos
                DESCRIPCION.ParameterName = "@articulo_descripcion";            // nombre de variable
                DESCRIPCION.SqlDbType     = SqlDbType.VarBinary;                // tipo de variable
                DESCRIPCION.Size          = 256;
                DESCRIPCION.Value         = ArticuloEdit.Articulo_descripcion;  // valor de la variable
                SQL_comando.Parameters.Add(DESCRIPCION);                        // Añadimos al comando

                SqlParameter IMAGEN = new SqlParameter();                       // instanciamos
                IMAGEN.ParameterName = "@articulo_imagen";                      // nombre de variable
                IMAGEN.SqlDbType     = SqlDbType.VarBinary;                     // tipo de variable
                IMAGEN.Size          = 256;
                IMAGEN.Value         = ArticuloEdit.Articulo_imagen;            // valor de la variable
                SQL_comando.Parameters.Add(IMAGEN);                             // Añadimos al comando

                SqlParameter PRECIO = new SqlParameter();                       // instanciamos
                PRECIO.ParameterName = "@articulo_precio";                      // nombre de variable
                PRECIO.SqlDbType     = SqlDbType.Decimal;                       // tipo de variable
                PRECIO.Size          = 256;
                PRECIO.Value         = ArticuloEdit.Articulo_nombre;            // valor de la variable
                SQL_comando.Parameters.Add(PRECIO);                             // Añadimos al comando

                respuesta = SQL_comando.ExecuteNonQuery() == 1 || true ? "Realizado Exitosamente" : "Error al modificar articulos";
            }
            catch (Exception error)
            {
                respuesta = error.Message;
                throw;
            }
            finally
            {
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(respuesta);
        }
示例#5
0
        // INSERT
        public string Create(DB_articulos ArticuloNew)
        {
            string        respuesta = "";
            SqlConnection SQL       = new SqlConnection();

            try
            {
                // Conexion
                SQL.ConnectionString = ConexionDB.StringConection;
                SQL.Open();

                // Establecer Procedimiento
                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection  = SQL;                         // Heredar conexion
                SQL_comando.CommandText = "POSTarticulos";             // comando de procedimiento almacenado
                SQL_comando.CommandType = CommandType.StoredProcedure; // Indicamos que es un procedimiento almacenado

                // Creamos parametros de ejecucion SQL
                SqlParameter ArticuloId = new SqlParameter();         // instanciamos
                ArticuloId.ParameterName = "@idarticulo";             // nombre de variable
                ArticuloId.SqlDbType     = SqlDbType.Int;             // tipo de variable
                ArticuloId.Direction     = ParameterDirection.Output; // formato de entrada / salida
                SQL_comando.Parameters.Add(ArticuloId);               // Añadimos al comando

                SqlParameter CATEGORIA = new SqlParameter();          // instanciamos
                CATEGORIA.ParameterName = "@categoria_id";            // nombre de variable
                CATEGORIA.SqlDbType     = SqlDbType.Int;              // tipo de variable
                CATEGORIA.Size          = 256;
                CATEGORIA.Value         = ArticuloNew.Categoria_id;
                SQL_comando.Parameters.Add(CATEGORIA);           // Añadimos al comando

                SqlParameter PRESENTACION = new SqlParameter();  // instanciamos
                PRESENTACION.ParameterName = "@presentacion_id"; // nombre de variable
                PRESENTACION.SqlDbType     = SqlDbType.Int;      // tipo de variable
                PRESENTACION.Size          = 256;
                PRESENTACION.Value         = ArticuloNew.Presentacion_id;
                SQL_comando.Parameters.Add(PRESENTACION);                      // Añadimos al comando

                SqlParameter NOMBRE = new SqlParameter();                      // instanciamos
                NOMBRE.ParameterName = "@articulo_nombre";                     // nombre de variable
                NOMBRE.SqlDbType     = SqlDbType.VarBinary;                    // tipo de variable
                NOMBRE.Size          = 256;
                NOMBRE.Value         = ArticuloNew.Articulo_nombre;            // valor de la variable
                SQL_comando.Parameters.Add(NOMBRE);                            // Añadimos al comando

                SqlParameter CODIGOBARRA = new SqlParameter();                 // instanciamos
                CODIGOBARRA.ParameterName = "@articulo_codigo_barra";          // nombre de variable
                CODIGOBARRA.SqlDbType     = SqlDbType.VarBinary;               // tipo de variable
                CODIGOBARRA.Size          = 256;
                CODIGOBARRA.Value         = ArticuloNew.Articulo_codigo_barra; // valor de la variable
                SQL_comando.Parameters.Add(CODIGOBARRA);                       // Añadimos al comando

                SqlParameter DESCRIPCION = new SqlParameter();                 // instanciamos
                DESCRIPCION.ParameterName = "@articulo_descripcion";           // nombre de variable
                DESCRIPCION.SqlDbType     = SqlDbType.VarBinary;               // tipo de variable
                DESCRIPCION.Size          = 256;
                DESCRIPCION.Value         = ArticuloNew.Articulo_descripcion;  // valor de la variable
                SQL_comando.Parameters.Add(DESCRIPCION);                       // Añadimos al comando

                SqlParameter IMAGEN = new SqlParameter();                      // instanciamos
                IMAGEN.ParameterName = "@articulo_imagen";                     // nombre de variable
                IMAGEN.SqlDbType     = SqlDbType.VarBinary;                    // tipo de variable
                IMAGEN.Size          = 256;
                IMAGEN.Value         = ArticuloNew.Articulo_imagen;            // valor de la variable
                SQL_comando.Parameters.Add(IMAGEN);                            // Añadimos al comando

                SqlParameter PRECIO = new SqlParameter();                      // instanciamos
                PRECIO.ParameterName = "@articulo_precio";                     // nombre de variable
                PRECIO.SqlDbType     = SqlDbType.Decimal;                      // tipo de variable
                PRECIO.Size          = 256;
                PRECIO.Value         = ArticuloNew.Articulo_nombre;            // valor de la variable
                SQL_comando.Parameters.Add(PRECIO);                            // Añadimos al comando


                // Ejecutar consulta
                respuesta = SQL_comando.ExecuteNonQuery() == 1 || true ? "Realizado Exitosamente" : "Error al guardar articulos";
            }
            catch (Exception error)
            {
                respuesta = error.Message;
                throw;
            }
            finally
            {
                // Cerramos la conexion
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(respuesta);
        }