private void aumentarUltimoComprobanteTenant() { using (var context = new TenantsDBContext()) { var entry = context.Tenants.Find(Common.TenantData.tenant.Id); entry.UltimoNroComprobante++; context.Entry(entry).CurrentValues.SetValues(entry); context.SaveChanges(); Common.TenantData.tenant = entry; //var ten = context.Tenants.Where(x => x.BaseDeDatos == Common.TenantData.tenant.BaseDeDatos).SingleOrDefault(); //ten.UltimoNroAsientoCargando++; } }
private void frmDiarioReporte_FormClosing(object sender, FormClosingEventArgs e) { Helpers.MessageBoxManager.Cancel = "Cancelar"; DialogResult r = MessageBox.Show("Ha impreso el libro diario sin errores?", "ConfirmaciĆ³n", MessageBoxButtons.OKCancel); //DialogResult r = Helpers.CreadorMensajes.mensajeConfirmacion(); if (r != DialogResult.Cancel) { using (var context = new VentasDBContext(Common.TenantData.tenant.ConnectionString)) { UltimoDiario u = new UltimoDiario(); u.UltimaFechaImpresion = FechaHasta; //DateTime.Now; u.UltimoNumeroAsiento = Common.TenantData.tenant.UltimoNroAsientoCargando; u.Id = context.UltimoDiario.FirstOrDefault().Id; var entry = context.UltimoDiario.Find(u.Id); context.Entry(entry).CurrentValues.SetValues(u); try { context.SaveChanges(); DialogResult = DialogResult.OK; } catch (Exception ex) { throw ex; } } using (var context = new TenantsDBContext()) { var entity = context.Tenants.Find(Common.TenantData.tenant.Id); //var t = new Tenant(); Tenant t = context.Tenants.SingleOrDefault(x => x.Id == Common.TenantData.tenant.Id); t.FechaImpresionUltimoDiario = FechaHasta; context.Entry(entity).CurrentValues.SetValues(t); context.SaveChanges(); } } }
public static void MigrateDatabase(Tenant tenant) //string DBName/*VentasDBContext ctx*/) { //context.Database.Create(); //var datab = context.Database; //Tenant tenant = new Tenant(); using (var context = new TenantsDBContext()) { //tenant.BaseDeDatos = DBName; tenant.ConnectionString = "data source=DESKTOP-JSIT42C\\SQLEXPRESS; MultipleActiveResultSets=true ;initial catalog=" + tenant.BaseDeDatos + "; integrated security=SSPI"; tenant.Host = (System.Environment.MachineName == "DESKTOP-JSIT42C") ? "DESKTOP-JSIT42C\\SQLEXPRESS" : "localhost"; tenant.Nombre = tenant.BaseDeDatos; context.Tenants.Add(tenant); context.SaveChanges(); } Common.TenantData.tenant = tenant; //using (var context = new VentasDBContext(tenant.ConnectionString)) //{ // UltimoDiario u = new UltimoDiario(); // u.UltimaFechaImpresion = tenant.FechaImpresionUltimoDiario; // u.UltimoNumeroAsiento = 1; // u.UltimoNumeroFolio = 1; // u.UltimoNumeroRenglon = 1; // u.UltimoNumeroTransporte = 1; // context.UltimoDiario.Add(u); // context.SaveChanges(); //} var newDbConnString = "data source=DESKTOP-JSIT42C\\SQLEXPRESS; MultipleActiveResultSets=true ;initial catalog=" + tenant.BaseDeDatos + "; integrated security=SSPI"; //context.Database.Connection.ConnectionString; var connStringBuilder = new SqlConnectionStringBuilder(newDbConnString); connStringBuilder.InitialCatalog = tenant.BaseDeDatos; ConfigurationVentas config = new ConfigurationVentas(); DbMigrator migrator = new DbMigrator(config); VentasDBContext ctx = new VentasDBContext(newDbConnString); ctx.Database.Create(); Console.WriteLine("Past migrations:"); foreach (string s in migrator.GetDatabaseMigrations()) { Console.WriteLine(s); } Console.WriteLine("Local migrations:"); foreach (string s in migrator.GetLocalMigrations()) { Console.WriteLine(s); } Console.WriteLine("Pending migrations:"); foreach (string s in migrator.GetPendingMigrations()) { Console.WriteLine(s); } Console.WriteLine("Migrating..."); foreach (string s in migrator.GetLocalMigrations()) //GetPendingMigrations()) { //Act Console.WriteLine("Applying migration {0}", s); Action act = () => migrator.Update(s); //Assert //act.ShouldNotThrow(); } }