Tareas Programadas 119
This commit is contained in:
BIN
TareasProgramadas/FormatosThalamus/FormatoAlmacenes.xlsx
Normal file
BIN
TareasProgramadas/FormatosThalamus/FormatoAlmacenes.xlsx
Normal file
Binary file not shown.
BIN
TareasProgramadas/FormatosThalamus/FormatoClientes.xlsx
Normal file
BIN
TareasProgramadas/FormatosThalamus/FormatoClientes.xlsx
Normal file
Binary file not shown.
BIN
TareasProgramadas/FormatosThalamus/FormatoProductos.xlsx
Normal file
BIN
TareasProgramadas/FormatosThalamus/FormatoProductos.xlsx
Normal file
Binary file not shown.
BIN
TareasProgramadas/FormatosThalamus/FormatoVentas.xlsx
Normal file
BIN
TareasProgramadas/FormatosThalamus/FormatoVentas.xlsx
Normal file
Binary file not shown.
@@ -10,7 +10,8 @@ using System.Web.Services.Protocols;
|
|||||||
using GemBox.Spreadsheet;
|
using GemBox.Spreadsheet;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using ClosedXML;
|
||||||
|
|
||||||
public class TareasJam : IHttpHandler
|
public class TareasJam : IHttpHandler
|
||||||
{
|
{
|
||||||
@@ -63,6 +64,13 @@ 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 FormatoVentas = $@"{ HttpContext.Current.Server.MapPath("~") }\TareasProgramadas\FormatosThalamus\FormatoVentas.xlsx";
|
||||||
|
string FormatoClientes = $@"{ HttpContext.Current.Server.MapPath("~") }\TareasProgramadas\FormatosThalamus\FormatoClientes.xlsx";
|
||||||
|
string FormatoAlmacenes = $@"{ HttpContext.Current.Server.MapPath("~") }\TareasProgramadas\FormatosThalamus\FormatoAlmacenes.xlsx";
|
||||||
|
string FormatoProductos = $@"{ HttpContext.Current.Server.MapPath("~") }\TareasProgramadas\FormatosThalamus\FormatoProductos.xlsx";
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(RutaProductos))
|
if (File.Exists(RutaProductos))
|
||||||
@@ -91,14 +99,14 @@ public class TareasJam : IHttpHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string FTPServer = "ftp://127.0.0.1/";
|
//string FTPServer = "ftp://127.0.0.1/";
|
||||||
string TFPUsr = "Toor";
|
//string TFPUsr = "Toor";
|
||||||
string FTPPass = "agj-3500";
|
//string FTPPass = "agj-3500";
|
||||||
|
|
||||||
|
|
||||||
//string FTPServer = "ftp://us2.hostedftp.com";
|
string FTPServer = "ftp://us2.hostedftp.com";
|
||||||
//string TFPUsr = "agrojam";
|
string TFPUsr = "agrojam";
|
||||||
//string FTPPass = "A12345678";
|
string FTPPass = "A12345678";
|
||||||
|
|
||||||
bool ErrorProceso = false;
|
bool ErrorProceso = false;
|
||||||
|
|
||||||
@@ -158,7 +166,7 @@ public class TareasJam : IHttpHandler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
DTProductos.Columns[0].ColumnName = "Código Producto Interno ";
|
DTProductos.Columns[0].ColumnName = "Código Producto Interno";
|
||||||
DTProductos.Columns[1].ColumnName = "Nombre del Producto";
|
DTProductos.Columns[1].ColumnName = "Nombre del Producto";
|
||||||
DTProductos.Columns[2].ColumnName = "Presentación";
|
DTProductos.Columns[2].ColumnName = "Presentación";
|
||||||
DTProductos.AcceptChanges();
|
DTProductos.AcceptChanges();
|
||||||
@@ -196,9 +204,6 @@ public class TareasJam : IHttpHandler
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DataTable dtCloned = DTVentas.Clone();
|
DataTable dtCloned = DTVentas.Clone();
|
||||||
dtCloned.Columns[3].DataType = typeof(string);
|
dtCloned.Columns[3].DataType = typeof(string);
|
||||||
|
|
||||||
@@ -210,7 +215,7 @@ public class TareasJam : IHttpHandler
|
|||||||
DTVentas = dtCloned;
|
DTVentas = dtCloned;
|
||||||
foreach (DataRow dRow in DTVentas.Rows)
|
foreach (DataRow dRow in DTVentas.Rows)
|
||||||
{
|
{
|
||||||
string tmpDate = dRow[3].ToString().ToDate().ToString("yyyy/MM/dd");//.ToDate().ToString("yyyy/MM/dd").ToDate();
|
string tmpDate = dRow[3].ToString().ToDate().ToString("yyyy/MM/dd");
|
||||||
dRow[3] = tmpDate;
|
dRow[3] = tmpDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,106 +233,98 @@ public class TareasJam : IHttpHandler
|
|||||||
DTAlmacenes = dtCloned;
|
DTAlmacenes = dtCloned;
|
||||||
foreach (DataRow dRow in DTAlmacenes.Rows)
|
foreach (DataRow dRow in DTAlmacenes.Rows)
|
||||||
{
|
{
|
||||||
//DateTime tmpDate = dRow[3].ToString().ToDate().ToString("yyyy/MM/dd").ToDate();
|
|
||||||
string tmpDate = dRow[3].ToString().ToDate().ToString("yyyy/MM/dd");
|
string tmpDate = dRow[3].ToString().ToDate().ToString("yyyy/MM/dd");
|
||||||
dRow[3] = tmpDate;
|
dRow[3] = tmpDate;
|
||||||
}
|
}
|
||||||
DTAlmacenes.AcceptChanges();
|
DTAlmacenes.AcceptChanges();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
SBLog.AppendLine("<b>Error al renombrar columnas</b>");
|
SBLog.AppendLine("<b>Error al renombrar columnas</b>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!ErrorProceso)
|
if (!ErrorProceso)
|
||||||
{
|
{
|
||||||
|
|
||||||
int contador = 0;
|
|
||||||
|
|
||||||
SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet());
|
//////////////////////////////////////////////////////////////
|
||||||
|
int count = 2;
|
||||||
|
var wbVentas = new ClosedXML.Excel.XLWorkbook(FormatoVentas);
|
||||||
|
var wsVentas = wbVentas.Worksheet(1);
|
||||||
|
|
||||||
var workbookAlmacenes = new ExcelFile();
|
foreach (DataRow DRow in DTVentas.Rows)
|
||||||
var worksheetAlmacenes = workbookAlmacenes.Worksheets.Add("Almacenes");
|
|
||||||
worksheetAlmacenes.InsertDataTable(DTAlmacenes, new InsertDataTableOptions()
|
|
||||||
{
|
{
|
||||||
ColumnHeaders = true,
|
wsVentas.Cell(count, 1).Value = "'" + DRow["systemId"].ToString();
|
||||||
StartRow = 0
|
wsVentas.Cell(count, 2).Value = DRow["Branch"].ToString();
|
||||||
});
|
wsVentas.Cell(count, 3).Value = "'" + DRow["Code"].ToString();
|
||||||
|
wsVentas.Cell(count, 4).Value = "'" + DRow["Sale Date"].ToString();
|
||||||
|
wsVentas.Cell(count, 5).Value = DRow["Quantity"].ToString();
|
||||||
|
wsVentas.Cell(count, 6).Value = DRow["Amount"].ToString();
|
||||||
|
wsVentas.Cell(count, 7).Value = DRow["Transaction ID"].ToString();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
wbVentas.SaveAs(RutaVentas);
|
||||||
|
|
||||||
|
var wbAlmacenes = new ClosedXML.Excel.XLWorkbook(FormatoAlmacenes);
|
||||||
|
var wsAlmacenes = wbAlmacenes.Worksheet(1);
|
||||||
|
|
||||||
|
count = 2;
|
||||||
|
|
||||||
foreach (DataRow DRow in DTAlmacenes.Rows)
|
foreach (DataRow DRow in DTAlmacenes.Rows)
|
||||||
{
|
{
|
||||||
|
wsAlmacenes.Cell(count, 1).Value = "'" + DRow["Code"].ToString();
|
||||||
//contador++;
|
wsAlmacenes.Cell(count, 2).Value = DRow["Quantity"].ToString();
|
||||||
//var cell = worksheetAlmacenes.Cells[contador, 3];
|
wsAlmacenes.Cell(count, 3).Value = DRow["Description"].ToString();
|
||||||
//cell.Style.WrapText = true;
|
wsAlmacenes.Cell(count, 4).Value = "'" + DRow["Stock Date"].ToString();
|
||||||
|
count++;
|
||||||
|
|
||||||
}
|
}
|
||||||
//worksheetAlmacenes.Columns[3].Style.NumberFormat = "yyyy/MM/dd";
|
wbAlmacenes.SaveAs(RutaAlmacenes);
|
||||||
workbookAlmacenes.Save(RutaAlmacenes);
|
|
||||||
|
|
||||||
var workbookProductos = new ExcelFile();
|
var wbAClientes = new ClosedXML.Excel.XLWorkbook(FormatoClientes);
|
||||||
var worksheetProductos = workbookProductos.Worksheets.Add("Productos");
|
var wsClientes = wbAClientes.Worksheet(1);
|
||||||
worksheetProductos.InsertDataTable(DTProductos, new InsertDataTableOptions()
|
|
||||||
|
count = 2;
|
||||||
|
|
||||||
|
foreach (DataRow DRow in DTClientes.Rows)
|
||||||
{
|
{
|
||||||
ColumnHeaders = true,
|
wsClientes.Cell(count, 1).Value = "'" + DRow["systemId"].ToString();
|
||||||
StartRow = 0
|
wsClientes.Cell(count, 2).Value = DRow["fiscalIdMex"].ToString();
|
||||||
});
|
wsClientes.Cell(count, 3).Value = DRow["fiscalName"].ToString();
|
||||||
workbookProductos.Save(RutaProductos);
|
wsClientes.Cell(count, 4).Value = DRow["email"].ToString();
|
||||||
|
wsClientes.Cell(count, 5).Value = DRow["address.countryId"].ToString();
|
||||||
var workbookVentas = new ExcelFile();
|
wsClientes.Cell(count, 6).Value = DRow["address.stateId"].ToString();
|
||||||
var worksheetVentas = workbookVentas.Worksheets.Add("Ventas");
|
wsClientes.Cell(count, 7).Value = DRow["address.city"].ToString();
|
||||||
worksheetVentas.InsertDataTable(DTVentas, new InsertDataTableOptions()
|
wsClientes.Cell(count, 8).Value = DRow["address.street1"].ToString();
|
||||||
{
|
wsClientes.Cell(count, 9).Value = DRow["address.street2"].ToString();
|
||||||
ColumnHeaders = true,
|
wsClientes.Cell(count, 10).Value = "'" + DRow["address.postalCode"].ToString();
|
||||||
StartRow = 0
|
wsClientes.Cell(count, 11).Value = DRow["phone.intCode"].ToString();
|
||||||
});
|
wsClientes.Cell(count, 12).Value = DRow["phone.areaCode"].ToString();
|
||||||
|
wsClientes.Cell(count, 13).Value = "'" + DRow["phone.number"].ToString();
|
||||||
|
wsClientes.Cell(count, 14).Value = DRow["salesman"].ToString();
|
||||||
contador = 0;
|
|
||||||
foreach (DataRow DRow in DTVentas.Rows)
|
|
||||||
{
|
|
||||||
|
|
||||||
//var value = DateTime.Now;
|
|
||||||
contador++;
|
|
||||||
|
|
||||||
var cell = worksheetVentas.Cells[contador, 3];
|
|
||||||
cell.Style.WrapText = false;
|
|
||||||
cell.Style.IsTextVertical = false;
|
|
||||||
cell.Style.Font.Italic = false;
|
|
||||||
|
|
||||||
//cell.Style.NumberFormat = "h:mm AM/PM"; // "yyyy-MM-dd";
|
|
||||||
//cell.SetValue(value);
|
|
||||||
|
|
||||||
|
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
wbAClientes.SaveAs(RutaClientes);
|
||||||
|
|
||||||
//worksheetVentas.Columns[3].Style.NumberFormat = "yyyy/MM/dd";
|
var wbProductos= new ClosedXML.Excel.XLWorkbook(FormatoProductos);
|
||||||
|
var wsProductos = wbProductos.Worksheet(1);
|
||||||
|
|
||||||
workbookVentas.Save(RutaVentas);
|
count = 2;
|
||||||
|
|
||||||
|
foreach (DataRow DRow in DTProductos.Rows)
|
||||||
var workbookClientes = new ExcelFile();
|
|
||||||
var worksheetClientes = workbookClientes.Worksheets.Add("Clientes");
|
|
||||||
worksheetClientes.InsertDataTable(DTClientes, new InsertDataTableOptions()
|
|
||||||
{
|
{
|
||||||
ColumnHeaders = true,
|
wsProductos.Cell(count, 1).Value = "'" + DRow["Código Producto Interno"].ToString();
|
||||||
StartRow = 0
|
wsProductos.Cell(count, 2).Value = DRow["Nombre del Producto"].ToString();
|
||||||
});
|
wsProductos.Cell(count, 3).Value = DRow["Presentación"].ToString();
|
||||||
workbookClientes.Save(RutaClientes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
wbProductos.SaveAs(RutaProductos);
|
||||||
|
/////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var FInfoProductos = new FileInfo(RutaProductos);
|
var FInfoProductos = new FileInfo(RutaProductos);
|
||||||
var FInfoVentas = new FileInfo(RutaVentas);
|
var FInfoVentas = new FileInfo(RutaVentas);
|
||||||
@@ -363,21 +360,22 @@ public class TareasJam : IHttpHandler
|
|||||||
CargaVentas = CargarArchivos(FInfoVentas, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
CargaVentas = CargarArchivos(FInfoVentas, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
||||||
if (CargaVentas)
|
if (CargaVentas)
|
||||||
{
|
{
|
||||||
CargaVentas = VerificarArchivo(FInfoVentas, FInfoVentas.Length, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
CargaVentas = VerificarArchivo(FInfoVentas, FInfoVentas.Length, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CargaVentas)
|
if (CargaVentas)
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Ventas</td><td>ok</td></tr>");
|
SBLog.AppendLine($"<tr><td>Ventas</td><td>ok</td></tr>");
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Ventas</td><td>Error carga</td></tr>");
|
SBLog.AppendLine($"<tr><td>Ventas</td><td>Error carga</td></tr>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CargaProductos & CargaVentas)
|
if (CargaProductos & CargaVentas)
|
||||||
{
|
{
|
||||||
CargaClientes = CargarArchivos(FInfoClientes, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
CargaClientes = CargarArchivos(FInfoClientes, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
||||||
if (CargaClientes)
|
if (CargaClientes)
|
||||||
{
|
{
|
||||||
CargaClientes = VerificarArchivo(FInfoClientes, FInfoClientes.Length, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
CargaClientes = VerificarArchivo(FInfoClientes, FInfoClientes.Length, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
||||||
@@ -387,12 +385,13 @@ public class TareasJam : IHttpHandler
|
|||||||
if (CargaClientes)
|
if (CargaClientes)
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Clientes</td><td>ok</td></tr>");
|
SBLog.AppendLine($"<tr><td>Clientes</td><td>ok</td></tr>");
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Clientes</td><td>Error carga</td></tr>");
|
SBLog.AppendLine($"<tr><td>Clientes</td><td>Error carga</td></tr>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CargaProductos & CargaVentas& CargaClientes )
|
if (CargaProductos & CargaVentas & CargaClientes)
|
||||||
{
|
{
|
||||||
CargaAlmacenes = CargarArchivos(FInfoAlmacenes, $"{FTPServer}/Stock", TFPUsr, FTPPass);
|
CargaAlmacenes = CargarArchivos(FInfoAlmacenes, $"{FTPServer}/Stock", TFPUsr, FTPPass);
|
||||||
if (CargaClientes)
|
if (CargaClientes)
|
||||||
@@ -404,7 +403,8 @@ public class TareasJam : IHttpHandler
|
|||||||
if (CargaAlmacenes)
|
if (CargaAlmacenes)
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Almacenes</td><td>ok</td></tr>");
|
SBLog.AppendLine($"<tr><td>Almacenes</td><td>ok</td></tr>");
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SBLog.AppendLine($"<tr><td>Almacenes</td><td>Error carga</td></tr>");
|
SBLog.AppendLine($"<tr><td>Almacenes</td><td>Error carga</td></tr>");
|
||||||
}
|
}
|
||||||
@@ -431,8 +431,6 @@ public class TareasJam : IHttpHandler
|
|||||||
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()}" ;
|
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, RutaProductos, RutaVentas, RutaClientes, RutaAlmacenes);
|
MandaCorreo(Cuerpo, Respuesta, RutaProductos, RutaVentas, RutaClientes, RutaAlmacenes);
|
||||||
|
|
||||||
return Respuesta;
|
return Respuesta;
|
||||||
@@ -457,14 +455,7 @@ public class TareasJam : IHttpHandler
|
|||||||
Ventas.Ruta = RutaVentas;
|
Ventas.Ruta = RutaVentas;
|
||||||
Clientes.Ruta = RutaClientes;
|
Clientes.Ruta = RutaClientes;
|
||||||
Almacenes.Ruta = RutaAlmacenes;
|
Almacenes.Ruta = RutaAlmacenes;
|
||||||
|
|
||||||
//FileInfo FIp = new FileInfo(RutaProductos);
|
|
||||||
//FileInfo FIv = new FileInfo(RutaVentas);
|
|
||||||
//FileInfo FIc = new FileInfo(RutaClientes);
|
|
||||||
//FileInfo FIa = new FileInfo(RutaAlmacenes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ListaArchivos.Add(Productos);
|
ListaArchivos.Add(Productos);
|
||||||
ListaArchivos.Add(Ventas);
|
ListaArchivos.Add(Ventas);
|
||||||
ListaArchivos.Add(Clientes);
|
ListaArchivos.Add(Clientes);
|
||||||
@@ -472,8 +463,8 @@ public class TareasJam : IHttpHandler
|
|||||||
|
|
||||||
|
|
||||||
ClsSisMail Correo = new ClsSisMail();
|
ClsSisMail Correo = new ClsSisMail();
|
||||||
// string Para = "julian@adssistemas.mx;rene.molina@adssistemas.mx;oscar.irigoyen@adssistemas.mx";
|
string Para = "julian@adssistemas.mx;rene.molina@adssistemas.mx;oscar.irigoyen@adssistemas.mx";
|
||||||
string Para = "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")}";
|
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, Archivos:ListaArchivos);
|
Correo.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Cuerpo, Archivos:ListaArchivos);
|
||||||
@@ -488,7 +479,7 @@ public class TareasJam : IHttpHandler
|
|||||||
private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass )
|
private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass )
|
||||||
{
|
{
|
||||||
bool Respuesta;
|
bool Respuesta;
|
||||||
//var FInfo = new FileInfo(RutaArchivo);
|
|
||||||
if (FInfo.Exists)
|
if (FInfo.Exists)
|
||||||
{
|
{
|
||||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
|
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
|
||||||
|
|||||||
Reference in New Issue
Block a user