272 lines
9.7 KiB
C#
272 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Data;
|
|
using Extensiones;
|
|
using static Extensiones.ModExtensiones;
|
|
public partial class GPS_CatEstatusTrayectos : ClsPaginas
|
|
{
|
|
#region "P R O P I E D A D E S"
|
|
public int CveEstatusTrayecto { get { return ViewState["CveEstatusTrayecto"].ToString().ToEntero(); } set { ViewState["CveEstatusTrayecto"] = value; } }
|
|
public int EsEditar { get { return ViewState["EsEditar"].ToString().ToEntero(); } set { ViewState["EsEditar"] = value; } }
|
|
public DataTable DtEstatus { get { return ((DataTable)ViewState["DtEstatus"]); } set { ViewState["DtEstatus"] = value; } }
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
}
|
|
private void CargaDatos()
|
|
{
|
|
using (var ObjGPS = new ClsGPS())
|
|
{
|
|
if (ObjGPS.GetEstatusTrayectos(-1, UsuarioActual.CveCliente))
|
|
{
|
|
DtEstatus = ObjGPS.DtResultados.FiltraParametros("CveCliente > 0");
|
|
GvEstatus.DataSource = DtEstatus;
|
|
GvEstatus.DataBind();
|
|
CargaEstatus();
|
|
LimpiaModal();
|
|
}
|
|
}
|
|
UpDatos.Update();
|
|
}
|
|
private void CargaEstatus()
|
|
{
|
|
if (DtEstatus != null)
|
|
{
|
|
RblInicioFin.Items.Clear();
|
|
|
|
var ExisteInicio = DtEstatus.COUNT("EsInicio", "EsInicio = true") > 0;
|
|
if (!ExisteInicio)
|
|
{
|
|
var ExisteInicial = RblInicioFin.Items.Cast<ListItem>().Any(x => x.Text == "Inicial");
|
|
RblInicioFin.Items.Insert(0, new ListItem("Inicial", "1", true));
|
|
}
|
|
|
|
if (ExisteInicio)
|
|
{
|
|
RblInicioFin.Items.Add(new ListItem("Intermedio", "2"));
|
|
}
|
|
|
|
var ExisteFin = DtEstatus.COUNT("EsFin", "EsFin = true") > 0;
|
|
if (!ExisteFin)
|
|
{
|
|
RblInicioFin.Items.Add(new ListItem("Final", "3"));
|
|
}
|
|
}
|
|
}
|
|
protected void BtnAgregarCatalogo_Click(object sender, EventArgs e)
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
try
|
|
{
|
|
string Estatus = TxtEstatus.Text.Trim();
|
|
bool EsInicio = false;
|
|
bool EsFin = false;
|
|
int CveEstatusAnterior = -1;
|
|
|
|
switch (RblInicioFin.SelectedValue)
|
|
{
|
|
case "1": //INICIO
|
|
EsInicio = true;
|
|
EsFin = false;
|
|
|
|
int NoEstatusInicio = DtEstatus.COUNT("CveEstatusTrayecto", "EsInicio = True");
|
|
if (NoEstatusInicio > 0)
|
|
{
|
|
this.Alert("Ya existe un estatus de inicio.", TipoMensaje.MsgAdvertencia);
|
|
ObjGPS.Dispose();
|
|
return;
|
|
}
|
|
break;
|
|
case "2":
|
|
EsInicio = false;
|
|
EsFin = false;
|
|
CveEstatusAnterior = DdlEstatusAnterior.SelectedValue.ToEntero();
|
|
break;
|
|
case "3"://FIN
|
|
EsInicio = false;
|
|
EsFin = true;
|
|
int NoEstatusFin = DtEstatus.COUNT("CveEstatusTrayecto", "EsFin = True");
|
|
if (NoEstatusFin > 0)
|
|
{
|
|
this.Alert("Ya existe un estatus de final.", TipoMensaje.MsgAdvertencia);
|
|
ObjGPS.Dispose();
|
|
return;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (RblInicioFin.SelectedValue == "2" && CveEstatusAnterior <= 0)
|
|
{
|
|
this.Alert("No se puede agregar el estatus. Debe seleccionar un estatus anterior.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
ObjGPS.Dispose();
|
|
return;
|
|
}
|
|
|
|
if (ObjGPS.AddEstatusTrayectos(Estatus, EsInicio, EsFin, CveEstatusAnterior, UsuarioActual.CveCliente))
|
|
{
|
|
int CveEstatusNuevo = ObjGPS.DtResultados.Rows[0]["CveEstatusTrayecto"].ToString().ToEntero();
|
|
int CveEstatusSiguiente = DdlEstatusSiguiente.SelectedValue.ToEntero();
|
|
|
|
if (CveEstatusSiguiente > 0)
|
|
{
|
|
if (ObjGPS.UpdateEstatusTrayectos(CveEstatusSiguiente,"",false,false, CveEstatusNuevo, UsuarioActual.CveCliente))
|
|
{
|
|
this.Alert("El estatus se actualizo correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
else
|
|
{
|
|
this.Alert("Ocurrió un error al actualizar el estatus.", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
}
|
|
this.Alert("El estatus se agrego correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
else
|
|
{
|
|
this.Alert("Ocurrió un error al agregar el estatus.", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error al agregar el estatus.", ex);
|
|
}
|
|
finally
|
|
{
|
|
ObjGPS.Dispose();
|
|
CargaDatos();
|
|
RegistraScript("$('#divAgregar').modal('hide');");
|
|
}
|
|
}
|
|
|
|
protected void BtnOpenDiv_Click(object sender, EventArgs e)
|
|
{
|
|
EsEditar = 0;
|
|
CargaEstatus();
|
|
LimpiaModal();
|
|
DdlEstatusAnterior_SelectedIndexChanged(DdlEstatusAnterior, EventArgs.Empty);
|
|
UpEstatus.Update();
|
|
UpAgregar.Update();
|
|
RegistraScript("$('#divAgregar').modal({backdrop: 'static', keyboard: false});");
|
|
}
|
|
private void LimpiaModal()
|
|
{
|
|
EsEditar = 0;
|
|
TxtEstatus.Text = "";
|
|
RblInicioFin.SelectedIndex = 0;
|
|
RblInicioFin_SelectedIndexChanged(DdlEstatusAnterior, EventArgs.Empty);
|
|
}
|
|
|
|
protected void RblInicioFin_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
switch (RblInicioFin.SelectedValue)
|
|
{
|
|
case "1": //INICIO
|
|
DivEstatus.Visible = false;
|
|
break;
|
|
case "2":
|
|
DivEstatus.Visible = true;
|
|
var dt = DtEstatus.FiltraParametros("EsFin=false");
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
DdlEstatusAnterior.DataSource = dt;
|
|
DdlEstatusAnterior.DataBind();
|
|
|
|
var CveEstatusSeleccion = dt.FiltroPrimeroValor("CveEstatusTrayecto", "CveEstatusSiguiente IS NULL").ToEntero();
|
|
if (CveEstatusSeleccion <= 0)
|
|
{
|
|
CveEstatusSeleccion = DtEstatus.FiltroPrimeroValor("CveEstatusAnterior", "EsFin = true").ToEntero();
|
|
}
|
|
DdlEstatusAnterior.SelectedValueExist(CveEstatusSeleccion);
|
|
}
|
|
else
|
|
{
|
|
DivEstatus.Visible = true;
|
|
}
|
|
|
|
break;
|
|
case "3"://FIN
|
|
DivEstatus.Visible = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
UpEstatus.Update();
|
|
}
|
|
|
|
protected void GvEstatus_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
|
{
|
|
var ObjGPS = new ClsGPS();
|
|
try
|
|
{
|
|
int CveEstatusTrayecto = GvEstatus.Rows[e.RowIndex].DataKey("CveEstatusTrayecto").ToEntero();
|
|
|
|
int CveEstatusAnterior = DtEstatus.FiltroPrimeroValor("CveEstatusAnterior", $"CveEstatusTrayecto = {CveEstatusTrayecto}").ToEntero();
|
|
int CveEstatusSiguiente = DtEstatus.FiltroPrimeroValor("CveEstatusSiguiente", $"CveEstatusTrayecto = {CveEstatusTrayecto}").ToEntero();
|
|
|
|
if (ObjGPS.RemoveEstatusTrayecto(CveEstatusTrayecto))
|
|
{
|
|
if (ObjGPS.UpdateEstatusTrayectos(CveEstatusSiguiente,"",false,false, CveEstatusAnterior, UsuarioActual.CveCliente))
|
|
{
|
|
this.Alert("El estatus se eliminó correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error al eliminar el estatus.", ex);
|
|
}
|
|
finally
|
|
{
|
|
ObjGPS.Dispose();
|
|
CargaDatos();
|
|
}
|
|
}
|
|
|
|
protected void GvEstatus_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("EsFin") == "True")
|
|
{
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-primary";
|
|
}
|
|
else if (e.Row.DBCampo("EsInicio") == "True")
|
|
{
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-success";
|
|
}
|
|
else if (e.Row.DBCampo("EsFin") == "False" && e.Row.DBCampo("EsInicio") == "False")
|
|
{
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-secondary";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void DdlEstatusAnterior_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
int CveEstatusSiguiente = DtEstatus.FiltroPrimeroValor("CveEstatusSiguiente", $"CveEstatusTrayecto = {DdlEstatusAnterior.SelectedValue}").ToEntero();
|
|
if (CveEstatusSiguiente > 0)
|
|
{
|
|
DdlEstatusSiguiente.DataSource = DtEstatus.FiltraParametros($"CveEstatusTrayecto={CveEstatusSiguiente}");
|
|
DdlEstatusSiguiente.DataBind();
|
|
}
|
|
else
|
|
{
|
|
DdlEstatusSiguiente.Items.Clear();
|
|
DdlEstatusSiguiente.Items.Insert(0, new ListItem("Ninguno", "-1"));
|
|
}
|
|
}
|
|
} |