Agregar archivos de proyecto.
This commit is contained in:
27
bdGrupoSanchoToro/dbcontext/EnumeracionesService.cs
Normal file
27
bdGrupoSanchoToro/dbcontext/EnumeracionesService.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using bdGrupoSanchoToro;
|
||||
using bdGrupoSanchoToro.db;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bdGrupoSanchoToro.dbcontext
|
||||
{
|
||||
public class EntidadService
|
||||
{
|
||||
private readonly tscGrupoSanchoToro _context;
|
||||
|
||||
public EntidadService(tscGrupoSanchoToro context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public tscGrupoSanchoToro GetContextFromEntity(enumeraciones entidad)
|
||||
{
|
||||
var entry = _context.Entry(entidad);
|
||||
return (tscGrupoSanchoToro)entry.Context;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
2186
bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs
Normal file
2186
bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs
Normal file
File diff suppressed because it is too large
Load Diff
93
bdGrupoSanchoToro/dbcontext/conexion.cs
Normal file
93
bdGrupoSanchoToro/dbcontext/conexion.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using tsUtilidades.Enumeraciones;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace bdGrupoSanchoToro.dbcontext
|
||||
{
|
||||
public class Conexion
|
||||
{
|
||||
public string Nombre { get; set; }
|
||||
public string Servidor { get; set; }
|
||||
public int Puerto { get; set; }
|
||||
|
||||
public string Database { get; set; }
|
||||
public string Usuario { get; set; }
|
||||
public string Contraseña { get; set; }
|
||||
|
||||
|
||||
public static List<Conexion> ListaConexiones()
|
||||
{
|
||||
List<Conexion> lc = new List<Conexion>();
|
||||
//lc.Add(new Conexion() { Nombre = "Producción", Puerto = 13306, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
lc.Add(new Conexion() { Nombre = "Producción", Puerto = 3306, Servidor = "10.10.10.1", Usuario = "root", Contraseña = "îéÂj,íçLÑ0*B", Database = "gruposanchotoro" });
|
||||
lc.Add(new Conexion() { Nombre = "Producción LOCAL", Puerto = 3306, Servidor = "192.168.41.44", Usuario = "root", Contraseña = "îéÂj,íçLÑ0*B", Database = "gruposanchotoro" });
|
||||
lc.Add(new Conexion() { Nombre = "Desarrollo", Puerto = 13306, Servidor = "localhost", Usuario = "root", Contraseña = "îéÂj,íçLÑ0*B", Database = "gruposanchotoro" });
|
||||
//lc.Add(new Conexion() { Nombre = "lunes", Puerto = 40001, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "martes", Puerto = 40002, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "miercoles", Puerto = 40003, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "jueves", Puerto = 40004, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "viernes", Puerto = 40005, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "sabado", Puerto = 40006, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "domingo", Puerto = 40007, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "enero", Puerto = 40101, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "febrero", Puerto = 40102, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "marzo", Puerto = 40103, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "abril", Puerto = 40104, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "mayo", Puerto = 40105, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "junio", Puerto = 40106, Servidor = "192.168.200.1",Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "julio", Puerto = 40107, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "agosto", Puerto = 40108, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "septiembre", Puerto = 40109, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "octubre", Puerto = 40110, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "noviembre", Puerto = 40111, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "diciembre", Puerto = 40112, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
//lc.Add(new Conexion() { Nombre = "replica", Puerto = 40000, Servidor = "192.168.200.1", Usuario = "m3soft", Contraseña = "îéÂj,íçLÑ0*B", Database = "GrupoSanchoToro" });
|
||||
return lc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
internal static string ObtieneConexionDefecto(string NombreConexion="Producción")
|
||||
{
|
||||
try
|
||||
{
|
||||
// optionsBuilder.UseMySql("server=GrupoSanchoToro;database=GrupoSanchoToro;port=13306;uid=m3soft;pwd=Romian2023--;persistsecurityinfo=True;TreatTinyAsBoolean=True;allowuservariables=True", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.2.0-mysql"));
|
||||
string cs = @";persistsecurityinfo=True;TreatTinyAsBoolean=False;allowuservariables=True";
|
||||
var lc = ListaConexiones();
|
||||
|
||||
var cn = lc.First(x => x.Nombre == NombreConexion);
|
||||
|
||||
string servidor = "";
|
||||
if (Environment.MachineName.ToUpper() == "SERVIDOR-ES")
|
||||
servidor = "localhost";
|
||||
else
|
||||
{
|
||||
servidor = cn.Servidor;
|
||||
try
|
||||
{
|
||||
servidor = System.Net.Dns.GetHostEntry("servidorbd").AddressList[0].ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
cs = "server=" + servidor + ";pwd=" + tsUtilidades.crypt.FEncS(cn.Contraseña, @"[JO1]", @"[JD1]", -875421649) + ";port=" + cn.Puerto.ToString() + ";uid=" + cn.Usuario + ";database=" + cn.Database + cs;
|
||||
return cs;
|
||||
}
|
||||
// End If
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
166
bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs
Normal file
166
bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
//using bdGrupoSanchoToro.CompiledModels;
|
||||
using bdGrupoSanchoToro.db;
|
||||
using bdGrupoSanchoToro.dbcontext;
|
||||
using bdGrupoSanchoToro.dbcontext;
|
||||
using Castle.Components.DictionaryAdapter.Xml;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.CompilerServices;
|
||||
using tsEFCore8.Extensiones;
|
||||
using tsUtilidades;
|
||||
using tsUtilidades.Enumeraciones;
|
||||
using tsUtilidades.Extensiones;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace bdGrupoSanchoToro
|
||||
{
|
||||
public class tscGrupoSanchoToro : bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext, tsUtilidades.ItsContexto
|
||||
|
||||
{
|
||||
|
||||
public static bool Cargado = false;
|
||||
private static String? _Ip = null;
|
||||
public string? ip
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Ip;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Ip = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Aplicaciones { get; private set; }
|
||||
|
||||
|
||||
|
||||
public static readonly Microsoft.Extensions.Logging.LoggerFactory _myLoggerFactory =
|
||||
new LoggerFactory(new[] {
|
||||
new Microsoft.Extensions.Logging.Debug.DebugLoggerProvider()
|
||||
});
|
||||
|
||||
private static string? ConexionPorDefecto=null;
|
||||
public static tscGrupoSanchoToro NuevoContexto(string NombreConexion = "" ,bool Lazy = true, bool SoloLectura = false, bool ConEventoSavingChanges = false, string aplicaciones = "")
|
||||
{
|
||||
|
||||
|
||||
|
||||
string? cnx = null;
|
||||
if (NombreConexion=="")
|
||||
{
|
||||
if (ConexionPorDefecto == null) ConexionPorDefecto = Conexion.ObtieneConexionDefecto();
|
||||
cnx = ConexionPorDefecto;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnx = Conexion.ObtieneConexionDefecto(NombreConexion);
|
||||
}
|
||||
|
||||
var ob = new DbContextOptionsBuilder<GrupoSanchoToroContext>();
|
||||
// ob.UseLoggerFactory(_myLoggerFactory);
|
||||
// ob.UseInternalServiceProvider(<EnumeracionesService>)
|
||||
ob.UseMySql(cnx, Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.0-mysql"));
|
||||
if (Lazy) ob.UseLazyLoadingProxies();
|
||||
if (SoloLectura) ob.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
var Opciones = ob.Options;
|
||||
tscGrupoSanchoToro bd = new tscGrupoSanchoToro(Opciones);
|
||||
bd.Aplicaciones = aplicaciones;
|
||||
if (ConEventoSavingChanges) bd.SavingChanges += GuardandoCambios;
|
||||
return bd;
|
||||
|
||||
}
|
||||
|
||||
//public static Datos.BBDD ObtieneBBDD(string NombreConexion)
|
||||
|
||||
private static void GuardandoCambios(object? sender, SavingChangesEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
tscGrupoSanchoToro bd = (tscGrupoSanchoToro)sender;
|
||||
var lap = bd.Aplicaciones.Split("|");
|
||||
foreach (string ap in lap)
|
||||
{
|
||||
switch (ap.ToLower())
|
||||
{
|
||||
case "facturas":
|
||||
{
|
||||
bdGrupoSanchoToro.db.facturas.GuardandoCambios(bd, ap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public tscGrupoSanchoToro(DbContextOptions<GrupoSanchoToroContext> Opciones) : base(Opciones)
|
||||
{
|
||||
if (_Ip == null) { ip = tsEFCore8.bbdd.ObtieneIPMysql(this); }
|
||||
else { ip = _Ip; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void AñadeObjeto(object Registro)
|
||||
{
|
||||
this.Add(Registro);
|
||||
}
|
||||
|
||||
public bool CompruebaUnico(EstadosAplicacion estado, string NombreCampo, object Valor, string NombreTablaBase, object DataContext)
|
||||
{
|
||||
return this.CompruebaRegistroUnico(estado == EstadosAplicacion.ModificandoRegistro, "bdGrupoSanchoToro.db", NombreTablaBase, NombreCampo, Valor, DataContext);
|
||||
}
|
||||
public void EliminaObjeto(object Registro)
|
||||
{
|
||||
if (this.Entry(Registro).State == Microsoft.EntityFrameworkCore.EntityState.Detached)
|
||||
{
|
||||
this.Entry(Registro).State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;
|
||||
}
|
||||
else if (this.Entry(Registro).State == Microsoft.EntityFrameworkCore.EntityState.Added)
|
||||
{
|
||||
this.Remove(Registro);
|
||||
this.Entry(Registro).State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Remove(Registro);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int GuardarCambios()
|
||||
{
|
||||
return this.SaveChanges();
|
||||
}
|
||||
|
||||
public bool HayModificaciones()
|
||||
{
|
||||
return this.ChangeTracker.HasChanges();
|
||||
//IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> res = from e in this.ChangeTracker.Entries()
|
||||
// where e.State.HasFlag(Microsoft.EntityFrameworkCore.EntityState.Added) ||
|
||||
// e.State.HasFlag(Microsoft.EntityFrameworkCore.EntityState.Modified) ||
|
||||
// e.State.HasFlag(Microsoft.EntityFrameworkCore.EntityState.Deleted)
|
||||
// select e;
|
||||
|
||||
//if (res.Any())
|
||||
// return true;
|
||||
//return false;
|
||||
}
|
||||
public int ObtieneLongitudCampo(string NombreTablaBase, string NombreCampo)
|
||||
{
|
||||
return this.ObtieneMaximaLongitudCampo("bdGrupoSanchoToro.db", NombreTablaBase, NombreCampo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user