diff --git a/App_Code/ClsBancos.vb b/App_Code/ClsBancos.vb index 7a66b5f73..7a39219a4 100644 --- a/App_Code/ClsBancos.vb +++ b/App_Code/ClsBancos.vb @@ -1453,6 +1453,7 @@ Public Class ClsBancos Catch Ex1 As SqlException 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: " & Folio & ".", TipoMensaje.MsgAdvertencia) Else Me.OnError("Ocurrió un error al Guardar el Movimiento.", Ex1, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) diff --git a/App_Code/ClsGenerales.vb b/App_Code/ClsGenerales.vb index 167b29d2b..e12f623c4 100644 --- a/App_Code/ClsGenerales.vb +++ b/App_Code/ClsGenerales.vb @@ -3194,6 +3194,33 @@ Public Class ClsGenerales #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 " ' Visual Basic agregó este código para implementar correctamente el modelo descartable. Public Sub Dispose() Implements IDisposable.Dispose diff --git a/Bancos/ProveedoresAbonar.aspx.vb b/Bancos/ProveedoresAbonar.aspx.vb index 0d611ddfb..b87311be9 100644 --- a/Bancos/ProveedoresAbonar.aspx.vb +++ b/Bancos/ProveedoresAbonar.aspx.vb @@ -296,7 +296,13 @@ Partial Class Bancos_ProveedoresAbonar Private Property OriReferenciaCIE As String Get - Return ViewState("OriReferenciaCIE").ToString + If ViewState("OriReferenciaCIE") Is Nothing Then + Return "" + Else + Return ViewState("OriReferenciaCIE").ToString + End If + + End Get Set(value As String) ViewState("OriReferenciaCIE") = value @@ -305,7 +311,12 @@ Partial Class Bancos_ProveedoresAbonar Private Property OriConceptoCIE As String Get - Return ViewState("OriConceptoCIE").ToString + If ViewState("OriReferenciaCIE") Is Nothing Then + Return "" + Else + Return ViewState("OriConceptoCIE").ToString + End If + End Get Set(value As String) ViewState("OriConceptoCIE") = value diff --git a/Productos202006221814.xlsx b/Productos202006221814.xlsx new file mode 100644 index 000000000..421d798b8 Binary files /dev/null and b/Productos202006221814.xlsx differ diff --git a/Productos202006221920.xlsx b/Productos202006221920.xlsx new file mode 100644 index 000000000..ae050ff6e Binary files /dev/null and b/Productos202006221920.xlsx differ diff --git a/TareasProgramadas/Tareas119.ashx b/TareasProgramadas/Tareas119.ashx index 5151052c0..a1b854f02 100644 --- a/TareasProgramadas/Tareas119.ashx +++ b/TareasProgramadas/Tareas119.ashx @@ -21,7 +21,11 @@ public class TareasJam : IHttpHandler string Metodo = context.Request["Metodo"] ==null?"": context.Request["Metodo"]; int CveEmpresa =context.Request["CveEmpresa"] ==null?0: context.Request["CveEmpresa"].ToEntero(); switch (Metodo) - { + { + case "TestConexion": + //PruebaConexionFTP("ftp://127.0.0.1/", "Toor", "agj-3500"); + retorno = PruebaConexionFTP("ftp://us2.hostedftp.com/", "agrojam", "A12345678"); + break; case "EjecutaThalamus": retorno =EjecutaThalamus(CveEmpresa); break; @@ -40,150 +44,259 @@ public class TareasJam : IHttpHandler context.Response.End(); //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"; - var DTVentas = new DataTable(); - DTVentas.Columns.Add("systemId"); - DTVentas.Columns.Add("Branch"); - DTVentas.Columns.Add("Code"); - DTVentas.Columns.Add("Sale Date"); - DTVentas.Columns.Add("Quantity"); - DTVentas.Columns.Add("Amount"); - DTVentas.Columns.Add("Transaction ID"); - for (int x = 0; x <= 50; x++) - { - DataRow dr = DTVentas.NewRow(); - dr[0] = $"systemId {x}"; - dr[1] = $"Branch {x}"; - dr[2] = $"{x}"; - dr[3] = $"{ DateTime.Now.ToString("yyyy-MM-dd")}"; - dr[4] = $"{x}"; - dr[5] = $"{x}.00"; - dr[6] = $"{x}"; - DTVentas.Rows.Add(dr); - } + if (ObjGenerales.GetJAMCorveta(3)) + { + DTClientes = ObjGenerales.DtResultados.Copy(); + } + else { ErrorProceso = true; } + + ObjGenerales.Dispose(); + + if (!ErrorProceso) + { + string RutaProductos = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Productos{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; + string RutaVentas = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Ventas{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; + string RutaClientes = $@"{ HttpContext.Current.Server.MapPath("~") }Temp\Clientes{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; + + string FTPServer = "ftp://127.0.0.1/"; + string TFPUsr = "Toor"; + string FTPPass = "agj-3500"; SpreadsheetInfo.SetLicense(Extensiones.ModExtensiones.SerialGemBoxSpreadsheet()); - var workbook = new ExcelFile(); - var worksheet = workbook.Worksheets.Add("Ventas"); - worksheet.InsertDataTable(DTVentas, new InsertDataTableOptions() + + var workbookProductos = new ExcelFile(); + var worksheetProductos = workbookProductos.Worksheets.Add("Ventas"); + worksheetProductos.InsertDataTable(DTProductos, new InsertDataTableOptions() { ColumnHeaders = true, StartRow = 0 }); - workbook.Save(RutaArchivoVentas); - string FTPServer = "ftp://127.0.0.1/"; - string TFPUsr = "Toor"; - string FTPPass = "agj-3500"; - var FInfo = new FileInfo(RutaArchivoVentas); - bool Carga = CargarArchivos(FInfo.FullName, FTPServer, TFPUsr, FTPPass); - if (Carga) + workbookProductos.Save(RutaProductos); + + var workbookVentas = new ExcelFile(); + var worksheetVentas = workbookVentas.Worksheets.Add("Ventas"); + worksheetVentas.InsertDataTable(DTVentas, new InsertDataTableOptions() { - 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) -{ - bool Respuesta; - var FInfo = new FileInfo(RutaArchivo); - if (FInfo.Exists) + + private bool CargarArchivos(FileInfo FInfo, string FTPServer, string FTPUsr, string FTPPass) { - FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}"); - request.Method = WebRequestMethods.Ftp.UploadFile; - int tamanio = 1024; - var buffer = new byte[tamanio + 1]; - int byteRead = 0; - bool Conected = false; - request.Credentials = new NetworkCredential(FTPUsr, FTPPass); - try + bool Respuesta; + //var FInfo = new FileInfo(RutaArchivo); + if (FInfo.Exists) { - request.GetResponse(); - Conected = true; - } - catch (Exception ex) - { - } - - if (Conected) - { - Stream ftpStream; - FileStream f; - ftpStream = request.GetRequestStream(); - f = File.OpenRead(FInfo.FullName); + FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}"); + request.Method = WebRequestMethods.Ftp.UploadFile; + int tamanio = 1024; + var buffer = new byte[tamanio + 1]; + int byteRead = 0; + bool Conected = false; + request.Credentials = new NetworkCredential(FTPUsr, FTPPass); try { - do - { - byteRead = f.Read(buffer, 0, tamanio); - ftpStream.Write(buffer, 0, byteRead); - } - while (byteRead != 0); - Respuesta = true; + request.GetResponse(); + Conected = true; } - // validar si existe archivo si coincide en tamaño 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; + // no se conecto al ftp probablemente credenciales erroneas } - if (f is object) - { - f.Close(); - } - - if (ftpStream is object) - { - ftpStream.Close(); - } } else { Respuesta = false; - // no se conecto al ftp probablemente credenciales erroneas - } - } - 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; + // El archivo no existe en el disco local } return Respuesta; } - - - public bool IsReusable - { - get { return false; } + + + private bool VerificarArchivo(FileInfo FInfo, long Tamanio, string FTPServer, string FTPUsr, string FTPPass) + { + 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; } } } \ No newline at end of file