This commit is contained in:
@@ -9,6 +9,8 @@ using System.Data;
|
||||
using System.Text;
|
||||
using static Extensiones.ModExtensiones;
|
||||
using System.Drawing;
|
||||
using iTextSharp.text.pdf;
|
||||
using System.IO;
|
||||
|
||||
public partial class Nomina_Nomina2 : ClsPaginas
|
||||
{
|
||||
@@ -343,7 +345,8 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
FiltCveSubProyecto = DdlSubProyecto.SelectedValue.ToEntero();
|
||||
FiltCveTurno = DdlTurno.SelectedValue.ToEntero();
|
||||
FiltCvePeriodo = DdlPeriodo.SelectedValue.ToEntero();
|
||||
FiltAgrupador = DdlAgrupador.SelectedValue.ToEntero();
|
||||
FiltAgrupador = 1;
|
||||
HypPDFSTimbrados.Attributes.Add("onclick", string.Format("GETPDF({0},{1})", -1, FiltCvePeriodo));
|
||||
cargaDatos();
|
||||
|
||||
}
|
||||
@@ -833,6 +836,30 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
dt.AcceptChanges();
|
||||
dt = dt.FiltraParametros("", "CveDepartamento,Departamento,Codigo,Nombre");
|
||||
}
|
||||
if (DdlAgrupadorB.SelectedValue == "3")
|
||||
{
|
||||
|
||||
foreach (DataRow drow in dtempleados.FiltraParametros("CvePersonal > 0", "", new string[] { "CveTurno", "Turno" }).Rows)
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
filtrogrupo = (drow["CveTurno"] == DBNull.Value ? "CveTurno IS NULL AND CvePersonal>0 " : string.Format("CveTurno = {0} AND CvePersonal>0", drow["CveTurno"]));
|
||||
foreach (DataRow row in dtConceptos.FiltraParametros("EsPadre = 1 ").Rows)
|
||||
{
|
||||
int CveConcepto = row["CveConcepto"].ToString().ToEntero();
|
||||
dr[string.Format("V_{0}", CveConcepto)] = dtempleados.SUM(string.Format("[V_{0}]", CveConcepto), filtrogrupo);
|
||||
}
|
||||
dr["CveTurno"] = drow["CveTurno"];
|
||||
dr["Turno"] = drow["Turno"];
|
||||
dr["SumaPercepciones"] = dtempleados.SUM("SumaPercepciones", filtrogrupo);
|
||||
dr["SumaDeducciones"] = dtempleados.SUM("SumaDeducciones", filtrogrupo);
|
||||
dr["Total"] = dtempleados.SUM("Total", filtrogrupo);
|
||||
dr["SumaObligaciones"] = dtempleados.SUM("SumaObligaciones", filtrogrupo);
|
||||
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
dt.AcceptChanges();
|
||||
dt = dt.FiltraParametros("", "CveDepartamento,Departamento,Codigo,Nombre");
|
||||
}
|
||||
GvNominas.DataSource = dt;
|
||||
GvNominas.DataBind();
|
||||
}
|
||||
@@ -904,8 +931,8 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
else
|
||||
{
|
||||
|
||||
e.Row.FCHyperLink("HypPDF").Attributes.Add("onclick", string.Format("GETPDF({0},{1})", cvePersonal, CvePeriodo));
|
||||
//e.Row.FindControl("HypPDF").Visible = true;
|
||||
e.Row.FCHyperLink("HypPDF").Attributes.Add("onclick", string.Format("GETPDF({0},{1})", -1, CvePeriodoSeleccionado));
|
||||
e.Row.FindControl("HypPDF").Visible = true;
|
||||
e.Row.CssClass = "SubTotales";
|
||||
}
|
||||
e.Row.FindControl("LnkSobreRecibo").Visible = false;
|
||||
@@ -917,6 +944,48 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected void LnkTimbrarTodos_Click(object sender, EventArgs e)
|
||||
{
|
||||
string msggral = "";
|
||||
foreach (GridViewRow gvRow in GvNominas.Rows)
|
||||
{
|
||||
int CvePeriodo = gvRow.DataKey("CvePeriodo").ToEntero();
|
||||
int CvePersonal = gvRow.DataKey("CvePersonal").ToEntero();
|
||||
int CveNomina = gvRow.DataKey("CveNomina").ToEntero();
|
||||
LinkButton LnkTimbrar = gvRow.FCLinkButton("LnkTimbrar");
|
||||
if (CvePersonal > 0 && LnkTimbrar.Visible)
|
||||
{
|
||||
LogicNominas lognom = new LogicNominas();
|
||||
|
||||
string Msg = lognom.TimbrarNomina(CveNomina, CvePersonal, CvePeriodo, UsuarioActual);
|
||||
if (Msg != null && Msg.Length > 0)
|
||||
{
|
||||
msggral = string.Format("{0}<tr><td>{3}</td><td>{2}</td><td><pre>{1}</pre></td></tr>", msggral, Msg, gvRow.DataKey("Nombre"), gvRow.DataKey("Codigo"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ClsNominas ObjPeriodo = new ClsNominas();
|
||||
ObjPeriodo.CambiaEstatusPeriodo(CvePeriodo, (int)enumNominasEstatus.Timbrada, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
|
||||
ObjPeriodo.Dispose();
|
||||
LnkTimbrar.Visible = false;
|
||||
gvRow.FindControl("ImgDelete").Visible = false;
|
||||
gvRow.FindControl("LnkCancelar").Visible = false;
|
||||
gvRow.FindControl("HypXml").Visible = true;
|
||||
gvRow.FindControl("HypPDF").Visible = true;
|
||||
|
||||
gvRow.ForeColor = Color.Green;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (msggral.Length > 0)
|
||||
{
|
||||
|
||||
Alert(string.Format("Ocurrieron los siguientes errores <table class=\"table table-striped table-hover mysmallbtn\" ><tbody><tr><th>Código</th><th>Nombre</th><th>Error</th></tr>{0}</tbody></table>", msggral), TipoMensaje.MsgAdvertencia);
|
||||
}
|
||||
UpDatos.Update();
|
||||
}
|
||||
|
||||
protected void LnkTimbrar_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -925,7 +994,6 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
int CvePeriodo = gvRow.DataKey("CvePeriodo").ToEntero();
|
||||
int CvePersonal = gvRow.DataKey("CvePersonal").ToEntero();
|
||||
int CveNomina = gvRow.DataKey("CveNomina").ToEntero();
|
||||
|
||||
LogicNominas lognom = new LogicNominas();
|
||||
|
||||
string Msg = lognom.TimbrarNomina(CveNomina, CvePersonal, CvePeriodo, UsuarioActual);
|
||||
@@ -939,8 +1007,8 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
Alert("Se ha timbrado correctamente");
|
||||
gvRow.FindControl("ImgDelete").Visible = false;
|
||||
gvRow.FindControl("LnkCancelar").Visible = false;
|
||||
|
||||
//gvRow.FCImage("ImgBandera").ImageUrl = "/Imagenes/flag_green.png";
|
||||
gvRow.FindControl("HypXml").Visible = true;
|
||||
gvRow.FindControl("HypPDF").Visible = true;
|
||||
gvRow.ForeColor = Color.Green;
|
||||
lnk.Visible = false; UpDatos.Update();
|
||||
}
|
||||
@@ -1379,7 +1447,22 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
protected void LnkSobreRecibo_Click(object sender, EventArgs e)
|
||||
{
|
||||
GridViewRow gvrow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
||||
if (DdlCtaContable.Items.Count == 0)
|
||||
{
|
||||
|
||||
using (ClsContPAQi ObjConta = new ClsContPAQi(UsuarioActual.Empresa))
|
||||
{
|
||||
|
||||
if (ObjConta.GetCuentas(-1, "-1", 1))
|
||||
{
|
||||
DdlCtaContable.DataSource = ObjConta.DtResultados;
|
||||
DdlCtaContable.DataBind();
|
||||
}
|
||||
}
|
||||
|
||||
DdlCtaContable.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlCtaContable.SelectedValueExist("-1");
|
||||
}
|
||||
string Nombre = gvrow.DataKey("Nombre").ToString();
|
||||
SRCvePersonal = gvrow.DataKey("CvePersonal").ToEntero();
|
||||
SRCvePeriodo = gvrow.DataKey("CvePeriodo").ToEntero();
|
||||
@@ -2179,22 +2262,29 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook();
|
||||
var libro = wb.AddWorksheet("Nomina");
|
||||
int column = 1;
|
||||
libro.Cell(1, column).Value = " ";
|
||||
libro.Cell(2, column).Value = "Codigo";
|
||||
libro.Cell(3, column).Value = " ";
|
||||
int filainicio = 3;
|
||||
libro.Cell(filainicio + 1, column).Value = " ";
|
||||
libro.Cell(filainicio + 2, column).Value = "Codigo";
|
||||
libro.Cell(filainicio + 3, column).Value = " ";
|
||||
column++;
|
||||
libro.Cell(1, column).Value = " ";
|
||||
libro.Cell(2, column).Value = "Empleado";
|
||||
libro.Cell(3, column).Value = " ";
|
||||
libro.Cell(filainicio + 1, column).Value = " ";
|
||||
libro.Cell(filainicio + 2, column).Value = "Empleado";
|
||||
libro.Cell(filainicio + 3, column).Value = " ";
|
||||
libro.Column(column).Width = 35;
|
||||
libro.Cell(1, 1).Value = "Empresa";
|
||||
libro.Range(1, 2, 1, 4).Merge().Value = UsuarioActual.Empresa.Empresa;
|
||||
libro.Cell(2, 1).Value = "período";
|
||||
string periodo = DdlPeriodo.SelectedItem.Text;
|
||||
periodo = periodo.Substring(0, (periodo.Length > 27 ? 27 : periodo.Length));
|
||||
libro.Range(2, 2, 2, 4).Merge().Value = periodo;
|
||||
|
||||
int iniciotipe = column;
|
||||
foreach (DataRow row in dtConceptos.FiltraParametros("Tipo ='P' AND EsPadre = 1 ").Rows)
|
||||
{
|
||||
|
||||
column++;
|
||||
libro.Cell(2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(3, column).Value = row["Codigo"].ToString();
|
||||
libro.Cell(filainicio + 2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(filainicio + 3, column).Value = row["Codigo"].ToString();
|
||||
libro.Column(column).Width = 15;
|
||||
if ((dtempleados.SUM(string.Format("[V_{0}]", row["CveConcepto"].ToString())) == 0))
|
||||
{
|
||||
@@ -2203,12 +2293,12 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
|
||||
}
|
||||
column++;
|
||||
libro.Range(2, column, 3, column).Merge().Value = "Percepciones";
|
||||
libro.Range(filainicio + 2, column, filainicio + 3, column).Merge().Value = "Percepciones";
|
||||
libro.Column(column).Width = 15;
|
||||
if (iniciotipe < column)
|
||||
{
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Merge().Value = "Percepciones";
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio + 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio + 1, column).Merge().Value = "Percepciones";
|
||||
}
|
||||
iniciotipe = column;
|
||||
|
||||
@@ -2216,8 +2306,8 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
foreach (DataRow row in dtConceptos.FiltraParametros("Tipo = 'D' AND EsPadre = 1 ").Rows)
|
||||
{
|
||||
column++;
|
||||
libro.Cell(2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(3, column).Value = row["Codigo"].ToString();
|
||||
libro.Cell(filainicio + 2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(filainicio + 3, column).Value = row["Codigo"].ToString();
|
||||
libro.Column(column).Width = 15;
|
||||
if ((dtempleados.SUM(string.Format("[V_{0}]", row["CveConcepto"].ToString())) == 0))
|
||||
{
|
||||
@@ -2227,26 +2317,26 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Range(2, column, 3, column).Merge().Value = "Deducciones";
|
||||
libro.Range(filainicio + 2, column, filainicio + 3, column).Merge().Value = "Deducciones";
|
||||
libro.Column(column).Width = 15;
|
||||
|
||||
if (iniciotipe < column)
|
||||
{
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Merge().Value = "Deducciones";
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio + 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio + 1, column).Merge().Value = "Deducciones";
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Cell(1, column).Value = " ";
|
||||
libro.Range(2, column, 3, column).Merge().Value = "Total";
|
||||
libro.Cell(filainicio + 1, column).Value = " ";
|
||||
libro.Range(filainicio + 2, column, filainicio + 3, column).Merge().Value = "Total";
|
||||
libro.Column(column).Width = 15;
|
||||
iniciotipe = column;
|
||||
|
||||
foreach (DataRow row in dtConceptos.FiltraParametros("Tipo = 'O' AND EsPadre = 1 ").Rows)
|
||||
{
|
||||
column++;
|
||||
libro.Cell(2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(3, column).Value = row["Codigo"].ToString();
|
||||
libro.Cell(filainicio + 2, column).Value = row["Concepto"].ToString();
|
||||
libro.Cell(filainicio + 3, column).Value = row["Codigo"].ToString();
|
||||
libro.Column(column).Width = 15;
|
||||
if ((dtempleados.SUM(string.Format("[V_{0}]", row["CveConcepto"].ToString())) == 0))
|
||||
{
|
||||
@@ -2255,31 +2345,34 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
|
||||
}
|
||||
column++;
|
||||
libro.Range(2, column, 3, column).Merge().Value = "Obligaciones";
|
||||
libro.Range(filainicio + 2, column, filainicio + 3, column).Merge().Value = "Obligaciones";
|
||||
libro.Column(column).Width = 15;
|
||||
|
||||
|
||||
if (iniciotipe < column)
|
||||
{
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(1, iniciotipe + 1, 1, column).Merge().Value = "Obligaciones";
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio + 1, column).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Center;
|
||||
libro.Range(filainicio + 1, iniciotipe + 1, filainicio+1, column).Merge().Value = "Obligaciones";
|
||||
}
|
||||
|
||||
libro.Row(1).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
libro.Row(2).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
libro.Row(3).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
libro.Row(1).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(177, 160, 199));
|
||||
libro.Row(2).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
libro.Row(3).Cell(1).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
libro.Row(3).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
//libro.Row(1).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
//libro.Row(2).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
//libro.Row(3).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
//libro.Row(1).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(177, 160, 199));
|
||||
//libro.Row(2).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
//libro.Row(3).Cell(1).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
//libro.Row(3).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
int maxnocolumn = column;
|
||||
|
||||
int Fila = 3;
|
||||
int Fila = filainicio+3;
|
||||
int cveSupProyecto = -5;
|
||||
string subproyecto = "";
|
||||
int oldcveSupProyecto = -5;
|
||||
bool newsubproyecto = false;
|
||||
bool newsubproyectoTitulo = false;
|
||||
foreach (DataRow erow in dtempleados.FiltraParametros("", "CveSubProyecto").Rows)
|
||||
DataTable dtsr = dtempleados.FiltraParametros("", "CveSubProyecto");
|
||||
dtsr.Rows.Add(dtsr.NewRow());
|
||||
foreach (DataRow erow in dtsr.Rows)
|
||||
{
|
||||
Fila++;
|
||||
newsubproyecto = false; newsubproyectoTitulo = false;
|
||||
@@ -2295,8 +2388,15 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
column = 1;
|
||||
libro.Cell(Fila, column).Value = string.Format("'{0}", erow["Codigo"]);
|
||||
column++;
|
||||
if (newsubproyectoTitulo) { libro.Cell(Fila - 1, column).Value = subproyecto; }
|
||||
if (newsubproyecto) { libro.Cell(Fila - 3, column).Value = "Total"; }
|
||||
if (newsubproyectoTitulo) {
|
||||
libro.Cell(Fila - 1, column).Value = subproyecto;
|
||||
libro.Range(Fila - 1, 1, Fila - 1, maxnocolumn).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(155, 194, 230));
|
||||
}
|
||||
if (newsubproyecto)
|
||||
{
|
||||
libro.Cell(Fila - 3, column).Value = "Total";
|
||||
libro.Range(Fila - 3, 1, Fila - 3, maxnocolumn).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(155, 194, 230));
|
||||
}
|
||||
libro.Cell(Fila, column).Value = erow["Nombre"];
|
||||
foreach (DataRow row in dtConceptos.FiltraParametros("Tipo = 'P' AND EsPadre = 1 ").Rows)
|
||||
{
|
||||
@@ -2313,6 +2413,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Cell(Fila, column).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(166, 166, 166));
|
||||
libro.Cell(Fila, column).Value = erow["SumaPercepciones"];
|
||||
if (newsubproyecto)
|
||||
{
|
||||
@@ -2333,6 +2434,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Cell(Fila, column).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(166, 166, 166));
|
||||
libro.Cell(Fila, column).Value = erow["SumaDeducciones"];
|
||||
if (newsubproyecto)
|
||||
{
|
||||
@@ -2340,6 +2442,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Cell(Fila, column).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(166, 166, 166));
|
||||
libro.Cell(Fila, column).Value = erow["Total"];
|
||||
if (newsubproyecto)
|
||||
{
|
||||
@@ -2359,6 +2462,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
column++;
|
||||
libro.Cell(Fila, column).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(166, 166, 166));
|
||||
libro.Cell(Fila, column).Value = erow["SumaObligaciones"];
|
||||
if (newsubproyecto)
|
||||
{
|
||||
@@ -2367,6 +2471,9 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
|
||||
|
||||
libro.Range(filainicio + 1, 1, filainicio + 4, maxnocolumn).Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
||||
libro.Range(filainicio + 1, 1, filainicio + 4, maxnocolumn).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
||||
|
||||
System.IO.Stream fs = new System.IO.MemoryStream();
|
||||
wb.SaveAs(fs);
|
||||
fs.Position = 0;
|
||||
@@ -2382,7 +2489,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
Response.Buffer = true;
|
||||
|
||||
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xlsx", "Nomina tabular"));
|
||||
Response.AddHeader("content-disposition", string.Format("attachment;filename={0} {1}.xlsx", "Nomina tabular", periodo ));
|
||||
Response.BinaryWrite(memoryStream.ToArray());
|
||||
Response.End();
|
||||
}
|
||||
@@ -4912,26 +5019,108 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] pdf2 = new byte[1];
|
||||
bool notfirst = false;
|
||||
List<byte[]> pdfs = new List<byte[]>();
|
||||
//byte[] pdf2 = new byte[1]; bool notfirst = false;
|
||||
foreach (DataRow dr in dtempleados.Rows)
|
||||
{
|
||||
if (notfirst)
|
||||
CvePersonal = dr["CvePersonal"].ToString().ToEntero();
|
||||
if (CvePersonal > 0)
|
||||
{
|
||||
pdfs.Add(GeneraPDFNomina(CvePersonal, CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta));
|
||||
|
||||
pdf2 = GeneraPDFNomina(dr["CvePersonal"].ToString().ToEntero(), CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
|
||||
byte[] newByteArray2 = pdf.Concat(pdf2).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
pdf = GeneraPDFNomina(dr["CvePersonal"].ToString().ToEntero(), CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
|
||||
}
|
||||
notfirst = true;
|
||||
//if (notfirst)
|
||||
//{
|
||||
|
||||
// pdf2 = GeneraPDFNomina(dr["CvePersonal"].ToString().ToEntero(), CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
|
||||
// byte[] newByteArray2 = pdf.Concat(pdf2).ToArray();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// pdf = GeneraPDFNomina(dr["CvePersonal"].ToString().ToEntero(), CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
|
||||
|
||||
//}
|
||||
//notfirst = true;
|
||||
}
|
||||
pdf = MergeFiles(pdfs);
|
||||
}
|
||||
ImprimirbytesPDF(pdf, nombre);
|
||||
|
||||
}
|
||||
public static byte[] MergeFiles(List<byte[]> sourceFiles)
|
||||
{
|
||||
string destinationFile;
|
||||
try
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
int f = 0;
|
||||
// we create a reader for a certain document
|
||||
PdfReader reader = new PdfReader(sourceFiles[f]);
|
||||
// we retrieve the total number of pages
|
||||
int n = reader.NumberOfPages;
|
||||
//Console.WriteLine("There are " + n + " pages in the original file.");
|
||||
// step 1: creation of a document-object
|
||||
iTextSharp.text.Document document = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
|
||||
// step 2: we create a writer that listens to the document
|
||||
//PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));
|
||||
PdfWriter writer = PdfWriter.GetInstance(document, ms);
|
||||
// step 3: we open the document
|
||||
document.Open();
|
||||
PdfContentByte cb = writer.DirectContent;
|
||||
PdfImportedPage page;
|
||||
int rotation;
|
||||
// step 4: we add content
|
||||
while (f < sourceFiles.Count)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
i++;
|
||||
document.SetPageSize(reader.GetPageSizeWithRotation(i));
|
||||
document.NewPage();
|
||||
page = writer.GetImportedPage(reader, i);
|
||||
rotation = reader.GetPageRotation(i);
|
||||
if (rotation == 90 || rotation == 270)
|
||||
{
|
||||
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
|
||||
}
|
||||
//Console.WriteLine("Processed page " + i);
|
||||
}
|
||||
f++;
|
||||
if (f < sourceFiles.Count)
|
||||
{
|
||||
reader = new PdfReader(sourceFiles[f]);
|
||||
// we retrieve the total number of pages
|
||||
n = reader.NumberOfPages;
|
||||
//Console.WriteLine("There are " + n + " pages in the original file.");
|
||||
}
|
||||
}
|
||||
// step 5: we close the document
|
||||
document.Close();
|
||||
return ms.ToArray();
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string strOb = e.Message;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int CountPageNo(string strFileName)
|
||||
{
|
||||
// we create a reader for a certain document
|
||||
PdfReader reader = new PdfReader(strFileName);
|
||||
// we retrieve the total number of pages
|
||||
return reader.NumberOfPages;
|
||||
}
|
||||
|
||||
|
||||
protected void BtnGenerateXml_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -4977,4 +5166,10 @@ public partial class Nomina_Nomina2 : ClsPaginas
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void LnkRegistrarProvision_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user