public void Guardar(DynamicGrid almacenDG ) { DBConexion db = new DBConexion(); db.conn.Open(); SqlTransaction trans = db.conn.BeginTransaction(IsolationLevel.Serializable); db.cmd.Transaction = trans; uSQL = new UbicacionSQL(db); DataTable temporal= uSQL.CrearUbicacionesDT(); uSQL.AgregarFilasToUbicacionesDT(temporal, almacenDG.Ubicaciones, id); uSQL.AgregarMasivo(temporal, trans); int exito= uSQL.ActualizarUbicacionMasivo(); if (exito > 0) { UtilesSQL util = new UtilesSQL(db); util.LimpiarTabla("TemporalUbicacion"); trans.Commit(); _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Se guardo el stock")); } else { trans.Rollback(); _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Error: Revisar conexión al servidor")); } }
public void GuardarMovimiento(DynamicGrid anaquel, DynamicGrid deposito) { int exito; /*Inicializacion de la transacción*/ DBConexion db = new DBConexion(); try { db.conn.Open(); SqlTransaction trans = db.conn.BeginTransaction(IsolationLevel.ReadCommitted); db.cmd.Transaction = trans; SectorSQL sectorSQL = new SectorSQL(db); UbicacionSQL ubicacionSQL = new UbicacionSQL(db); /*Tablas temporales*/ DataTable sectoresDT = sectorSQL.CrearSectoresDT(); DataTable ubicacionesDT = ubicacionSQL.CrearUbicacionesDT(); List<Sector> lstSectores = new List<Sector>(); List<Ubicacion> ubicacionesModificadas = new List<Ubicacion>(); /*Agrupo todos los sectores y ubicaciones modificadas*/ for (int i = 0; i < anaquel.lstZonas.Count; i++) { lstSectores.AddRange(anaquel.lstZonas[i].LstSectores); for (int j = 0; j < anaquel.lstZonas[i].LstSectores.Count; j++) { ubicacionesModificadas.AddRange(anaquel.lstZonas[i].LstSectores[j].LstUbicaciones); } } /*Agrego las filas a los DT*/ sectorSQL.AgregarFilasToSectoresDT(sectoresDT, lstSectores); ubicacionSQL.AgregarFilasToUbicacionesDT(ubicacionesDT, ubicacionesModificadas); /*empieza el guardado en la bd*/ exito = sectorSQL.AgregarMasivo(sectoresDT, trans); //insertados en TemporalSector if (exito > 0) { exito = sectorSQL.ActualizarSectorMasivo(); //actualizados en tabla Sector if (exito > 0) { exito = sectorSQL.ActualizarIdSector(); //actualizo idSector en tabla sector if (exito > 0) { /*Agrego las ubicaciones de almacen de salida*/ ubicacionSQL.AgregarFilasToUbicacionesDT(ubicacionesDT, deposito.Ubicaciones, deposito.Ubicaciones[0][0][0].IdAlmacen); exito = ubicacionSQL.AgregarMasivo(ubicacionesDT, trans); if (exito > 0) { exito = ubicacionSQL.ActualizarIdSector(); if (exito > 0) { exito = ubicacionSQL.ActualizarUbicacionMasivo(); if (exito > 0) { /*Agrego el movimiento como un "todo" a la bd*/ NotaISSQL notaSQL = new NotaISSQL(db); /*Salida para el depósito*/ NotaIS nota = new NotaIS(); nota.IdMotivo = 8; nota.Tipo = 2; nota.Observaciones = ""; nota.IdDoc = 0; nota.IdAlmacen = idDeposito; nota.IdResponsable = idResponsable; /*Entrada para el anaquel*/ NotaIS notaAn = new NotaIS(); notaAn.IdMotivo = 8; notaAn.Tipo = 1; notaAn.Observaciones = ""; notaAn.IdDoc = 0; notaAn.IdAlmacen = idAnaquel; notaAn.IdResponsable = idResponsable; int idNotaDeposito = notaSQL.AgregarNota(nota, 1); int idNotaAnaquel = notaSQL.AgregarNota(notaAn, 1); if (idNotaDeposito > 0 && idNotaAnaquel> 0) { exito = sectorSQL.ActualizarTemporalSector(idNotaDeposito); if (exito > 0) { exito = notaSQL.AgregarNotaxSector(); if (exito > 0) { exito = sectorSQL.ActualizarTemporalSector(idNotaAnaquel); if (exito > 0) { exito = notaSQL.AgregarNotaxSector(); if (exito > 0) { UtilesSQL util = new UtilesSQL(db); util.LimpiarTabla("TemporalUbicacion"); util.LimpiarTabla("TemporalSector"); trans.Commit(); _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Los productos fueron transferidos correctamente")); return; } } } } } } } } } } } _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Lo sentimos , se produjo un error")); trans.Rollback(); } catch (SqlException e) { _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Se fue la conexión")); } }