Envio de correo Tareas 119

This commit is contained in:
Rakcsle Supertramp
2020-07-06 11:55:10 -07:00
parent 78419dc0bb
commit e3b83c84f0

View File

@@ -9,6 +9,7 @@ using System.Web.Services;
using System.Web.Services.Protocols; using System.Web.Services.Protocols;
using GemBox.Spreadsheet; using GemBox.Spreadsheet;
using System.Data; using System.Data;
using System.Text;
public class TareasJam : IHttpHandler public class TareasJam : IHttpHandler
{ {
@@ -46,6 +47,9 @@ public class TareasJam : IHttpHandler
private bool EjecutaThalamus(int CveEmpresa) private bool EjecutaThalamus(int CveEmpresa)
{ {
bool Respuesta = false;
StringBuilder SBLog = new StringBuilder();
ClsGenerales ObjGenerales = new ClsGenerales(); ClsGenerales ObjGenerales = new ClsGenerales();
DataTable DTProductos = new DataTable(); DataTable DTProductos = new DataTable();
@@ -53,53 +57,98 @@ public class TareasJam : IHttpHandler
DataTable DTClientes = new DataTable(); DataTable DTClientes = new DataTable();
DataTable DTAlmacenes = new DataTable(); DataTable DTAlmacenes = new DataTable();
string FTPServer = "ftp://127.0.0.1/";
string TFPUsr = "Toor";
string FTPPass = "agj-3500";
bool ErrorProceso = false; bool ErrorProceso = false;
SBLog.AppendLine("<b>Consultas</b><br>");
SBLog.AppendLine("<table border='1'><tr><th>Consulta</th><th>Registros</th></tr>");
if (ObjGenerales.GetJAMCorveta(1)) if (ObjGenerales.GetJAMCorveta(1))
{ {
DTProductos = ObjGenerales.DtResultados.Copy(); DTProductos = ObjGenerales.DtResultados.Copy();
SBLog.AppendLine($"<tr><td>Productos</td><td>{DTProductos.Rows.Count}</td></tr>");
}
else {
ErrorProceso = true;
SBLog.AppendLine($"<tr><td>Productos</td><td>Error al consultar</td></tr>");
} }
else { ErrorProceso = true; }
if (ObjGenerales.GetJAMCorveta(2)) if (ObjGenerales.GetJAMCorveta(2) & ErrorProceso == false)
{ {
DTVentas = ObjGenerales.DtResultados.Copy(); DTVentas = ObjGenerales.DtResultados.Copy();
SBLog.AppendLine($"<tr>Ventas<td></td><td>{DTVentas.Rows.Count}</td></tr>");
}
else
{
ErrorProceso = true;
SBLog.AppendLine($"<tr><td>Ventas</td><td>Error al consultar</td></tr>");
} }
else { ErrorProceso = true; }
if (ObjGenerales.GetJAMCorveta(3)) if (ObjGenerales.GetJAMCorveta(3) & ErrorProceso == false)
{ {
DTClientes = ObjGenerales.DtResultados.Copy(); DTClientes = ObjGenerales.DtResultados.Copy();
} SBLog.AppendLine($"<tr><td>Clientes</td><td>{DTClientes.Rows.Count}</td></tr>");
else { ErrorProceso = true; }
if (ObjGenerales.GetJAMCorveta(4)) }
else {
ErrorProceso = true;
SBLog.AppendLine($"<tr><td>Clientes</td><td>Error al consultar</td></tr>");
}
if (ObjGenerales.GetJAMCorveta(4) & ErrorProceso == false)
{ {
DTAlmacenes = ObjGenerales.DtResultados.Copy(); DTAlmacenes = ObjGenerales.DtResultados.Copy();
SBLog.AppendLine($"<tr><td>Almacenes</td><td>{DTAlmacenes.Rows.Count}</td></tr>");
} }
else { ErrorProceso = true; } else {
ErrorProceso = true;
SBLog.AppendLine($"<tr><td>Almacenes</td><td>Error al consultar</td></tr>");
}
SBLog.AppendLine("</table>");
SBLog.AppendLine("<br>");
ObjGenerales.Dispose(); ObjGenerales.Dispose();
DTProductos.Columns[0].ColumnName = "Código Producto Interno "; if (!ErrorProceso)
DTProductos.Columns[1].ColumnName = "Nombre del Producto"; {
DTProductos.Columns[2].ColumnName = "Presentación";
DTProductos.AcceptChanges(); try
{
DTProductos.Columns[0].ColumnName = "Código Producto Interno ";
DTProductos.Columns[1].ColumnName = "Nombre del Producto";
DTProductos.Columns[2].ColumnName = "Presentación";
DTProductos.AcceptChanges();
DTClientes.Columns[4].ColumnName = "address.countryId"; DTClientes.Columns[4].ColumnName = "address.countryId";
DTClientes.Columns[5].ColumnName = "address.stateId"; DTClientes.Columns[5].ColumnName = "address.stateId";
DTClientes.Columns[6].ColumnName = "address.city"; DTClientes.Columns[6].ColumnName = "address.city";
DTClientes.Columns[7].ColumnName = "address.street1"; DTClientes.Columns[7].ColumnName = "address.street1";
DTClientes.Columns[8].ColumnName = "address.street2"; DTClientes.Columns[8].ColumnName = "address.street2";
DTClientes.Columns[9].ColumnName = "address.postalCode"; DTClientes.Columns[9].ColumnName = "address.postalCode";
DTClientes.Columns[9].ColumnName = "phone.intCode"; DTClientes.Columns[9].ColumnName = "phone.intCode";
DTClientes.Columns[9].ColumnName = "phone.areaCode"; DTClientes.Columns[9].ColumnName = "phone.areaCode";
DTClientes.Columns[9].ColumnName = "phone.number"; DTClientes.Columns[9].ColumnName = "phone.number";
DTClientes.Dispose(); DTClientes.Dispose();
DTVentas.Columns.RemoveAt(7);
DTVentas.AcceptChanges();
}
catch (Exception e)
{
SBLog.AppendLine("<b>Error al renombrar columnas</b>");
}
}
DTVentas.Columns.RemoveAt(7);
DTVentas.AcceptChanges();
if (!ErrorProceso) if (!ErrorProceso)
@@ -109,11 +158,6 @@ public class TareasJam : IHttpHandler
string RutaClientes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Clientes{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; string RutaClientes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Clientes{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
string RutaAlmacenes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Almacenes{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; string RutaAlmacenes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Almacenes{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
string FTPServer = "ftp://127.0.0.1/";
string TFPUsr = "Toor";
string FTPPass = "agj-3500";
SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet()); SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet());
var workbookProductos = new ExcelFile(); var workbookProductos = new ExcelFile();
@@ -160,18 +204,30 @@ public class TareasJam : IHttpHandler
var FInfoClientes = new FileInfo(RutaClientes); var FInfoClientes = new FileInfo(RutaClientes);
var FInfoAlmacenes = new FileInfo(RutaAlmacenes); var FInfoAlmacenes = new FileInfo(RutaAlmacenes);
bool CargaProductos = false; bool CargaProductos = false;
bool CargaVentas = false; bool CargaVentas = false;
bool CargaClientes = false; bool CargaClientes = false;
bool CargaAlmacenes = false; bool CargaAlmacenes = false;
SBLog.AppendLine("<b>Cargas</b><br>");
SBLog.AppendLine("<table border='1'> <tr><th>Archivo</th><th>Estado</th></tr>");
CargaProductos = CargarArchivos(FInfoProductos, FTPServer, TFPUsr, FTPPass); CargaProductos = CargarArchivos(FInfoProductos, FTPServer, TFPUsr, FTPPass);
if (CargaProductos) if (CargaProductos)
{ {
CargaProductos = VerificarArchivo(FInfoProductos, FInfoProductos.Length, FTPServer, TFPUsr, FTPPass); CargaProductos = VerificarArchivo(FInfoProductos, FInfoProductos.Length, FTPServer, TFPUsr, FTPPass);
} }
if (CargaProductos)
{
SBLog.AppendLine($"<tr><td>Productos</td><td>ok</td></tr>");
}
else
{
SBLog.AppendLine($"<tr><td>Productos</td><td>Error carga</td></tr>");
}
if (CargaProductos) if (CargaProductos)
{ {
CargaVentas = CargarArchivos(FInfoVentas, FTPServer, TFPUsr, FTPPass); CargaVentas = CargarArchivos(FInfoVentas, FTPServer, TFPUsr, FTPPass);
@@ -181,6 +237,14 @@ public class TareasJam : IHttpHandler
} }
} }
if (CargaVentas)
{
SBLog.AppendLine($"<tr><td>Ventas</td><td>ok</td></tr>");
}else
{
SBLog.AppendLine($"<tr><td>Ventas</td><td>Error carga</td></tr>");
}
if (CargaProductos & CargaVentas) if (CargaProductos & CargaVentas)
{ {
CargaClientes = CargarArchivos(FInfoClientes, FTPServer, TFPUsr, FTPPass); CargaClientes = CargarArchivos(FInfoClientes, FTPServer, TFPUsr, FTPPass);
@@ -190,6 +254,13 @@ public class TareasJam : IHttpHandler
} }
} }
if (CargaClientes)
{
SBLog.AppendLine($"<tr><td>Clientes</td><td>ok</td></tr>");
}else
{
SBLog.AppendLine($"<tr><td>Clientes</td><td>Error carga</td></tr>");
}
if (CargaProductos & CargaVentas& CargaClientes ) if (CargaProductos & CargaVentas& CargaClientes )
{ {
@@ -200,25 +271,60 @@ public class TareasJam : IHttpHandler
} }
} }
if (CargaAlmacenes)
{
SBLog.AppendLine($"<tr><td>Almacenes</td><td>ok</td></tr>");
}else
{
SBLog.AppendLine($"<tr><td>Almacenes</td><td>Error carga</td></tr>");
}
if (CargaProductos & CargaVentas & CargaClientes & CargaAlmacenes) if (CargaProductos & CargaVentas & CargaClientes & CargaAlmacenes)
{ {
return true; Respuesta = true;
} }
else else
{ {
return false; Respuesta = false;
} }
SBLog.AppendLine("</table>");
} }
else else
{ {
return false; Respuesta = false;
} }
string Cuerpo = Respuesta ? $"<b>Correcto</b><br>Tarea de carga de archios Corteva realizada correctamente<br> {SBLog.ToString()}" : $"<b>Error</b><br> Error tarea de carga de archios Corteva<br> {SBLog.ToString()}" ;
MandaCorreo(Cuerpo, Respuesta);
return Respuesta;
} }
private void MandaCorreo(string Cuerpo, bool ErrorProceso)
{
try
{
ClsSisMail Correo = new ClsSisMail();
//string Para = "julian@adssistemas.mx;rene.molina@adssistemas.mx;oscar.irigoyen@adssistemas.mx";
string Para = "oscar.irigoyen@adssistemas.mx";
string Asunto = ErrorProceso ? $"Carga Layout Corteva {DateTime.Now.ToString("yyyy-MM-dd")}" : $"Carga Layout Corteva Error {DateTime.Now.ToString("yyyy-MM-dd")}";
Correo.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Cuerpo);
}catch(Exception ex)
{
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 error enviar mail --> {ex.Message} ");
}
}
private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass) private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass)
{ {