Files
SIG/Inventarios/EntregaAlmacenRuta.aspx.cs
2022-07-14 12:01:52 -07:00

1055 lines
37 KiB
C#

using Extensiones;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
public partial class Inventarios_EntregaAlmacenRuta : ClsPaginas
{
DataTable DTGenerarDocumentos
{
get
{
if (ViewState["DTGenerarDocumentos"] == null)
{
ViewState["DTGenerarDocumentos"] = new DataTable();
}
return (DataTable)ViewState["DTGenerarDocumentos"];
}
set
{
ViewState["DTGenerarDocumentos"] = (DataTable)value;
}
}
DataTable DTDatosConsulta
{
get
{
if (ViewState["DTDatosConsulta"] == null)
{
ViewState["DTDatosConsulta"] = new DataTable();
}
return (DataTable)ViewState["DTDatosConsulta"];
}
set
{
ViewState["DTDatosConsulta"] = (DataTable)value;
}
}
DataTable DTRecoleccion
{
get
{
if (ViewState["DTRecoleccion"] == null)
{
ViewState["DTRecoleccion"] = InitDTRecoleccion();
}
return (DataTable)ViewState["DTRecoleccion"];
}
set
{
ViewState["DTRecoleccion"] = (DataTable)value;
}
}
bool SeleccionEntrega
{
get
{
if (ViewState["SeleccionEntrega"] == null)
{
ViewState["SeleccionEntrega"] = false;
}
return (bool)ViewState["SeleccionEntrega"];
}
set
{
ViewState["SeleccionEntrega"] = (bool)value;
}
}
int CveEntregaAlmacen
{
get
{
if (ViewState["CveEntregaAlmacen"] == null)
{
ViewState["CveEntregaAlmacen"] = -1;
}
return (int)ViewState["CveEntregaAlmacen"];
}
set
{
ViewState["CveEntregaAlmacen"] = (int)value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SeleccionEntrega = true;
CargaCombos();
CargaDatos();
#region RECOLEECION
// CargaDatosRecoleccion();
#endregion
}
}
protected void BtnAsignar_Click(object sender, EventArgs e)
{
if (DdlChofer.SelectedValue.ToEntero() <= 0)
{
Alert("Debe seleccionar un chofer.", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
if (DdlUnidadCamion.SelectedValue.ToEntero() <= 0)
{
Alert("Debe seleccionar una unidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
StringBuilder SBError = new StringBuilder();
ActualizaOrdenDTGenerarDocumentos();
List<int> ListaTimbres = new List<int>();
bool TieneError = false;
ClsGenerales ObjGeneral = new ClsGenerales();
ObjGeneral.IniciaTransacSQL();
GridViewRowCollection Grid = GvGenerarDocumentos.Rows;
string Usuario = DdlChofer.SelectedItem.Text;
int CveDireccionOrigen = -1;
foreach (GridViewRow row in Grid)
{
int Orden = row.DataKey("Orden").ToEntero();
int CveDireccionDestino = row.DataKey("CveDireccionEnvio").ToEntero();
if (CveDireccionDestino <= 0)
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} el cliente {row.DataKey("Nombre")} no tiene una dirección de envio. ");
TieneError = true;
break;
}
DateTime fechallegada = (TxtFechaEntrega.Text + " 23:59").ToDate();
int CveEntregaAlmacen = ObjGeneral.AddInvEntregaAlmacenRuta(row.DataKey("CveSubProyectoOrigen").ToEntero(), CveDireccionOrigen, CveDireccionDestino, row.DataKey("CveMovimiento").ToEntero(), DdlChofer.SelectedValue.ToEntero(), DdlUnidadCamion.SelectedValue.ToEntero(), TxtFechaEntrega.Text.ToDate(), fechallegada, "E", "", "", "1900-01-01".ToDate(), Orden, 0, 1);
CveDireccionOrigen = row.DataKey("CveDireccionEnvio").ToEntero();
if (CveEntregaAlmacen > 0)
{
int CveTimbre = ObjGeneral.AddGralTimbre("Ent", row.DataKey("CveSubProyectoOrigen").ToEntero(), TxtFechaEntrega.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEntregaAlmacen: CveEntregaAlmacen, AplicaCP: ChkEmitirCartaPorte.Checked);
if (CveTimbre <= 0)
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar timbre. ");
TieneError = true;
break;
}
else
{
ListaTimbres.Add(CveTimbre);
}
}
else
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar entrega almacen. ");
TieneError = true;
break;
}
}
if (!TieneError)
{
foreach (GridViewRow row in Grid)
{
try
{
//MandarNotificacionCorreo(row);
}
catch (Exception ex)
{
TieneError = true;
ModExtensiones.GuardaLog(ex.Message);
}
}
if (!TieneError)
{
ObjGeneral.Commit();
StringBuilder MensajeAlert = new StringBuilder();
//recorrer para timbrar
MensajeAlert.Append(" Entregas creadas correctamente <br/><br/>");
foreach (int cvetimbre in ListaTimbres)
{
Timbres ObjTimbres = new Timbres("Ent", cvetimbre, UsuarioActual);
MensajeAlert.AppendFormat("Folio: <b>{0}</b> &nbsp;", ObjTimbres.ObjFactura.SerieFolio);
if (ObjTimbres.Timbrar())
{
MensajeAlert.AppendFormat("<a class='texto' style='color:#337ab7' href='/Compras/PopUpVerFactura.aspx?P={0}' target='_blank'>XML &nbsp;<i class='fa fa-file'></i></i></a>&nbsp;&nbsp;", ModExtensiones.Encripta(String.Format("OP=DesXmlTra&CveTimbre={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", cvetimbre, "XML", ObjTimbres.ObjFactura.SerieFolio, ObjTimbres.ObjFactura.TipoDocto)));
MensajeAlert.AppendFormat("<a class='texto' style='color:#337ab7' href='/Compras/PopUpVerFactura.aspx?P={0}' target='_blank'>PDF &nbsp;<i class='fa fa-ad-pdf'></i></i></i></a>&nbsp;", ModExtensiones.Encripta(String.Format("OP=CARPOTIMBRE&CVETIMBRE={0}", cvetimbre)));
MensajeAlert.Append("<br/>");
DdlChofer.SelectedValueExist("-1");
DdlUnidadCamion.SelectedValueExist("-1");
ChkEmitirCartaPorte.Checked = false;
SeleccionEntrega = false;
SeleccionarGenerar(1);
}
else
{
MensajeAlert.AppendFormat("<ul><li>{0}</li></ul>", ObjTimbres.MsgError);
}
}
Alert(MensajeAlert.ToString(), ModExtensiones.TipoMensaje.MsgInformacion);
CargaDatos();
UpDatos.Update();
}
else
{
ObjGeneral.RollBack();
}
ObjGeneral.Dispose();
}
else
{
Alert(SBError.ToString(), ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
protected void LnkGeneraRecoleccion_Click(object sender, EventArgs e)
{
if (DdlChoferRec.SelectedValue.ToEntero() <= 0)
{
Alert("Debe seleccionar un chofer.", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
if (DdlUnidadRec.SelectedValue.ToEntero() <= 0)
{
Alert("Debe seleccionar una unidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
StringBuilder SBError = new StringBuilder();
//ActualizaOrdenDTGenerarDocumentos();
List<int> ListaTimbres = new List<int>();
bool TieneError = false;
ClsGenerales ObjGeneral = new ClsGenerales();
ObjGeneral.IniciaTransacSQL();
string Usuario = DdlChofer.SelectedItem.Text;
int CveDireccionOrigen = -1;
foreach (GridViewRow row in gvR.Rows)
{
int Orden = row.DataKey("Orden").ToEntero();
int CveEntregaAlmacen = row.DataKey("CveEntregaAlmacen").ToEntero();
if (row.FCCheckBox("Chk").Checked)
{
CveDireccionOrigen = row.DataKey("CveDireccionOrigen").ToEntero();
if (CveEntregaAlmacen > 0)
{
// se actualizan los datos de unidad, chofer, fechas y Carta porte
if (ObjGeneral.AsignaEntregaAlmacenRuta(DdlUnidadRec.SelectedValue.ToEntero(), DdlChoferRec.SelectedValue.ToEntero(), TxtFechaRec.Text.ToDate(), (TxtFechaRec.Text + " 23:59").ToDate(), CveEntregaAlmacen, UsuarioActual.CveEmpresa))
{
int CveTimbre = ObjGeneral.AddGralTimbre("Rec", row.DataKey("CveSubProyecto").ToEntero(), TxtFechaEntrega.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEntregaAlmacen: CveEntregaAlmacen, AplicaCP: ChkEmitirPorteRec.Checked);
if (CveTimbre <= 0)
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar timbre. ");
TieneError = true;
break;
}
else
{
ListaTimbres.Add(CveTimbre);
}
}
else
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al aplicar condiciones de entrega. ");
TieneError = true;
break;
}
}
else
{
SBError.AppendLine($"Factura {row.DataKey("SerieFolio")} error al agregar entrega almacen. ");
TieneError = true;
break;
}
}
}
if (!TieneError)
{
foreach (GridViewRow row in gvR.Rows)
{
try
{
//MandarNotificacionCorreo(row);
}
catch (Exception ex)
{
TieneError = true;
ModExtensiones.GuardaLog(ex.Message);
}
}
if (!TieneError)
{
ObjGeneral.Commit();
StringBuilder MensajeAlert = new StringBuilder();
//recorrer para timbrar
MensajeAlert.Append(" Entregas creadas correctamente <br/><br/>");
foreach (int cvetimbre in ListaTimbres)
{
Timbres ObjTimbres = new Timbres("Rec", cvetimbre, UsuarioActual);
if (ObjTimbres.Timbrar())
{
//ClsPaginas.PdfFactura(ref ObjTimbres.ObjFactura,"0",true);
//MensajeAlert.Append("Emitido con éxito.");
////XML
//string ArchivoXML = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjTimbres.ObjFactura.TipoDocto, ObjTimbres.ObjFactura.SerieFolio);
//if (System.IO.File.Exists(ArchivoXML))
// MensajeAlert.AppendFormat("<ul><li><a class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'>Descargar XML</a></li></ul>", ModExtensiones.Encripta(String.Format("OP=DesXmlTra&CveTimbre={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", cvetimbre, "XML", ObjTimbres.ObjFactura.SerieFolio, ObjTimbres.ObjFactura.TipoDocto)));
MensajeAlert.AppendFormat("Folio: <b>{0}</b> &nbsp;", ObjTimbres.ObjFactura.SerieFolio);
MensajeAlert.AppendFormat("<a class='texto' style='color:#337ab7' href='/Compras/PopUpVerFactura.aspx?P={0}' target='_blank'>XML &nbsp;<i class='fa fa-file'></i></i></a>&nbsp;&nbsp;", ModExtensiones.Encripta(String.Format("OP=DesXmlTra&CveTimbre={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", cvetimbre, "XML", ObjTimbres.ObjFactura.SerieFolio, ObjTimbres.ObjFactura.TipoDocto)));
MensajeAlert.AppendFormat("<a class='texto' style='color:#337ab7' href='/Compras/PopUpVerFactura.aspx?P={0}' target='_blank'>PDF &nbsp;<i class='fa fa-ad-pdf'></i></i></i></a>&nbsp;", ModExtensiones.Encripta(String.Format("OP=CARPOTIMBRE&CVETIMBRE={0}", cvetimbre)));
MensajeAlert.Append("<br/>");
////PDF
//string ArchivoPDF = String.Format("{0}/PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjTimbres.ObjFactura.TipoDocto, ObjTimbres.ObjFactura.SerieFolio);
//if (System.IO.File.Exists(ArchivoPDF))
// MensajeAlert.AppendFormat("<ul><li><a class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'>Descargar PDF</a></li></ul>", Encripta(String.Format("OP=DesPdfTra&CVEMOVIMIENTO={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", CveMovimientoTimbrado, "PDF", ObjTimbres.ObjFactura.SerieFolio, ObjTimbres.ObjFactura.TipoDocto)));
//if (UsuarioActual.Empresa.Funcionalidad(161) == "1")
// MensajeAlert.AppendFormat("<ul><li><a class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'>Descargar Carta Porte</a></li></ul>", Encripta(String.Format("OP=CARPOTIMBRE&CVETIMBRE={0}", cvetimbre)));
//else
// MensajeAlert.AppendFormat("<ul><li><a class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'>Descargar Carta Porte</a></li></ul>", ModExtensiones.Encripta(String.Format("OP=CARPO&CveTimbre={0}", cvetimbre)));
}
else
{
MensajeAlert.AppendFormat("<ul><li>{0}</li></ul>", ObjTimbres.MsgError);
}
}
Alert(MensajeAlert.ToString(), ModExtensiones.TipoMensaje.MsgInformacion);
CargaDatosRecoleccion();
DdlChofer.SelectedValueExist("-1");
DdlUnidadCamion.SelectedValueExist("-1");
SeleccionEntrega = false;
SeleccionarGenerar(1);
UpDatos.Update();
}
else
{
ObjGeneral.RollBack();
}
ObjGeneral.Dispose();
}
else
{
Alert(SBError.ToString(), ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
private void CargaDatos()
{
ClsGenerales ObjGeneral = new ClsGenerales();
if (ObjGeneral.GetInvEntregaAlmacenRuta(DdlSubProyecto.SelectedValue.ToEntero(), TxtFechaI.Text.ToDate(), TxtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1))
{
GvEntregas.DataSource = ObjGeneral.DtResultados;
DTDatosConsulta = ObjGeneral.DtResultados;
DTGenerarDocumentos = ObjGeneral.DtResultados.Clone();
}
ObjGeneral.Dispose();
GvEntregas.DataBind();
UpDatos.Update();
}
private void CargaCombos()
{
DdlUnidadCamion.DataSource = get_GlobalDTInvCamiones(UsuarioActual.CveEmpresa);
DdlUnidadCamion.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlUnidadCamion.DataBind();
DdlUnidadRec.DataSource = get_GlobalDTInvCamiones(UsuarioActual.CveEmpresa);
DdlUnidadRec.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlUnidadRec.DataBind();
TxtFechaI.Text = DateTime.Now.AddDays(-1).ToShortDateString();
TxtFechaF.Text = DateTime.Now.AddDays(3).ToShortDateString();
DdlChofer.DataSource = get_GlobalDTChoferes(UsuarioActual.CveEmpresa);
DdlChofer.DataBind();
DdlChofer.Items.Insert(0, new ListItem("Seleccione", "-1"));
DdlChoferRec.DataSource = get_GlobalDTChoferes(UsuarioActual.CveEmpresa);
DdlChoferRec.DataBind();
DdlChoferRec.Items.Insert(0, new ListItem("Seleccione", "-1"));
TxtFechaEntrega.Text = DateTime.Now.ToShortDateString();
TabRecoleccion.Visible = UsuarioActual.Empresa.Funcionalidad(531) == "1";
TxtFechaLimite.Text = DateTime.Now.ToShortDateString();
CargarCentrosDeCosto(null, DdlSubProyecto, null, LblSubProyecto);
CargarCentrosDeCosto(null, DdlSubProyectoRecoleccion, null, LblSubProyectoRecoleccion);
}
protected void LnkGenerarDocumentos_Click(object sender, EventArgs e)
{
SeleccionarGenerar(1);
}
private void SeleccionarGenerar(int Opcion)
{
if (SeleccionEntrega)
{
DTGenerarDocumentos.Rows.Clear();
if (Opcion == 2) //cuando es recolección
{
int CountRows = 0;
foreach (GridViewRow GvRow in gvR.Rows)
{
CheckBox ChkAsigna = GvRow.FCCheckBox("Chk");
if (ChkAsigna.Checked)
{
int CveMovimiento = GvRow.DataKey("Cve").ToEntero();
DataRow dRow = DTGenerarDocumentos.NewRow();
DataRow dRowOrigen = DTDatosConsulta.FiltraParametros($"CveMovimiento = {CveMovimiento}").Rows[0];
int IndexColun = 0;
foreach (DataColumn dColumn in DTDatosConsulta.Columns)
{
dRow[IndexColun] = dRowOrigen[IndexColun];
IndexColun++;
}
dRow["Num"] = CountRows + 1;
DTGenerarDocumentos.Rows.Add(dRow);
CountRows++;
}
}
}
else
{
int CountRows = 0;
foreach (GridViewRow GvRow in GvEntregas.Rows)
{
CheckBox ChkAsigna = GvRow.FCCheckBox("ChkAsigna");
if (ChkAsigna.Checked)
{
int CveMovimiento = GvRow.DataKey("CveMovimiento").ToEntero();
DataRow dRow = DTGenerarDocumentos.NewRow();
DataRow dRowOrigen = DTDatosConsulta.FiltraParametros($"CveMovimiento = {CveMovimiento}").Rows[0];
int IndexColun = 0;
foreach (DataColumn dColumn in DTDatosConsulta.Columns)
{
dRow[IndexColun] = dRowOrigen[IndexColun];
IndexColun++;
}
dRow["Num"] = CountRows + 1;
DTGenerarDocumentos.Rows.Add(dRow);
CountRows++;
}
}
DTGenerarDocumentos.AcceptChanges();
SeleccionEntrega = false;
LnkGenerarDocumentos.Text = "Regresar";
LnkGenerarDocumentos.CssClass = "btn btn-default";
OcultarmostarDatosEntrega(true);
BtnConsultar.Visible = false;
UpDatos.Update();
UpFiltro.Update();
if (CountRows > 0)
{
GvGenerarDocumentos.DataSource = DTGenerarDocumentos;
GvGenerarDocumentos.DataBind();
DVGvGenerarDocumentos.Visible = true;
BtnAsignar.Visible = true;
DVGvEntregas.Visible = false;
RegistraScript("InitOrdenamientoGvGenerarDocumentos();");
}
else
{
Alert("No hay entregas seleccionadas", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
}
}
else
{
BtnConsultar.Visible = true;
SeleccionEntrega = true;
LnkGenerarDocumentos.Text = "Preseleccionar";
LnkGenerarDocumentos.CssClass = "btn btn-primary";
OcultarmostarDatosEntrega(false);
BtnAsignar.Visible = false;
DVGvGenerarDocumentos.Visible = false;
DVGvEntregas.Visible = true;
UpDatos.Update();
UpFiltro.Update();
}
}
private void OcultarmostarDatosEntrega(bool mostrar)
{
//DVDatosEntrega1.Visible = mostrar;
DVDatosEntrega2.Visible = mostrar;
//DVDatosEntrega3.Visible = mostrar;
DVDatosEntrega4.Visible = mostrar;
//DVDatosEntrega5.Visible = mostrar;
DVDatosEntrega6.Visible = mostrar;
//if (mostrar)
//{
// DVDatosEntrega7.Attributes.Add("class", "col-md-1");
//}
//else
//{
// DVDatosEntrega7.Attributes.Add("class", "col-md-9");
//}
if (UsuarioActual.Empresa.Funcionalidad(161).ToEntero() == 1)
{
DvCartaPorte2.Visible = mostrar;
}
}
private void ActualizaOrdenDTGenerarDocumentos()
{
string[] OrdenMovimientos = Request.Form.GetValues("OrdenMovimientos");
int NumOrden = 1;
foreach (string CveMovimiento in OrdenMovimientos)
{
foreach (DataRow dRow in DTGenerarDocumentos.Rows)
{
if (CveMovimiento.ToEntero() == dRow["CveMovimiento"].ToString().ToEntero())
{
dRow["Orden"] = NumOrden;
}
}
DTGenerarDocumentos.AcceptChanges();
NumOrden++;
}
DataView DTview = new DataView(DTGenerarDocumentos);
// Sort by State and ZipCode column in descending order
DTview.Sort = "Orden ASC";
GvGenerarDocumentos.DataSource = DTview;
GvGenerarDocumentos.DataBind();
UpDatos.Update();
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
if (Tab.ActiveTabIndex == 0)
{
CargaDatos();
}
else
{
CargaDatosRecoleccion();
}
}
#region RECOLECCION
private DataTable InitDTRecoleccion()
{
DataTable DT = new DataTable();
DT.Columns.Add("CveEntregaAlmacenDetalle", System.Type.GetType("System.Int32"));
DT.Columns.Add("CveEntregaAlmacen", System.Type.GetType("System.Int32"));
DT.Columns.Add("CvePS", System.Type.GetType("System.Int32"));
DT.Columns.Add("Cantidad", System.Type.GetType("System.Double"));
DT.Columns.Add("CveUnidadMedida", System.Type.GetType("System.Int32"));
DT.Columns.Add("CveUsuario", System.Type.GetType("System.Int32"));
DT.Columns.Add("FechaIng", System.Type.GetType("System.DateTime"));
DT.Columns.Add("CodigoPS", System.Type.GetType("System.String"));
DT.Columns.Add("Abreviatura", System.Type.GetType("System.String"));
return DT;
}
private void CargaDatosRecoleccion()
{
ClsGenerales ObjGeneral = new ClsGenerales();
if (ObjGeneral.GetInvEntregaAlmacenRuta(DdlSubProyecto.SelectedValue.ToEntero(), TxtFechaI.Text.ToDate(), TxtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 2, 0))
{
gvR.DataSource = ObjGeneral.DtResultados;
}
ObjGeneral.Dispose();
gvR.DataBind();
UpDatosRecoleccion.Update();
}
private void CargaDatosRecoleccionDetallePS()
{
if (CveEntregaAlmacen > 0)
{
ClsGenerales ObjGenerales = new ClsGenerales();
if (ObjGenerales.GetEntregaAlmacenRutaDetalle(CveEntregaAlmacen))
{
GvModalPSRecoleccion.DataSource = ObjGenerales.DtResultados;
}
else
{
GvModalPSRecoleccion.DataSource = null;
}
ObjGenerales.Dispose();
}
else
{
GvModalPSRecoleccion.DataSource = DTRecoleccion;
}
GvModalPSRecoleccion.DataBind();
UpModalRecoleccion.Update();
}
protected void DdlModalRecoleccionCliente_SelectedIndexChanged(object sender, EventArgs e)
{
ModalRecoleccionCargaDirecciones();
}
private void ModalRecoleccionCargaDirecciones()
{
if (DdlModalRecoleccionCliente.SelectedValue.ToEntero() > 0)
{
ClsClientes ObjClientes = new ClsClientes();
if (ObjClientes.DireccionEnvioGet(-1, DdlModalRecoleccionCliente.SelectedValue.ToEntero(), -1))
{
DdlmodalRecoleccionDireccion.DataSource = ObjClientes.DtResultados.FiltraParametros("CveSubProyecto = " + DdlSubProyectoRecoleccion.SelectedValue.ToEntero());
}
ObjClientes.Dispose();
}
DdlmodalRecoleccionDireccion.DataBind();
DdlmodalRecoleccionDireccion.Items.Insert(0, new ListItem("Seleccione", "-1"));
UpModalRecoleccion.Update();
}
protected void LnkAgregarRecoleccion_Click(object sender, EventArgs e)
{
LtlModalRecoleccionTitulo.Text = "Agregar Recolección";
BtnModalRecoleccionGuardar.Text = "Agregar";
LimpiarModalRecoleccion();
RegistraScript("$('#DivModalRecoleccion').modal('show');");
CveEntregaAlmacen = -1;
}
protected void LnkGvDatosRecoleccionEditar_Click(object sender, EventArgs e)
{
LinkButton LnkEliminar = (LinkButton)sender;
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
CveEntregaAlmacen = GvRow.DataKey("CveEntregaAlmacen").ToEntero();
int CveDireccionOrigen = GvRow.DataKey("CveDireccionOrigen").ToEntero();
int CveClienteEnvio = -1;
string NombreCliente = "";
ClsClientes ObjClientes = new ClsClientes();
DataTable DtTempDirecciones = new DataTable();
if (ObjClientes.DireccionEnvioGet(CveDireccionOrigen, -1, -1))
{
CveClienteEnvio = ObjClientes.DtResultados.FiltroPrimeroValor("CveCliente").ToEntero();
NombreCliente = ObjClientes.DtResultados.FiltroPrimeroValor("NombreCliente");
if (ObjClientes.DireccionEnvioGet(-1, CveClienteEnvio, -1))
{
DdlmodalRecoleccionDireccion.DataSource = ObjClientes.DtResultados;
}
}
ObjClientes.Dispose();
DdlmodalRecoleccionDireccion.DataBind();
DdlmodalRecoleccionDireccion.Items.Add(new ListItem("Seleccione una", "-1"));
DdlmodalRecoleccionDireccion.SelectedValueExist(CveDireccionOrigen);
DdlModalRecoleccionCliente.SelectedValue = CveClienteEnvio.ToString();
DdlModalRecoleccionCliente.SelectedText = NombreCliente;
DdlSubProyectoRecoleccion.SelectedValueExist(GvRow.DataKey("CveSubProyecto"));
TxtFolioReferencia.Text = GvRow.DataKey("FolioReferencia");
TxtReferencia.Text = GvRow.DataKey("Referencia");
CargaDatosRecoleccionDetallePS();
LtlModalRecoleccionTitulo.Text = "Actualizar Recolección";
BtnModalRecoleccionGuardar.Text = "Actualizar";
UpModalRecoleccion.Update();
RegistraScript("$('#DivModalRecoleccion').modal('show');");
}
private void LimpiarModalRecoleccion()
{
// DdlModalRecoleccionCliente.SelectedValueExist(-1);
DdlmodalRecoleccionDireccion.SelectedValueExist(-1);
TxtModalRecoleccionCantidad.Text = "";
DdlModalRecoleccionUnidad.Items.Clear();
DdlModalRecoleccionUnidad.Items.Add(new ListItem("Seleccione una", "-1"));
DdlProducto2.txtValue.Value = "";
DdlProducto2.txtText.Value = "";
DdlSubProyectoRecoleccion.SelectedValueExist("-1");
DdlModalRecoleccionCliente.SelectedValue = "-1";
DdlModalRecoleccionCliente.SelectedText = "Seleccione";
TxtFolioReferencia.Text = "";
TxtReferencia.Text = "";
DTRecoleccion.Rows.Clear();
GvModalPSRecoleccion.DataSource = DTRecoleccion;
GvModalPSRecoleccion.DataBind();
UpModalRecoleccion.Update();
}
protected void DdlProducto_ValueChanged(object sender, EventArgs e)
{
ElProductoChange();
}
private void ElProductoChange()
{
DdlModalRecoleccionUnidad.Items.Clear();
DdlModalRecoleccionUnidad.DataSource = get_GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero(), -1, UsuarioActual.CveEmpresa);
DdlModalRecoleccionUnidad.DataBind();
UpModalRecoleccion.Update();
}
protected void BtnModalRecoleccionGuardar_Click(object sender, EventArgs e)
{
if (DdlmodalRecoleccionDireccion.SelectedValue.ToEntero() <= 0)
{
Alert("Debe seleccionar la dirección de recolección", ModExtensiones.TipoMensaje.MsgAdvertencia);
return;
}
bool ProcesoOK = false;
ClsGenerales ObjGenerales = new ClsGenerales();
ObjGenerales.IniciaTransacSQL();
if (CveEntregaAlmacen == -1)
{
DateTime fechallegada = (TxtFechaEntrega.Text + " 23:59").ToDate();
CveEntregaAlmacen = ObjGenerales.AddInvEntregaAlmacenRuta(DdlSubProyectoRecoleccion.SelectedValue.ToEntero(), DdlmodalRecoleccionDireccion.SelectedValue.ToEntero(), -1, -1, DdlChoferRec.SelectedValue.ToEntero(), DdlUnidadRec.SelectedValue.ToEntero(), TxtFechaEntrega.Text.ToDate(), fechallegada, "R", TxtFolioReferencia.Text, TxtReferencia.Text, TxtFechaLimite.Text.ToDate(), 1, 0, 1);
if (CveEntregaAlmacen > 0)
{
//CveTimbrenuevo = ObjGenerales.AddGralTimbre("Rec", "-1", -1, "-1", TxtFechaEntrega.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, -1, ChkEmitirCartaPorte.Checked, CveEntregaAlmacen, -1);
//if (CveTimbrenuevo > 0)
//{
foreach (DataRow dRow in DTRecoleccion.Rows)
{
if (ObjGenerales.AddEntregaAlmacenRutaDetalle(CveEntregaAlmacen, dRow["CvePS"].ToString().ToEntero(), dRow["Cantidad"].ToString().ToDecimal(), dRow["CveUnidadMedida"].ToString().ToEntero(), UsuarioActual.CveUsuario))
{
ProcesoOK = true;
}
else
{
ProcesoOK = false;
break;
}
}
//}
}
}
else
{
ProcesoOK = ObjGenerales.UpdateInvEntregaAlmacenRuta(CveEntregaAlmacen, DdlmodalRecoleccionDireccion.SelectedValue.ToEntero(), -1, DdlChoferRec.SelectedValue.ToEntero(), DdlUnidadRec.SelectedValue.ToEntero(), TxtFechaEntrega.Text.ToDate(), UsuarioActual.CveEmpresa,FolioReferencia:TxtFolioReferencia.Text,Referencia: TxtReferencia.Text,CveSubProyecto: DdlSubProyectoRecoleccion.SelectedValue.ToEntero());
}
if (ProcesoOK)
{
ObjGenerales.Commit();
Alert("Recolección Guardada correctamente.");
RegistraScript("$('#DivModalRecoleccion').modal('hide');");
}
else
{
ObjGenerales.RollBack();
Alert("Ocurrió un error.", ModExtensiones.TipoMensaje.MsgError);
}
ObjGenerales.Dispose();
CargaDatosRecoleccion();
}
protected void LnkGvDatosRecoleccionEliminar_Click(object sender, EventArgs e)
{
LinkButton LnkEliminar = (LinkButton)sender;
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
int CveEntregaAlmacenEliminar = GvRow.DataKey("CveEntregaAlmacen").ToEntero();
ClsGenerales ObjGenerales = new ClsGenerales();
if (ObjGenerales.RemoveInvEntregaAlmacenRuta(CveEntregaAlmacenEliminar, UsuarioActual.CveEmpresa))
{
Alert("Producto Eliminado correctamente.");
}
ObjGenerales.Dispose();
CargaDatosRecoleccion();
}
#endregion
protected void LnkModalGvModalPSRecoleccionEliminar_Click(object sender, EventArgs e)
{
LinkButton LnkEliminar = (LinkButton)sender;
GridViewRow GvRow = (GridViewRow)LnkEliminar.NamingContainer;
if (CveEntregaAlmacen > 0)
{
int CveEntregaAlmacenDetalleEliminar = GvRow.DataKey("CveEntregaAlmacenDetalle").ToEntero();
ClsGenerales ObjGenerales = new ClsGenerales();
if (ObjGenerales.RemoveEntregaAlmacenRutaDetalle(CveEntregaAlmacenDetalleEliminar))
{
Alert("Recolección Eliminada correctamente.");
}
ObjGenerales.Dispose();
}
else
{
int DTIndex = GvRow.RowIndex;
DTRecoleccion.Rows[DTIndex].Delete();
DTRecoleccion.AcceptChanges();
}
CargaDatosRecoleccionDetallePS();
}
protected void LnkModalAgregarPS_Click(object sender, EventArgs e)
{
if (CveEntregaAlmacen > 0)
{
ClsGenerales ObjGenerales = new ClsGenerales();
if (ObjGenerales.AddEntregaAlmacenRutaDetalle(CveEntregaAlmacen, DdlProducto2.SelectedValue.ToEntero(), TxtModalRecoleccionCantidad.Text.ToEntero(), DdlModalRecoleccionUnidad.SelectedValue.ToEntero(), UsuarioActual.CveUsuario))
{
}
ObjGenerales.Dispose();
}
else
{
DataRow dRow = DTRecoleccion.NewRow();
dRow["CveEntregaAlmacenDetalle"] = -1;
dRow["CveEntregaAlmacen"] = CveEntregaAlmacen;
dRow["CvePS"] = DdlProducto2.SelectedValue.ToEntero();
dRow["Cantidad"] = TxtModalRecoleccionCantidad.Text.ToEntero();
dRow["CveUnidadMedida"] = DdlModalRecoleccionUnidad.SelectedValue.ToEntero();
dRow["CveUsuario"] = UsuarioActual.CveUsuario;
dRow["FechaIng"] = DateTime.Now;
dRow["CodigoPS"] = DdlProducto2.txtText.Value;
dRow["Abreviatura"] = DdlModalRecoleccionUnidad.SelectedItem.Text;
DTRecoleccion.Rows.Add(dRow);
//GvModalPSRecoleccion.DataSource = DTRecoleccion;
}
LimpiarControlesPS();
CargaDatosRecoleccionDetallePS();
}
private void LimpiarControlesPS()
{
TxtModalRecoleccionCantidad.Text = "";
DdlModalRecoleccionUnidad.Items.Clear();
DdlProducto2.txtText.Value = "";
DdlProducto2.txtValue.Value = "";
UpModalRecoleccion.Update();
}
protected void Tab_ActiveTabChanged(object sender, EventArgs e)
{
if (Tab.ActiveTabIndex == 0)
{
SeleccionEntrega = false;
SeleccionarGenerar(1);
}
else
{
OcultarmostarDatosEntrega(true);
}
}
private void CargaModalCombosDirecciones(int CveCliente, int CveDireccionEnvio)
{
DdlModalDireccionEnvio.Items.Clear();
DataTable dtt = new DataTable();
ClsClientes ObjClientes = new ClsClientes();
if (ObjClientes.DireccionEnvioGet(-1, CveCliente, -1))
{
dtt = ObjClientes.DtResultados;
}
ObjClientes.Dispose();
DdlModalDireccionEnvio.DataSource = dtt;
DdlModalDireccionEnvio.DataBind();
DdlModalDireccionEnvio.SelectedValueExist(CveDireccionEnvio);
dtt.Dispose();
}
protected void LnkEditarDir_Click(object sender, EventArgs e)
{
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
int CveDireccion = GvRow.DataKey("CveDireccionEnvio").ToEntero();
HdnCveVenta.Value = GvRow.DataKey("CveVenta");
CargaModalCombosDirecciones(CveCliente, CveDireccion);
UpModalEditarentrega.Update();
this.RegistraScript("$('#DivEditarEntrega').modal('show');");
}
protected void BtnModalEditarentrega_Click(object sender, EventArgs e)
{
bool ProcesoOK = true;
ClsVentas ObjVentas = new ClsVentas();
if (!ObjVentas.UpdateDireccionEnvioVenta(HdnCveVenta.Value.ToEntero(), DdlModalDireccionEnvio.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa))
{
ProcesoOK = false;
}
ObjVentas.Dispose();
if (ProcesoOK)
{
this.RegistraScript("$('#DivEditarEntrega').modal('hide');");
Alert("Dirección Actualizada correctamente.", ModExtensiones.TipoMensaje.ToastInformacion);
CargaDatos();
}
}
protected void gvR_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton LnkEditar = e.Row.FCLinkButton("LnkGvDatosRecoleccionEditar");
LinkButton LnkEliminar = e.Row.FCLinkButton("LnkGvDatosRecoleccionEliminar");
if (e.Row.DataKey("Estatus") == "0" || e.Row.DataKey("Estatus") == "")
{
LnkEditar.Visible = true;
LnkEliminar.Visible = true;
}
if (e.Row.DataKey("CveTimbre") != "")
{
e.Row.FCCheckBox("Chk").Visible = false;
}
}
}
}