public string LoginIe(UserModel UserEnc) { try { string UserDecrypted = Encoding.UTF8.GetString(CryptoHelper.DecryptData(Convert.FromBase64String(UserEnc.User))); string PasswordDecrypted = Encoding.UTF8.GetString(CryptoHelper.DecryptData(Convert.FromBase64String(UserEnc.Password))); IenetUsers UserO = ( from U in DbO.IenetUsers where U.CodUsr == UserDecrypted && U.UsrPassword == PasswordDecrypted select U ).Fod(); if (UserO == null) { return(string.Empty); } UserO.HashId = EdiBase.GetHashId(); DbO.IenetUsers.Update(UserO); DbO.SaveChangesAsync(); string Ret = $"UserO.IdIenetGroup|{UserO.IdIenetGroup}|UserO.ClientId|{UserO.ClienteId}|UserO.HashId|{UserO.HashId}|UserO.TiendaId|{UserO.TiendaId}|UserO.IdUser|{UserO.Id}"; Ret = Convert.ToBase64String(CryptoHelper.EncryptData(Encoding.UTF8.GetBytes(Ret))); return(Ret); } catch (Exception e1) { return("Error: " + e1.ToString()); } }
public void Put(string _EdiStr, ref EdiDBContext _DbO, string Tipo) { try { string FtpFile = EdiBase.GetHashId(); StreamWriter Sw = new StreamWriter(FtpFile, false); Sw.Write(_EdiStr); Sw.Close(); CheckMaxEdiComs(ref _DbO, MaxEdiComs); ftpRequest = UseHost2 ? (FtpWebRequest)WebRequest.Create($"{host2}/{DirOut}/{FtpFile}") : (FtpWebRequest)WebRequest.Create($"{host}/{DirOut}/{FtpFile}"); ftpRequest.Credentials = new NetworkCredential(user, pass); ftpRequest.UseBinary = true; ftpRequest.UsePassive = true; ftpRequest.KeepAlive = true; ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpStream = ftpRequest.GetRequestStream(); FileStream localFileStream = new FileStream(FtpFile, FileMode.Open); byte[] byteBuffer = new byte[bufferSize]; int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); try { while (bytesSent != 0) { ftpStream.Write(byteBuffer, 0, bytesSent); bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); } AddComLog(ref _DbO, Id, $"Archivo enviado en {(UseHost2 ? host2 : host)}. Tipo: {Tipo}"); } catch (Exception ex) { AddComLog(ref _DbO, Id, $"Error al procesar el archivo en {(UseHost2 ? host2 : host)}. Info: {ex.ToString()}. Tipo: {Tipo}"); } localFileStream.Close(); ftpStream.Close(); ftpRequest = null; File.Delete(FtpFile); } catch (Exception ex) { AddComLog(ref _DbO, Id, $"Error relacionado con la conexión de {(UseHost2 ? host2 : host)}. Info: {ex.ToString()}. Tipo: {Tipo}"); } return; }
public ActionResult <RetInfo> AutoSendInventary830(bool Force = false, string Idusr = "") { DateTime StartTime = DateTime.Now; try { if (((DateTime.Now.DayOfWeek == DayOfWeek.Friday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday ) && DateTime.Now.Hour > 18) || Force ) { string DateLastRep = LastRep(); if (string.IsNullOrEmpty(DateLastRep)) { EdiRepSent EdiSent = new EdiRepSent() { Tipo = "830", Fecha = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat), Log = "Procesando reporte", Code = "0", EdiStr = "", HashId = EdiBase.GetHashId() }; DbO.EdiRepSent.Add(EdiSent); DbO.SaveChanges(); LearRep830 LearRep830O = new LearRep830(ref DbO, ref WmsDb); string EdiStr = LearRep830O.AutoSendInventary830(ref EdiSent); SendEdiFtp(EdiStr, "830 de inventario"); return(new RetInfo() { CodError = 0, Mensaje = "ok", ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds }); } else { DateTime LastDateRep = DateLastRep.ToDateEsp(); if ((DateTime.Now - LastDateRep).TotalDays > 4) { int CodUsr = (from U in WmsDb.Usrsystem where U.Idusr == Idusr select U.Codusr).Fod(); EdiRepSent EdiSent = new EdiRepSent() { Tipo = "830", Fecha = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat), Log = "Procesando reporte", Code = "0", EdiStr = "", HashId = EdiBase.GetHashId(), CodUsr = CodUsr }; DbO.EdiRepSent.Add(EdiSent); DbO.SaveChanges(); LearRep830 LearRep830O = new LearRep830(ref DbO, ref WmsDb); string EdiStr = LearRep830O.AutoSendInventary830(ref EdiSent); SendEdiFtp(EdiStr, "830 de inventario"); return(new RetInfo() { CodError = 0, Mensaje = "ok", ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds }); } } } return(new RetInfo() { CodError = 0, Mensaje = "ok", ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds }); } catch (Exception e1) { return(new RetInfo() { CodError = -1, Mensaje = e1.ToString(), ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds }); } }