286 lines
9.2 KiB
C#
286 lines
9.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
using Extensiones;
|
|
using Microsoft.Reporting.WebForms;
|
|
using static Extensiones.ModExtensiones;
|
|
using iTextSharp;
|
|
using iTextSharp.text;
|
|
using iTextSharp.text.pdf;
|
|
using System.IO;
|
|
using Ionic.Zip;
|
|
public partial class OC_RepSolicitudesAnticipo : ClsPaginas
|
|
{
|
|
#region "Propiedades"
|
|
private int CveProveedor
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveProveedor"].ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveProveedor"] = value;
|
|
}
|
|
}
|
|
private DateTime FechaI
|
|
{
|
|
get
|
|
{
|
|
return ViewState["FechaI"].ToDateTime();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["FechaI"] = value;
|
|
}
|
|
}
|
|
private DateTime FechaF
|
|
{
|
|
get
|
|
{
|
|
return ViewState["FechaF"].ToDateTime();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["FechaF"] = value;
|
|
}
|
|
}
|
|
private DataTable DtDatos
|
|
{
|
|
get { return DtDatos = (DataTable)ViewState["DtDatos"]; }
|
|
set { ViewState["DtDatos"] = value; }
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InicializaDatos();
|
|
}
|
|
}
|
|
|
|
protected void InicializaDatos()
|
|
{
|
|
txtFechaI.Text = DateTime.Now.AddMonths(-1).FirstDayOfMonth().ToShortDateString();
|
|
txtFechaF.Text = DateTime.Now.ToShortDateString();
|
|
CveProveedor = -1;
|
|
CargaSubProyectos();
|
|
CargaProveedor();
|
|
CargaUsuarios();
|
|
CargaDatos();
|
|
}
|
|
|
|
private void CargaSubProyectos()
|
|
{
|
|
CargarCentrosDeCosto(null,DdlSubProyecto,null,lblSubProyecto);
|
|
}
|
|
|
|
private void CargaUsuarios()
|
|
{
|
|
DdlUsuarios.DataSource = get_GlobalDTUsuarios(CveEmpresa:UsuarioActual.CveEmpresa);
|
|
DdlUsuarios.DataBind();
|
|
}
|
|
|
|
protected void CargaProveedor()
|
|
{
|
|
DdlProveedores.setEsWebService(true);
|
|
DdlProveedores.Attributes.Add("data-metodo", "getproveedores");
|
|
DdlProveedores.SelectedText = "Todos";
|
|
DdlProveedores.SelectedValue = "-1";
|
|
}
|
|
|
|
protected void CargaDatos()
|
|
{
|
|
ClsOC ObjOC = new ClsOC();
|
|
|
|
CveProveedor = DdlProveedores.SelectedValue.ToEntero();
|
|
FechaI = (txtFechaI.Text.ToString() != "" ? txtFechaI.Text.ToDateTime() : MinFecha);
|
|
FechaF = (txtFechaF.Text.ToString() != "" ? txtFechaF.Text.ToDateTime() : DateTime.Now);
|
|
|
|
if (ObjOC.GetRepSolicitudAnticipos(UsuarioActual.CveEmpresa, CveProveedor, FechaI, FechaF, DdlEstatus.SelectedValue.ToEntero(),DdlUsuarios.SelectedValue.ToEntero(),DdlSubProyecto.SelectedValue.ToEntero()))
|
|
{
|
|
DtDatos = ObjOC.DtResultados;
|
|
GvSolicitudes.DataSource = DtDatos;
|
|
}
|
|
|
|
ObjOC.Dispose();
|
|
GvSolicitudes.DataBind();
|
|
UPDatos.Update();
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
if (DdlEstatus.SelectedValue.ToEntero() == 3)
|
|
{
|
|
GvSolicitudes.Columns[6].Visible = false;
|
|
GvSolicitudes.Columns[10].Visible = false;
|
|
|
|
GvSolicitudes.Columns[7].Visible = true;
|
|
GvSolicitudes.Columns[8].Visible = true;
|
|
|
|
}
|
|
else
|
|
{
|
|
GvSolicitudes.Columns[6].Visible = true;
|
|
GvSolicitudes.Columns[10].Visible = true;
|
|
|
|
GvSolicitudes.Columns[7].Visible = false;
|
|
GvSolicitudes.Columns[8].Visible = false;
|
|
|
|
}
|
|
CargaDatos();
|
|
}
|
|
|
|
protected void LnkExcel_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("EXCEL");
|
|
}
|
|
|
|
protected void LnkPdf_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("PDF");
|
|
}
|
|
protected void LnkImpresionMasiva_Click(object sender,EventArgs e)
|
|
{
|
|
GenerarImpresionMasiva();
|
|
}
|
|
protected void LnkCambiarFecha_Click(object sender, EventArgs e)
|
|
{
|
|
GvSolicitudes.Columns[0].Visible = true;
|
|
LnkGuardar.Visible = true;
|
|
LnkCambiarFecha.Visible = false;
|
|
|
|
UPAcciones.Update();
|
|
UPDatos.Update();
|
|
}
|
|
protected void BtnGuardarArchivo_Click(object sender, EventArgs e)
|
|
{
|
|
ActualizarFechas();
|
|
RegistraScript("$('#ModalUpload').modal('hide')", "hidemodal1");
|
|
GvSolicitudes.Columns[0].Visible = false;
|
|
LnkGuardar.Visible = false;
|
|
LnkCambiarFecha.Visible = true;
|
|
UPAcciones.Update();
|
|
UPDatos.Update();
|
|
}
|
|
private void ActualizarFechas()
|
|
{
|
|
ClsOIEventos ObjEvento = new ClsOIEventos();
|
|
DateTime FechaInicio;
|
|
DateTime FechaFin;
|
|
int CveEvento;
|
|
Boolean TieneError = true;
|
|
|
|
foreach (GridViewRow Gvr in GvSolicitudes.Rows)
|
|
{
|
|
if (Gvr.FCCheckBox("ChkOrdenCompra").Checked)
|
|
{
|
|
FechaInicio = txtFechaActualizar.Text.ToDateTime();
|
|
FechaFin = txtFechaActualizar.Text.ToDateTime();
|
|
CveEvento = Gvr.DataKey("CveEvento").ToEntero();
|
|
if (ObjEvento.UpdateEvento("-1", "-1", -1, -1, -1, FechaInicio, FechaFin, -1, "-1", CveEvento))
|
|
{
|
|
TieneError = false;
|
|
}
|
|
else
|
|
{
|
|
TieneError = true;
|
|
Alert("Ocurrio un error al actulizar las fechas", TipoMensaje.MsgError);
|
|
ObjEvento.RollBack();
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
if (TieneError == false) {
|
|
ObjEvento.Commit();
|
|
Alert("Las Fechas se actualizaron correctamente");
|
|
}
|
|
ObjEvento.Dispose();
|
|
CargaDatos();
|
|
}
|
|
|
|
protected void GenerarPDF(String Opcion)
|
|
{
|
|
String FechaI;
|
|
if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = ""; } else { FechaI = $" <b>Fecha Inicial:</b> {txtFechaI.Text}"; }
|
|
String FechaF;
|
|
if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = ""; } else { FechaF = $" <b>Fecha Final:</b> {txtFechaF.Text}"; }
|
|
String Proveedor;
|
|
if (DdlProveedores.SelectedValue != "-1") { Proveedor = $" <b>Proveedor:</b> {DdlProveedores.SelectedText}"; } else { Proveedor = ""; }
|
|
String Estatus;
|
|
if (DdlEstatus.SelectedValue != "1") { Estatus = $" <b>Estatus:</b> {DdlEstatus.SelectedItem.Text}"; } else { Estatus = ""; }
|
|
String Usuario;
|
|
if (DdlUsuarios.SelectedValue != "-1") { Usuario = $" <b>Usuario:</b> {DdlUsuarios.SelectedItem.Text}"; } else { Usuario = ""; }
|
|
String SubProyectos;
|
|
if (DdlSubProyecto.SelectedValue != "-1") { SubProyectos = $" <b>{lblSubProyecto.Text}:</b> {DdlSubProyecto.SelectedItem.Text}"; } else { SubProyectos = ""; }
|
|
|
|
if (DtDatos.Rows.Count > 0)
|
|
{
|
|
System.IO.FileInfo Imagen = new System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
|
|
String logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
List<ReportParameter> para = new List<ReportParameter>();
|
|
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
para.Add(new ReportParameter("Estatus", DdlEstatus.SelectedValue));
|
|
String Agrupadores = $"{Proveedor}{FechaI}{FechaF}{Estatus}{Usuario}{SubProyectos}";
|
|
para.Add(new ReportParameter("AgrupadoPor", (Agrupadores == "" ? "": $" {Agrupadores}")));
|
|
if (Imagen.Exists)
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", logouri));
|
|
}
|
|
else
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", ""));
|
|
}
|
|
ImprimirPDF("Empresas/Grales/Formatos/RepSolicitudAnticipo.rdlc", DtDatos, para, "Reporte de Solicitudes de Anticipos", Opcion);
|
|
}
|
|
else
|
|
{
|
|
Alert("No hay datos consultados", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
private void GenerarImpresionMasiva()
|
|
{
|
|
|
|
byte[] all;
|
|
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
using (Document d = new Document())
|
|
{
|
|
using (PdfCopy copy = new PdfCopy(d,ms))
|
|
{
|
|
d.Open();
|
|
foreach (GridViewRow Gvr in GvSolicitudes.Rows)
|
|
{
|
|
int CveOC = Gvr.DataKey("CveOrdenCompra").ToEntero();
|
|
byte[] reporteByte = NewGeneraBytesOC(CveOC);
|
|
PdfReader reader = new PdfReader(reporteByte);
|
|
int n = reader.NumberOfPages;
|
|
int page = 0;
|
|
while (page < n)
|
|
{
|
|
page++;
|
|
copy.AddPage(copy.GetImportedPage(reader, page));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
all = ms.ToArray();
|
|
}
|
|
ImprimirbytesPDF(all, "RepSolicitudesAnticipo");
|
|
|
|
}
|
|
} |