Beispiel #1
0
 public ActionResult VerCompras()
 {
     ML.DetalleVenta detalleVenta = new ML.DetalleVenta();
     ML.Result       result       = BL.DetalleVenta.GetAll();
     detalleVenta.DetalleVentas = result.Objects;
     return(View(detalleVenta));
 }
 public static ML.Result UpdateEF(ML.DetalleVenta detalleVenta)
 {
     ML.Result result = new ML.Result();
     try
     {
         using (DL_EF.ComercioEntities context = new DL_EF.ComercioEntities())
         {
             var query = context.DetalleVentaUpdate(detalleVenta.IdDetalleVenta, detalleVenta.Producto.IdProducto,
                                                    detalleVenta.Venta.IdVenta, detalleVenta.Piezas);
             if (query >= 1)
             {
                 result.Correct = true;
             }
             else
             {
                 result.Correct = false;
                 result.Message = "No se pudo actualizar.";
             }
         }
     }
     catch (Exception e)
     {
         result.Correct = false;
         result.Message = e.Message;
     }
     return(result);
 }
 public static ML.Result DeleteEF(ML.DetalleVenta detalleVenta)
 {
     ML.Result result = new ML.Result();
     try
     {
         using (DL_EF.ComercioEntities context = new DL_EF.ComercioEntities())
         {
             var query = context.DetalleVentaDelete(detalleVenta.IdDetalleVenta);
             if (query >= 1)
             {
                 result.Correct = true;
             }
             else
             {
                 result.Correct = false;
                 result.Message = "No se pudo eliminar";
             }
         }
     }
     catch (Exception e)
     {
         result.Correct = false;
         result.Message = e.Message;
     }
     return(result);
 }
 public static ML.Result AddEF(ML.DetalleVenta detalleVenta)
 {
     ML.Result result = new ML.Result();
     try
     {
         using (DL_EF.ComercioEntities context = new DL_EF.ComercioEntities())
         {
             ObjectParameter idDetalleVenta = new ObjectParameter("IdDetalleVenta", typeof(int));
             var             query          = context.DetalleVentaAdd(detalleVenta.Producto.IdProducto, detalleVenta.Venta.IdVenta,
                                                                      detalleVenta.Piezas, idDetalleVenta);
             if (query >= 1)
             {
                 result.Correct = true;
             }
             else
             {
                 result.Correct = false;
                 result.Message = "No se pudo agregar.";
             }
         }
     }
     catch (Exception e)
     {
         result.Correct = false;
         result.Message = e.Message;
     }
     return(result);
 }
        public static ML.Result GetByIdEF(ML.DetalleVenta detalleVenta)
        {
            ML.Result result = new ML.Result();
            try
            {
                using (DL_EF.ComercioEntities context = new DL_EF.ComercioEntities())
                {
                    var query = context.DetalleVentaGetById(detalleVenta.IdDetalleVenta);
                    if (query != null)
                    {
                        object obj = query;
                        detalleVenta.Producto.IdProducto = ((ML.DetalleVenta)obj).Producto.IdProducto;
                        detalleVenta.Venta.IdVenta       = ((ML.DetalleVenta)obj).Venta.IdVenta;
                        detalleVenta.Piezas = ((ML.DetalleVenta)obj).Piezas;

                        result.Object  = detalleVenta;
                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct = false;
                        result.Message = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception e)
            {
                result.Correct = false;
                result.Message = e.Message;
            }
            return(result);
        }
        /*public ActionResult ListProduct(List<ML.Producto> producto)
         * {
         *  ML.Producto productos = new ML.Producto();
         *
         *
         *  if (Session["Carrito"] == null)
         *  {
         *      var result = new ML.Result();
         *      result.Objects = new List<Object>();
         *      //Existe
         *      foreach (ML.Producto productoItem in producto)
         *      {
         *
         *          if (productoItem.Selected == true)
         *          {
         *              productos.IdProducto = productoItem.IdProducto;
         *              var consult = BL.Producto.GetByIdEF(productos);
         *
         *
         *              result.Objects.Add(consult.Object);
         *          }
         *          else
         *          {
         *              //No esta Seleccionado
         *          }
         *
         *      }
         *
         *      Session["Carrito"] = result.Objects;
         *      return View("AddGetAll", result);
         *  }
         *
         *  else
         *  {
         *      var result = new ML.Result();
         *      result.Objects = new List<Object>();
         *      result.Objects = (List<Object>)Session["Carrito"];
         *      int pos = 0;
         *
         *
         *      foreach (ML.Producto productoItem in producto.ToList())
         *      {
         *
         *          if (productoItem.Selected == true)
         *          {
         *
         *              if (productoItem.IdProducto == producto[pos].IdProducto)
         *              {
         *                  producto[pos].DetalleVenta = new ML.DetalleVenta();
         *                  producto[pos].DetalleVenta.Cantidad++;
         *                  producto[pos].DetalleVenta.Venta.Total =Convert.ToInt32(producto[pos].DetalleVenta.Cantidad * producto[pos].Precio);
         *              }
         *              else
         *              {
         *                  productos.IdProducto = productoItem.IdProducto;
         *                  var consult = BL.Producto.GetByIdEF(productos);
         *                  result.Objects.Add(consult.Object);
         *                  Session["Carrito"] = result.Objects;
         *              }
         *
         *
         *          }
         *          else
         *          {
         *              //No esta Seleccionado
         *          }
         *          pos++;
         *      }
         *      return View("GetAll", result);
         *
         *  }
         * }
         *
         */

        /*public ActionResult GetAll()
         * {
         *   return View(BL.Pedido.GetEFSP());
         *
         * }*/
        public ActionResult GetVenta(int IdPedido)
        {
            ML.DetalleVenta pedido = new ML.DetalleVenta();
            pedido.Venta         = new ML.Venta();
            pedido.Venta.IdVenta = IdPedido;

            return(View(BL.DetalleVenta.GetByIdEF(pedido)));
        }
Beispiel #7
0
        //[HttpPost]
        //[ValidateInput(false)]
        //public FileResult Export(string GridHtml)
        //{
        //    using (MemoryStream stream = new System.IO.MemoryStream())
        //    {
        //        StringReader sr = new StringReader(GridHtml);
        //        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
        //        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
        //        pdfDoc.Open();
        //        XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
        //        pdfDoc.Close();
        //        return File(stream.ToArray(), "application/pdf", "Grid.pdf");
        //    }
        //}

        public FileResult CreateDocument()
        {
            using (PdfDocument document = new PdfDocument())
            {
                //Create a new PDF document.
                PdfDocument doc = new PdfDocument();
                //Adds page settings
                document.PageSettings.Orientation = PdfPageOrientation.Landscape;
                document.PageSettings.Margins.All = 50;

                //Add a page.
                PdfPage     page     = doc.Pages.Add();
                PdfGraphics graphics = page.Graphics;
                //Create a PdfGrid.
                PdfGrid    pdfGrid = new PdfGrid();
                PdfImage   image   = PdfImage.FromFile(Server.MapPath("../Content/img/índice.png"));
                RectangleF bounds  = new RectangleF(0, 0, 150, 150);
                //Draws the image to the PDF page
                page.Graphics.DrawImage(image, bounds);
                //Create a DataTable.
                DataTable dataTable = new DataTable();

                //Add columns to the DataTable
                dataTable.Columns.Add("IdVenta");
                dataTable.Columns.Add("Nombre Producto");
                dataTable.Columns.Add("Descripcion");
                dataTable.Columns.Add("Precio");
                dataTable.Columns.Add("Fecha");
                dataTable.Columns.Add("Cantidad");
                dataTable.Columns.Add("Total");
                //Add rows to the DataTable.
                ML.DetalleVenta detalleVenta = new ML.DetalleVenta();
                detalleVenta.Venta    = new ML.Venta();
                detalleVenta.Producto = new ML.Producto();
                ML.Result result = BL.DetalleVenta.GetAll();
                detalleVenta.DetalleVentas = result.Objects;

                foreach (ML.DetalleVenta detalle in detalleVenta.DetalleVentas)
                {
                    dataTable.Rows.Add(new object[] { detalle.Venta.IdVenta, detalle.Producto.Nombre, detalle.Producto.Descripcion,
                                                      detalle.Producto.Precio, detalle.Venta.Fecha, detalle.Cantidad, detalle.Venta.Total });
                }



                //Assign data source.
                pdfGrid.DataSource = dataTable;
                //Draw grid to the page of PDF document.
                pdfGrid.Draw(page, new PointF(10, 10));
                // Open the document in browser after saving it
                doc.Save("Output.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                //close the document
                doc.Close(true);
            }
            return(null);
        }
Beispiel #8
0
        public static ML.Result GetByIdEF(ML.Producto productos)
        {
            ML.Result result = new ML.Result();

            try
            {
                using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities())
                {
                    var alumnos = context.ProductoGetById(productos.IdProducto).FirstOrDefault();



                    if (alumnos != null)
                    {
                        ML.DetalleVenta detalle  = new ML.DetalleVenta();
                        ML.Producto     producto = new ML.Producto();
                        producto.IdProducto  = alumnos.IdProducto;
                        producto.Nombre      = alumnos.NombreProducto;
                        producto.Descripcion = alumnos.Descripcion;
                        producto.PaisOrigen  = alumnos.PaisOrigen;
                        producto.Precio      = alumnos.Precio;
                        producto.Stock       = Convert.ToInt32(alumnos.Stock);

                        producto.SubCategoria = new ML.SubCategoria();
                        producto.SubCategoria.IdSubcategoria        = alumnos.IdSubCategori;
                        producto.SubCategoria.Categoria             = new ML.Categoria();
                        producto.SubCategoria.Categoria.IdCategoria = alumnos.IdCategoria;
                        producto.LogoTipo = Convert.FromBase64String(alumnos.Imagen);

                        producto.DetalleVenta          = new ML.DetalleVenta();
                        producto.DetalleVenta.Cantidad = 1;

                        producto.DetalleVenta.Venta       = new ML.Venta();
                        producto.DetalleVenta.Venta.Total = Convert.ToInt32(producto.Precio * producto.DetalleVenta.Cantidad);
                        //producto.DetalleVenta.Venta.Total = alumnos.Precio;
                        result.Object = producto;

                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct      = false;
                        result.ErrorMessage = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Beispiel #9
0
        public static ML.Result AddEF(ML.Venta venta, List <Object> Objects)
        {
            ML.Result       result  = new ML.Result();
            ML.DetalleVenta detalle = new ML.DetalleVenta();
            detalle.Venta = new ML.Venta();
            try
            {
                using (DL.EmpresaXEntities context = new DL.EmpresaXEntities())
                {
                    //var query = context.VentaAddSP(venta.Total, venta.Cliente.IdCliente);


                    var IdResult = new ObjectParameter("IdVenta", typeof(int));
                    int ventas   = context.VentaAdd(IdResult, venta.Total, venta.Cliente.IdCliente);
                    venta.IdVenta = (int)IdResult.Value;

                    int    IdUsuario = Convert.ToInt32(venta.Cliente.IdCliente);
                    double Total     = Convert.ToDouble(detalle.Cantidad);
                    //int Ventas = 1;

                    //var IdResult = new ObjectParameter("IdVenta", typeof(int));
                    //int IdVenta = Convert.ToInt32(context.VentaAdd(IdResult,venta.Total, IdUsuario));

                    Console.WriteLine("El IdVenta es: " + venta.IdVenta);

                    foreach (ML.SucursalProducto productoItem in Objects)
                    {
                        BL.DetalleVenta.Add(venta.IdVenta, productoItem.IdSucursalProducto, productoItem.DetalleVenta.Cantidad);
                    }

                    if (ventas >= 1)
                    {
                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct      = false;
                        result.ErrorMessage = "No se insertó el registro";
                    }

                    result.Correct = true;
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
Beispiel #10
0
        public static ML.Result GetByIdEF(ML.DetalleVenta detalle)
        {
            ML.Result result = new ML.Result();

            try
            {
                using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities())
                {
                    var alumnos = context.DetalleVentaGetAllInner().FirstOrDefault();



                    if (alumnos != null)
                    {
                        ML.DetalleVenta detalles = new ML.DetalleVenta();
                        ML.Producto     producto = new ML.Producto();
                        detalles.Producto.IdProducto = alumnos.IdProducto;
                        detalles.Producto.Nombre     = alumnos.Nombre;
                        detalles.Producto.Precio     = alumnos.Precio;


                        detalles.Producto.LogoTipo = Convert.FromBase64String(alumnos.Imagen);


                        result.Object = producto;

                        /*foreach (var obj in alumnos)
                         * {
                         *
                         * }*/

                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct      = false;
                        result.ErrorMessage = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Beispiel #11
0
        public static ML.Result GetAll()
        {
            ML.Result result = new ML.Result();
            try
            {
                using (DL_EF.EcommerceRubenEntities contex = new DL_EF.EcommerceRubenEntities())
                {
                    var query = contex.VentasGetAll().ToList();

                    result.Objects = new List <object>();

                    if (query != null)
                    {
                        foreach (var obj in query)
                        {
                            ML.DetalleVenta detalle = new ML.DetalleVenta();
                            detalle.Venta                = new ML.Venta();
                            detalle.Producto             = new ML.Producto();
                            detalle.Venta.Cliente        = new ML.Cliente();
                            detalle.Venta.Cliente.Nombre = obj.NombreCliente;
                            detalle.Producto.IdProducto  = obj.IdProducto;
                            detalle.Producto.Nombre      = obj.NombreProducto;
                            detalle.Producto.Descripcion = obj.Descripcion;
                            detalle.Producto.Precio      = obj.Precio;
                            detalle.Venta.IdVenta        = obj.IdVenta;
                            detalle.Venta.Fecha          = Convert.ToDateTime(obj.Fecha);
                            detalle.Venta.Total          = Convert.ToInt32(obj.Total);
                            detalle.Cantidad             = Convert.ToInt32(obj.Cantidad);
                            result.Objects.Add(detalle);
                        }
                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct = false;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
        public static ML.Result GetAllEF()
        {
            ML.Result result = new ML.Result();
            try
            {
                using (DL_EF.ComercioEntities conetxt = new DL_EF.ComercioEntities())
                {
                    var query = conetxt.DetalleVentaGetAll();
                    if (query != null)
                    {
                        result.Objects = new List <object>();
                        foreach (object obj in query)
                        {
                            ML.DetalleVenta detalleVenta = new ML.DetalleVenta();
                            detalleVenta.Producto = new ML.Producto();
                            detalleVenta.Venta    = new ML.Venta();

                            detalleVenta.IdDetalleVenta      = ((ML.DetalleVenta)obj).IdDetalleVenta;
                            detalleVenta.Producto.IdProducto = ((ML.DetalleVenta)obj).Producto.IdProducto;
                            detalleVenta.Venta.IdVenta       = ((ML.DetalleVenta)obj).Venta.IdVenta;
                            detalleVenta.Piezas = ((ML.DetalleVenta)obj).Piezas;

                            result.Objects.Add(detalleVenta);
                        }
                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct = false;
                        result.Message = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception e)
            {
                result.Correct = false;
                result.Message = e.Message;
            }
            return(result);
        }
        public ActionResult AddCarrito(int IdProducto)
        {
            ML.Producto     producto = new ML.Producto();
            ML.DetalleVenta detalle  = new ML.DetalleVenta();

            if (Session["Carrito"] == null)
            {
                detalle.Producto            = new ML.Producto();
                detalle.Producto.IdProducto = IdProducto;

                //detalle.Producto = new ML.Producto();
                //producto.IdProducto = IdProducto;
                var result = BL.Producto.GetByIdEF(detalle.Producto);

                result.Objects = new List <Object>();
                result.Objects.Add(result.Object);
                Session["Carrito"] = result.Objects;

                return(View("AddCarrito", result));
            }
            else
            {
                //producto.IdProducto = IdProducto.Value;
                detalle.Producto            = new ML.Producto();
                detalle.Producto.IdProducto = IdProducto;
                var result = BL.Producto.GetByIdEF(detalle.Producto);

                result.Objects = (List <Object>)Session["Carrito"];

                int  pos       = 0;
                bool comprobar = false;

                foreach (ML.Producto productos in result.Objects.ToList())
                {
                    if (productos.IdProducto == IdProducto)
                    {
                        comprobar = true;
                        pos       = productos.IdProducto;
                    }
                    else
                    {
                        comprobar = false;
                    }
                }


                if (comprobar == true)
                {
                    foreach (ML.Producto productos in result.Objects.ToList())
                    {
                        if (producto.IdProducto == pos)
                        {
                            detalle.Cantidad++;

                            detalle.Venta.Total = (detalle.Venta.Total + (Int32)(detalle.Cantidad * productos.Precio));
                            //detalle.Venta.Total = Convert.ToInt32((detalle.Cantidad * detalle.Producto.Precio));
                            break;
                        }
                    }
                }
                else
                {
                    result.Objects.Add(result.Object);
                    Session["Carrito"] = result.Objects;
                }

                return(View("AddCarrito", result));
            }
        }