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 System.Data;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using ClosedXML;
|
||||
|
||||
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 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
|
||||
{
|
||||
if (File.Exists(RutaProductos))
|
||||
@@ -91,14 +99,14 @@ public class TareasJam : IHttpHandler
|
||||
}
|
||||
|
||||
|
||||
string FTPServer = "ftp://127.0.0.1/";
|
||||
string TFPUsr = "Toor";
|
||||
string FTPPass = "agj-3500";
|
||||
//string FTPServer = "ftp://127.0.0.1/";
|
||||
//string TFPUsr = "Toor";
|
||||
//string FTPPass = "agj-3500";
|
||||
|
||||
|
||||
//string FTPServer = "ftp://us2.hostedftp.com";
|
||||
//string TFPUsr = "agrojam";
|
||||
//string FTPPass = "A12345678";
|
||||
string FTPServer = "ftp://us2.hostedftp.com";
|
||||
string TFPUsr = "agrojam";
|
||||
string FTPPass = "A12345678";
|
||||
|
||||
bool ErrorProceso = false;
|
||||
|
||||
@@ -158,7 +166,7 @@ public class TareasJam : IHttpHandler
|
||||
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[2].ColumnName = "Presentación";
|
||||
DTProductos.AcceptChanges();
|
||||
@@ -196,9 +204,6 @@ public class TareasJam : IHttpHandler
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DataTable dtCloned = DTVentas.Clone();
|
||||
dtCloned.Columns[3].DataType = typeof(string);
|
||||
|
||||
@@ -210,7 +215,7 @@ public class TareasJam : IHttpHandler
|
||||
DTVentas = dtCloned;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -228,106 +233,98 @@ public class TareasJam : IHttpHandler
|
||||
DTAlmacenes = dtCloned;
|
||||
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");
|
||||
dRow[3] = tmpDate;
|
||||
}
|
||||
DTAlmacenes.AcceptChanges();
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SBLog.AppendLine("<b>Error al renombrar columnas</b>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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();
|
||||
var worksheetAlmacenes = workbookAlmacenes.Worksheets.Add("Almacenes");
|
||||
worksheetAlmacenes.InsertDataTable(DTAlmacenes, new InsertDataTableOptions()
|
||||
foreach (DataRow DRow in DTVentas.Rows)
|
||||
{
|
||||
ColumnHeaders = true,
|
||||
StartRow = 0
|
||||
});
|
||||
wsVentas.Cell(count, 1).Value = "'" + DRow["systemId"].ToString();
|
||||
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)
|
||||
{
|
||||
|
||||
//contador++;
|
||||
//var cell = worksheetAlmacenes.Cells[contador, 3];
|
||||
//cell.Style.WrapText = true;
|
||||
|
||||
|
||||
wsAlmacenes.Cell(count, 1).Value = "'" + DRow["Code"].ToString();
|
||||
wsAlmacenes.Cell(count, 2).Value = DRow["Quantity"].ToString();
|
||||
wsAlmacenes.Cell(count, 3).Value = DRow["Description"].ToString();
|
||||
wsAlmacenes.Cell(count, 4).Value = "'" + DRow["Stock Date"].ToString();
|
||||
count++;
|
||||
}
|
||||
//worksheetAlmacenes.Columns[3].Style.NumberFormat = "yyyy/MM/dd";
|
||||
workbookAlmacenes.Save(RutaAlmacenes);
|
||||
wbAlmacenes.SaveAs(RutaAlmacenes);
|
||||
|
||||
var workbookProductos = new ExcelFile();
|
||||
var worksheetProductos = workbookProductos.Worksheets.Add("Productos");
|
||||
worksheetProductos.InsertDataTable(DTProductos, new InsertDataTableOptions()
|
||||
var wbAClientes = new ClosedXML.Excel.XLWorkbook(FormatoClientes);
|
||||
var wsClientes = wbAClientes.Worksheet(1);
|
||||
|
||||
count = 2;
|
||||
|
||||
foreach (DataRow DRow in DTClientes.Rows)
|
||||
{
|
||||
ColumnHeaders = true,
|
||||
StartRow = 0
|
||||
});
|
||||
workbookProductos.Save(RutaProductos);
|
||||
|
||||
var workbookVentas = new ExcelFile();
|
||||
var worksheetVentas = workbookVentas.Worksheets.Add("Ventas");
|
||||
worksheetVentas.InsertDataTable(DTVentas, new InsertDataTableOptions()
|
||||
{
|
||||
ColumnHeaders = true,
|
||||
StartRow = 0
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
|
||||
wsClientes.Cell(count, 1).Value = "'" + DRow["systemId"].ToString();
|
||||
wsClientes.Cell(count, 2).Value = DRow["fiscalIdMex"].ToString();
|
||||
wsClientes.Cell(count, 3).Value = DRow["fiscalName"].ToString();
|
||||
wsClientes.Cell(count, 4).Value = DRow["email"].ToString();
|
||||
wsClientes.Cell(count, 5).Value = DRow["address.countryId"].ToString();
|
||||
wsClientes.Cell(count, 6).Value = DRow["address.stateId"].ToString();
|
||||
wsClientes.Cell(count, 7).Value = DRow["address.city"].ToString();
|
||||
wsClientes.Cell(count, 8).Value = DRow["address.street1"].ToString();
|
||||
wsClientes.Cell(count, 9).Value = DRow["address.street2"].ToString();
|
||||
wsClientes.Cell(count, 10).Value = "'" + DRow["address.postalCode"].ToString();
|
||||
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();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
var workbookClientes = new ExcelFile();
|
||||
var worksheetClientes = workbookClientes.Worksheets.Add("Clientes");
|
||||
worksheetClientes.InsertDataTable(DTClientes, new InsertDataTableOptions()
|
||||
foreach (DataRow DRow in DTProductos.Rows)
|
||||
{
|
||||
ColumnHeaders = true,
|
||||
StartRow = 0
|
||||
});
|
||||
workbookClientes.Save(RutaClientes);
|
||||
|
||||
|
||||
|
||||
wsProductos.Cell(count, 1).Value = "'" + DRow["Código Producto Interno"].ToString();
|
||||
wsProductos.Cell(count, 2).Value = DRow["Nombre del Producto"].ToString();
|
||||
wsProductos.Cell(count, 3).Value = DRow["Presentación"].ToString();
|
||||
|
||||
count++;
|
||||
}
|
||||
wbProductos.SaveAs(RutaProductos);
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
var FInfoProductos = new FileInfo(RutaProductos);
|
||||
var FInfoVentas = new FileInfo(RutaVentas);
|
||||
@@ -363,21 +360,22 @@ public class TareasJam : IHttpHandler
|
||||
CargaVentas = CargarArchivos(FInfoVentas, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
||||
if (CargaVentas)
|
||||
{
|
||||
CargaVentas = VerificarArchivo(FInfoVentas, FInfoVentas.Length, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
||||
CargaVentas = VerificarArchivo(FInfoVentas, FInfoVentas.Length, $"{FTPServer}/Ventas", TFPUsr, FTPPass);
|
||||
}
|
||||
}
|
||||
|
||||
if (CargaVentas)
|
||||
{
|
||||
SBLog.AppendLine($"<tr><td>Ventas</td><td>ok</td></tr>");
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
SBLog.AppendLine($"<tr><td>Ventas</td><td>Error carga</td></tr>");
|
||||
}
|
||||
|
||||
if (CargaProductos & CargaVentas)
|
||||
{
|
||||
CargaClientes = CargarArchivos(FInfoClientes, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
||||
CargaClientes = CargarArchivos(FInfoClientes, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
||||
if (CargaClientes)
|
||||
{
|
||||
CargaClientes = VerificarArchivo(FInfoClientes, FInfoClientes.Length, $"{FTPServer}/Clientes", TFPUsr, FTPPass);
|
||||
@@ -387,12 +385,13 @@ public class TareasJam : IHttpHandler
|
||||
if (CargaClientes)
|
||||
{
|
||||
SBLog.AppendLine($"<tr><td>Clientes</td><td>ok</td></tr>");
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
if (CargaClientes)
|
||||
@@ -404,7 +403,8 @@ public class TareasJam : IHttpHandler
|
||||
if (CargaAlmacenes)
|
||||
{
|
||||
SBLog.AppendLine($"<tr><td>Almacenes</td><td>ok</td></tr>");
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
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()}" ;
|
||||
|
||||
|
||||
|
||||
|
||||
MandaCorreo(Cuerpo, Respuesta, RutaProductos, RutaVentas, RutaClientes, RutaAlmacenes);
|
||||
|
||||
return Respuesta;
|
||||
@@ -457,14 +455,7 @@ public class TareasJam : IHttpHandler
|
||||
Ventas.Ruta = RutaVentas;
|
||||
Clientes.Ruta = RutaClientes;
|
||||
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(Ventas);
|
||||
ListaArchivos.Add(Clientes);
|
||||
@@ -472,8 +463,8 @@ public class TareasJam : IHttpHandler
|
||||
|
||||
|
||||
ClsSisMail Correo = new ClsSisMail();
|
||||
// string Para = "julian@adssistemas.mx;rene.molina@adssistemas.mx;oscar.irigoyen@adssistemas.mx";
|
||||
string Para = "oscar.irigoyen@adssistemas.mx";
|
||||
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, Archivos:ListaArchivos);
|
||||
@@ -488,7 +479,7 @@ public class TareasJam : IHttpHandler
|
||||
private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass )
|
||||
{
|
||||
bool Respuesta;
|
||||
//var FInfo = new FileInfo(RutaArchivo);
|
||||
|
||||
if (FInfo.Exists)
|
||||
{
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
|
||||
|
||||
Reference in New Issue
Block a user