CRUD completo de la tabla Exp_ExportacionesDescargas

This commit is contained in:
SLopez
2025-07-15 15:58:41 -07:00
parent 5eb958fafb
commit a6bfb26cb2
3 changed files with 406 additions and 12 deletions

View File

@@ -35,6 +35,7 @@ Public Class ClsExportaciones
Public Property CveExportacion As Integer
Public Property CveExportacionDetalle As Integer
Public Property CveExportacionDescarga As Integer
#End Region
@@ -419,6 +420,81 @@ Public Class ClsExportaciones
End Function
#End Region
#Region "DESCARGAS"
Public Function GetDescargas(CveEmpresa As Integer, Optional CveExportacion As Integer = -1, Optional CveExportacionDescarga As Integer = -1, Optional CveExportacionDetalle As Integer = -1, Optional CveImportacionDetalle As Integer = -1) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_Exp_ExportacionesDescargaGet")
With SqlAdapter.SelectCommand.Parameters
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
.Add("@CveExportacion", SqlDbType.Int).Value = CveExportacion
.Add("@CveExportacionDescarga", SqlDbType.Int).Value = CveExportacionDescarga
.Add("@CveExportacionDetalle", SqlDbType.Int).Value = CveExportacionDetalle
.Add("@CveImportacionDetalle", SqlDbType.Int).Value = CveImportacionDetalle
End With
Try
SqlAdapter.Fill(Data)
Retorno = True
Catch ex As Exception
OnError("Ocurrió un error al obtener las Descargas.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())
End Try
Return Retorno
End Function
Public Function AddDescarga(CveExportacionDetalle As Integer, CveImportacionDetalle As Integer, Cantidad As Decimal, CveEmpresa As Integer) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_Exp_ExportacionesDescargaAdd")
With SqlAdapter.SelectCommand.Parameters
.Add("@CveExportacionDetalle", SqlDbType.Int).Value = CveExportacionDetalle
.Add("@CveImportacionDetalle", SqlDbType.Int).Value = CveImportacionDetalle
.Add("@Cantidad", SqlDbType.Decimal).Value = Cantidad
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
.Add("@CveExportacionDescarga", SqlDbType.Int).Direction = ParameterDirection.Output
End With
Try
SqlAdapter.Fill(Data)
CveExportacionDescarga = SqlAdapter.SelectCommand.Parameters("@CveExportacionDescarga").Value.ToString.ToEntero
Retorno = True
Catch ex As Exception
OnError("Ocurrió un error al guardar la Descarga.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())
End Try
Return Retorno
End Function
Public Function UpdateDescarga(CveExportacionDescarga As Integer, CveExportacionDetalle As Integer, CveImportacionDetalle As Integer, Cantidad As Decimal) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_Exp_ExportacionesDescargaUpdate")
With SqlAdapter.SelectCommand.Parameters
.Add("@CveExportacionDescarga", SqlDbType.Int).Value = CveExportacionDescarga
.Add("@CveExportacionDetalle", SqlDbType.Int).Value = CveExportacionDetalle
.Add("@CveImportacionDetalle", SqlDbType.Int).Value = CveImportacionDetalle
.Add("@Cantidad", SqlDbType.Decimal).Value = Cantidad
End With
Try
SqlAdapter.Fill(Data)
Retorno = True
Catch ex As Exception
OnError("Ocurrió un error al actualizar la Descarga.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())
End Try
Return Retorno
End Function
Public Function RemoveDescarga(CveExportacionDescarga As Integer) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_Exp_ExportacionesDescargaRemove")
With SqlAdapter.SelectCommand.Parameters
.Add("@CveExportacionDescarga", SqlDbType.Int).Value = CveExportacionDescarga
End With
Try
SqlAdapter.Fill(Data)
Retorno = True
Catch ex As Exception
OnError("Ocurrió un error al eliminar la Descarga.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
End Try
Return Retorno
End Function
#End Region
#Region "AGENTES"
Public Function GetAgentes(Optional CveAgente As Integer = -1, Optional CveEmpresa As Integer = -1) As Boolean
Dim Retorno As Boolean = False

View File

@@ -744,6 +744,54 @@
</asp:UpdatePanel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="TabDescargas" runat="server" HeaderText="Descargas">
<ContentTemplate>
<asp:UpdatePanel ID="UpDescargas" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button runat="server" ID="BtnAgregarDescarga" OnClick="BtnAgregarDescarga_Click" Text="Agregar Descarga" CssClass="btn btn-primary" style="margin-top: 5px;" />
<br />
<br />
<div style="overflow-x: auto; width: 1235px;">
<asp:GridView ID="GVDescargas" runat="server" data-sort="true" AutoGenerateColumns="False" DataKeyNames="CveExportacionDescarga" OnRowCommand="GVDescargas_RowCommand" ShowFooter="true" OnRowDataBound="GVDescargas_RowDataBound" Width="100%" EmptyDataText="No se encontraron Descargas" ToolTip="Descargas" CssClass="table table-striped table-advance table-hover Widthall ScrollAD mysmallbtn" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Descarga" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDescarga" runat="server" Text='<%# Eval("CveExportacionDescarga")%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Partida Exportación" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDescargaExp" runat="server" Text='<%# Eval("PSCodigoExp")%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Partida Importación" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDescargaImp" runat="server" Text='<%# Eval("PSCodigoImp")%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cantidad" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblDescargaCant" runat="server" Text='<%# Eval("Cantidad")%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Editar" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton data-toggle="tooltip" title="Editar" ID="LnkEditarDescarga" CommandName="EditarDescarga" CommandArgument='<%# Eval("CveExportacionDescarga") %>' CssClass="btn btn-circle btn-sm green" runat="server" Text="<i class='fa fa-pencil'></i>"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Eliminar" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton ID="LnkEliminarDescarga" runat="server" CommandName="EliminarDescarga" CommandArgument='<%# Eval("CveExportacionDescarga") %>' CssClass="btn btn-circle btn-sm red" Text="<i class='icon-trash'></i>" data-toggle="confirmation" data-popout="true" data-original-title="¿Está seguro que desea eliminar la Descarga?" data-btn-ok-label="Sí" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajax:TabPanel>
</ajax:TabContainer>
<br />
@@ -877,6 +925,90 @@
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="DModalDescarga" class="modal ADS fade" role="dialog">
<asp:UpdatePanel ID="UpDescarga" class="modal-dialog" tabindex="-1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="H2" runat="server">Agregar Descarga</h4>
</div>
<div id="DVBodyAddDescarga" style="overflow: auto!important">
<div class="modal-body">
<asp:UpdatePanel ID="UpBodyAddDescarga" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div class="row">
<div class="col-md-6">
<asp:UpdatePanel ID="UpDExportacion" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<div class="form-group form-md-line-input input-iconright">
<asp:DropDownList ID="DdlPartidaExp" runat="server" CssClass=" form-control input-sm select2me" AppendDataBoundItems="true" DataTextField="PSCodigo" DataValueField="CveExportacionDetalle" Width="100%" ValidationGroup="GrpAgregaDescarga"></asp:DropDownList></td>
<label for="<%= DdlPartidaExp.ClientID.ToString()%>">Partida Exportación:</label>
<asp:RequiredFieldValidator ID="RFVPartidaExp" runat="server" ControlToValidate="DdlPartidaExp" Display="None" InitialValue="-1" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Partida Exportación''</b> es necesario, por favor ingréselo." ValidationGroup="GrpAgregaDescarga"></asp:RequiredFieldValidator>
<ajax:ValidatorCalloutExtender ID="VCEPartidaExp" runat="server" HighlightCssClass="vco" TargetControlID="RFVPartidaExp" Width="350px"></ajax:ValidatorCalloutExtender>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<br />
<div class="row">
<div class="col-md-6">
<asp:UpdatePanel ID="UpDImportacion" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<div class="form-group form-md-line-input input-iconright">
<asp:DropDownList ID="DdlPartidaImp" runat="server" CssClass=" form-control input-sm select2me" AppendDataBoundItems="true" DataTextField="PSCodigo" DataValueField="CveExportacionDetalle" Width="100%" ValidationGroup="GrpAgregaDescarga"></asp:DropDownList></td>
<label for="<%= DdlPartidaImp.ClientID.ToString()%>">Partida Importación:</label>
<asp:RequiredFieldValidator ID="RFVPartidaImp" runat="server" ControlToValidate="DdlPartidaImp" Display="None" InitialValue="-1" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Partida Importación''</b> es necesario, por favor ingréselo." ValidationGroup="GrpAgregaDescarga"></asp:RequiredFieldValidator>
<ajax:ValidatorCalloutExtender ID="VCEPartidaImp" runat="server" HighlightCssClass="vco" TargetControlID="RFVPartidaImp" Width="350px"></ajax:ValidatorCalloutExtender>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<br />
<div class="row">
<div class="col-md-4">
<div class="form-group form-md-line-input input-iconright">
<asp:TextBox ID="TxtDCantidad" ClientIDMode="Static" runat="server" CssClass=" form-control " CausesValidation="true" MaxLength="12" ValidationGroup="GrpAgregaDescarga"></asp:TextBox>
<ajax:FilteredTextBoxExtender ID="FTEDCantidad" runat="server" TargetControlID="TxtDCantidad" FilterType="Custom, Numbers" ValidChars="." />
<label for="<%= TxtDCantidad.ClientID.ToString()%>">Cantidad:</label>
</div>
</div>
</div>
<br />
<div class="row">
<div class="col-md-12">
<div class="form-group form-md-line-input input-iconright" align="right" id="DivAgregarOtraDescarga" runat="server">
<label>Continuar agregando:</label>
<asp:CheckBox ID="ChkSeguirAgregandoDescargas" runat="server" Checked="true" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<div class="modal-footer">
<asp:UpdatePanel ID="UpAddDescargaBotones" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="row">
<div class="col-md-12">
<asp:Button ID="BtnDescargaGuardar" OnClick="BtnDescargaGuardar_Click" runat="server" Text="Agregar" CssClass="btn btn-primary" ValidationGroup="GrpAgregaDescarga" />
<asp:Button ID="BtnDescargaActualizar" OnClick="BtnDescargaGuardar_Click" runat="server" Text="Actualizar" CssClass="btn btn-primary" ValidationGroup="GrpAgregaDescarga" />
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
<asp:Content ID="Content8" ContentPlaceHolderID="JS" Runat="Server">
<script type="text/javascript">

View File

@@ -35,6 +35,11 @@ public partial class Export_ExpDetalle : ClsPaginas
get { return (ViewState["CveExportacionDetalle"] == null) ? -1 : Convert.ToInt32(ViewState["CveExportacionDetalle"]); }
set { ViewState["CveExportacionDetalle"] = value; }
}
private int CveExportacionDescarga
{
get { return (ViewState["CveExportacionDescarga"] == null) ? -1 : Convert.ToInt32(ViewState["CveExportacionDescarga"]); }
set { ViewState["CveExportacionDescarga"] = value; }
}
private bool EsImportacion
{
@@ -228,6 +233,7 @@ public partial class Export_ExpDetalle : ClsPaginas
DdlDirCon.SelectedValue = DTExportaciones.FiltroPrimeroValor("CveDirConsignatario");
CargarPartidas();
CargarDescargas();
}
}
Exportaciones.Dispose();
@@ -744,6 +750,7 @@ public partial class Export_ExpDetalle : ClsPaginas
if (Continuar)
{
Alert("La Partida se ha eliminado correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
CargarDescargas();
}
}
else
@@ -996,6 +1003,7 @@ public partial class Export_ExpDetalle : ClsPaginas
{
//RegistraScript("$('#DModalPartida').modal('hide');");
Alert("La Partida se ha actualizado correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
CargarDescargas();
}
}
if (ChkSeguirAgregandoPartidas.Checked == false)
@@ -1015,6 +1023,196 @@ public partial class Export_ExpDetalle : ClsPaginas
}
CargarPartidas();
}
protected void CargarDescargas()
{
DataTable DTDescargas = new DataTable();
ClsExportaciones Descargas = new ClsExportaciones();
if (CveExportacion != -1)
{
if (Descargas.GetDescargas(UsuarioActual.CveEmpresa, CveExportacion))
{
DTDescargas = Descargas.DtResultados;
if (DTDescargas.Rows.Count > 0)
{
GVDescargas.DataSource = DTDescargas;
GVDescargas.DataBind();
UpDescargas.Update();
}
}
}
Descargas.Dispose();
}
protected void AbrirModalDescarga()
{
RegistraScript("$('#DModalDescarga').modal();");
int CveEmpresa = UsuarioActual.CveEmpresa;
DdlPartidaExp.Items.Clear();
DdlPartidaImp.Items.Clear();
ClsExportaciones Partidas = new ClsExportaciones();
if (Partidas.GetPartidas(UsuarioActual.CveEmpresa, CveExportacion))
{
DdlPartidaExp.DataSource = Partidas.DtResultados;
DdlPartidaImp.DataSource = Partidas.DtResultados;
}
Partidas.Dispose();
DdlPartidaExp.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlPartidaExp.DataBind();
DdlPartidaImp.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlPartidaImp.DataBind();
if (CveExportacionDescarga != -1)
{
ChkSeguirAgregandoDescargas.Checked = false;
DivAgregarOtraDescarga.Visible = false;
BtnDescargaGuardar.Visible = false;
BtnDescargaActualizar.Visible = true;
ClsExportaciones Descargas = new ClsExportaciones();
if (Descargas.GetDescargas(CveEmpresa, CveExportacion, CveExportacionDescarga))
{
DataTable DTDescargas = Descargas.DtResultados;
if (DTDescargas.Rows.Count > 0)
{
string CveExpDetalle = DTDescargas.FiltroPrimeroValor("CveExportacionDetalle");
DdlPartidaExp.SelectedValue = CveExpDetalle;
string CveImpDetalle = DTDescargas.FiltroPrimeroValor("CveImportacionDetalle");
DdlPartidaImp.SelectedValue = CveImpDetalle;
TxtDCantidad.Text = DTDescargas.FiltroPrimeroValor("Cantidad");
}
}
Partidas.Dispose();
}
else
{
ChkSeguirAgregandoDescargas.Checked = true;
DivAgregarOtraDescarga.Visible = true;
BtnDescargaGuardar.Visible = true;
BtnDescargaActualizar.Visible = false;
TxtDCantidad.Text = "";
}
UpDescarga.Update();
}
protected void BtnAgregarDescarga_Click(object sender, EventArgs e)
{
if (CveExportacion != -1)
{
ClsExportaciones Partidas = new ClsExportaciones();
if (Partidas.GetPartidas(UsuarioActual.CveEmpresa, CveExportacion))
{
if (Partidas.DtResultados.Rows.Count > 0)
{
CveExportacionDescarga = -1;
AbrirModalDescarga();
}
else
{
Alert("Agregue Partidas para poder añadir una Descarga.", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
Partidas.Dispose();
}
else
{
Alert("Guarde los cambios para poder agregar una Descarga.", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
protected void BtnDescargaGuardar_Click(object sender, EventArgs e)
{
int CveExpDetalle = DdlPartidaExp.Text.ToEntero();
int CveImpDetalle = DdlPartidaImp.Text.ToEntero();
decimal Cantidad = ModExtensiones.ToDecimal(TxtDCantidad.Text);
int CveUsuario = UsuarioActual.CveUsuario;
ClsExportaciones Descargas = new ClsExportaciones();
if (CveExportacionDescarga == -1)
{
if (CveExportacion != -1)
{
bool Continuar = Descargas.AddDescarga(CveExpDetalle, CveImpDetalle, Cantidad, UsuarioActual.CveEmpresa);
Descargas.Dispose();
if (Continuar)
{
Alert("La Descarga se ha agregado correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
}
}
}
else
{
bool Continuar = Descargas.UpdateDescarga(CveExportacionDescarga, CveExpDetalle, CveImpDetalle, Cantidad);
Descargas.Dispose();
if (Continuar)
{
Alert("La Descarga se ha actualizado correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
}
}
if (ChkSeguirAgregandoDescargas.Checked == false)
{
RegistraScript("$('#DModalDescarga').modal('hide');");
}
else
{
DdlPartidaExp.SelectedValue = "-1";
DdlPartidaImp.SelectedValue = "-1";
TxtDCantidad.Text = "";
UpDescarga.Update();
}
CargarDescargas();
}
protected void GVDescargas_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer && GVDescargas.Rows.Count > 0)
{
decimal TotalCantidad = 0;
foreach (GridViewRow row in GVDescargas.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
Label lblDescargaCant = (Label)row.FindControl("lblDescargaCant");
if (lblDescargaCant != null && lblDescargaCant.Text != "")
TotalCantidad += Convert.ToDecimal(lblDescargaCant.Text.Replace(",", "").Trim());
}
}
e.Row.Cells[0].Text = "Total:";
e.Row.Cells[3].Text = TotalCantidad.ToString("#,###.####");
e.Row.Font.Bold = true;
e.Row.BackColor = System.Drawing.Color.LightGray;
}
}
protected void GVDescargas_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditarDescarga")
{
CveExportacionDescarga = -1;
if (CveExportacion != -1)
{
CveExportacionDescarga = e.CommandArgument.ToEntero();
}
AbrirModalDescarga();
}
if (e.CommandName == "EliminarDescarga")
{
if (CveExportacion != -1)
{
ClsExportaciones Descargas = new ClsExportaciones();
bool Continuar = Descargas.RemoveDescarga(e.CommandArgument.ToEntero());
Descargas.Dispose();
if (Continuar)
{
Alert("La Descarga se ha eliminado correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
}
}
CargarDescargas();
}
}
protected void DdlPS_SelectedIndexChanged(object sender, EventArgs e)
{
CargarUnidadMedida(DdlPS.Text, DdlUM.Text, DdlTipoEmpaque.Text);
@@ -1296,18 +1494,6 @@ public partial class Export_ExpDetalle : ClsPaginas
}
protected void LBImprimir_Click(object sender, EventArgs e)
{
/*if (DtDatos != null)
{
ImprimirReporte();
}
else
{
CargaDatos();
if (DtDatos != null)
Alert("No se encontró información para el reporte.", ModExtensiones.TipoMensaje.MsgAdvertencia);
else
ImprimirReporte();
}*/
ImprimirReporte();
}