public ActionResult ModCargFam(Carg_Familiar CargFami) { try { using (CargFam = new EmpleadosEntities()) { var ModCargFam = CargFam.Sp_UPD_Carg_Familiar( CargFami.Rut_Benef, CargFami.Nombre, CargFami.ApPat, CargFami.ApMat, CargFami.Telefono1, CargFami.Telefono2, CargFami.Fecha_Nac, CargFami.Cod_Sexo, CargFami.Calle_Pje, CargFami.Num_Casa, CargFami.Villa_Pobl, CargFami.Comuna_Id, CargFami.Provincia_Id, CargFami.email, CargFami.Id_Nac, CargFami.Descripcion); return(Json(ModCargFam)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public FileResult GetCsv() { using (var ManEmp = new EmpleadosEntities()) { var ListEmp = ManEmp.Sp_Mues_Empresas().ToList(); List <object> customers = (from customer in ListEmp select new[] { customer.Rut_Empresa, customer.Nombre_Empresa, customer.Calle_Pje_Avda, customer.Numero, customer.Vill_Pobl, customer.Comuna, customer.Provincia_Nombre, customer.fono, customer.emailemp }).ToList <object>(); //Insert the Column Names. customers.Insert(0, new string[9] { "Rut", "Nombre", "Dirección", "Número", "Villa", "Comuna", "Ciudad", "Fono", "Email" }); StringBuilder sb = new StringBuilder(); for (int i = 0; i < customers.Count; i++) { string[] customer = (string[])customers[i]; for (int j = 0; j < customer.Length; j++) { //Append data with separator. sb.Append(customer[j] + ','); } //Append new line character. sb.Append("\r\n"); } return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "ListaEmpresas.csv")); } }
//busca el rut del empleado y verifica si este esta en la tabla de empleados public ActionResult BuscEmp(Empleados emplead) { try { int Verifica; using (Empleados = new EmpleadosEntities()) { var BuscEmp = Empleados.Sp_Sel_Empleado(emplead.Rut_Empleado).ToList(); if (BuscEmp.Count != 0) { Verifica = 1; } else { Verifica = 0; } return(Json(Verifica)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public FileResult GetCsv() { using (var Salud = new EmpleadosEntities()) { var ListInstSalud = this.Salud.Salud.ToList(); List <object> customers = (from customer in ListInstSalud select new[] { customer.Cod_Salud.ToString(), customer.Nombre_Salud, customer.Porc_Cotiz.ToString() }).ToList <object>(); //Insert the Column Names. customers.Insert(0, new string[3] { "Codigo Isapre", "Nombre Isapre", "% Cotización" }); StringBuilder sb = new StringBuilder(); for (int i = 0; i < customers.Count; i++) { string[] customer = (string[])customers[i]; for (int j = 0; j < customer.Length; j++) { //Append data with separator. sb.Append(customer[j] + ';'); } //Append new line character. sb.Append("\r\n"); } return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "ListaIsapres.csv")); } }
public FileResult CargFamCsv() { using (CargFam = new EmpleadosEntities()) { var ListCargFam = CargFam.Sp_Mues_CargFam().ToList(); List <object> customers = (from customer in ListCargFam select new[] { customer.Rut_Carga, customer.Nombre, customer.Paterno, customer.Materno, customer.Fono_Movil, customer.Fono_Fijo, customer.Fecha_Nacimiento, customer.Sexo, customer.Direccion, customer.Villa, customer.Comuna, customer.Ciudad, customer.Email, customer.Nombre_Empleado, customer.Comentarios }).ToList <object>(); //Insert the Column Names. customers.Insert(0, new string[15] { "Rut", "Nombre", "Ap. Paterno", "Ap. Materno", "Fono Movil", "Fono Fijo", "Fech. Nacimiento", "Sexo", "Dirección", "Villa", "Comuna", "Ciudad", "Correo", "Nombre Empleado", "Comentarios" }); StringBuilder sb = new StringBuilder(); for (int i = 0; i < customers.Count; i++) { string[] customer = (string[])customers[i]; for (int j = 0; j < customer.Length; j++) { //Append data with separator. sb.Append(customer[j] + ','); } //Append new line character. sb.Append("\r\n"); } return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "ListaEmpleados.csv")); } }
public FileResult GetCsv() { using (var ManNac = new EmpleadosEntities()) { var ListNac = ManNac.Nacionalidad.ToList(); List <object> customers = (from customer in ListNac select new[] { customer.Id_Nac.ToString(), customer.Descripcion }).ToList <object>(); //Insert the Column Names. customers.Insert(0, new string[2] { "Codigo Nacionalidad", "Nombre Nacionalidad" }); StringBuilder sb = new StringBuilder(); for (int i = 0; i < customers.Count; i++) { string[] customer = (string[])customers[i]; for (int j = 0; j < customer.Length; j++) { //Append data with separator. sb.Append(customer[j] + ','); } //Append new line character. sb.Append("\r\n"); } return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "ListaNacionalidades.csv")); } }
// GET: CargFam #region Carg_CargFam public ActionResult Index() { try { using (CargFam = new EmpleadosEntities()) { var ListCargFam = CargFam.Sp_Mues_CargFam().ToList(); var ListCom = Comun.Sp_Mues_Comunas().ToList(); ViewBag.ListComu = new SelectList(ListCom, "Comuna_Id", "Comuna"); var LisSex = Sexo.Sexo.ToList(); ViewBag.ListSexos = new SelectList(LisSex, "Id_Sexo", "Descripcion"); var LisNac = Nacion.Nacionalidad.ToList(); ViewBag.ListNacion = new SelectList(LisNac, "Id_Nac", "Descripcion"); return(View(ListCargFam)); } }catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public void GetXls() { using (var Cargos = new EmpleadosEntities()) { var ListCargos = this.Cargos.Cargos.ToList(); ExcelPackage excel = new ExcelPackage(); //agrega 1 hoja al libro y le da un nombre excel.Workbook.Worksheets.Add("Lista_Cargos"); // crea la cabecera var headerRow = new System.Collections.Generic.List <string[]>() { new string[] { "Código Cargo", "Cargos" } }; // Le da un Nombre a la Hoja var worksheet = excel.Workbook.Worksheets["Lista_Cargos"]; // asigna el rango de despliegue de la cabecera string headerRange = "A2:B2"; // Agrega la Cabecera a la hoja de trabajo worksheet.Cells[headerRange].LoadFromArrays(headerRow); //le da estilo a la cabecera worksheet.Cells[headerRange].Style.Font.Bold = true; worksheet.Cells[headerRange].Style.Font.Size = 14; worksheet.Cells[headerRange].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[headerRange].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; int rowStart = 3; // fila (de inicio) en la que se empiezan a dejar los datos // carga los datos a las filas y les da format foreach (var item in ListCargos) { worksheet.Cells[string.Format("A{0}", rowStart)].Value = item.Id_Carg; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("A{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("B{0}", rowStart)].Value = item.Descr_Cargo; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("B{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); rowStart++; } // Auto Ajusta el tamaño de Las Columnas worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); // Graba la planilla Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=\"ListaCargos.xlsx\""); Response.BinaryWrite(excel.GetAsByteArray()); Response.End(); } }
static void Main(string[] args) { var ctx = new EmpleadosEntities(); //INSERTAR ELEMENTO: var p = new Cargo() { nombre = "Tecnico IT", salarioBase = 3000 }; //ctx.Cargo.Add(p); //ctx.SaveChanges(); //BORRAR ELEMENTO: var elemento = ctx.Cargo.Find(1); //if (elemento != null) // ctx.Cargo.Remove(elemento); //MODIFICAR ELEMENTO: var elemento2 = ctx.Cargo.Find(3); //if (elemento != null) // elemento2.salarioBase = 5500; //ctx.SaveChanges(); //MOSTRAR LISTA Console.WriteLine("------------------------"); Console.WriteLine("CARGO ----- SALARIO BASE"); Console.WriteLine("------------------------"); foreach (var puesto in ctx.Cargo) { Console.WriteLine(puesto); } //Alta empleado con puesto var e = new Empleados() { alta = DateTime.Now, nombre = "Alberto", //puesto = 3 Cargo1 = elemento2, }; //ctx.Empleados.Add(e); //Mostrar por cargos: Console.WriteLine("--------------------------------"); Console.WriteLine("EMPLEADOS DE {0}",elemento2.nombre); Console.WriteLine("--------------------------------"); foreach (var empleado in elemento2.Empleados) { Console.WriteLine(empleado.nombre); } Console.ReadLine(); }
// GET: Salud #region Carga_InstSalud public ActionResult Index() { using (Salud = new EmpleadosEntities()) { try { var ListInstSalud = Salud.Salud.ToList(); return(View(ListInstSalud)); } catch (Exception) { throw; } } }
static void Main(string[] args) { var ctx = new EmpleadosEntities(); var p = new Puesto() { nombre = "Tecnico IT", salarioBase = 30000 }; ctx.Puesto.Add(p); ctx.SaveChanges(); }
public ActionResult Grab_AFP(Afp afp) { try { using (var ManAfp = new EmpleadosEntities()) { var GrabaAfp = ManAfp.Sp_Ins_Afp(afp.Nom_Afp, afp.Porc_Desc); return(Json(GrabaAfp)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult Index() { using (ManAfp = new EmpleadosEntities()) { try { var ListAfp = ManAfp.Afp.ToList(); return(View(ListAfp)); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } } }
public ActionResult GrabaDepto(Departamento departamento) { try { using (var Deptos = new EmpleadosEntities()) { var Graba = Deptos.Sp_Ins_Depto(departamento.NomDepto); return(Json(Graba)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult ModAFP(Afp afp) { try { using (var ManAfp = new EmpleadosEntities()) { var ActAfp = ManAfp.Sp_UPD_Afp(afp.Cod_Afp, afp.Nom_Afp, afp.Porc_Desc); } return(RedirectToAction("Index")); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult GrabaCargos(Cargos cargos) { try { using (var Cargos = new EmpleadosEntities()) { var GrabaCarg = Cargos.Sp_Ins_Cargos(cargos.Descr_Cargo); return(Json(GrabaCarg)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult ElimCargFam(Carg_Familiar CargFami) { try { using (CargFam = new EmpleadosEntities()) { var ElimCargFam = CargFam.Sp_Del_Carga_Familiar(CargFami.Rut_Benef); return(Json(ElimCargFam)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult ModSistSalud(Salud salud) { try { using (var Salud = new EmpleadosEntities()) { var ActSalud = Salud.Sp_UPD_Salud(salud.Cod_Salud, salud.Nombre_Salud, salud.Porc_Cotiz); } return(RedirectToAction("Index")); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult GrabSalud(Salud salud) { try { using (var Salud = new EmpleadosEntities()) { var GrabaSalud = Salud.Sp_Ins_Salud(salud.Nombre_Salud, salud.Porc_Cotiz); return(Json(GrabaSalud)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult Index() { using (ManEmp = new EmpleadosEntities()) { try { var ListEmp = ManEmp.Sp_Mues_Empresas().ToList(); var ListCom = Comun.Sp_Mues_Comunas().ToList(); ViewBag.ListComu = new SelectList(ListCom, "Comuna_Id", "Comuna"); return(View(ListEmp)); }catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } } }
public ActionResult GrabaEmp(Empresa empresa) { try { using (ManEmp = new EmpleadosEntities()) { var GrabaEmp = ManEmp.Sp_Ins_Empresas(empresa.Rut_Empresa, empresa.Nombre_Empresa, empresa.Calle_Pje_Avda, empresa.Numero, empresa.Vill_Pobl, Convert.ToString(empresa.Comuna_Id), Convert.ToString(empresa.Provincia_Id), empresa.fono, empresa.emailemp); return(Json(GrabaEmp)); } }catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult EditCarg(Cargos cargos) { try { using (var Cargos = new EmpleadosEntities()) { var UpdCargos = Cargos.Sp_UPD_Cargos(cargos.Id_Carg, cargos.Descr_Cargo); } return(RedirectToAction("Index")); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult EditDept(Departamento departamento) { try { using (var Deptos = new EmpleadosEntities()) { var ActDep = Deptos.Sp_UPD_Depto(departamento.Id_Depto, departamento.NomDepto); } return(RedirectToAction("Index")); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult BuscCargFam(Carg_Familiar BuscCargFam) { try { using (CargFam = new EmpleadosEntities()) { var BucaEmpleado = CargFam.Sp_Sel_CargFamxRut(BuscCargFam.Rut_Benef).ToList(); return(Json(BucaEmpleado)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult EditNac(Nacionalidad nacionalidad) { try { using (var ManNac = new EmpleadosEntities()) { var UpdNac = ManNac.Sp_UPD_Nacionalidad(nacionalidad.Id_Nac, nacionalidad.Descripcion); } return(RedirectToAction("Index")); } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult GrabaNacionalidad(Nacionalidad nacionalidad) { try { using (var ManNac = new EmpleadosEntities()) { var GrabNac = ManNac.Sp_Ins_Nacionalidad(nacionalidad.Descripcion); return(Json(GrabNac)); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public void CargFamXls() { try{ using (CargFam = new EmpleadosEntities()) { var ListCargFam = CargFam.Sp_Mues_CargFam().ToList(); ExcelPackage excel = new ExcelPackage(); //agrega 1 hoja al libro y le da un nombre excel.Workbook.Worksheets.Add("Lista_Cargas_familiares"); // crea la cabecera var headerRow = new System.Collections.Generic.List <string[]>() { new string[] { "Rut", "Nombre", "Ap. Paterno", "Ap. Materno", "Fono Movil", "Fono Fijo", "Fech. Nacimiento", "Sexo", "Dirección", "Villa", "Comuna", "Ciudad", "Correo", "Nombre Empleado", "Comentarios" } }; // Le da un Nombre a la Hoja var worksheet = excel.Workbook.Worksheets["Lista_Cargas_familiares"]; // asigna el rango de despliegue de la cabecera //string headerRange = "A1:" + Char.ConvertFromUtf32(headerRow[0].Length + 64) + "1"; string headerRange = "A2:O2"; // Agrega la Cabecera a la hoja de trabajo worksheet.Cells[headerRange].LoadFromArrays(headerRow); //le da estilo a la cabecera worksheet.Cells[headerRange].Style.Font.Bold = true; worksheet.Cells[headerRange].Style.Font.Size = 15; worksheet.Cells[headerRange].Style.Font.Color.SetColor(System.Drawing.Color.Black); worksheet.Cells[headerRange].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; int rowStart = 3; // fila (de inicio) en la que se empiezan a dejar los datos // carga los datos a las filas y les da format foreach (var item in ListCargFam) { worksheet.Cells[string.Format("A{0}", rowStart)].Value = item.Rut_Carga; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("A{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("B{0}", rowStart)].Value = item.Nombre; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("B{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("C{0}", rowStart)].Value = item.Paterno; worksheet.Cells[string.Format("C{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("C{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("C{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("D{0}", rowStart)].Value = item.Materno; worksheet.Cells[string.Format("D{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("D{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("D{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("E{0}", rowStart)].Value = item.Fono_Movil; worksheet.Cells[string.Format("E{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("E{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("E{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("F{0}", rowStart)].Value = item.Fono_Fijo; worksheet.Cells[string.Format("F{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("F{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("F{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("G{0}", rowStart)].Value = item.Fecha_Nacimiento; worksheet.Cells[string.Format("G{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("G{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("G{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("H{0}", rowStart)].Value = item.Sexo; worksheet.Cells[string.Format("H{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("H{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("H{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("I{0}", rowStart)].Value = item.Direccion; worksheet.Cells[string.Format("I{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("I{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("I{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("J{0}", rowStart)].Value = item.Villa; worksheet.Cells[string.Format("J{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("J{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("J{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("K{0}", rowStart)].Value = item.Comuna; worksheet.Cells[string.Format("K{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("K{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("K{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("L{0}", rowStart)].Value = item.Ciudad; worksheet.Cells[string.Format("L{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("L{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("L{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("M{0}", rowStart)].Value = item.Email; worksheet.Cells[string.Format("M{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("M{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("M{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("N{0}", rowStart)].Value = item.Nombre_Empleado; worksheet.Cells[string.Format("N{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("N{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("N{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("O{0}", rowStart)].Value = item.Comentarios; worksheet.Cells[string.Format("O{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("O{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("O{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); rowStart++; } // Auto Ajusta el tamaño de Las Columnas worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); // Graba la planilla Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=\"ListaCargFam.xlsx\""); Response.BinaryWrite(excel.GetAsByteArray()); Response.End(); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; //return Json(Response); } }
//Exportaciones #region Crea_Pdf public ActionResult GetPdf() { try { using (var ManNac = new EmpleadosEntities()) { var ListNac = ManNac.Nacionalidad.ToList(); MemoryStream ms = new MemoryStream(); iTextSharp.text.Document document = new iTextSharp.text.Document(); document.SetPageSize(PageSize.A4); document.SetMargins(50, 50, 50, 50); PdfWriter pdf = PdfWriter.GetInstance(document, ms); //agrega el autor del documento document.AddAuthor("Rodrigo Menares Guzman"); // document.AddTitle("Listado_de_Cargos"); //hace la insercion del pie de pagina pdf.PageEvent = new HeadFooter(); document.Open(); //insercion de imagenes string url = Server.MapPath("/Imagenes/bg.jpg"); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(url); image.ScaleToFit(140f, 120f); image.Alignment = Element.ALIGN_LEFT; document.Add(image); // fin de insercion de imagenes //fuente, tamaño y color de cabecera BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.EMBEDDED); iTextSharp.text.Font fontText2 = new iTextSharp.text.Font(bf, 16, 4, BaseColor.BLUE); //creacion e insercion de titulos al documento iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph(string.Format("Listado de Nacionalidades"), fontText2); titulo.Alignment = 1; //0-Left, 1 middle,2 Right //inserta al documento document.Add(titulo); //inserta nueva linea al texto document.Add(iTextSharp.text.Chunk.NEWLINE); //esto es para estilo de letra de la tabla BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1250, BaseFont.EMBEDDED); //tamaño y color iTextSharp.text.Font fontText = new iTextSharp.text.Font(bf2, 10, 0, BaseColor.BLACK); iTextSharp.text.Font fontText3 = new iTextSharp.text.Font(bf2, 10, 0, BaseColor.WHITE); // instancia la tabla y le indica la cantidad de columnas PdfPTable table = new PdfPTable(2); //indica q ancho de la hoja va a ocupar la tabla table.WidthPercentage = 95; // instancia para la generacion de celdas en la tabla PdfPCell _cell = new PdfPCell(); //genera la cabecera de la tabla _cell = new PdfPCell(new iTextSharp.text.Paragraph("Código Nacionalidad", fontText3)); _cell.BackgroundColor = iTextSharp.text.BaseColor.DARK_GRAY; _cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(_cell); _cell = new PdfPCell(new iTextSharp.text.Paragraph("Nacionalidad", fontText3)); _cell.BackgroundColor = iTextSharp.text.BaseColor.DARK_GRAY; _cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(_cell); //llena la tabla y ademas le da la alineacion a los datos foreach (var item in ListNac) { PdfPCell _cell2 = new PdfPCell(); _cell2 = new PdfPCell(new iTextSharp.text.Paragraph(item.Id_Nac.ToString(), fontText)); _cell2.HorizontalAlignment = Element.ALIGN_RIGHT; table.AddCell(_cell2); _cell2 = new PdfPCell(new iTextSharp.text.Paragraph(item.Descripcion, fontText)); _cell2.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(_cell2); } //agrega la tabla al documento document.Add(table); //cierra el documento document.Close(); //vacia la memoria(documento) hacia memory stream byte[] byteStream = ms.ToArray(); ms = new MemoryStream(); ms.Write(byteStream, 0, byteStream.Length); ms.Position = 0; //esto permite que el archivo pdf se muestre por pantalla en el explorador y a su vez sea guardado en el disco return(File(ms, "application/pdf", "ListaNacionalidades.pdf")); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult GetDocx() { try { using (var ManNac = new EmpleadosEntities()) { var ListNac = ManNac.Nacionalidad.ToList(); //Ubicacion de Archivo string filename = @"C:\Users\Rodrigo_Menares\Downloads\ListaNacionalidades.docx"; var doc = DocX.Create(filename); //Carga una imagen en formato JPG var image = doc.AddImage(Server.MapPath("/Imagenes/bg.jpg")); // Set Picture Height and Width. var picture = image.CreatePicture(50, 50); picture.Width = 50; picture.Height = 50; //Titulo Del Documento string title = "Lista De Cargos"; //Formato del Titulo Formatting titleFormat = new Formatting(); //Specify font family titleFormat.FontFamily = new Xceed.Document.NET.Font("Arial Black"); //Specify font size y color del texto titleFormat.Size = 14D; titleFormat.Position = 40; titleFormat.FontColor = System.Drawing.Color.Orange; titleFormat.UnderlineColor = System.Drawing.Color.Gray; titleFormat.Italic = true; //combina el titulo con el formato definido Xceed.Document.NET.Paragraph paragraphTitle = doc.InsertParagraph(title, false, titleFormat); // alinea el titulo al centro paragraphTitle.Alignment = Alignment.center; //Insert text Table tbl = doc.AddTable(ListNac.Count + 1, 2); //hace que la tabla este al centro de la pagina tbl.Alignment = Alignment.center; tbl.Design = TableDesign.ColorfulList; //agrega los titulos de la tabla tbl.Rows[0].Cells[0].Paragraphs.First().Append("Código Nacionalidad").FontSize(12D).Alignment = Alignment.center; tbl.Rows[0].Cells[1].Paragraphs.First().Append("Nombre Nacionalidad").FontSize(12D).Alignment = Alignment.center; //llena las celdas con los datos int fila = 1; int columna = 0; foreach (var item in ListNac) { tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Id_Nac)).FontSize(12D).Alignment = Alignment.right; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Descripcion)).FontSize(12D).Alignment = Alignment.center; fila++; columna = 0; } //inserta la tabla dentro del documento doc.InsertTable(tbl); //Genera el Pie de Pagina del Documento doc.AddFooters(); //Indica que que la primera página tendrá pies de página independientes doc.DifferentFirstPage = true; //Indica que que la página par e impar tendrá pies de página separados doc.DifferentOddAndEvenPages = true; Footer footer_main = doc.Footers.First; Paragraph pFooter = footer_main.Paragraphs.First(); pFooter.Alignment = Alignment.center; pFooter.Append("Página ").Bold(); pFooter.AppendPageNumber(PageNumberFormat.normal).Bold(); pFooter.Append("/").Bold(); pFooter.AppendPageCount(PageNumberFormat.normal).Bold(); //graba el documento doc.Save(); //abre word y el documento Process.Start("WINWORD", filename); return(RedirectToAction("Index")); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public ActionResult CargFamDocx() { try { using (CargFam = new EmpleadosEntities()) { var ListCargFam = CargFam.Sp_Mues_CargFam().ToList(); //Ubicacion de Archivo string filename = @"C:\Users\Rodrigo_Menares\Downloads\ListaCargFam.docx"; var doc = DocX.Create(filename); //cambia la orientacion de la pagina doc.PageLayout.Orientation = Orientation.Landscape; //Carga una imagen en formato JPG var image = doc.AddImage(Server.MapPath("/Imagenes/bg.jpg")); // Set Picture Height and Width. var picture = image.CreatePicture(50, 50); picture.Width = 50; picture.Height = 50; //Titulo Del Documento string title = "Lista De Cargas Familiares"; //Formato del Titulo Formatting titleFormat = new Formatting(); //Specify font family titleFormat.FontFamily = new Xceed.Document.NET.Font("Arial Black"); //Specify font size y color del texto titleFormat.Size = 14D; titleFormat.Position = 40; titleFormat.FontColor = System.Drawing.Color.Orange; titleFormat.UnderlineColor = System.Drawing.Color.Gray; titleFormat.Italic = true; //combina el titulo con el formato definido Xceed.Document.NET.Paragraph paragraphTitle = doc.InsertParagraph(title, false, titleFormat); // alinea el titulo al centro paragraphTitle.Alignment = Alignment.center; //define las dimensiones de la tabla (tbl(f,c)) Table tbl = doc.AddTable(ListCargFam.Count + 1, 11); //hace que la tabla este al centro de la pagina tbl.Alignment = Alignment.center; tbl.Design = TableDesign.ColorfulList; tbl.AutoFit = AutoFit.Contents; //agrega los titulos de la tabla tbl.Rows[0].Cells[0].Paragraphs.First().Append("Rut").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[1].Paragraphs.First().Append("Nombre").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[2].Paragraphs.First().Append("Ap. Paterno").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[3].Paragraphs.First().Append("Fono Movil").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[4].Paragraphs.First().Append("Fecha Nacimiento").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[5].Paragraphs.First().Append("Sexo").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[6].Paragraphs.First().Append("Dirección").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[7].Paragraphs.First().Append("Comuna").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[8].Paragraphs.First().Append("Correo").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[9].Paragraphs.First().Append("Nombre Empleado").FontSize(8D).Alignment = Alignment.center; tbl.Rows[0].Cells[10].Paragraphs.First().Append("Comentarios").FontSize(8D).Alignment = Alignment.center; //llena las celdas con los datos int fila = 1; int columna = 0; foreach (var item in ListCargFam) { tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Rut_Carga)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Nombre)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Paterno)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Fono_Movil)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Fecha_Nacimiento)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Sexo)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Direccion)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Comuna)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Email)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Nombre_Empleado)).FontSize(8D).Alignment = Alignment.left; columna++; tbl.Rows[fila].Cells[columna].Paragraphs.First().Append(Convert.ToString(item.Comentarios)).FontSize(8D).Alignment = Alignment.left; fila++; columna = 0; } //inserta la tabla dentro del documento doc.InsertTable(tbl); //Genera el Pie de Pagina del Documento doc.AddFooters(); //Indica que que la primera página tendrá pies de página independientes doc.DifferentFirstPage = true; //Indica que que la página par e impar tendrá pies de página separados doc.DifferentOddAndEvenPages = true; Footer footer_main = doc.Footers.First; Paragraph pFooter = footer_main.Paragraphs.First(); pFooter.Alignment = Alignment.center; pFooter.Append("Página ").Bold(); pFooter.AppendPageNumber(PageNumberFormat.normal).Bold(); pFooter.Append("/").Bold(); pFooter.AppendPageCount(PageNumberFormat.normal).Bold(); //graba el documento doc.Save(); //abre word y el documento Process.Start("WINWORD", filename); return(RedirectToAction("Index")); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; return(Json(Response)); } }
public void GetXls() { try { using (var ManNac = new EmpleadosEntities()) { var ListNac = ManNac.Nacionalidad.ToList(); ExcelPackage excel = new ExcelPackage(); //agrega 1 hoja al libro y le da un nombre excel.Workbook.Worksheets.Add("Lista_Nacionalidades"); // crea la cabecera var headerRow = new System.Collections.Generic.List <string[]>() { new string[] { "Código Nación", "Nación" } }; // Le da un Nombre a la Hoja var worksheet = excel.Workbook.Worksheets["Lista_Nacionalidades"]; // asigna el rango de despliegue de la cabecera //string headerRange = "A1:" + Char.ConvertFromUtf32(headerRow[0].Length + 64) + "1"; string headerRange = "A2:B2"; // Agrega la Cabecera a la hoja de trabajo worksheet.Cells[headerRange].LoadFromArrays(headerRow); //le da estilo a la cabecera worksheet.Cells[headerRange].Style.Font.Bold = true; worksheet.Cells[headerRange].Style.Font.Size = 14; worksheet.Cells[headerRange].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[headerRange].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; int rowStart = 3; // fila (de inicio) en la que se empiezan a dejar los datos // carga los datos a las filas y les da format foreach (var item in ListNac) { worksheet.Cells[string.Format("A{0}", rowStart)].Value = item.Id_Nac; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("A{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; worksheet.Cells[string.Format("A{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); worksheet.Cells[string.Format("B{0}", rowStart)].Value = item.Descripcion; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Size = 12; worksheet.Cells[string.Format("B{0}", rowStart)].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; worksheet.Cells[string.Format("B{0}", rowStart)].Style.Font.Color.SetColor(System.Drawing.Color.Blue); rowStart++; } // Auto Ajusta el tamaño de Las Columnas worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); // Graba la planilla Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=\"ListaNacionalidad.xlsx\""); Response.BinaryWrite(excel.GetAsByteArray()); Response.End(); } } catch (Exception ex) { Logger.Error("Error On:", ex); Response.StatusCode = 500; Response.StatusDescription = ex.Message; //return Json(Response); } }