Version OScar
This commit is contained in:
436
ADSUtileriasService/Helpers/ADSSqlite/SqlLiteBase.cs
Normal file
436
ADSUtileriasService/Helpers/ADSSqlite/SqlLiteBase.cs
Normal file
@@ -0,0 +1,436 @@
|
||||
using System.Data.SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ADSUtileriasService.Helpers.ADSSqlite
|
||||
{
|
||||
|
||||
public class SqlLiteBase : IDisposable
|
||||
{
|
||||
private SQLiteConnection conexion;
|
||||
private string ConnectionString;
|
||||
private SqlLiteConnectionEnum BDTypecon;
|
||||
private bool isopened;
|
||||
private SQLiteCommand comando;
|
||||
private SQLiteTransaction transaccion;
|
||||
public SQLiteCommand command { get { return comando; } }
|
||||
public bool Isopen { get { return isopened; } }
|
||||
public SqlLiteConnectionEnum BDType { get { return BDTypecon; } }
|
||||
/// <summary>
|
||||
/// Crear variable de conexion a la BD de la aplicacion empresa (SqLiteBaseConection.Empresa)
|
||||
/// </summary>
|
||||
public SqlLiteBase() : this(SqlLiteConnectionEnum.Empresa, -2)
|
||||
{ }
|
||||
/// <summary>
|
||||
/// Crear variable de conexion a la BD
|
||||
/// </summary>
|
||||
/// <param name="bdtypecon">Empresa o configuracion</param>
|
||||
public SqlLiteBase(SqlLiteConnectionEnum bdtypecon, int CveEmpresa)
|
||||
{
|
||||
if (CveEmpresa == -2)
|
||||
{
|
||||
CveEmpresa = GlobalVars.user.CveEmpresa;
|
||||
}
|
||||
switch (bdtypecon)
|
||||
{
|
||||
case SqlLiteConnectionEnum.AppConfig:
|
||||
ConnectionString = string.Format("Data Source={0}AppConfig.db;Version=3;", ADSNetLibrary.Helpers.ModVars.FilesDir);
|
||||
break;
|
||||
case SqlLiteConnectionEnum.Empresa:
|
||||
string dir = string.Format("{0}Empresas\\{1}\\", ADSNetLibrary.Helpers.ModVars.FilesDir, CveEmpresa);
|
||||
if (!System.IO.Directory.Exists(dir))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(dir);
|
||||
}
|
||||
ConnectionString = string.Format("Data Source={0}EmpresaBD.db;Version=3;", dir);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this.BDTypecon = bdtypecon;
|
||||
isopened = false;
|
||||
try
|
||||
{
|
||||
conexion = new SQLiteConnection(ConnectionString);//;Version=3;
|
||||
conexion.Open();
|
||||
isopened = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Mod.GuardaLog(e,"Error al inicializar la base de datos local", LogsNames.LocalRepository); }
|
||||
}
|
||||
public SQLiteTransaction BeginTransaction()
|
||||
{
|
||||
if(transaccion == null)
|
||||
{
|
||||
transaccion= conexion.BeginTransaction();
|
||||
}
|
||||
return transaccion;
|
||||
}
|
||||
public void Commit()
|
||||
{
|
||||
transaccion.Commit();
|
||||
transaccion = null;
|
||||
}
|
||||
public void Rollback()
|
||||
{
|
||||
transaccion.Rollback();
|
||||
transaccion = null;
|
||||
}
|
||||
public bool ClearCommand(string query)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (comando == null)
|
||||
{
|
||||
comando = conexion.CreateCommand();
|
||||
}
|
||||
comando.CommandText = query;
|
||||
comando.Parameters.Clear();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Mod.GuardaLog(e, "Error al inicializar Comando", LogsNames.LocalRepository);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public int ExecuteNonQuery()
|
||||
{
|
||||
return comando.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public int RunExecuteNonQuery(string query)
|
||||
{
|
||||
int retorno = -1;
|
||||
ClearCommand(query);
|
||||
retorno = comando.ExecuteNonQuery();
|
||||
return retorno;
|
||||
}
|
||||
public SQLiteDataReader ExecuteReader()
|
||||
{
|
||||
return comando.ExecuteReader();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene una lista de objetos es necesario ejecutar el metodo ClearCommand y agregar los parametros antes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Clase genérica en donde se obtiene la información del SqlDataReader.</typeparam>
|
||||
/// <returns>Lista de objetos "T".</returns>
|
||||
public List<T> QueryToList<T>() where T : class, new()
|
||||
{
|
||||
List<T> retorno = null;
|
||||
using (SQLiteDataReader reader = comando.ExecuteReader())
|
||||
{
|
||||
retorno = CreateList<T>(reader);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene un Objeto es necesario ejecutar el metodo ClearCommand y agregar los parametros antes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Clase genérica en donde se obtiene la información de la consulta.</typeparam>
|
||||
/// <returns>Objeto "T".</returns>
|
||||
public T QueryToObject<T>() where T : class, new()
|
||||
{
|
||||
T retorno = null;
|
||||
using (SQLiteDataReader reader = comando.ExecuteReader())
|
||||
{
|
||||
retorno = CreateObject<T>(reader);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
|
||||
|
||||
#region mapperReader
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene una lista de objetos a partir de un SqlDataReader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Clase genérica en donde se obtiene la información del SqlDataReader.</typeparam>
|
||||
/// <param name="dataReader">SqlDataReader a leer.</param>
|
||||
/// <returns>Lista de objetos.</returns>
|
||||
public static List<T> CreateList<T>(SQLiteDataReader dataReader) where T : class, new()
|
||||
{
|
||||
var results = new List<T>();
|
||||
var properties = typeof(T).GetProperties();
|
||||
List<System.Reflection.PropertyInfo> propinobj = new List<System.Reflection.PropertyInfo>();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
|
||||
if (IsColumnExists(dataReader, property.Name))
|
||||
{
|
||||
propinobj.Add(property);
|
||||
}
|
||||
}
|
||||
while (dataReader.Read())
|
||||
{
|
||||
var item = Activator.CreateInstance<T>();
|
||||
foreach (var property in propinobj)
|
||||
{
|
||||
if (!dataReader.IsDBNull(dataReader.GetOrdinal(property.Name)))
|
||||
{
|
||||
Type convertTo = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
|
||||
object objvalue;
|
||||
switch (property.PropertyType.Name)
|
||||
{
|
||||
case "Boolean":
|
||||
{
|
||||
objvalue = (dataReader[property.Name].ToString().ToUpper().Contiene(new string[] { "1", "TRUE"}));
|
||||
property.SetValue(item, objvalue, null);
|
||||
break;
|
||||
}
|
||||
case "DateTime":
|
||||
{
|
||||
/*
|
||||
*
|
||||
* DateTime.Ticks
|
||||
*
|
||||
*/
|
||||
try
|
||||
{
|
||||
property.SetValue(item, Convert.ChangeType(dataReader[property.Name], convertTo), null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
property.SetValue(item, new DateTime(dataReader[property.Name].ToString().ToEntero()), null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
property.SetValue(item, Convert.ChangeType(dataReader[property.Name], convertTo), null);
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
/*
|
||||
case "Byte":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Char":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "DateTime":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Decimal":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Double":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Guid":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Int16":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Int32":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Int64":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "SByte":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "Single":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "String":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "TimeSpan":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "UInt16":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "UInt32":
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case "UInt64":
|
||||
{
|
||||
break;
|
||||
}
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(item);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene un objeto a partir de un SqlDataReader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Clase genérica en donde se obtiene la información del SqlDataReader.</typeparam>
|
||||
/// <param name="dataReader">SqlDataReader a leer.</param>
|
||||
/// <returns>Objeto T.</returns>
|
||||
public static T CreateObject<T>(SQLiteDataReader dataReader) where T : class, new()
|
||||
{
|
||||
var properties = typeof(T).GetProperties();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
var item = Activator.CreateInstance<T>();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (IsColumnExists(dataReader, property.Name))
|
||||
{
|
||||
if (!dataReader.IsDBNull(dataReader.GetOrdinal(property.Name)))
|
||||
{
|
||||
Type convertTo = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
|
||||
property.SetValue(item, Convert.ChangeType(dataReader[property.Name], convertTo), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Valida si existe un nombre de porpiedad como campo de el IDataReader.
|
||||
/// </summary>
|
||||
/// <param name="dataReader">IDataReader a validar.</param>
|
||||
/// <param name="columnName">Nombre de la columna.</param>
|
||||
/// <returns>True = si existe, False = no existe.</returns>
|
||||
private static bool IsColumnExists(SQLiteDataReader dataReader, string columnName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataReader.GetSchemaTable().Select($"ColumnName= '{columnName}'").Count() > 0)
|
||||
{
|
||||
dataReader.GetOrdinal(columnName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
if (transaccion != null)
|
||||
{
|
||||
transaccion.Rollback();
|
||||
transaccion.Dispose();
|
||||
transaccion=null;
|
||||
}
|
||||
if (comando != null)
|
||||
{
|
||||
try { comando.Dispose(); }
|
||||
catch (Exception) { }
|
||||
comando = null;
|
||||
}
|
||||
if (conexion != null)
|
||||
{
|
||||
try { conexion.Close(); }
|
||||
catch (Exception e)
|
||||
{
|
||||
Mod.GuardaLog(e, "Error al cerrar base de datos", LogsNames.LocalRepository);
|
||||
}
|
||||
try { conexion.Dispose(); }
|
||||
catch (Exception e) { Mod.GuardaLog(e, "Error al liberar recursos de base de datos", LogsNames.LocalRepository); }
|
||||
conexion = null;
|
||||
}
|
||||
isopened = false;
|
||||
}
|
||||
//static void CreateTable(SQLiteConnection conn)
|
||||
//{
|
||||
|
||||
// SQLiteCommand sqlite_cmd;
|
||||
// string Createsql = "CREATE TABLE SampleTable (Col1 VARCHAR(20), Col2 INT)";
|
||||
// string Createsql1 = "CREATE TABLE SampleTable1 (Col1 VARCHAR(20), Col2 INT)";
|
||||
// sqlite_cmd = conn.CreateCommand();
|
||||
// sqlite_cmd.CommandText = Createsql;
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
// sqlite_cmd.CommandText = Createsql1;
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
|
||||
//}
|
||||
|
||||
//static void InsertData(SQLiteConnection conn)
|
||||
//{
|
||||
// SQLiteCommand sqlite_cmd;
|
||||
// sqlite_cmd = conn.CreateCommand();
|
||||
// sqlite_cmd.CommandText = "INSERT INTO SampleTable (Col1, Col2) VALUES('Test Text ', 1); ";
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
// sqlite_cmd.CommandText = "INSERT INTO SampleTable (Col1, Col2) VALUES('Test1 Text1 ', 2); ";
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
// sqlite_cmd.CommandText = "INSERT INTO SampleTable (Col1, Col2) VALUES('Test2 Text2 ', 3); ";
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
// sqlite_cmd.CommandText = "INSERT INTO SampleTable1 (Col1, Col2) VALUES('Test3 Text3 ', 3); ";
|
||||
// sqlite_cmd.ExecuteNonQuery();
|
||||
|
||||
//}
|
||||
|
||||
//static void ReadData(SQLiteConnection conn)
|
||||
//{
|
||||
// SQLiteDataReader sqlite_datareader;
|
||||
// SQLiteCommand sqlite_cmd;
|
||||
// sqlite_cmd = conn.CreateCommand();
|
||||
// sqlite_cmd.CommandText = "SELECT * FROM SampleTable";
|
||||
|
||||
// sqlite_datareader = sqlite_cmd.ExecuteReader();
|
||||
// while (sqlite_datareader.Read())
|
||||
// {
|
||||
// string myreader = sqlite_datareader.GetString(0);
|
||||
// Console.WriteLine(myreader);
|
||||
// }
|
||||
// conn.Close();
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ADSUtileriasService.Helpers.ADSSqlite
|
||||
{
|
||||
public enum SqlLiteConnectionEnum
|
||||
{
|
||||
AppConfig = 1,
|
||||
Empresa = 2,
|
||||
|
||||
}
|
||||
}
|
||||
30
ADSUtileriasService/Helpers/GlobalVars.cs
Normal file
30
ADSUtileriasService/Helpers/GlobalVars.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ADSUtileriasService.Helpers
|
||||
{
|
||||
/*
|
||||
* ADSUtileriasService.Helpers.GlobalVars._authorization
|
||||
* ADSUtileriasService.Helpers.GlobalVars.continuarService
|
||||
*/
|
||||
public static class GlobalVars
|
||||
{
|
||||
/*
|
||||
* Ubicacion de los archivos locales
|
||||
*/
|
||||
//public static string FilesDir = System.Configuration.ConfigurationManager.AppSettings["FilesDir"].ToString();
|
||||
public static string UrlApi = System.Configuration.ConfigurationManager.AppSettings["UrlApi"].ToString();
|
||||
public static string _authorization = "";
|
||||
public static DateTime fechaChecadorlup = DateTime.MinValue;
|
||||
public static Modelos.AppSystem.Usuario user;
|
||||
public static bool continuarService=false;
|
||||
|
||||
public static string UserName = System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString();
|
||||
public static string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString();
|
||||
public static string CveEmpresa = System.Configuration.ConfigurationManager.AppSettings["CveEmpresa"].ToString();
|
||||
|
||||
}
|
||||
}
|
||||
884
ADSUtileriasService/Helpers/ModExtensiones.cs
Normal file
884
ADSUtileriasService/Helpers/ModExtensiones.cs
Normal file
@@ -0,0 +1,884 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ADSUtileriasService.Helpers
|
||||
{
|
||||
public enum requestMethod
|
||||
{
|
||||
POST = 1,
|
||||
GET = 2
|
||||
}
|
||||
public enum LogsNames
|
||||
{
|
||||
Log = 1,
|
||||
another = 2,
|
||||
LocalRepository = 3,
|
||||
SigLog = 4
|
||||
}
|
||||
/*contentType= "text/xml; charset=utf-8";
|
||||
* Headers
|
||||
*
|
||||
*/
|
||||
|
||||
public static class Mod
|
||||
{
|
||||
|
||||
public static void GuardaLog(Exception e,string Str, LogsNames logname = LogsNames.Log)
|
||||
{
|
||||
GuardaLog(string.Format("{0}\r\n{1}", Str, e), logname);
|
||||
}
|
||||
public static void GuardaLog(string Str, LogsNames logname= LogsNames.Log )
|
||||
{
|
||||
string strLineaTMP;
|
||||
strLineaTMP = string.Format("{0}{1}{2: dd-MM-yyyy HH\\:mm}", "\r\n", Str, DateTime.Now);
|
||||
string strLog = "NotImplemented";
|
||||
switch (logname)
|
||||
{
|
||||
case LogsNames.Log:
|
||||
strLog = string.Format("Log{0:yyyyMMdd}", DateTime.Now);
|
||||
break;
|
||||
case LogsNames.another:
|
||||
strLog = "another";
|
||||
break;
|
||||
case LogsNames.LocalRepository:
|
||||
strLog = "LocalRepository";
|
||||
break;
|
||||
case LogsNames.SigLog:
|
||||
strLog = "SigLog";
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
string strdir = string.Format("{0}\\logs\\", AppDomain.CurrentDomain.BaseDirectory);
|
||||
if (!System.IO.Directory.Exists(strdir))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(strdir);
|
||||
}
|
||||
using (System.IO.StreamWriter ArchivoW = new System.IO.StreamWriter(string.Format("{0}{1}_{2:yyyy-MM}.txt", strdir, strLog,DateTime.Now), true, System.Text.Encoding.UTF8))
|
||||
{
|
||||
ArchivoW.WriteLine(strLineaTMP);
|
||||
ArchivoW.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
}
|
||||
}
|
||||
static public object GetValObjDy(this object obj, string propertyName)
|
||||
{
|
||||
return obj.GetType().GetProperty(propertyName).GetValue(obj, null);
|
||||
}
|
||||
public static string FormatoNumero(this string Str, int Decimales = 2)
|
||||
{
|
||||
decimal numero = 0;
|
||||
decimal.TryParse(Str, out numero);
|
||||
StringBuilder zeros = new StringBuilder();
|
||||
for (int i = 0; i < Decimales; i++)
|
||||
{
|
||||
zeros.Append("0");
|
||||
}
|
||||
if (zeros.Length > 0)
|
||||
{
|
||||
zeros.Insert(0, ".");
|
||||
}
|
||||
string Tmp = string.Format("{0:#,0.00}", numero);
|
||||
return Tmp;
|
||||
}
|
||||
|
||||
public static bool Contiene(this int Valor, params int[] Valores)
|
||||
{
|
||||
return Array.IndexOf(Valores, Valor) >= 0;
|
||||
}
|
||||
public static bool Contiene(this string Valor, params string[] Valores)
|
||||
{
|
||||
return Array.IndexOf(Valores, Valor) >= 0;
|
||||
}
|
||||
public static string Mid(string input, int index, char newChar)
|
||||
|
||||
{
|
||||
|
||||
if (input == null)
|
||||
|
||||
{
|
||||
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
}
|
||||
|
||||
char[] chars = input.ToCharArray();
|
||||
|
||||
chars[index - 1] = newChar;
|
||||
|
||||
return new string(chars);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is equivalent to Mid Function in VB6
|
||||
/// </summary>
|
||||
/// <param name="s"> String to Check.</param>
|
||||
/// <param name="a">Position of Character</param>
|
||||
/// <param name="b">Length </param>
|
||||
/// <returns></returns> ]
|
||||
public static string Mid(string s, int a, int b)
|
||||
|
||||
{
|
||||
|
||||
string temp = s.Substring(a - 1, b);
|
||||
|
||||
return temp;
|
||||
|
||||
}
|
||||
|
||||
public static System.Data.DataTable FiltraParametros(this System.Data.DataTable dt, string RowFilter, string Orderby = "", string[] DistinctColumns = null)
|
||||
{
|
||||
System.Data.DataTable TmpDt = new System.Data.DataTable();
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
System.Data.DataView Dv = new System.Data.DataView(dt, RowFilter, Orderby, System.Data.DataViewRowState.CurrentRows);
|
||||
if (DistinctColumns != null)
|
||||
TmpDt = Dv.ToTable(true, DistinctColumns);
|
||||
else
|
||||
try
|
||||
{
|
||||
TmpDt = Dv.ToTable();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
TmpDt = null;
|
||||
}
|
||||
|
||||
Dv.Dispose();
|
||||
}
|
||||
else { TmpDt = dt; }
|
||||
return TmpDt;
|
||||
}
|
||||
|
||||
public static System.Data.DataRow FiltroPrimero(this System.Data.DataTable dt, string RowFilter, string Orderby = "")
|
||||
{
|
||||
System.Data.DataRow TmpDr = null;
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
if (RowFilter != "")
|
||||
{
|
||||
System.Data.DataView Dv = new System.Data.DataView(dt, RowFilter, Orderby, System.Data.DataViewRowState.CurrentRows);
|
||||
if (Dv.ToTable().Rows.Count > 0)
|
||||
TmpDr = Dv.ToTable().Rows[0];
|
||||
Dv.Dispose();
|
||||
}
|
||||
else
|
||||
TmpDr = dt.Rows[0];
|
||||
}
|
||||
return TmpDr;
|
||||
}
|
||||
public static bool HasRows(this System.Data.DataTable dt)
|
||||
{
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string Texto2Letras(this double Importe, int CveMoneda = 1)
|
||||
{
|
||||
string Moneda, AbrevMoneda;
|
||||
switch (CveMoneda)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
Moneda = "Dólares"; AbrevMoneda = "USD";
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
Moneda = "Euro"; AbrevMoneda = "EUR";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
Moneda = "pesos"; AbrevMoneda = "M.N.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Importe == 0)
|
||||
return string.Format("cero {0} 00/100 {1}", Moneda, AbrevMoneda);
|
||||
|
||||
string Retorno;
|
||||
string Numero = Importe.ToString("F2"); // no se usa N2,porque pone comma, y F2, no la pone
|
||||
// ********Declara variables de tipo cadena************
|
||||
string entero, dec, flag;
|
||||
StringBuilder palabras = new StringBuilder();
|
||||
dec = "";
|
||||
entero = "";
|
||||
|
||||
// ********Declara variables de tipo entero***********
|
||||
int num, x, y;
|
||||
|
||||
flag = "N";
|
||||
|
||||
// **********Número Negativo***********
|
||||
if (Mid(Numero, 1, 1) == "-")
|
||||
{
|
||||
Numero = Mid(Numero, 2, Numero.ToString().Length - 1).ToString();
|
||||
palabras.Append("menos ");
|
||||
}
|
||||
|
||||
// **********Si tiene ceros a la izquierda*************
|
||||
for (x = 1; x <= Numero.ToString().Length; x++)
|
||||
{
|
||||
if (Mid(Numero, 1, 1) == "0")
|
||||
{
|
||||
Numero = Mid(Numero, 2, Numero.ToString().Length).ToString().Trim();
|
||||
if (Numero.ToString().Length == 0)
|
||||
palabras.Clear();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// *********Dividir parte entera y decimal************
|
||||
for (y = 1; y <= Numero.Length; y++)
|
||||
{
|
||||
if (Mid(Numero, y, 1) == ".")
|
||||
flag = "S";
|
||||
else if (flag == "N")
|
||||
entero = entero + Mid(Numero, y, 1);
|
||||
else
|
||||
dec = dec + Mid(Numero, y, 1);
|
||||
}
|
||||
|
||||
// If Len(dec) = 1 Then dec = dec & "0"
|
||||
dec = dec.PadRight(2, '0');
|
||||
|
||||
// **********proceso de conversión***********
|
||||
flag = "N";
|
||||
|
||||
if (Convert.ToDouble(Numero) <= 999999999)
|
||||
{
|
||||
for (y = entero.Length; y >= 1; y += -1)
|
||||
{
|
||||
num = entero.Length - (y - 1);
|
||||
switch (y)
|
||||
{
|
||||
case 3:
|
||||
case 6:
|
||||
case 9:
|
||||
{
|
||||
// **********Asigna las palabras para las centenas***********
|
||||
switch (Mid(entero, num, 1))
|
||||
{
|
||||
case "1":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0" & Mid(entero, num + 2, 1) == "0")
|
||||
palabras.Append("cien ");
|
||||
else
|
||||
palabras.Append("ciento ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "2":
|
||||
{
|
||||
palabras.Append("doscientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "3":
|
||||
{
|
||||
palabras.Append("trescientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "4":
|
||||
{
|
||||
palabras.Append("cuatrocientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "5":
|
||||
{
|
||||
palabras.Append("quinientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "6":
|
||||
{
|
||||
palabras.Append("seiscientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "7":
|
||||
{
|
||||
palabras.Append("setecientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "8":
|
||||
{
|
||||
palabras.Append("ochocientos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "9":
|
||||
{
|
||||
palabras.Append("novecientos ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 5:
|
||||
case 8:
|
||||
{
|
||||
// *********Asigna las palabras para las decenas************
|
||||
switch (Mid(entero, num, 1))
|
||||
{
|
||||
case "0":
|
||||
{
|
||||
// CASO:260,505.81
|
||||
flag = "N";
|
||||
break;
|
||||
}
|
||||
|
||||
case "1":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("diez ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1) == "1")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("once ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1) == "2")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("doce ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1) == "3")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("trece ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1) == "4")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("catorce ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1) == "5")
|
||||
{
|
||||
flag = "S";
|
||||
palabras.Append("quince ");
|
||||
}
|
||||
if (Mid(entero, num + 1, 1).ToEntero() > 5)
|
||||
{
|
||||
flag = "N";
|
||||
palabras.Append("dieci");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "2":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("veinte ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("veinti");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "3":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("treinta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("treinta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "4":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("cuarenta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("cuarenta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "5":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("cincuenta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("cincuenta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "6":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("sesenta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("sesenta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "7":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("setenta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("setenta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "8":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("ochenta ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("ochenta y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "9":
|
||||
{
|
||||
if (Mid(entero, num + 1, 1) == "0")
|
||||
{
|
||||
palabras.Append("noventa ");
|
||||
flag = "S";
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.Append("noventa y ");
|
||||
flag = "N";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
case 4:
|
||||
case 7:
|
||||
{
|
||||
// *********Asigna las palabras para las unidades*********
|
||||
switch (Mid(entero, num, 1))
|
||||
{
|
||||
case "1":
|
||||
{
|
||||
if (flag == "N")
|
||||
{
|
||||
if (y == 1)
|
||||
palabras.Append("uno ");
|
||||
else
|
||||
palabras.Append("un ");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "2":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("dos ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "3":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("tres ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "4":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("cuatro ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "5":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("cinco ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "6":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("seis ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "7":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("siete ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "8":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("ocho ");
|
||||
break;
|
||||
}
|
||||
|
||||
case "9":
|
||||
{
|
||||
if (flag == "N")
|
||||
palabras.Append("nueve ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ***********Asigna la palabra mil***************
|
||||
if (y == 4)
|
||||
{
|
||||
if ((Mid(entero, 4, 1) != "0") | (Mid(entero, 4, 1) == "0" & entero.Length == 4) | (Mid(entero, 5, 1) != "0" & entero.Length == 5) | (Mid(entero, 6, 1) != "0" & entero.Length == 6) | (Mid(entero, 5, 1) == "0" & entero.Length == 7) | (Mid(entero, 5, 1) == "0" & Mid(entero, 4, 1) == "0" & entero.Length <= 5) | (Mid(entero, 6, 1) == "0" & Mid(entero, 5, 1) == "0" & Mid(entero, 4, 1) == "0" & entero.Length <= 6) | (Mid(entero, 7, 1) == "0" & Mid(entero, 6, 1) == "0" & Mid(entero, 5, 1) == "0" & Mid(entero, 4, 1) == "0" & entero.Length < 7) | (Mid(entero, 8, 1) == "0" & Mid(entero, 7, 1) == "0" & Mid(entero, 6, 1) == "0" & Mid(entero, 5, 1) == "0" & Mid(entero, 4, 1) == "0" & entero.Length < 8) | (Mid(entero, 3, 1) != "0" & entero.Length == 7) | (Mid(entero, 3, 1) != "0" & entero.Length == 8) | (Mid(entero, 8, 1) == "0" & Mid(entero, 8, 1) == "0" & Mid(entero, 7, 1) == "0" & Mid(entero, 6, 1) == "0" & Mid(entero, 5, 1) == "0" & Mid(entero, 4, 1) == "0" & entero.Length == 9))
|
||||
palabras.Append("mil ");
|
||||
}
|
||||
|
||||
// **********Asigna la palabra millón*************
|
||||
if (y == 7)
|
||||
{
|
||||
if (entero.Length == 7 & Mid(entero, 1, 1) == "1")
|
||||
palabras.Append("millón ");
|
||||
else
|
||||
palabras.Append("millones ");
|
||||
}
|
||||
}
|
||||
|
||||
// **********Une la parte entera y la parte decimal*************
|
||||
if (dec != "")
|
||||
{
|
||||
palabras.AppendFormat("{0} {1} /100 {2}", Moneda, dec, AbrevMoneda);
|
||||
|
||||
Retorno = palabras.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
palabras.AppendFormat("{0} {1} /100 {2}", Moneda, dec, AbrevMoneda);
|
||||
|
||||
Retorno = palabras.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
Retorno = "";
|
||||
|
||||
return Retorno;
|
||||
}
|
||||
|
||||
public static int ToEntero(this string Obj)
|
||||
{
|
||||
int result = 0;
|
||||
// restriccion menor a 10, se quitan ceros a la izquiera primero, porque provoca desbordamiento si pasa mas de una cantidad,Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.
|
||||
Obj = Obj.ToString().Trim().Replace(",", "");
|
||||
int.TryParse(Obj, out result);
|
||||
return result;
|
||||
}
|
||||
public static double ToDouble(this string Str)
|
||||
{
|
||||
double result = 0;
|
||||
Str = Str.Trim().Replace(",", "");
|
||||
if (!string.IsNullOrEmpty(Str))
|
||||
{
|
||||
double.TryParse(Str, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static double ToDouble(this string Str, double TipoCambio)
|
||||
{
|
||||
return Str.ToDouble() * TipoCambio;
|
||||
}
|
||||
public static decimal ToDecimal(this string Str)
|
||||
{
|
||||
decimal result = 0;
|
||||
Str = Str.Trim().Replace(",", "");
|
||||
if (!string.IsNullOrEmpty(Str))
|
||||
{
|
||||
Decimal.TryParse(Str, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static decimal ToDecimal(this string Str, decimal TipoCambio)
|
||||
{
|
||||
return Str.ToDecimal() * TipoCambio;
|
||||
}
|
||||
|
||||
public static DateTime ToDateTime(this string Str)
|
||||
{
|
||||
return Str.ToDate();
|
||||
}
|
||||
public static DateTime ToDate(this string Str, IFormatProvider culture = null)
|
||||
{
|
||||
DateTime retorno = DateTime.MinValue;
|
||||
if (Str != null && !string.IsNullOrEmpty(Str.Trim()))
|
||||
{
|
||||
if (culture == null)
|
||||
{
|
||||
DateTime.TryParse(Str, out retorno);
|
||||
//retorno = Convert.ToDateTime(Str.Trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
retorno = Convert.ToDateTime(Str.ToString().Trim(), culture);
|
||||
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
}
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Realizar un request a un Sitio
|
||||
/// </summary>
|
||||
/// <param name="URL">http:sig.adssistemas.mx/inicio2.aspx</param>
|
||||
/// <param name="metodo">post,get,put</param>
|
||||
/// <param name="headers">{"Titulo","Value"} ó {"SOAPAction: actionmethod"}</param>
|
||||
/// <param name="contentType">"text/xml; charset=utf-8"</param>
|
||||
/// <param name="body">body request</param>
|
||||
/// <param name="postData">var1=value1&var2=value2</param>
|
||||
/// <param name="maxTimeMilliseconds"> 120 sec</param>
|
||||
public static string SendRequest(string URL, requestMethod metodo, IEnumerable<string[]> headers, string contentType, string body, string postData, int maxTimeseconds = 120)
|
||||
{
|
||||
string resultado = "";
|
||||
try
|
||||
{
|
||||
|
||||
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
|
||||
request.Timeout = maxTimeseconds * 1000;
|
||||
request.Method = metodo.ToString("G");
|
||||
request.ContentType = contentType;
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (string[] item in headers)
|
||||
{
|
||||
if (item.Length > 1)
|
||||
{
|
||||
request.Headers.Add(item[0], item[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Headers.Add(item[0]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (request.Method == "POST")
|
||||
//{
|
||||
// if (postData != null)
|
||||
// {
|
||||
// request.ContentLength = postData.Length;
|
||||
// using (var dataStream = request.GetRequestStream())
|
||||
// {
|
||||
// dataStream.Write(postData, 0, postData.Length);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
using (System.IO.Stream stream = request.GetRequestStream())
|
||||
using (System.IO.StreamWriter stmw = new System.IO.StreamWriter(stream))
|
||||
{
|
||||
stmw.Write(body);
|
||||
}
|
||||
System.Net.WebResponse response = (System.Net.WebResponse)request.GetResponse();
|
||||
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
|
||||
resultado = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Extenciones.ApplicationParameter.GuardaLogEx(ex, $"SOAPAction : {SOAPAction} XML : {xml}");
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
|
||||
#region Encripta desencripta
|
||||
|
||||
private static byte[] _Key = new byte[] { };
|
||||
private readonly static byte[] _IV = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
||||
private readonly static byte[] _IVAES = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
||||
private static string SEncryptionKey = "$Ap7+5&z";
|
||||
//private static string SEncryptionKeyAES = "$Ap7+5&z$Ap7+5&z$Ap7+5&z$Ap7+5&z";
|
||||
public static string Decripta(string stringToDecrypt, string TipoEncryption = "DES")
|
||||
{
|
||||
string Salida;
|
||||
|
||||
if (stringToDecrypt != "")
|
||||
{
|
||||
Salida = stringToDecrypt.Replace(" ", "+");
|
||||
byte[] inputByteArray = new byte[Salida.Length + 1];
|
||||
|
||||
try
|
||||
{
|
||||
switch (TipoEncryption)
|
||||
{
|
||||
case "DES":
|
||||
{
|
||||
_Key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8));
|
||||
using (System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider())
|
||||
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
||||
using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(_Key, _IV), System.Security.Cryptography.CryptoStreamMode.Write))
|
||||
{
|
||||
inputByteArray = Convert.FromBase64String(Salida);
|
||||
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
cs.FlushFinalBlock();
|
||||
Encoding encoding = System.Text.Encoding.UTF8;
|
||||
Salida = encoding.GetString(ms.ToArray());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "AES":
|
||||
{
|
||||
//_Key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKeyAES, 32));
|
||||
//AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
|
||||
//inputByteArray = Convert.FromBase64String(Salida);
|
||||
|
||||
//MemoryStream ms = new MemoryStream();
|
||||
//CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(_Key, _IVAES), CryptoStreamMode.Write);
|
||||
//cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
//cs.FlushFinalBlock();
|
||||
//Encoding encoding = System.Text.Encoding.UTF8;
|
||||
|
||||
//Salida = encoding.GetString(ms.ToArray());
|
||||
//aes.Dispose(); ms.Dispose(); cs.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Alert("Parametros incorrectos", TipoMensaje.MsgError)
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
return "";
|
||||
|
||||
return Salida;
|
||||
}
|
||||
public static string Encripta(string stringToEncrypt, string TipoEncryption = "DES")
|
||||
{
|
||||
string Retorno = "";
|
||||
switch (TipoEncryption)
|
||||
{
|
||||
case "DES":
|
||||
{
|
||||
_Key = Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8));
|
||||
using (System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider())
|
||||
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
||||
using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(_Key, _IV), System.Security.Cryptography.CryptoStreamMode.Write))
|
||||
{
|
||||
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
|
||||
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
cs.FlushFinalBlock();
|
||||
Retorno = Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "AES":
|
||||
{
|
||||
//_Key = Encoding.UTF8.GetBytes(Left(SEncryptionKeyAES, 32));
|
||||
//AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
|
||||
//byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
|
||||
//MemoryStream ms = new MemoryStream();
|
||||
//CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(_Key, _IVAES), CryptoStreamMode.Write);
|
||||
//cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
//cs.FlushFinalBlock();
|
||||
//Retorno = Convert.ToBase64String(ms.ToArray());
|
||||
//aes.Dispose(); ms.Dispose(); cs.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Retorno;
|
||||
}
|
||||
public static string Left(this string value, int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return value;
|
||||
maxLength = Math.Abs(maxLength);
|
||||
return (value.Length <= maxLength ? value : value.Substring(0, maxLength));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user