Ejemplo n.º 1
0
        public void Salida_Mercancia_Reporte(Cls_Mdl_Salida_Mercancia Objeto, List <Cls_Mdl_Salida_Mercancia> Lista)
        {
            using (ExcelPackage p = new ExcelPackage(template, true))
            {
                ExcelWorksheet ws = p.Workbook.Worksheets[1];
                CultureInfo    ci = new CultureInfo("en-us");

                aux_renglon = renglon;
                String s = String.Empty;

                for (int i = 0; i < Lista.Count; i++)
                {
                    ws.Cells[renglon, 1].Value = Lista[i].Proveedor.ToString();
                    ws.Cells[renglon, 2].Value = Lista[i].Producto.ToString();
                    ws.Cells[renglon, 3].Value = Lista[i].Chofer.ToString();
                    ws.Cells[renglon, 4].Value = Lista[i].Cantidad.ToString();
                    ws.Cells[renglon, 5].Value = Objeto.Total.ToString();

                    renglon++;
                }

                ws.Cells[aux_renglon, 1, renglon - 1, 5].Style.Border.Left.Style   = ExcelBorderStyle.Thin;
                ws.Cells[aux_renglon, 1, renglon - 1, 5].Style.Border.Right.Style  = ExcelBorderStyle.Thin;
                ws.Cells[aux_renglon, 1, renglon - 1, 5].Style.Border.Top.Style    = ExcelBorderStyle.Thin;
                ws.Cells[aux_renglon, 1, renglon - 1, 5].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;

                Byte[] bin  = p.GetAsByteArray();
                String file = ruta_nueva_archivo;
                File.WriteAllBytes(file, bin);
            }
        }
Ejemplo n.º 2
0
        public String Guardar(String Datos, String Lista)
        {
            Cls_Ctrl_Operaciones            Controlador        = new Cls_Ctrl_Operaciones();
            Cls_Mdl_Salida_Mercancia        Obj_Capturado      = new Cls_Mdl_Salida_Mercancia();
            List <Cls_Mdl_Salida_Mercancia> Lista_Productos    = new List <Cls_Mdl_Salida_Mercancia>();
            JsonSerializerSettings          Configuracion_Json = new JsonSerializerSettings();
            Respuesta Obj_Respuesta = new Respuesta();
            String    Str_Respuesta = String.Empty;

            try
            {
                Obj_Capturado   = JsonConvert.DeserializeObject <Cls_Mdl_Salida_Mercancia>(Datos);
                Lista_Productos = JsonConvert.DeserializeObject <List <Cls_Mdl_Salida_Mercancia> >(Lista);

                Obj_Capturado.Usuario_Registro = Sessiones.Nombre;

                if (Controlador.Guardar_Salida(Obj_Capturado, Lista_Productos))
                {
                    Archivos_Excel(Obj_Capturado, Lista_Productos);
                    Obj_Respuesta.Estatus   = true;
                    Obj_Respuesta.Mensaje   = "Registro exitoso.";
                    Obj_Respuesta.Registros = "Productos_Traspaso.xlsx";
                }
            }
            catch (Exception ex)
            {
                Obj_Respuesta.Estatus = false;
                Obj_Respuesta.Mensaje = "Guardar Cliente[" + ex.Message + "]";
            }
            finally
            {
                Str_Respuesta = JsonConvert.SerializeObject(Obj_Respuesta, Formatting.Indented, Configuracion_Json);
            }
            return(Str_Respuesta);
        }
Ejemplo n.º 3
0
        public String Archivos_Excel(Cls_Mdl_Salida_Mercancia Objeto, List <Cls_Mdl_Salida_Mercancia> Lista)
        {
            Cls_Mdl_Salida_Mercancia Obj_Negocio = new Cls_Mdl_Salida_Mercancia();
            Respuesta Obj_Resp       = new Respuesta();
            String    Json_Resultado = String.Empty;
            DataTable Dt_Registros   = new DataTable();

            Obj_Resp.Registros = "{}";

            try
            {
                //if (Dt_Registros.Rows.Count > 0)
                //{
                Workbook Book_Reporte        = new Workbook();
                String   Ruta                = HttpContext.Current.Server.MapPath("~") + "\\Temporal";
                String   ruta_plantilla      = System.AppDomain.CurrentDomain.BaseDirectory + "Plantillas\\Productos_Traspaso.xlsx";
                String   nombre_archivo      = "Productos_Traspaso.xlsx";
                String   ruta_almacenamiento = Ruta + "\\" + nombre_archivo;

                Rpt_Excel Obj_Reporte = new Rpt_Excel(ruta_plantilla, ruta_almacenamiento);
                Obj_Reporte.Salida_Mercancia_Reporte(Objeto, Lista);

                if (!Directory.Exists(Ruta))
                {
                    Directory.CreateDirectory(Ruta);
                }

                HttpContext.Current.ApplicationInstance.Response.Clear();
                HttpContext.Current.ApplicationInstance.Response.Buffer      = true;
                HttpContext.Current.ApplicationInstance.Response.ContentType = "application/vnd.ms-excel";
                HttpContext.Current.ApplicationInstance.Response.AddHeader("Content-Disposition", "attachment; filename=" + nombre_archivo);
                HttpContext.Current.ApplicationInstance.Response.Charset         = "UTF-8";
                HttpContext.Current.ApplicationInstance.Response.ContentEncoding = Encoding.Default;
                HttpContext.Current.ApplicationInstance.Response.WriteFile(ruta_almacenamiento);
                HttpContext.Current.ApplicationInstance.CompleteRequest();

                Obj_Resp.Registros = "Productos_Traspaso.xls";
                Obj_Resp.Estatus   = true;
                //}
                //else
                //{
                //    Obj_Resp.Mensaje = "No hay datos que mostrar.";
                //    Obj_Resp.Estatus = false;
                //}
            }
            catch (Exception Ex)
            {
                Obj_Resp.Estatus = false;
                Obj_Resp.Mensaje = "Archivos_Excel[" + Ex.Message + "]";
            }
            finally
            {
                Json_Resultado = JsonMapper.ToJson(Obj_Resp);
            }
            return(Json_Resultado);
        }