コード例 #1
0
        public async Task <IEnumerable <TpvsInstaladasGraficaResponse> > getTpvsInstaladas(TpvInstaladaRequest req)
        {
            try
            {
                List <TpvsInstaladasGraficaResponse> tpvs = await _context.Query <TpvsInstaladasGraficaResponse>().FromSql("EXEC SP_GET_REPORTE_MODELOS_PROVEEDOR @p0, @p1",
                                                                                                                           req.fecini,
                                                                                                                           req.fecfin
                                                                                                                           ).ToListAsync();

                return(tpvs);
            }
            catch (Exception ex)
            {
                List <TpvsInstaladasGraficaResponse> tpvs = new List <TpvsInstaladasGraficaResponse>();
                return(tpvs);
            }
        }
コード例 #2
0
        public async Task <ActionResult> PosTpvsInstaladas(TpvInstaladaRequest req)
        {
            try
            {
                string folder      = "C:\\inetpub\\wwwroot\\" + appname + "\\TPVS\\INSTALACIONES\\ARCHIVOS";
                string name        = "TPVS_INSTALADAS_" + RandomString(8) + ".xlsx";
                string downloadUrl = folder + "\\" + name;

                FileInfo file = new FileInfo(Path.Combine(folder, name));

                var columnHeaders = new string[]
                {
                    "TIPO DE SERVICIO",
                    "SUBTIPO DE SERVICIO",
                    "ODT",
                    "NO_AFILIACION",
                    "DESC_NEGOCIO",
                    "CONCLUSIONES",
                    "DESC_MODELO",
                    "DESC_STATUS_UNIDAD",
                    "NO_SERIE",
                    "CAJA",
                    "FEC_CIERRE_ODT",
                    "FEC_CIERRE_INVENTARIO",
                    "CONECTIVIDAD",
                    "APLICATIVO"
                };

                if (file.Exists)
                {
                    file.Delete();
                    file = new FileInfo(Path.Combine(folder, name));
                }

                List <TpvInstaladaResponse> tpvs = await _context.Query <TpvInstaladaResponse>().FromSql("EXEC SP_REPORTE_TPV_INSTALADAS @p0, @p1",
                                                                                                         req.fecini,
                                                                                                         req.fecfin
                                                                                                         ).ToListAsync();

                using (var package = new ExcelPackage(file))
                {
                    var worksheet = package.Workbook.Worksheets.Add("HOJA");
                    using (var cells = worksheet.Cells[1, 1, 1, 14])
                    {
                        cells.Style.Font.Bold = true;
                        cells.Style.Font.Color.SetColor(Color.White);
                        cells.Style.Fill.PatternType = ExcelFillStyle.Solid;
                        cells.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(0, 128, 255));
                    }

                    for (int i = 0; i < columnHeaders.Count(); i++)
                    {
                        worksheet.Cells[1, i + 1].Value = columnHeaders[i];
                    }
                    var j = 2;

                    foreach (var tpv in tpvs)
                    {
                        worksheet.Cells["A" + j].Value = tpv.DESC_SERVICIO;
                        worksheet.Cells["B" + j].Value = tpv.DESC_FALLA;
                        worksheet.Cells["C" + j].Value = tpv.NO_AR;
                        worksheet.Cells["D" + j].Style.Numberformat.Format = "0";
                        worksheet.Cells["D" + j].Value = tpv.NO_AFILIACION;
                        worksheet.Cells["E" + j].Value = tpv.DESC_NEGOCIO;
                        worksheet.Cells["F" + j].Value = tpv.CADENA_CIERRE;
                        worksheet.Cells["G" + j].Value = tpv.DESC_MODELO;
                        worksheet.Cells["H" + j].Value = tpv.DESC_STATUS_UNIDAD;
                        worksheet.Cells["I" + j].Value = tpv.NO_SERIE;
                        worksheet.Cells["J" + j].Value = tpv.CAJA;
                        worksheet.Cells["K" + j].Style.Numberformat.Format = "@";
                        worksheet.Cells["K" + j].Value = String.Format("{0:dd/MM/yyyy HH:mm:ss}", tpv.FEC_CIERRE);
                        worksheet.Cells["L" + j].Style.Numberformat.Format = "@";
                        worksheet.Cells["L" + j].Value = String.Format("{0:dd/MM/yyyy HH:mm:ss}", tpv.FEC_STATUS);
                        worksheet.Cells["M" + j].Value = tpv.DESC_CONECTIVIDAD;
                        worksheet.Cells["N" + j].Value = tpv.DESC_SOFTWARE;

                        j++;
                    }
                    worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
                    package.Save();
                }

                return(Ok(name));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }