Beispiel #1
0
 public static ProductosEntity GetSingle(string pConnection, ProductosEntity pProductos)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlDataAdapter lDataAdapter = new SqlDataAdapter("SELECT TOP 1 * FROM tb_productos WHERE id=@id", lConnection))
         {
             lDataAdapter.SelectCommand.CommandType = CommandType.Text;
             lDataAdapter.SelectCommand.Parameters.AddWithValue("@id", pProductos.id);
             DataTable lDataTable = new DataTable();
             lDataAdapter.Fill(lDataTable);
             if (lDataTable != null && lDataTable.Rows.Count > 0)
             {
                 DataRow         lRow       = lDataTable.Rows[0];
                 ProductosEntity lProductos = new ProductosEntity();
                 lProductos.id          = Convert.ToInt32(lRow["id"]);
                 lProductos.nombre      = Convert.ToString(lRow["nombre"]);
                 lProductos.descripcion = Convert.ToString(lRow["descripcion"]);
                 lProductos.code        = Convert.ToString(lRow["code"]);
                 lProductos.cantidad    = Convert.ToInt32(lRow["cantidad"]);
                 lProductos.precio      = Convert.ToDecimal(lRow["precio"]);
                 return(lProductos);
             }
         }
     }
     return(null);
 }
        public ActionResult Save(ProductosEntity entity)
        {
            try
            {
                var result = new DBEntity();

                if (entity.IdProductos.HasValue)
                {
                    result          = IApp.productosService.Actualizar(entity);
                    TempData["msg"] = "Se Actualizo el registro con exito!";
                }
                else
                {
                    result          = IApp.productosService.Insertar(entity);
                    TempData["msg"] = "Se agrego el registro con exito!";
                }


                if (result.CodeError != 0)
                {
                    throw new Exception(result.MsgError);
                }



                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Beispiel #3
0
        public static bool GuardarProductos(ProductosEntity producto)
        {
            MySqlConnection conex = ConexionBD();

            conex.Open();
            string sql = @"INSERT INTO tbproductos
                                (Codigo, Descripcion, 
                                 Stock, Presentacion, 
                                 Valor)
                             VALUES 
                                 (@Codigo, @Descripcion, 
                                  @Stock, @Presentacion, 
                                  @Valor)";

            MySqlCommand cmd = new MySqlCommand(sql, conex);

            cmd.Parameters.AddWithValue("@Codigo", producto.IdProducto);
            cmd.Parameters.AddWithValue("@Descripcion", producto.Codigo);
            cmd.Parameters.AddWithValue("@Stock", producto.Descripcion);
            cmd.Parameters.AddWithValue("@Presentacion", producto.Presentacion);
            cmd.Parameters.AddWithValue("@Valor", producto.Valor);

            int NumeroFilas = Convert.ToInt32(cmd.ExecuteNonQuery());

            if (NumeroFilas > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public static List <ProductosEntity> GetAllQuery(string pConnection, string pQuery)
        {
            List <ProductosEntity> lReturnList = new List <ProductosEntity>();

            using (SqlConnection lConnection = new SqlConnection(pConnection))
            {
                using (SqlDataAdapter lDataAdapter = new SqlDataAdapter(pQuery, lConnection))
                {
                    lDataAdapter.SelectCommand.CommandType = CommandType.Text;
                    DataTable lDataTable = new DataTable();
                    lDataAdapter.Fill(lDataTable);
                    if (lDataTable != null && lDataTable.Rows.Count > 0)
                    {
                        foreach (DataRow lRow in lDataTable.Rows)
                        {
                            ProductosEntity lProductos = new ProductosEntity();
                            lProductos.id          = Convert.ToInt32(lRow["id"]);
                            lProductos.nombre      = Convert.ToString(lRow["nombre"]);
                            lProductos.descripcion = Convert.ToString(lRow["descripcion"]);
                            lProductos.code        = Convert.ToString(lRow["code"]);
                            lProductos.cantidad    = Convert.ToInt32(lRow["cantidad"]);
                            lProductos.precio      = Convert.ToDecimal(lRow["precio"]);
                            lReturnList.Add(lProductos);
                        }
                    }
                }
            }
            return(lReturnList);
        }
Beispiel #5
0
        public DBEntity Actualizar(ProductosEntity entity)
        {
            try
            {
                var result = sql.QueryExecute("ProductosActualizar", new
                {
                    entity.IdProductos,
                    entity.IdProveedores,
                    entity.NombreProductos,
                    entity.SesionesRayosUVA,
                    entity.RenovacionCuota,
                    entity.ProductosConsumidos,
                    entity.EstadoProducto
                });


                return(result);
            }
            catch (Exception ex)
            {
                return(new DBEntity {
                    CodeError = ex.HResult, MsgError = ex.Message
                });
            }
        }
Beispiel #6
0
        public static bool Exists(string pConnection, int id)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id = id;

            return(ProductosDAL.Exists(pConnection, pProductos));
        }
Beispiel #7
0
        public void Delete(string pConnection)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id = id;

            ProductosDAL.Delete(pConnection, pProductos);
        }
Beispiel #8
0
        public void DeleteTransaction(SqlConnection pConnection, SqlTransaction pTransaction)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id = id;

            ProductosDAL.DeleteTransaction(pConnection, pTransaction, pProductos);
        }
Beispiel #9
0
 public ProductosBO(ProductosEntity pProductos)
 {
     try
     {
         this.FillEntity(pProductos);
     }
     catch
     {
         this.FillEntity();
     }
 }
Beispiel #10
0
 public static void Delete(string pConnection, ProductosEntity pProductos)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("DELETE FROM tb_productos WHERE id=@id", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@id", pProductos.id);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
Beispiel #11
0
        public ProductosBO(string pConnection, int pId)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id = pId;

            try
            {
                this.FillEntity(ProductosDAL.GetSingle(pConnection, pProductos));
            }
            catch
            {
                this.FillEntity();
            }
        }
Beispiel #12
0
 public DBEntity Eliminar(ProductosEntity entity)
 {
     try
     {
         var result = sql.QueryExecute("ProductosEliminar", new
         {
             entity.IdProductos
         });
         return(result);
     }
     catch (Exception ex)
     {
         return(new DBEntity {
             CodeError = ex.HResult, MsgError = ex.Message
         });
     }
 }
Beispiel #13
0
 private void FillEntity(ProductosEntity pProductos)
 {
     try
     {
         id          = pProductos.id;
         nombre      = pProductos.nombre;
         descripcion = pProductos.descripcion;
         code        = pProductos.code;
         cantidad    = pProductos.cantidad;
         precio      = pProductos.precio;
         IsNew       = false;
     }
     catch
     {
         this.FillEntity();
     }
 }
Beispiel #14
0
 public static void Add(string pConnection, ProductosEntity pProductos)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("INSERT INTO tb_productos (nombre,descripcion,code,cantidad,precio) VALUES (@nombre,@descripcion,@code,@cantidad,@precio)", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@id", pProductos.id);
             lCommand.Parameters.AddWithValue("@nombre", pProductos.nombre);
             lCommand.Parameters.AddWithValue("@descripcion", pProductos.descripcion);
             lCommand.Parameters.AddWithValue("@code", pProductos.code);
             lCommand.Parameters.AddWithValue("@cantidad", pProductos.cantidad);
             lCommand.Parameters.AddWithValue("@precio", pProductos.precio);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
Beispiel #15
0
 public static void Update(string pConnection, ProductosEntity pProductos)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("UPDATE tb_productos SET nombre=@nombre,descripcion=@descripcion,code=@code,cantidad=@cantidad,precio=@precio WHERE id=@id", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@id", pProductos.id);
             lCommand.Parameters.AddWithValue("@nombre", pProductos.nombre);
             lCommand.Parameters.AddWithValue("@descripcion", pProductos.descripcion);
             lCommand.Parameters.AddWithValue("@code", pProductos.code);
             lCommand.Parameters.AddWithValue("@cantidad", pProductos.cantidad);
             lCommand.Parameters.AddWithValue("@precio", pProductos.precio);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
Beispiel #16
0
        public void SaveTransaction(SqlConnection pConnection, SqlTransaction pTransaction)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id          = id;
            pProductos.nombre      = nombre;
            pProductos.descripcion = descripcion;
            pProductos.code        = code;
            pProductos.cantidad    = cantidad;
            pProductos.precio      = precio;
            if (IsNew == false)
            {
                ProductosDAL.UpdateTransaction(pConnection, pTransaction, pProductos);
            }
            else
            {
                ProductosDAL.AddTransaction(pConnection, pTransaction, pProductos);
            }
        }
Beispiel #17
0
        public void Save(string pConnection)
        {
            ProductosEntity pProductos = new ProductosEntity();

            pProductos.id          = id;
            pProductos.nombre      = nombre;
            pProductos.descripcion = descripcion;
            pProductos.code        = code;
            pProductos.cantidad    = cantidad;
            pProductos.precio      = precio;
            if (IsNew == false)
            {
                ProductosDAL.Update(pConnection, pProductos);
            }
            else
            {
                ProductosDAL.Add(pConnection, pProductos);
            }
        }
Beispiel #18
0
        public static bool Exists(string pConnection, ProductosEntity pProductos)
        {
            bool lExists = false;

            using (SqlConnection lConnection = new SqlConnection(pConnection))
            {
                using (SqlCommand lCommand = new SqlCommand("SELECT COUNT(*) FROM tb_productos WHERE id=@id", lConnection))
                {
                    lCommand.CommandType = CommandType.Text;
                    lCommand.Parameters.AddWithValue("@id", pProductos.id);
                    lConnection.Open();
                    object lReturnValue = lCommand.ExecuteScalar();
                    lConnection.Close();
                    if (!object.ReferenceEquals(lReturnValue, DBNull.Value) && lReturnValue != null)
                    {
                        lExists = Convert.ToInt32(lReturnValue) > 0;
                    }
                }
            }

            return(lExists);
        }
Beispiel #19
0
 public static ProductosBO GetSingle(string pConnection, ProductosEntity pProductos)
 {
     pProductos = ProductosDAL.GetSingle(pConnection, pProductos);
     return(new ProductosBO(pProductos));
 }
Beispiel #20
0
 public static void DeleteTransaction(SqlConnection pConnection, SqlTransaction pTransaction, ProductosEntity pProductos)
 {
     using (SqlCommand lCommand = new SqlCommand("DELETE FROM tb_productos WHERE id=@id", pConnection))
     {
         lCommand.Transaction = pTransaction;
         lCommand.CommandType = CommandType.Text;
         lCommand.Parameters.AddWithValue("@id", pProductos.id);
         lCommand.ExecuteNonQuery();
     }
 }