This commit is contained in:
Rakcsle Supertramp
2020-06-23 14:39:56 -07:00
parent 91f7085ae1
commit a1edf2e402
6 changed files with 265 additions and 113 deletions

View File

@@ -1453,6 +1453,7 @@ Public Class ClsBancos
Catch Ex1 As SqlException Catch Ex1 As SqlException
If Ex1.Message.Contains("Número: 2627;") Or Ex1.Message.Contains("Número: 2601;") Then If Ex1.Message.Contains("Número: 2627;") Or Ex1.Message.Contains("Número: 2601;") Then
Me.OnError("Ocurrió un error al Guardar el Movimiento.", Ex1, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())
Alert("Ya existe un movimiento bancario con el mismo Folio: <b>" & Folio & "</b>.", TipoMensaje.MsgAdvertencia) Alert("Ya existe un movimiento bancario con el mismo Folio: <b>" & Folio & "</b>.", TipoMensaje.MsgAdvertencia)
Else Else
Me.OnError("Ocurrió un error al Guardar el Movimiento.", Ex1, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) Me.OnError("Ocurrió un error al Guardar el Movimiento.", Ex1, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())

View File

@@ -3194,6 +3194,33 @@ Public Class ClsGenerales
#End Region #End Region
#Region ""
Public Function GetJAMCorveta(Opcion As Integer) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_JAM_Corteva")
With SqlAdapter.SelectCommand.Parameters
.Add("@Opcion", SqlDbType.Int).Value = Opcion
End With
Try
SqlAdapter.Fill(Data)
Retorno = True
Catch ex As Exception
OnError($"Ocurrió un error al obtener los datos de Corveta op {Opcion}.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo())
End Try
Return Retorno
End Function
#End Region
#Region " IDisposable Support " #Region " IDisposable Support "
' Visual Basic agregó este código para implementar correctamente el modelo descartable. ' Visual Basic agregó este código para implementar correctamente el modelo descartable.
Public Sub Dispose() Implements IDisposable.Dispose Public Sub Dispose() Implements IDisposable.Dispose

View File

@@ -296,7 +296,13 @@ Partial Class Bancos_ProveedoresAbonar
Private Property OriReferenciaCIE As String Private Property OriReferenciaCIE As String
Get Get
Return ViewState("OriReferenciaCIE").ToString If ViewState("OriReferenciaCIE") Is Nothing Then
Return ""
Else
Return ViewState("OriReferenciaCIE").ToString
End If
End Get End Get
Set(value As String) Set(value As String)
ViewState("OriReferenciaCIE") = value ViewState("OriReferenciaCIE") = value
@@ -305,7 +311,12 @@ Partial Class Bancos_ProveedoresAbonar
Private Property OriConceptoCIE As String Private Property OriConceptoCIE As String
Get Get
Return ViewState("OriConceptoCIE").ToString If ViewState("OriReferenciaCIE") Is Nothing Then
Return ""
Else
Return ViewState("OriConceptoCIE").ToString
End If
End Get End Get
Set(value As String) Set(value As String)
ViewState("OriConceptoCIE") = value ViewState("OriConceptoCIE") = value

BIN
Productos202006221814.xlsx Normal file

Binary file not shown.

BIN
Productos202006221920.xlsx Normal file

Binary file not shown.

View File

@@ -21,7 +21,11 @@ public class TareasJam : IHttpHandler
string Metodo = context.Request["Metodo"] ==null?"": context.Request["Metodo"]; string Metodo = context.Request["Metodo"] ==null?"": context.Request["Metodo"];
int CveEmpresa =context.Request["CveEmpresa"] ==null?0: context.Request["CveEmpresa"].ToEntero(); int CveEmpresa =context.Request["CveEmpresa"] ==null?0: context.Request["CveEmpresa"].ToEntero();
switch (Metodo) switch (Metodo)
{ {
case "TestConexion":
//PruebaConexionFTP("ftp://127.0.0.1/", "Toor", "agj-3500");
retorno = PruebaConexionFTP("ftp://us2.hostedftp.com/", "agrojam", "A12345678");
break;
case "EjecutaThalamus": case "EjecutaThalamus":
retorno =EjecutaThalamus(CveEmpresa); retorno =EjecutaThalamus(CveEmpresa);
break; break;
@@ -40,150 +44,259 @@ public class TareasJam : IHttpHandler
context.Response.End(); context.Response.End();
//ModExtensiones.GuardaLogAD(string.Format("{3} CveEmpresa={0} cveTareaProgramada={1} CveTareaProgramadaHistorial={2}", CveEmpresa, cveTareaProgramada, CveTareaProgramadaHistorial, Metodo), "Tareas Programadas"); //ModExtensiones.GuardaLogAD(string.Format("{3} CveEmpresa={0} cveTareaProgramada={1} CveTareaProgramadaHistorial={2}", CveEmpresa, cveTareaProgramada, CveTareaProgramadaHistorial, Metodo), "Tareas Programadas");
} }
private bool EjecutaThalamus(int CveEmpresa) private bool EjecutaThalamus(int CveEmpresa)
{
ClsGenerales ObjGenerales = new ClsGenerales();
DataTable DTProductos = new DataTable();
DataTable DTVentas = new DataTable();
DataTable DTClientes = new DataTable();
bool ErrorProceso = false;
if (ObjGenerales.GetJAMCorveta(1))
{ {
DTProductos = ObjGenerales.DtResultados.Copy();
}
else { ErrorProceso = true; }
if (ObjGenerales.GetJAMCorveta(2))
{
DTVentas = ObjGenerales.DtResultados.Copy();
}
else { ErrorProceso = true; }
string RutaArchivoVentas = $@"C:\Temp\Ventas{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; if (ObjGenerales.GetJAMCorveta(3))
var DTVentas = new DataTable(); {
DTVentas.Columns.Add("systemId"); DTClientes = ObjGenerales.DtResultados.Copy();
DTVentas.Columns.Add("Branch"); }
DTVentas.Columns.Add("Code"); else { ErrorProceso = true; }
DTVentas.Columns.Add("Sale Date");
DTVentas.Columns.Add("Quantity"); ObjGenerales.Dispose();
DTVentas.Columns.Add("Amount");
DTVentas.Columns.Add("Transaction ID"); if (!ErrorProceso)
for (int x = 0; x <= 50; x++) {
{ string RutaProductos = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Productos{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
DataRow dr = DTVentas.NewRow(); string RutaVentas = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Ventas{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
dr[0] = $"systemId {x}"; string RutaClientes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Clientes{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
dr[1] = $"Branch {x}";
dr[2] = $"{x}"; string FTPServer = "ftp://127.0.0.1/";
dr[3] = $"{ DateTime.Now.ToString("yyyy-MM-dd")}"; string TFPUsr = "Toor";
dr[4] = $"{x}"; string FTPPass = "agj-3500";
dr[5] = $"{x}.00";
dr[6] = $"{x}";
DTVentas.Rows.Add(dr);
}
SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet()); SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet());
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Ventas"); var workbookProductos = new ExcelFile();
worksheet.InsertDataTable(DTVentas, new InsertDataTableOptions() var worksheetProductos = workbookProductos.Worksheets.Add("Ventas");
worksheetProductos.InsertDataTable(DTProductos, new InsertDataTableOptions()
{ {
ColumnHeaders = true, ColumnHeaders = true,
StartRow = 0 StartRow = 0
}); });
workbook.Save(RutaArchivoVentas); workbookProductos.Save(RutaProductos);
string FTPServer = "ftp://127.0.0.1/";
string TFPUsr = "Toor"; var workbookVentas = new ExcelFile();
string FTPPass = "agj-3500"; var worksheetVentas = workbookVentas.Worksheets.Add("Ventas");
var FInfo = new FileInfo(RutaArchivoVentas); worksheetVentas.InsertDataTable(DTVentas, new InsertDataTableOptions()
bool Carga = CargarArchivos(FInfo.FullName, FTPServer, TFPUsr, FTPPass);
if (Carga)
{ {
Carga = VerificarArchivo(FInfo.Name, FInfo.Length, FTPServer, TFPUsr, FTPPass); ColumnHeaders = true,
StartRow = 0
});
workbookVentas.Save(RutaVentas);
var workbookClientes = new ExcelFile();
var worksheetClientes = workbookClientes.Worksheets.Add("Ventas");
worksheetClientes.InsertDataTable(DTClientes, new InsertDataTableOptions()
{
ColumnHeaders = true,
StartRow = 0
});
workbookClientes.Save(RutaClientes);
var FInfoProductos = new FileInfo(RutaProductos);
var FInfoVentas = new FileInfo(RutaVentas);
var FInfoClientes = new FileInfo(RutaClientes);
bool CargaProductos = false;
bool CargaVentas = false;
bool CargaClientes = false;
CargaProductos = CargarArchivos(FInfoProductos, FTPServer, TFPUsr, FTPPass);
if (CargaProductos)
{
CargaProductos = VerificarArchivo(FInfoProductos, FInfoProductos.Length, FTPServer, TFPUsr, FTPPass);
} }
return Carga; if (CargaProductos)
{
CargaVentas = CargarArchivos(FInfoVentas, FTPServer, TFPUsr, FTPPass);
if (CargaVentas)
{
CargaVentas = VerificarArchivo(FInfoVentas, FInfoVentas.Length, FTPServer, TFPUsr, FTPPass);
}
}
if (CargaProductos & CargaVentas)
{
CargaClientes = CargarArchivos(FInfoClientes, FTPServer, TFPUsr, FTPPass);
if (CargaClientes)
{
CargaClientes = VerificarArchivo(FInfoClientes, FInfoClientes.Length, FTPServer, TFPUsr, FTPPass);
}
}
if (CargaProductos & CargaVentas & CargaClientes)
{
return true;
}
else
{
return false;
}
} }
else
{
return false;
}
}
private bool CargarArchivos(string RutaArchivo, string FTPServer, string FTPUsr, string FTPPass)
{ 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}"); bool Respuesta;
request.Method = WebRequestMethods.Ftp.UploadFile; //var FInfo = new FileInfo(RutaArchivo);
int tamanio = 1024; if (FInfo.Exists)
var buffer = new byte[tamanio + 1];
int byteRead = 0;
bool Conected = false;
request.Credentials = new NetworkCredential(FTPUsr, FTPPass);
try
{ {
request.GetResponse(); FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
Conected = true; request.Method = WebRequestMethods.Ftp.UploadFile;
} int tamanio = 1024;
catch (Exception ex) var buffer = new byte[tamanio + 1];
{ int byteRead = 0;
} bool Conected = false;
request.Credentials = new NetworkCredential(FTPUsr, FTPPass);
if (Conected)
{
Stream ftpStream;
FileStream f;
ftpStream = request.GetRequestStream();
f = File.OpenRead(FInfo.FullName);
try try
{ {
do request.GetResponse();
{ Conected = true;
byteRead = f.Read(buffer, 0, tamanio);
ftpStream.Write(buffer, 0, byteRead);
}
while (byteRead != 0);
Respuesta = true;
} }
// validar si existe archivo si coincide en tamaño
catch (Exception ex) catch (Exception ex)
{
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 Conexión a servidor FTP archivo { FInfo.Name } {ex.Message} ");
}
if (Conected)
{
Stream ftpStream;
FileStream f;
ftpStream = request.GetRequestStream();
f = File.OpenRead(FInfo.FullName);
try
{
do
{
byteRead = f.Read(buffer, 0, tamanio);
ftpStream.Write(buffer, 0, byteRead);
}
while (byteRead != 0);
Respuesta = true;
}
catch (Exception ex)
{
Respuesta = false;
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 cargando archivo { FInfo.Name } {ex.Message} ");
}
if (f is object)
{
f.Close();
}
if (ftpStream is object)
{
ftpStream.Close();
}
}
else
{ {
Respuesta = false; Respuesta = false;
// no se conecto al ftp probablemente credenciales erroneas
} }
if (f is object)
{
f.Close();
}
if (ftpStream is object)
{
ftpStream.Close();
}
} }
else else
{ {
Respuesta = false; Respuesta = false;
// no se conecto al ftp probablemente credenciales erroneas // El archivo no existe en el disco local
}
}
else
{
Respuesta = false;
// El archivo no existe en el disco local
}
return Respuesta;
}
private bool VerificarArchivo(string Archivo, long Tamanio, string FTPServer, string FTPUsr, string FTPPass)
{
bool Respuesta = false;
FtpWebRequest reqSize = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPServer + Archivo));
reqSize.Credentials = new NetworkCredential(FTPUsr, FTPPass);
reqSize.Method = WebRequestMethods.Ftp.GetFileSize;
reqSize.UseBinary = true;
FtpWebResponse loginresponse = (FtpWebResponse)reqSize.GetResponse();
FtpWebResponse respSize = (FtpWebResponse)reqSize.GetResponse();
respSize = (FtpWebResponse)reqSize.GetResponse();
long size = respSize.ContentLength;
respSize.Close();
if (Tamanio == size)
{
Respuesta = true;
} }
return Respuesta; return Respuesta;
} }
public bool IsReusable private bool VerificarArchivo(FileInfo FInfo, long Tamanio, string FTPServer, string FTPUsr, string FTPPass)
{ {
get { return false; } bool Respuesta = false;
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
request.Credentials = new NetworkCredential(FTPUsr, FTPPass);
request.Method = WebRequestMethods.Ftp.GetFileSize;
request.UseBinary = true;
FtpWebResponse loginresponse = (FtpWebResponse)request.GetResponse();
FtpWebResponse respSize = (FtpWebResponse)request.GetResponse();
respSize = (FtpWebResponse)request.GetResponse();
long size = respSize.ContentLength;
respSize.Close();
if (Tamanio == size)
{
Respuesta = true;
}
}catch(Exception ex)
{
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 verificando archivo { FInfo.Name } {ex.Message} ");
Respuesta = false;
}
return Respuesta;
}
private bool PruebaConexionFTP( string FTPServer, string FTPUsr, string FTPPass)
{
bool Respuesta = false;
FtpWebRequest request =(FtpWebRequest)WebRequest.Create($"{FTPServer}/Test.log");
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(FTPUsr, FTPPass);
try
{
request.GetResponse();
Respuesta = true;
}
catch (Exception ex)
{
Extensiones.ModExtensiones.GuardaLog(null, $"Error Tareas Programadas 119 error Prueba de Conexión a servidor FTP archivo {ex.Message} ");
}
return Respuesta;
}
public bool IsReusable
{
get { return false; }
} }
} }