Files
SIG/Export/RepExportaciones.aspx.cs
2025-07-08 17:02:23 -06:00

201 lines
7.6 KiB
C#

using DocumentFormat.OpenXml.Wordprocessing;
using Extensiones;
using HigLabo.Core;
using iText.Layout.Element;
using StackExchange.Redis;
using System;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Statements;
using System.Collections.Generic;
using System.EnterpriseServices.Internal;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using static Stimulsoft.Report.Export.DeflaterHuffman;
public partial class Export_RepExportaciones : ClsPaginas
{
#region Propiedades
private int CveExportacion
{
get { return (ViewState["CveExportacion"] == null) ? -1 : Convert.ToInt32(ViewState["CveExportacion"]); }
set { ViewState["CveExportacion"] = value; }
}
private bool EsImportacion
{
get { return (ViewState["EsImportacion"] == null) ? false : Boolean.Parse(ViewState["EsImportacion"].ToString()); }
set { ViewState["EsImportacion"] = value; }
}
public string EmptyDataTextPersonalizado { get; set; }
public string ToolTipPersonalizado { get; set; }
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
EsImportacion = false;
if (Request["Opcion"] != null)
{
if (Request["Opcion"] == "I")
EsImportacion = true;
}
Page.Title = EsImportacion ? "Importaciones" : "Exportaciones";
// Ahora sí, usa la bandera para los textos
if (EsImportacion)
{
LtlTitulo.Text = "Importaciones";
EmptyDataTextPersonalizado = "No se encontraron importaciones";
ToolTipPersonalizado = "Importaciones";
HLAgregarExp.Text = "<i class='fa fa-plus'></i> Agregar Importación";
HLAgregarExp.NavigateUrl = "ExpDetalle.aspx?CveExportacion=-1&Opcion=I";
}
else
{
LtlTitulo.Text = "Exportaciones";
EmptyDataTextPersonalizado = "No se encontraron exportaciones";
ToolTipPersonalizado = "Exportaciones";
HLAgregarExp.Text = "<i class='fa fa-plus'></i> Agregar Exportación";
HLAgregarExp.NavigateUrl = "ExpDetalle.aspx?CveExportacion=-1";
}
GVExportaciones.EmptyDataText = EmptyDataTextPersonalizado;
GVExportaciones.ToolTip = ToolTipPersonalizado;
InicializarValores();
//CargaExportaciones();
}
}
protected void InicializarValores()
{
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto: DivProyecto);
DdlProyecto.Visible = false;
LblProyecto.Visible = false;
DivProyecto.Visible = false;
LblSubProyecto.Text = $"{LblSubProyecto.Text}:";
txtFechaI.Text = NowADS().FirstDayOfMonth().ToShortDateString();
txtFechaF.Text = NowADS().ToShortDateString();
CargaExportaciones();
}
protected void CargaExportaciones()
{
bool EsExportacion = !EsImportacion;
string SubProyectos = DdlSubProyecto.GetSelectedValuesM();
SubProyectos = SubProyectos == "" ? "-1" : SubProyectos;
DateTime FechaInicio = DateTime.TryParse(txtFechaI.Text, out _) ? txtFechaI.Text.ToDate() : ModExtensiones.MinFecha;
DateTime FechaFin = DateTime.TryParse(txtFechaF.Text, out _) ? txtFechaF.Text.ToDate() : ModExtensiones.MaxFecha;
ClsExportaciones Exportaciones = new ClsExportaciones();
if (Exportaciones.GetExportacion(-1, UsuarioActual.CveEmpresa, EsExportacion, FechaInicio, FechaFin, SubProyectos))
{
GVExportaciones.DataSource = Exportaciones.DtResultados;
GVExportaciones.DataBind();
}
Exportaciones.Dispose();
upDatosExp.Update();
}
protected void EditarExp_Click(object sender, EventArgs e)
{
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
Response.Redirect($"/Export/ExpDetalle.aspx?CveExportacion={gvRow.DataKey("CveExportacion")}", true);
upDatosExp.Update();
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
CargaExportaciones();
upDatosExp.Update();
}
protected void EliminarExp_Click(object sender, EventArgs e)
{
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
ClsExportaciones Exportaciones = new ClsExportaciones();
bool Continuar = Exportaciones.RemoveExportacion(gvRow.DataKey("CveExportacion").ToEntero());
Exportaciones.Dispose();
if (Continuar)
{
CargaExportaciones();
Alert("La Exportación se ha eliminado correctamente.");
}
}
protected void GVExportaciones_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var dataItem = (System.Data.DataRowView)e.Row.DataItem;
int cveExportacion = Convert.ToInt32(dataItem["CveExportacion"]);
HyperLink hl = (HyperLink)e.Row.FindControl("HlExpDetalle");
// Usa la bandera EsImportacion de la página
if (EsImportacion)
hl.NavigateUrl = $"ExpDetalle.aspx?CveExportacion={cveExportacion}&Opcion=I";
else
hl.NavigateUrl = $"ExpDetalle.aspx?CveExportacion={cveExportacion}";
// EDITAR
HyperLink hlEditar = (HyperLink)e.Row.FindControl("HlEditar");
if (EsImportacion)
hlEditar.NavigateUrl = $"ExpDetalle.aspx?CveExportacion={cveExportacion}&Opcion=I";
else
hlEditar.NavigateUrl = $"ExpDetalle.aspx?CveExportacion={cveExportacion}";
// Tipo Exportación
Label lblTipoExp = (Label)e.Row.FindControl("lblTipoExp");
if (lblTipoExp != null)
{
string valor = dataItem["TipoExportacion"].ToString();
switch (valor)
{
case "1":
lblTipoExp.Text = "(IMP) Importación";
break;
case "2":
lblTipoExp.Text = "(EXP) Exportación/retorno";
break;
case "3":
lblTipoExp.Text = "(TRA) Tránsitos";
break;
default:
lblTipoExp.Text = "Desconocido";
break;
}
}
// Estatus
Label lblEstatus = (Label)e.Row.FindControl("lblEstatus");
if (lblEstatus != null)
{
string valor = dataItem["CveExportacionEstatus"].ToString();
switch (valor)
{
case "1":
lblEstatus.Text = "Tránsito";
break;
case "2":
lblEstatus.Text = "Completa";
break;
default:
lblEstatus.Text = "Desconocido";
break;
}
}
}
}
protected void GVExportaciones_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// Cambia el texto del primer encabezado (ajusta el índice si no es la primera columna)
e.Row.Cells[0].Text = EsImportacion ? "Importación" : "Exportación";
}
}
}