146 lines
5.2 KiB
C#
146 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using System.Data;
|
|
using System.Net;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.IO;
|
|
using Microsoft.Reporting.WebForms;
|
|
|
|
public partial class GPS_RepIgnicion : ClsPaginas
|
|
{
|
|
#region "P R O P I E D A D E S"
|
|
private DataTable DtIgniciones
|
|
{
|
|
get
|
|
{
|
|
return ((DataTable)(ViewState["DtIgniciones"]));
|
|
}
|
|
set
|
|
{
|
|
ViewState["DtIgniciones"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CargaFecha();
|
|
CargaDispositivos();
|
|
UPFiltros.Update();
|
|
}
|
|
}
|
|
private void CargaFecha()
|
|
{
|
|
txtFechaI.Text = $"{DateTime.Now.AddDays(-7).ToString("dd/MM/yyyy")} 00:00";
|
|
txtFechaF.Text = $"{DateTime.Now.ToString("dd/MM/yyyy")} 23:59";
|
|
}
|
|
private void CargaDispositivos()
|
|
{
|
|
DdlDispositivo.DataSource = get_GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario);
|
|
DdlDispositivo.DataBind();
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
using (var ObjGPS = new ClsGPS())
|
|
{
|
|
int CveDispositivo = DdlDispositivo.SelectedValue.ToEntero();
|
|
DateTime FechaI = txtFechaI.Text.ToDateTime(), FechaF = txtFechaF.Text.ToDateTime();
|
|
|
|
if (ObjGPS.GetRepIgnicion(CveDispositivo, FechaI, FechaF, UsuarioActual.CveCliente))
|
|
{
|
|
DtIgniciones = ObjGPS.DtResultados;
|
|
GvIgnicion.DataSource = DtIgniciones;
|
|
GvIgnicion.DataBind();
|
|
LnkImprimirPDF.Visible = true;
|
|
LnkImprimirEXCEL.Visible = true;
|
|
}
|
|
}
|
|
UpDatos.Update();
|
|
}
|
|
|
|
protected void GvIgnicion_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
CargaDireccion(e.Row.DBCampo("LatitudInicial"), e.Row.DBCampo("LongitudInicial"), "DireccionInical", "LtlDireccionInicial", e.Row);
|
|
CargaDireccion(e.Row.DBCampo("LatitudFinal"), e.Row.DBCampo("LongitudFinal"), "DireccionFinal", "LtlDireccionFinal", e.Row);
|
|
}
|
|
}
|
|
private void CargaDireccion(string lat, string lng, string campo, string control, GridViewRow row)
|
|
{
|
|
try
|
|
{
|
|
string DireccionJSON = "";
|
|
WebRequest request;
|
|
JObject js = null;
|
|
request = WebRequest.Create(String.Format("{0}nominatim/reverse.php?format=jsonv2&lat={1}&lon={2}", ClsPaginas.UrlDirecciones, lat, lng));
|
|
request.Method = "GET";
|
|
WebResponse response = request.GetResponse();
|
|
Stream inputstream1 = response.GetResponseStream();
|
|
StreamReader reader = new StreamReader(inputstream1);
|
|
DireccionJSON = reader.ReadToEnd();
|
|
inputstream1.Dispose();
|
|
reader.Close();
|
|
response.Close();
|
|
request = null;
|
|
js = JObject.Parse(DireccionJSON);
|
|
if (js != null)
|
|
{
|
|
DtIgniciones.Rows[row.RowIndex][campo] = js["display_name"].ToString();
|
|
row.FCLiteral(control).Text = js["display_name"].ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.GuardaLog(ex.ToString());
|
|
}
|
|
}
|
|
|
|
protected void LnkImprimirPDF_Click(object sender, EventArgs e)
|
|
{
|
|
EnviarReporteProgramado("PDF");
|
|
}
|
|
protected void LnkImprimirEXCEL_Click(object sender, EventArgs e)
|
|
{
|
|
EnviarReporteProgramado("EXCEL");
|
|
}
|
|
public void EnviarReporteProgramado(string Formato = "PDF")
|
|
{
|
|
if (DtIgniciones != null)
|
|
{
|
|
byte[] retorno;
|
|
string RutaReporte = ModExtensiones.DirectorioBaseEmpresas + "Empresas/Grales/ReportesProgramados/RPIgnicion.rdlc";
|
|
|
|
try
|
|
{
|
|
List<ReportParameter> RptParametro = new List<ReportParameter>();
|
|
RptParametro.Add(new ReportParameter("FechaInicio", txtFechaI.Text.ToDateTime().ToString("dd/MM/yyyy HH:mm")));
|
|
RptParametro.Add(new ReportParameter("FechaFin", txtFechaF.Text.ToDateTime().ToString("dd/MM/yyyy HH:mm")));
|
|
RptParametro.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Usuario));
|
|
RptParametro.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToString("dd/MM/yyyy HH:mm tt")));
|
|
|
|
retorno = StreamPDF(RutaReporte, DtIgniciones, RptParametro, "ReporteEventos", Formato, "DsOC");
|
|
// TODO: Labeled Arguments not supported. Argument: 6 := 'MR'
|
|
// TODO: Labeled Arguments not supported. Argument: 7 := 'RDSName'
|
|
ImprimirbytesPDF(retorno, "ReporteEventos", Formato: Formato);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.GuardaLog(string.Format("Ocurrio un error al generar el reporte RLDC {0}", ex));
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Alert("No se pudo imprimir el pdf, ya que no se ha hecho una consulta, o esta no arrojo resultados.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
|
|
}
|
|
} |