1010 lines
37 KiB
C#
1010 lines
37 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using GemBox.Spreadsheet;
|
|
using System.Text;
|
|
|
|
public partial class GPS_WizardDispositivos : ClsPaginas
|
|
{
|
|
|
|
#region P R O P I E D A D E S
|
|
public int GPSNEW
|
|
{
|
|
get
|
|
{
|
|
return ViewState["GPSNEW"].ToString().ToEntero();
|
|
}
|
|
set
|
|
{
|
|
ViewState["GPSNEW"] = value;
|
|
}
|
|
}
|
|
|
|
public int CveCliente
|
|
{
|
|
get { return ViewState["CveCliente"] != null ? ViewState["CveCliente"].ToString().ToEntero() : -1; }
|
|
set { ViewState["CveCliente"] = value; }
|
|
}
|
|
public int CveDispositivo
|
|
{
|
|
get { return ViewState["CveDispositivo"] != null ? ViewState["CveDispositivo"].ToString().ToEntero() : -1; }
|
|
set { ViewState["CveDispositivo"] = value; }
|
|
}
|
|
public string ArrayDisp
|
|
{
|
|
get { return ViewState["ArrayDisp"] != null ? ViewState["ArrayDisp"].ToString() : ""; }
|
|
set { ViewState["ArrayDisp"] = value; }
|
|
}
|
|
public int EsEditar
|
|
{
|
|
get
|
|
{
|
|
return ViewState["EsEditar"].ToString().ToEntero();
|
|
}
|
|
set
|
|
{
|
|
ViewState["EsEditar"] = value;
|
|
}
|
|
}
|
|
public int CveConductor
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveConductor"].ToString().ToEntero();
|
|
}
|
|
set
|
|
{
|
|
ViewState["CveConductor"] = value;
|
|
}
|
|
}
|
|
public string UrlIMGEncriptada(string param)
|
|
{
|
|
return ModExtensiones.Encripta(param);
|
|
}
|
|
private DataTable DTControlesValores
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTControlesValores"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DTControlesValores"] = value;
|
|
}
|
|
}
|
|
private DataTable DtUnidadMedida
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DtUnidadMedida"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DtUnidadMedida"] = value;
|
|
}
|
|
}
|
|
private DataTable DtModelos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DtModelos"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DtModelos"] = value;
|
|
}
|
|
}
|
|
private DataTable DtDispositivosEventos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DtDispositivosEventos"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DtDispositivosEventos"] = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
if (UsuarioActual.Empresa.Funcionalidad(541)=="1")
|
|
{
|
|
LnkAgregar.Visible = false;
|
|
}
|
|
|
|
if (Request["CveCliente"] != null && Request["CveCliente"].ToEntero() > 0)
|
|
{
|
|
CveCliente = Request["CveCliente"].ToEntero();
|
|
}
|
|
else { CveCliente = -1; }
|
|
|
|
if (Request["CveDispositivo"] != null && Request["CveDispositivo"].ToEntero() > 0)
|
|
{
|
|
CveDispositivo = Request["CveDispositivo"].ToEntero();
|
|
}
|
|
else { CveDispositivo = -1; }
|
|
if (Request["ArrayDisp"] != null)
|
|
{
|
|
ArrayDisp = Request["ArrayDisp"].ToString();
|
|
}
|
|
else { ArrayDisp = ""; }
|
|
GPSNEW = (CveDispositivo > 0) ? 0 : 1;
|
|
((BaseMasterPage)this.Master).EsPopup = true;
|
|
CargaUsuarios();
|
|
cargaddls();
|
|
CargaDatos(CveDispositivo);
|
|
CargaImagenes();
|
|
}
|
|
}
|
|
|
|
|
|
protected void TabContainer_ActiveTabChanged(object sender, EventArgs e)
|
|
{
|
|
if (CveDispositivo < 0)
|
|
{
|
|
TabContainer.ActiveTabIndex = 0;
|
|
Alert("Debe guardar el dispositivo primero",ModExtensiones.TipoMensaje.MsgAdvertencia );
|
|
}
|
|
}
|
|
|
|
private void cargaddls()
|
|
{
|
|
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.GetMarca(-1, 1))
|
|
{
|
|
DdlMarca.DataSource = ObjGPS.DtResultados.Copy();
|
|
}
|
|
|
|
if (ObjGPS.ModeloGet(-1, 1))
|
|
{
|
|
DtModelos = ObjGPS.DtResultados.Copy();
|
|
}
|
|
|
|
ObjGPS.Dispose();
|
|
|
|
DdlMarca.DataBind();
|
|
DdlMarca.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
CargaCuentas();
|
|
}
|
|
|
|
private void CargaDatos(int CveDispositivo)
|
|
{
|
|
|
|
if (CveDispositivo > 0)
|
|
{
|
|
var TieneError = false;
|
|
string msgError = "";
|
|
int TipoDispositivo = -1;
|
|
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
TieneError = !ObjGPS.DispositivosGet(CveDispositivo, -1, -1);
|
|
DataRow drow = ObjGPS.DtResultados.Rows.Count > 0 ? ObjGPS.DtResultados.Rows[0] : null;
|
|
ObjGPS.Dispose();
|
|
|
|
if (!TieneError && drow!= null)
|
|
{
|
|
TipoDispositivo = drow["TipoDispositivo"].ToString().ToEntero();
|
|
DdlTipo.SelectedValueExist(TipoDispositivo.ToString());
|
|
DdlTipo_SelectedIndexChanged(DdlTipo, EventArgs.Empty);
|
|
|
|
//DISPOSITVO GPS
|
|
if (TipoDispositivo == 1)
|
|
{
|
|
DdlMarca.SelectedValueExist(drow["CveMarca"].ToString());
|
|
DdlMarca_SelectedIndexChanged(DdlMarca, EventArgs.Empty);
|
|
if (DdlMarca.SelectedValue == drow["CveMarca"].ToString())
|
|
{
|
|
DdlModelo.SelectedValueExist(drow["CveModelo"].ToString());
|
|
if (DdlModelo.SelectedValue != drow["CveModelo"].ToString())
|
|
{
|
|
TieneError = true;
|
|
msgError = "Ocurrió un error al cargar el modelo";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TieneError = true;
|
|
msgError = "Ocurrió un error al cargar la marca";
|
|
}
|
|
|
|
}
|
|
TxtSerie.Text = drow["Serie"].ToString();
|
|
TxtIMEI.Text = drow["IMEI"].ToString();
|
|
TxtSerieV.Text = drow["SerieVehiculo"].ToString();
|
|
TxtNombreV.Text = drow["NombreVehiculo"].ToString();
|
|
TxtNoEconomico.Text = drow["NoEconomico"].ToString();
|
|
TxtColorV.Text = drow["ColorVehiculo"].ToString();
|
|
TxtDevId.Text = drow["DevID"].ToString();
|
|
;
|
|
TxtTelefonoMovil.Text = drow["NumTelefonoMovil"].ToString();
|
|
TxtModeloV.Text = drow["ModeloVehiculo"].ToString();
|
|
TxtAñoV.Text = drow["AñoVehiculo"].ToString();
|
|
TxtPlacas.Text = drow["PlacasVehiculo"].ToString();
|
|
ChkTipoLinea.Checked = drow["CveProveedorComunicacionCuenta"].ToString().ToEntero() <= 0;
|
|
|
|
}
|
|
else
|
|
{
|
|
TieneError = true;
|
|
}
|
|
|
|
if (!TieneError)
|
|
{
|
|
switch (TipoDispositivo)
|
|
{
|
|
case 1:
|
|
CargaModeloEntradasSalidas();
|
|
CargaComandosDispositivo();
|
|
CargaDispositivosSensores();
|
|
CargaConductores();
|
|
cargaUsuariosDispositivo();
|
|
break;
|
|
case 2:
|
|
CargaConductores();
|
|
cargaUsuariosDispositivo();
|
|
break;
|
|
}
|
|
}
|
|
ChkTipoLinea_CheckedChanged(ChkTipoLinea, EventArgs.Empty);
|
|
|
|
Updatos.Update();
|
|
UpModelo.Update();
|
|
upLinea.Update();
|
|
UpDispositivo.Update();
|
|
UpEventos.Update();
|
|
UpComandos.Update();
|
|
UpSensores.Update();
|
|
UpConductores.Update();
|
|
UpGaleria.Update();
|
|
UpAgregarConductor.Update();
|
|
|
|
if (TieneError)
|
|
{
|
|
Alert(msgError, ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#region Información Dispositivo
|
|
|
|
protected void DdlTipo_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
bool EsGPS = DdlTipo.SelectedValue == "1";
|
|
TabEventos.Visible = EsGPS;
|
|
TabComandos.Visible = EsGPS;
|
|
TabCalibracion.Visible = EsGPS;
|
|
|
|
DivMarca.Visible = EsGPS;
|
|
DivModelo.Visible = EsGPS;
|
|
DivIMEI.Visible = EsGPS;
|
|
DivSERIE.Visible = EsGPS;
|
|
|
|
if (CveDispositivo <= 0 && !EsGPS)
|
|
{
|
|
if (string.IsNullOrEmpty(TxtDevId.Text.Trim()))
|
|
{
|
|
var DevID = GenerarDevID();
|
|
var NumID = get_GlobalDTDispositivos(-1).COUNT("CveDispositivo", $"DevID = '{DevID}'");
|
|
if (NumID == 0)
|
|
{
|
|
TxtDevId.Text = DevID;
|
|
}
|
|
}
|
|
}
|
|
|
|
UpModelo.Update();
|
|
Updatos.Update();
|
|
}
|
|
private string GenerarDevID()
|
|
{
|
|
long ticks = DateTime.Now.Ticks;
|
|
byte[] bytes = BitConverter.GetBytes(ticks);
|
|
string id = Convert.ToBase64String(bytes)
|
|
.Replace('+','A')
|
|
.Replace('/', 'Z')
|
|
.TrimEnd('=').ToUpper();
|
|
return id;
|
|
}
|
|
protected void DdlMarca_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
int CveMarca = DdlMarca.SelectedValue.ToEntero();
|
|
DdlModelo.DataSource = DtModelos.FiltraParametros($"CveMarca = {CveMarca}");
|
|
DdlModelo.DataBind();
|
|
|
|
UpModelo.Update();
|
|
}
|
|
|
|
protected void LnkGuardarInfoDisp_Click(object sender, EventArgs e)
|
|
{
|
|
bool continuar = true;
|
|
int TipoDispositivo = DdlTipo.SelectedValue.ToEntero();
|
|
int puerto = 0;
|
|
int modelo = TipoDispositivo == 1 ? DdlModelo.SelectedValue.ToEntero() : -1;
|
|
int LineaTelefonica = !ChkTipoLinea.Checked ? DdlLineaTelefono.SelectedValue.ToEntero() : -1;
|
|
string IMEI = TipoDispositivo == 1 ? TxtIMEI.Text : "-1";
|
|
string Serie = TipoDispositivo == 1 ? TxtSerie.Text : "-1";
|
|
string SerieV = TxtSerieV.Text.Trim();
|
|
string ColorV = TxtColorV.Text.Trim();
|
|
string NombreV = TxtNombreV.Text.Trim().ToUpper();
|
|
string NoEconomico = TxtNoEconomico.Text.Trim().ToUpper();
|
|
string DevId = TxtDevId.Text;
|
|
string ModeloV = TxtModeloV.Text;
|
|
string AñoV = TxtAñoV.Text;
|
|
string ClaseVehiculo = "";//TxtClaseVehiculo.Text;
|
|
string Placas = TxtPlacas.Text;
|
|
bool LimiteVelocidad = false;
|
|
double LimiteVelocidadV = 0;//chkLimiteVelocidad.Checked ? TxtLimiteVelocidad.Text.ToDouble : 0
|
|
string Detalles = "";//TxtDetalles.Text;
|
|
double Rendimiento = 0;//TxtRendimiento.Text.ToDouble;
|
|
string icono = "rsz_11rsz_car";
|
|
string Color = "#0088FF";
|
|
string NumTelefono = ChkTipoLinea.Checked ? TxtTelefonoMovil.Text.Trim().Replace("(","").Replace(")","").Replace("-","").Replace(" ","") : "-1";
|
|
|
|
if (continuar)
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.IniciaTransacSQL();
|
|
if (CveDispositivo > 0)
|
|
{
|
|
continuar = ObjGPS.DispositivosUpdate(TipoDispositivo,NumTelefono, CveDispositivo, modelo, LineaTelefonica, CveCliente, IMEI, Serie, 1, SerieV, ColorV, NombreV, NoEconomico, DevId, puerto,
|
|
ModeloV, AñoV, ClaseVehiculo, Placas, LimiteVelocidad, LimiteVelocidadV, Detalles, Rendimiento, icono, Color,UsuarioActual.CveUsuario);
|
|
}
|
|
else
|
|
{
|
|
continuar = ObjGPS.DispositivoAdd(TipoDispositivo, NumTelefono, modelo, LineaTelefonica, CveCliente, IMEI, Serie, 1, SerieV, ColorV, NombreV, NoEconomico, DevId, puerto,
|
|
ModeloV, AñoV, ClaseVehiculo, Placas, LimiteVelocidad, LimiteVelocidadV, Detalles, Rendimiento, icono, Color, UsuarioActual.CveUsuario);
|
|
CveDispositivo = ObjGPS.CveDispositivo;
|
|
}
|
|
if (continuar)
|
|
{
|
|
ObjGPS.Commit();
|
|
this.RecargaGlobalDTDispositivos(ObjGPS);
|
|
CargaDatos(CveDispositivo);
|
|
Updatos.Update();
|
|
string script = "";
|
|
if (GPSNEW == 1) {
|
|
TabContainer.ActiveTabIndex = 1; script = $"RegresaValor({CveDispositivo})";
|
|
ClsSisMail correo = new ClsSisMail();
|
|
Correo.SendMail(UsuarioActual.EmpresaNotificaciones, "paola@adssistemas.mx;Caudillo.90d@gmail.com", "Alta nuevo dispositivo",
|
|
$"se le informa la alta de un nuevo dispositivo en la empresa \"{UsuarioActual.Empresa.Empresa}\"\r\nIMEI : \"{IMEI}\"\r\nSerie : \"{Serie}\"\r\nModelo : \"{modelo}\"");
|
|
|
|
}
|
|
|
|
Alert("El dispositivo y sus configuraciones, se han guardado correctamente", ModExtensiones.TipoMensaje.MsgInformacion, script);
|
|
if (TipoDispositivo == 2)
|
|
{
|
|
var Msg = new StringBuilder();
|
|
Msg.AppendFormat("Se ha creado/actualizado un dispositivo con el siguiente ID: {0}", DevId);
|
|
var ObjMovil = new ClsTecnoMovil();
|
|
ObjMovil.EnviarMensajeWS(NumTelefono, Msg.ToString());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ObjGPS.RollBack();
|
|
}
|
|
ObjGPS.Dispose();
|
|
}
|
|
}
|
|
|
|
protected void CargaImagenes()
|
|
{
|
|
bool TienePermisoImagenes = false;
|
|
var ObjUsuarios = new ClsSisUsuarios();
|
|
if (ObjUsuarios.GetUsuariosModulos(UsuarioActual.CveUsuario,UsuarioActual.CveEmpresa,CvePlataforma:5))
|
|
{
|
|
TienePermisoImagenes = ObjUsuarios.DtResultados.COUNT("CveModulo", "CveModulo = 5010 AND Permitir = 1") == 1;
|
|
TabImagenes.Visible = TienePermisoImagenes;
|
|
}
|
|
ObjUsuarios.Dispose();
|
|
|
|
if (TienePermisoImagenes)
|
|
{
|
|
var ObjGPS = new ClsGPS();
|
|
if (ObjGPS.GetImagenesDispositivo(CveDispositivo))
|
|
{
|
|
if (ObjGPS.DtResultados.Rows.Count > 0)
|
|
{
|
|
RptFotos.DataSource = ObjGPS.DtResultados;
|
|
}
|
|
}
|
|
ObjGPS.Dispose();
|
|
RptFotos.DataBind();
|
|
UpGaleria.Update();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
#region Lineas de teléfono
|
|
|
|
private void CargaDdlProveedoresComunicacion()
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.DdlProveedoresComunicacionGet())
|
|
DdlProveedorComunicacion.DataSource = ObjGPS.DtResultados;
|
|
ObjGPS.Dispose();
|
|
DdlProveedorComunicacion.DataBind();
|
|
DdlProveedorComunicacion.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
private void CargaDdlPlanDatos()
|
|
{
|
|
if (DdlProveedorComunicacion.SelectedValue == "-1")
|
|
{
|
|
DdlPlanDatos.Items.Clear();
|
|
DdlPlanDatos.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
else
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.DdlPlanDatosGet(UsuarioActual.CveEmpresa, DdlProveedorComunicacion.SelectedValue.ToEntero()))
|
|
DdlPlanDatos.DataSource = ObjGPS.DtResultados;
|
|
ObjGPS.Dispose();
|
|
DdlPlanDatos.DataBind();
|
|
DdlPlanDatos.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
}
|
|
upLinea.Update();
|
|
}
|
|
protected void DdlProveedorComunicacion_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaDdlPlanDatos();
|
|
}
|
|
|
|
private void CargaCuentas()
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.ProveedoresComunicacionCuentasGet(-1, UsuarioActual.CveEmpresa);
|
|
DdlLineaTelefono.SelectedIndex = -1;
|
|
DdlLineaTelefono.DataSource = ObjGPS.DtResultados.FiltraParametros($"CveDispositivo is NULL OR CveDispositivo = {CveDispositivo}");
|
|
ObjGPS.Dispose();
|
|
DdlLineaTelefono.DataBind();
|
|
DdlLineaTelefono.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlLineaTelefono.SelectedValue = "-1";
|
|
DataRow drow = ObjGPS.DtResultados.FiltroPrimero($"CveDispositivo is NULL OR CveDispositivo = {CveDispositivo}");
|
|
if (drow != null)
|
|
{
|
|
DdlLineaTelefono.SelectedValue = drow["CveProveedorComunicacionCuenta"].ToString();
|
|
}
|
|
upLinea.Update();
|
|
}
|
|
protected void DdlProveedorComunicacion_SelectedIndexChanged1(object sender, EventArgs e)
|
|
{
|
|
CargaDdlPlanDatos();
|
|
}
|
|
protected void LnkAgregar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
TxtSSID.Text = "";
|
|
TxtIP.Text = "";
|
|
TxtNumeroTelefono.Text = "";
|
|
LnkAgregar.Visible = false;
|
|
PnlAddlinea.Visible = true;
|
|
RegistraScript($"$('html, body').animate({{scrollTop: ($('#{BtnAgregarAddLinea.ClientID}').first().offset().top)}},500);");
|
|
CargaDdlProveedoresComunicacion();
|
|
|
|
}
|
|
protected void BtnAgregarAddLinea_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
string numerodetelefono = TxtNumeroTelefono.Text.Replace("(", "").Replace(")", "").Replace("-", "");
|
|
bool continuar = ObjGPS.ProveedoresComunicacionCuentasAdd(DdlProveedorComunicacion.SelectedValue.ToEntero(), DdlPlanDatos.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, TxtIP.Text, TxtSSID.Text, numerodetelefono, 1, UsuarioActual.CveEmpresa,"",-1);
|
|
if (continuar)
|
|
{
|
|
CargaCuentas();
|
|
Alert("La cuenta de comunicación se agrego correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
CargaCuentas();
|
|
LnkAgregar.Visible = true;
|
|
PnlAddlinea.Visible = false;
|
|
Updatos.Update();
|
|
|
|
}
|
|
|
|
protected void LnkCancelaraddLinea_Click(object sender, EventArgs e)
|
|
{
|
|
LnkAgregar.Visible = true;
|
|
PnlAddlinea.Visible = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Eventos
|
|
private void CargaModeloEntradasSalidas()
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.GetEventosAlias(CveDispositivo))
|
|
GvEventos.DataSource = ObjGPS.DtResultados;
|
|
else
|
|
GvEventos.DataSource = null;
|
|
// DtEventos = New DataTable
|
|
|
|
/*if (ObjGPS.DtResultados.Rows.Count > 0)
|
|
Alert($@"El módelo {DdlModelo.SelectedItem.Text} cuenta con Entradas y Salidas programables, éstas podrán ser programadas en la siguiente pantalla.\n Si desea programarlas en otro momento, haga click en finalizar.");*/
|
|
ObjGPS.Dispose();
|
|
GvEventos.DataBind();
|
|
}
|
|
|
|
protected void LnkProgramaEventos_Click(object sender, EventArgs e)
|
|
{
|
|
bool continuar = true;
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.IniciaTransacSQL();
|
|
bool chkEv = false;
|
|
int CveEvento = 0;
|
|
int Valor = 0;
|
|
string nombre = "";
|
|
foreach (GridViewRow row in GvEventos.Rows)
|
|
{
|
|
chkEv = row.FCCheckBox("chkEv").Checked;
|
|
CveEvento = row.DataKey("CveEvento").ToEntero();
|
|
Valor = row.FCTextBox("TxtValor").Text.ToEntero();
|
|
nombre = row.FCTextBox("TxtNombre").Text;
|
|
|
|
if (continuar) { continuar = ObjGPS.RemoveEventoAlias(CveDispositivo, CveEvento, Valor); }
|
|
if (chkEv && continuar)
|
|
{
|
|
continuar = ObjGPS.AddEventoAlias(CveDispositivo, CveEvento, Valor, nombre);
|
|
}
|
|
if (!continuar)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
ObjGPS.Commit();
|
|
if (GPSNEW == 1) { TabContainer.ActiveTabIndex = 2; }
|
|
Alert("los eventos se han guardado satisfactoriamente");
|
|
}
|
|
else
|
|
{
|
|
ObjGPS.RollBack();
|
|
}
|
|
ObjGPS.Dispose();
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region Comandos
|
|
private void CargaComandosDispositivo()
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.GetComandosDispositivosAlias(CveDispositivo))
|
|
GvComandos.DataSource = ObjGPS.DtResultados;
|
|
else
|
|
GvComandos.DataSource = null;
|
|
|
|
/*if (ObjGPS.DtResultados.Rows.Count > 0)
|
|
Alert($@"El módelo {DdlModelo.SelectedItem.Text} cuenta con comandos programables, éstas podrán ser programadas en la siguiente pantalla.\n Si desea programarlas en otro momento, haga click en finalizar.");*/
|
|
ObjGPS.Dispose();
|
|
GvComandos.DataBind();
|
|
UpComandos.Update();
|
|
}
|
|
|
|
protected void LnkProgramarComandos_Click(object sender, EventArgs e)
|
|
{
|
|
bool continuar = true;
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.IniciaTransacSQL();
|
|
bool chkEv = false;
|
|
int CveComando = 0;
|
|
int Valor = 0;
|
|
string nombre = "";
|
|
|
|
foreach (GridViewRow row in GvComandos.Rows)
|
|
{
|
|
chkEv = row.FCCheckBox("chkEv").Checked;
|
|
CveComando = row.DataKey("CveComando").ToEntero();
|
|
Valor = row.FCTextBox("TxtValor").Text.ToEntero();
|
|
nombre = row.FCTextBox("TxtNombre").Text;
|
|
if (continuar) { continuar = ObjGPS.RemoveComandoAlias(CveDispositivo, CveComando, Valor); }
|
|
if (chkEv && continuar)
|
|
{
|
|
continuar = ObjGPS.AddComandoAlias(CveDispositivo, CveComando, Valor, nombre);
|
|
}
|
|
if (!continuar)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
ObjGPS.Commit();
|
|
if (GPSNEW == 1) { TabContainer.ActiveTabIndex = 3; }
|
|
Alert("los Comandos se han guardado satisfactoriamente");
|
|
}
|
|
else
|
|
{
|
|
ObjGPS.RollBack();
|
|
}
|
|
ObjGPS.Dispose();
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region Calibración
|
|
|
|
private void CargaDispositivosSensores()
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.GetDispositivosSensores(CveDispositivo))
|
|
{
|
|
GVDispositivosSensores.DataSource = ObjGPS.DtResultados;
|
|
ObjGPS.GETDispositivosControlValores(CveDispositivo);
|
|
DTControlesValores = ObjGPS.DtResultados;
|
|
ObjGPS.UnidadMedidaGet();
|
|
DtUnidadMedida = ObjGPS.DtResultados;
|
|
}
|
|
else
|
|
{
|
|
GVDispositivosSensores.DataSource = null;
|
|
}
|
|
ObjGPS.Dispose();
|
|
GVDispositivosSensores.DataBind();
|
|
if (DTControlesValores != null)
|
|
{
|
|
DTControlesValores.Dispose();
|
|
}
|
|
if (DtUnidadMedida != null)
|
|
{
|
|
DtUnidadMedida.Dispose();
|
|
}
|
|
}
|
|
|
|
protected void GVDispositivosSensores_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
int CveControl = e.Row.DataKey("CveControl").ToEntero();
|
|
string CveUnidadMedida = e.Row.DataKey("CveUnidadMedida");
|
|
string CveTipoControl = e.Row.DataKey("CveTipoControl");
|
|
Panel pnlCalibracion = (Panel)e.Row.FindControl("pnlCalibracion");
|
|
GridView GVCalibracion = (GridView)e.Row.FindControl("GVCalibracion");
|
|
DropDownList DdlUnidadMedida = (DropDownList)e.Row.FindControl("DdlUnidadMedida");
|
|
DropDownList ddltipoSensor = (DropDownList)e.Row.FindControl("ddltipoSensor");
|
|
DdlUnidadMedida.DataSource = DtUnidadMedida;
|
|
DdlUnidadMedida.DataBind();
|
|
ddltipoSensor.SelectedValueExist(CveTipoControl);
|
|
if (CveControl > 0)
|
|
{
|
|
pnlCalibracion.Visible = true;
|
|
DdlUnidadMedida.SelectedValueExist(CveUnidadMedida);
|
|
GVCalibracion.DataSource = DTControlesValores.FiltraParametros(string.Format("CveControl={0}", CveControl), "Nivel");
|
|
GVCalibracion.DataBind();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void LnkGuardarSensor_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
int CveControl = GvRow.DataKey("CveControl").ToEntero();
|
|
DropDownList DdlUnidadMedida = GvRow.FCDropDownList("DdlUnidadMedida");
|
|
DropDownList ddltipoSensor = GvRow.FCDropDownList("ddltipoSensor");
|
|
TextBox TxtCapacidad = GvRow.FCTextBox("TxtCapacidad");
|
|
TextBox TxtLargo = GvRow.FCTextBox("TxtLargo");
|
|
TextBox TxtAncho = GvRow.FCTextBox("TxtAncho");
|
|
TextBox TxtAlto = GvRow.FCTextBox("TxtAlto");
|
|
TextBox TxtLongitud = GvRow.FCTextBox("TxtLongitud");
|
|
TextBox TxtSensor = GvRow.FCTextBox("TxtSensor");
|
|
string SensorName = GvRow.DataKey("SensorName");
|
|
int CveMetrica = GvRow.DataKey("CveMetrica").ToEntero();
|
|
int UnidadMedida = DdlUnidadMedida.SelectedValue.ToEntero();
|
|
int CveTipoControl = ddltipoSensor.SelectedValue.ToEntero();
|
|
double Capacidad = TxtCapacidad.Text.ToDouble();
|
|
double Largo = TxtLargo.Text.ToDouble();
|
|
double Ancho = TxtAncho.Text.ToDouble();
|
|
double Alto = TxtAlto.Text.ToDouble();
|
|
double Longitud = TxtLongitud.Text.ToDouble();
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
bool continuar = true;
|
|
if (CveControl > 0)
|
|
{
|
|
continuar = ObjGPS.ControlUpdate(SensorName, UnidadMedida, Capacidad, Largo, Ancho, Alto, Longitud, TxtSensor.Text, CveDispositivo, CveControl, CveDispositivo, CveTipoControl);
|
|
}
|
|
else
|
|
{
|
|
continuar = ObjGPS.ControlAdd(SensorName, UnidadMedida, Capacidad, Largo, Ancho, Alto, Longitud, TxtSensor.Text, CveDispositivo, CveMetrica, CveTipoControl);
|
|
if (continuar)
|
|
{
|
|
CveControl = ObjGPS.CveControl;
|
|
}
|
|
}
|
|
ObjGPS.Dispose();
|
|
if (continuar)
|
|
{
|
|
CargaDispositivosSensores();
|
|
Alert("el sensor se a actualizado correctamente");
|
|
}
|
|
}
|
|
|
|
protected void LnkEliminarSensor_Click(object sender, EventArgs e)
|
|
{
|
|
ClsGPS objgps = new ClsGPS();
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
int CveControl = GvRow.DataKey("CveControl").ToEntero();
|
|
if (objgps.ControlesDelete(CveControl))
|
|
{
|
|
Alert("El Control se eliminó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
CargaDispositivosSensores();
|
|
}
|
|
UpSensores.Update();
|
|
}
|
|
protected void LnkCancelarCal_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
Panel PnlUpCalibracion = (Panel)GvRow.FindControl("PnlUpCalibracion");
|
|
LinkButton LnkupCalibracion = (LinkButton)GvRow.FindControl("LnkupCalibracion");
|
|
|
|
LnkupCalibracion.Visible = true;
|
|
PnlUpCalibracion.Visible = false;
|
|
}
|
|
|
|
protected void LnkGuardarcalibracion_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
Panel PnlUpCalibracion = (Panel)GvRow.FindControl("PnlUpCalibracion");
|
|
LinkButton LnkupCalibracion = (LinkButton)GvRow.FindControl("LnkupCalibracion");
|
|
TextBox TxtCalibracion = (TextBox)GvRow.FindControl("TxtCalibracion");
|
|
int CveControl = GvRow.DataKey("CveControl").ToEntero();
|
|
bool continuar = true;
|
|
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.IniciaTransacSQL();
|
|
if (TxtCalibracion.getfiles().Archivos.Count > 0 && CveControl > 0 && continuar)
|
|
{
|
|
|
|
try
|
|
{
|
|
Archivo Archivo = TxtCalibracion.getfiles().Archivos[0];
|
|
string Path = $"{ModExtensiones.DirectorioBaseEmpresas}TablasCalibracion";
|
|
string dirSonido = string.Format(@"{0}\{1}.{2}", Path, FormatearNombreArchivo(Archivo.filenameO), Archivo.Extencion);
|
|
if (File.Exists(dirSonido)) { File.Delete(dirSonido); }
|
|
File.Move(Archivo.FileUrl, dirSonido);
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet());
|
|
ExcelFile EF = ExcelFile.Load(dirSonido);
|
|
ExcelWorksheet Hoja = EF.Worksheets[0];
|
|
CreateDataTableOptions Opciones = new CreateDataTableOptions();
|
|
Opciones.ColumnHeaders = true;
|
|
Opciones.StartRow = 0;
|
|
Opciones.NumberOfColumns = 3;
|
|
Opciones.NumberOfRows = Hoja.Rows.Count;
|
|
Opciones.Resolution = ColumnTypeResolution.AutoPreferStringInvariantCulture;
|
|
DataTable TempDT = Hoja.CreateDataTable(Opciones);
|
|
if (TempDT.Columns[0].ColumnName != "Nivel Varilla")
|
|
{
|
|
Alert("El nombre de la primera columna debe ser 'Nivel Varilla'.Favor de corregirlo", ModExtensiones.TipoMensaje.MsgError);
|
|
continuar = false;
|
|
}
|
|
if (TempDT.Columns[1].ColumnName != "Valor")
|
|
{
|
|
Alert("El nombre de la segunda columna debe ser 'Valor'.Favor de corregirlo", ModExtensiones.TipoMensaje.MsgError);
|
|
continuar = false;
|
|
}
|
|
|
|
if (continuar)
|
|
{
|
|
foreach (DataRow row in TempDT.Select("[Nivel Varilla]>0"))
|
|
{
|
|
double Nivel = row["Nivel Varilla"].ToString().ToDouble();
|
|
double Valor = row["Valor"].ToString().ToDouble();
|
|
if (!ObjGPS.CalibracionAdd(Nivel, Valor, CveControl))
|
|
{
|
|
continuar = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (continuar) { continuar = ObjGPS.EjecutaCalibracion(); }
|
|
}
|
|
catch
|
|
{
|
|
continuar = false;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
GridView GVCalibracion = GvRow.FCGridView("GVCalibracion");
|
|
ObjGPS.CalibracionGet(0, CveControl);
|
|
GVCalibracion.DataSource = ObjGPS.DtResultados;
|
|
GVCalibracion.DataBind();
|
|
ObjGPS.Commit();
|
|
Alert("Calibración actualizada");
|
|
}
|
|
else
|
|
{
|
|
ObjGPS.RollBack();
|
|
}
|
|
ObjGPS.Dispose();
|
|
LnkupCalibracion.Visible = true;
|
|
PnlUpCalibracion.Visible = false;
|
|
}
|
|
|
|
protected void LnkupCalibracion_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
Panel PnlUpCalibracion = (Panel)GvRow.FindControl("PnlUpCalibracion");
|
|
LinkButton LnkupCalibracion = (LinkButton)GvRow.FindControl("LnkupCalibracion");
|
|
LinkButton LnkGuardarSensor = (LinkButton)GvRow.FindControl("LnkGuardarSensor");
|
|
LnkupCalibracion.Visible = false;
|
|
PnlUpCalibracion.Visible = true;
|
|
RegistraScript($"setTimeout(function () {{$('html, body').animate({{scrollTop: ($('#{LnkGuardarSensor.ClientID}').first().offset().top)}},500);}}, 200);");
|
|
}
|
|
#endregion
|
|
#region Usuarios
|
|
protected void CargaUsuarios()
|
|
{
|
|
|
|
GvUsuarios.DataSource = get_GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa, CveCliente, -1);
|
|
GvUsuarios.DataBind();
|
|
|
|
}
|
|
protected void cargaUsuariosDispositivo()
|
|
{
|
|
DataTable dtuser;
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
ObjGPS.DispositivosUsuariosGet(CveDispositivo, -1, CveCliente);
|
|
dtuser = ObjGPS.DtResultados;
|
|
foreach (GridViewRow gvRow in GvUsuarios.Rows)
|
|
{
|
|
CheckBox ChkPermitir = gvRow.FCCheckBox("ChkPermitir");
|
|
int CveUsuario = gvRow.DataKey("CveUsuario").ToEntero();
|
|
if (dtuser.COUNT("CveUsuario", string.Format("CveUsuario={0}", CveUsuario)) > 0)
|
|
{
|
|
ChkPermitir.Checked = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
protected void LnkGuardarUsuarios_Click(object sender, EventArgs e)
|
|
{
|
|
bool continuar = true;
|
|
ClsSisUsuarios ObjUsuarios = new ClsSisUsuarios();
|
|
ObjUsuarios.IniciaTransacSQL();
|
|
foreach (GridViewRow row in GvUsuarios.Rows)
|
|
{
|
|
if (!ObjUsuarios.UpdateUsuariosDispositivos(row.DataKey("CveUsuario").ToEntero(), CveDispositivo, row.FCCheckBox("ChkPermitir").Checked))
|
|
{
|
|
continuar = false;
|
|
break;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
ObjUsuarios.Commit();
|
|
if (GPSNEW == 1) { TabContainer.ActiveTabIndex = 5; }
|
|
Alert("Se ha actualizado Correctamente");
|
|
}
|
|
else
|
|
{
|
|
ObjUsuarios.RollBack();
|
|
}
|
|
ObjUsuarios.Dispose();
|
|
}
|
|
#endregion
|
|
|
|
#region Conductores
|
|
private void CargaConductores()
|
|
{
|
|
ClsGPS GPS = new ClsGPS();
|
|
if (GPS.ConductoresGet(-1, "-1", 1, CveCliente))
|
|
GvConductores.DataSource = GPS.DtResultados.FiltraParametros($"CveDispositivo is NULL OR CveDispositivo = {CveDispositivo}");
|
|
else
|
|
GvConductores.DataSource = null;
|
|
GPS.Dispose();
|
|
GvConductores.DataBind();
|
|
UpConductores.Update();
|
|
}
|
|
|
|
protected void LnkUpConductor_Click(object sender, EventArgs e)
|
|
{
|
|
ClsGPS ObjGPS = new ClsGPS();
|
|
if (ObjGPS.ConductorDispositivoUpdate(CveConductor, CveDispositivo))
|
|
{
|
|
Alert("El conductor se ha actualizado");
|
|
}
|
|
ObjGPS.Dispose();
|
|
|
|
}
|
|
protected void imgEC_Click(object sender, EventArgs e)
|
|
{
|
|
var Boton = (LinkButton)sender;
|
|
CveConductor = Boton.CommandArgument.ToEntero();
|
|
GridViewRow GvRow = (GridViewRow)Boton.NamingContainer;
|
|
TxtSerieLicencia.Text = GvRow.DataKey("SerieLicencia").ToString();
|
|
TxtConductor.Text = GvRow.DataKey("Conductor").ToString();
|
|
TxtFechaVenc.Text = GvRow.DataKey("VencimientoLicencia").ToString();
|
|
TxtFechaNacimiento.Text = GvRow.DataKey("FechaNacimiento").ToString();
|
|
chkEstatus.Checked = System.Convert.ToBoolean(GvRow.DataKey("Estatus"));
|
|
EsEditar = 1;
|
|
myModalLabel.InnerHtml = "Actualizar Conductor";
|
|
LnkAddConductor.Text = "Actualizar";
|
|
dvEstatus.Visible = true;
|
|
UpAgregarConductor.Update();
|
|
RegistraScript("$('#divAgregar').modal()");
|
|
}
|
|
protected void BtnAgregarConductor_Click(object sender, EventArgs e)
|
|
{
|
|
TxtConductor.Text = "";
|
|
TxtSerieLicencia.Text = "";
|
|
myModalLabel.InnerHtml = "Agregar Conductor";
|
|
LnkAddConductor.Text = "Guardar";
|
|
TxtFechaVenc.Text = "";
|
|
TxtFechaNacimiento.Text = "";
|
|
dvEstatus.Visible = false;
|
|
UpAgregarConductor.Update();
|
|
RegistraScript("$('#divAgregar').modal({backdrop: 'static', keyboard: false});");
|
|
}
|
|
protected void LnkAddConductor_Click(object sender, EventArgs e)
|
|
{
|
|
ClsGPS GPS = new ClsGPS();
|
|
|
|
if (EsEditar == 0)
|
|
{
|
|
if (GPS.ConductorAdd(TxtConductor.Text.Trim(), true, UsuarioActual.CveUsuario, TxtSerie.Text, TxtFechaNacimiento.Text.Trim().ToDate(), TxtFechaVenc.Text.Trim().ToDate(), CveCliente))
|
|
Alert("El conductor se agregó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
else
|
|
Alert("Ocurrió un error al agregar el conductor", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
else if (GPS.ConductoresUpdate(CveConductor, TxtConductor.Text.Trim(), chkEstatus.Checked, TxtSerieLicencia.Text, TxtFechaNacimiento.Text.Trim().ToDate(), TxtFechaVenc.Text.Trim().ToDate()))
|
|
Alert("El conductor se agregó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
RegistraScript("$('#divAgregar').modal('hide')");
|
|
GPS.Dispose();
|
|
TxtConductor.Text = "";
|
|
TxtSerieLicencia.Text = "";
|
|
TxtFechaVenc.Text = "";
|
|
TxtFechaNacimiento.Text = "";
|
|
EsEditar = 0;
|
|
|
|
CargaConductores();
|
|
UpAgregarConductor.Update();
|
|
}
|
|
#endregion
|
|
|
|
//otros metodos
|
|
public string FormatearNombreArchivo(string nombreArchivoOriginal)
|
|
{
|
|
string nombreArchivoFormateado;
|
|
nombreArchivoFormateado = nombreArchivoOriginal.Replace(" ", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("'", "");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace(((char)34).ToString(), "");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("$", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("#", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("%", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("!", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("&", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("?", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¿", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¡", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("*", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("~", "_");
|
|
nombreArchivoFormateado = nombreArchivoFormateado.Replace("^", "_");
|
|
return nombreArchivoFormateado;
|
|
}
|
|
|
|
protected void ChkTipoLinea_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
DivLinea.Visible = !ChkTipoLinea.Checked;
|
|
DivTelefono.Visible = ChkTipoLinea.Checked;
|
|
|
|
UpModelo.Update();
|
|
Updatos.Update();
|
|
}
|
|
} |