From 03f0726425ca35d086d24e3acc3fdc90e9365f87 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Wed, 17 Jun 2020 21:17:47 -0700 Subject: [PATCH] tarea web terminada, falta cargar la imagen de la entrega --- TareasProgramadas/Tareas72.ashx | 134 ++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 TareasProgramadas/Tareas72.ashx diff --git a/TareasProgramadas/Tareas72.ashx b/TareasProgramadas/Tareas72.ashx new file mode 100644 index 000000000..1edc5d88a --- /dev/null +++ b/TareasProgramadas/Tareas72.ashx @@ -0,0 +1,134 @@ +<%@ WebHandler Language="C#" Class="Tareas72" %> + +using System; +using System.Web; +using System.Data; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Extensiones; +using System.IO; +using Microsoft.Reporting.WebForms; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Text; +public class Tareas72 : IHttpHandler +{ + + public void ProcessRequest(HttpContext context) + { + context.Response.ContentType = "text/plain"; + context.Response.Write("Hello World"); + + bool retorno = false; + string Metodo = context.Request["Metodo"] == null ? "" : context.Request["Metodo"]; + switch (Metodo) + { + case "ActualizarProcesoPaqueterias": + retorno = ActualizarProcesoPaqueterias(); + break; + } + + context.Response.Write(retorno); + context.Response.End(); + } + + private bool ActualizarProcesoPaqueterias() + { + bool retorno = true; + ClsGenerales ObjGenerales = new ClsGenerales(); + ClsClientes ObjClientes = new ClsClientes(); + ClsVentas ObjVentas = new ClsVentas(); + ClsVtaVendedores ObjVendedores = new ClsVtaVendedores(); + ClsSisMail Correo = new ClsSisMail(); + + ClsSisEmpresas ObjEmpresa = new ClsSisEmpresas(); + Empresa Empresa = new Empresa(); + if (ObjEmpresa.GetEmpresas(72, "-1", "-1", "-1", "-1")) + { + Empresa = ObjEmpresa.Empresa; + } + try + { + if (ObjGenerales.GetPaqueteriasGuias(-1, -1, 7, 1, -1, 72, "-1", "01/01/1990", "01/01/2100")) + { + DataRowCollection GuiasPendientes = ObjGenerales.DtResultados.Rows; + foreach (DataRow Guia in GuiasPendientes) + { + int CvePaqueteriaGuia = Guia["CvePaqueteriaGuia"].ToString().ToEntero(); + string GuiaConsultar = Guia["Guia"].ToString(); + + //CONSULTAMOS CADA GUIA EN LA SIGUIENTE API + string uriConsultaGuia = string.Format("https://cc.paquetexpress.com.mx/ptxws/rest/api/v2/guia/historico/ultimoevento/{0}/@1@2@3@4@5", GuiaConsultar); + HttpClient Client = new HttpClient(); + HttpResponseMessage ResponseMessage = Client.GetAsync(uriConsultaGuia).Result; + string JsonString = ResponseMessage.Content.ReadAsStringAsync().Result; + string JsonStringFormat = JsonString.Replace("Resultado(", "{\"Resultado\":").Replace(")", "}"); + DataSet dataSet = JsonConvert.DeserializeObject(JsonStringFormat); + DataTable dataTable = dataSet.Tables["Resultado"]; + if (dataTable.Rows[0]["eventoId"].ToString() == "Hdc") + { + int EstatusEntregado = 3; + + //MANDAMOS A ACTUALIZAR CON ESTATUS DE ENTREGADO + if (ObjGenerales.UpdatePaqueteriasGuias(CvePaqueteriaGuia, -1, -1, -1, EstatusEntregado, "-1", "", "", -1, -1, "-1", "-1", "")) + { + #region 'MANDAR CORREOS' + int CveCliente = Guia["CveCliente"].ToString().ToEntero(); + int CveVenta = Guia["CveAgrupador"].ToString().ToEntero(); + StringBuilder correos = new StringBuilder(""); + + if (ObjClientes.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, -1)) + { + if (ObjClientes.DtResultados.Rows.Count > 0) + { + DataRow DatosCliente = ObjClientes.DtResultados.Rows[0]; + if (DatosCliente["CorreoEntregaCompras"].ToString().Length > 0) correos.Append(string.Format("{0};", DatosCliente["CorreoEntregaCompras"].ToString())); + if (DatosCliente["CorreoEntregaAlmacen"].ToString().Length > 0) correos.Append(string.Format("{0};", DatosCliente["CorreoEntregaAlmacen"].ToString())); + } + } + + if (ObjVentas.GetVenta(CveVenta, 72)) + { + if (ObjVentas.DtResultados.Rows.Count > 0) + { + int CveVendedor = ObjVentas.DtResultados.Rows[0]["CveVendedor"].ToEntero(); + if (ObjVendedores.GetVendedores(72)) + { + DataRow DatosVendedor = ObjVendedores.DtResultados.FiltroPrimero(string.Format("CveVendedor = {0}", CveVendedor)); + if (DatosVendedor["Correo"].ToString().Length > 0) correos.Append(string.Format("{0};", DatosVendedor["Correo"].ToString())); + if (DatosVendedor["CorreoAdicionalNotificaciones"].ToString().Length > 0) correos.Append(string.Format("{0};", DatosVendedor["CorreoAdicionalNotificaciones"].ToString())); + } + } + } + string CorreosString = correos.ToString(); + if (CorreosString.Length > 0) + { + Correo.SendMail(Empresa, correos.ToString(), "Actualización de paqueterias entregadas", ""); + } + #endregion + } + } + } + } + } + catch (Exception e) + { + ModExtensiones.GuardaLogAD(string.Format("{3} CveEmpresa={0} cveTareaProgramada={1} CveTareaProgramadaHistorial={2}", 72, "", "", e.Message), "Tareas Programadas"); + retorno = false; + } + + ObjGenerales.Dispose(); + ObjClientes.Dispose(); + ObjVentas.Dispose(); + ObjVendedores.Dispose(); + ObjEmpresa.Dispose(); + return false; + } + + public bool IsReusable + { + get { return false; } + } + +} \ No newline at end of file