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 int GuardarTienda(MadeInHouse.Dictionary.DynamicGrid anaquel, MadeInHouse.Dictionary.DynamicGrid deposito) { Evaluador eva = new Evaluador(); if (String.IsNullOrEmpty(TxtAlturaAnq) || String.IsNullOrEmpty(TxtNumColumnsAnq) || String.IsNullOrEmpty(TxtNumRowsAnq) || String.IsNullOrEmpty(TxtAlturaDto) || String.IsNullOrEmpty(TxtNumColumnsDto) || String.IsNullOrEmpty(TxtNumRowsDto) || !eva.esNumeroEntero(TxtNumColumnsAnq) || !eva.esNumeroEntero(TxtNumColumnsDto) || !eva.esNumeroEntero(TxtNumRowsAnq) || !eva.esNumeroEntero(TxtNumRowsDto) || !eva.esNumeroEntero(TxtAlturaAnq) || !eva.esNumeroEntero(TxtAlturaDto) || int.Parse(TxtAlturaDto) <= 0 || int.Parse(TxtAlturaAnq) <= 0 || int.Parse(TxtNumColumnsAnq) <= 0 || int.Parse(TxtNumColumnsDto) <= 0 || int.Parse(TxtNumRowsAnq) <= 0 || int.Parse(TxtNumRowsDto) <= 0 ) { System.Windows.MessageBox.Show("Debes ingresar un numero entero para el numero de filas , columnas y altura"); return 1; } int exito = 0; DBConexion db = new DBConexion(); db.conn.Open(); SqlTransaction trans = db.conn.BeginTransaction(IsolationLevel.Serializable); db.cmd.Transaction = trans; pxaSQL = new ProductoSQL(db); /*Agrega una tienda*/ Tienda tienda = new Tienda(); tienda.Estado = 1; tienda.Nombre = txtNombre; tienda.Direccion = txtDir; tienda.Telefono = txtTelef; tienda.Administrador = txtAdmin; Ubigeo seleccionado = new Ubigeo(); UbigeoSQL uSQL = new UbigeoSQL(db); seleccionado = uSQL.buscarUbigeo(selectedDpto, selectedProv, selectedDist); tienda.IdUbigeo = seleccionado.IdUbigeo; tienda.FechaReg = DateTime.Today; TiendaSQL gw = new TiendaSQL(db); int idTienda=-1; if (accion == 1) idTienda = gw.AgregarTienda(tienda); else if (accion == 2) { tienda.IdTienda = this.idTienda; exito = gw.ActualizarTienda(tienda); } if (idTienda > 0 || exito>0) { /*Se agregan las dos partes de la tienda*/ AlmacenSQL aSQL = new AlmacenSQL(db); /*anaquel*/ Almacenes ana = new Almacenes(); ana.CodAlmacen = "ANA00" + tienda.IdTienda.ToString(); ana.IdTienda = tienda.IdTienda; ana.Nombre = "Anaquel de "+ txtNombre; ana.Telefono = tienda.Telefono; ana.Direccion = tienda.Direccion; ana.NroColumnas = int.Parse(TxtNumColumnsAnq); ana.NroFilas = int.Parse(TxtNumRowsAnq); ana.Altura = int.Parse(TxtAlturaAnq); ana.Tipo = 2; int idAnaquel=-1; if (accion == 1) idAnaquel = aSQL.Agregar(ana); else if (accion == 2) { ana.IdAlmacen = this.idAnaquel; exito = aSQL.Actualizar(ana); } if (idAnaquel > 0 || exito>0) { /*deposito*/ Almacenes dto = new Almacenes(); dto.CodAlmacen = "DTO00" + tienda.IdTienda.ToString(); dto.IdTienda = tienda.IdTienda; dto.Nombre = "Deposito de " + txtNombre; dto.Telefono = tienda.Telefono; dto.Direccion = tienda.Direccion; dto.NroColumnas = int.Parse(TxtNumColumnsDto); dto.NroFilas = int.Parse(TxtNumRowsDto); dto.Altura = int.Parse(TxtAlturaDto); dto.Tipo = 1; int idDeposito=-1; if (accion == 1) idDeposito = aSQL.Agregar(dto); else if (accion == 2) { dto.IdAlmacen = this.idDeposito; exito = aSQL.Actualizar(dto); } if (idDeposito > 0 || exito>0) { if (accion == 1) { /*Productos de la tienda*/ for (int i = 0; i < LstProductos.Count; i++) { LstProductos[i].IdAlmacen = idDeposito; LstProductos[i].IdTienda = idTienda; exito = pxaSQL.AgregarProductoxAlmacen(LstProductos[i]); if (exito <= 0) break; } } else if (accion == 2) { DataTable productoxAlmacenDT= pxaSQL.CrearProductoxAlmacenDT(); pxaSQL.AgregarFilasToDT(productoxAlmacenDT, LstProductos); exito = pxaSQL.ActualizarProductoxAlmacen(productoxAlmacenDT,trans); } if (exito > 0) { DataTable zonaxAlmacenData = CrearZonasDT(); AgregarFilasToZonasDT(zonaxAlmacenData, anaquel.listaZonas, (accion==1) ? idAnaquel :this.idAnaquel ); AgregarFilasToZonasDT(zonaxAlmacenData, deposito.listaZonas, (accion==1) ? idDeposito : this.idDeposito ); if (accion==1) exito = aSQL.AgregarZonasMasivo(zonaxAlmacenData, trans); else if (accion==2) exito = aSQL.ActualizarZonasMasivo(zonaxAlmacenData, trans); if (exito > 0) { UbicacionSQL ubSQL = new UbicacionSQL(db); /*Ubicaciones del anaquel*/ DataTable ubicacionesData = CrearUbicacionesDT(); AgregarFilasToUbicacionesDT(ubicacionesData, anaquel.Ubicaciones, (accion == 1) ? idAnaquel : this.idAnaquel); AgregarFilasToUbicacionesDT(ubicacionesData, deposito.Ubicaciones, (accion == 1) ? idDeposito : this.idDeposito); if (accion == 1) exito = ubSQL.AgregarMasivo(ubicacionesData, trans); else if (accion == 2) exito = ubSQL.ActualizarUbicacionMasivo(ubicacionesData, trans); if (exito > 0) { trans.Commit(); if (accion == 1) { //1: Agregar, 2: Editar, 3: Eliminar, 4: Recuperar, 5: Desactivar DataObjects.Seguridad.LogSQL.RegistrarActividad("Registrar Tienda", tienda.IdTienda+"", 1); System.Windows.MessageBox.Show("Se creó la tienda correctamente"); } else if (accion == 2) { //1: Agregar, 2: Editar, 3: Eliminar, 4: Recuperar, 5: Desactivar DataObjects.Seguridad.LogSQL.RegistrarActividad("Actualizar Tienda",tienda.IdTienda+"" , 2); System.Windows.MessageBox.Show("Se editó la tienda correctamente"); } return 1; } else { System.Windows.MessageBox.Show("ERROR"); } } else { System.Windows.MessageBox.Show("ERROR"); } } else { System.Windows.MessageBox.Show("ERROR"); } } else { System.Windows.MessageBox.Show("ERROR"); } } else { System.Windows.MessageBox.Show("ERROR"); } } else { System.Windows.MessageBox.Show("ERROR"); } trans.Rollback(); return -1; // System.Windows.MessageBox.Show("Se creo correctamente la tienda con id: " + idTienda.ToString() + " con anaquel id: " + idAnaquel.ToString() + " y con deposito id :" + idDeposito.ToString()); }
public int GuardarAlmacen(MadeInHouse.Dictionary.DynamicGrid deposito) { int exito = 1; DBConexion db = new DBConexion(); db.conn.Open(); SqlTransaction trans = db.conn.BeginTransaction(IsolationLevel.Serializable); db.cmd.Transaction = trans; Almacenes central = new Almacenes(); central.Estado = 1; central.CodAlmacen = "CENTRAL001"; central.Nombre = TxtNombre; central.Direccion = TxtDir; central.Telefono = TxtTelefono; central.Administrador = txtAdmin; Ubigeo seleccionado = new Ubigeo(); UbigeoSQL uSQL = new UbigeoSQL(db); seleccionado = uSQL.buscarUbigeo(selectedDpto, selectedProv, selectedDist); central.IdUbigeo = seleccionado.IdUbigeo; central.FechaReg = DateTime.Today; AlmacenSQL aSQL = new AlmacenSQL(db); if (TxtNumColumns != null) central.NroColumnas = int.Parse(TxtNumColumns); else return -1; central.NroFilas = int.Parse(TxtNumRows); if (TxtAltura != null) central.Altura = int.Parse(TxtAltura); else return -1; central.Tipo = 3; int idAlmacen = aSQL.Agregar(central); central.IdAlmacen = idAlmacen; central.CodAlmacen = "CENTRAL001"; int up = aSQL.Actualizar(central); if (idAlmacen > 0 && up > 0) { DataTable zonaxAlmacenData = CrearZonasDT(); AgregarFilasToZonasDT(zonaxAlmacenData, deposito.listaZonas, idAlmacen); /*Agrego las zonas por almacen*/ exito = aSQL.AgregarZonasMasivo(zonaxAlmacenData, trans); if (exito > 0) { UbicacionSQL ubSQL = new UbicacionSQL(db); /*Ubicaciones del anaquel*/ DataTable ubicacionesData = CrearUbicacionesDT(); AgregarFilasToUbicacionesDT(ubicacionesData, deposito.Ubicaciones, idAlmacen); exito = ubSQL.AgregarMasivo(ubicacionesData, trans); trans.Commit(); _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Se creó el almacen central correctamente")); return 1; } else { _windowManager.ShowDialog(new AlertViewModel(_windowManager, "ERROR")); } } else { _windowManager.ShowDialog(new AlertViewModel(_windowManager, "ERROR")); } trans.Rollback(); return -1; }
public List<Sector> ObtenerSectores(int idAlmacen = -1, int idTipoZona = -1) { List<Sector> lstSectores = null; db.cmd.CommandText = "SELECT S.* FROM Sector S" + " WHERE S.idAlmacen=@idAlmacen and S.idTipoZona=@idTipoZona"; db.cmd.Parameters.AddWithValue("@idAlmacen", idAlmacen); db.cmd.Parameters.AddWithValue("@idTipoZona", idTipoZona); try { db.conn.Open(); SqlDataReader reader = db.cmd.ExecuteReader(); lstSectores = new List<Sector>(); while (reader.Read()) { Sector s = new Sector(); s.IdSector= int.Parse(reader["idSector"].ToString()); s.IdAlmacen = idAlmacen; s.IdTipoZona = idTipoZona; s.IdProducto = reader.IsDBNull(reader.GetOrdinal("idProducto")) ? 0 : int.Parse(reader["idProducto"].ToString()); s.Cantidad = reader.IsDBNull(reader.GetOrdinal("cantidad")) ? 0 : int.Parse(reader["cantidad"].ToString()); s.VolOcupado = reader.IsDBNull(reader.GetOrdinal("volOcupado")) ? 0: int.Parse(reader["volOcupado"].ToString()); s.NroColor = reader.IsDBNull(reader.GetOrdinal("nroColor")) ? 0 : int.Parse(reader["nroColor"].ToString()); s.Capacidad = reader.IsDBNull(reader.GetOrdinal("capacidad")) ? 0 : int.Parse(reader["capacidad"].ToString()); s.NroUbicaciones = reader.IsDBNull(reader.GetOrdinal("nroUbicaciones")) ? 0 : int.Parse(reader["nroUbicaciones"].ToString()); lstSectores.Add(s); } reader.Close(); db.conn.Close(); db.cmd.Parameters.Clear(); } catch (SqlException e) { Console.WriteLine(e); return null; } catch (Exception e) { Console.WriteLine(e.StackTrace.ToString()); return null; } UbicacionSQL uSQL = new UbicacionSQL(); for (int i = 0; i < lstSectores.Count; i++) { lstSectores[i].LstUbicaciones = uSQL.ObtenerUbicaciones(idAlmacen, lstSectores[i].IdTipoZona,lstSectores[i].IdSector); } return lstSectores; }
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")); } }
public List<TipoZona> ObtenerZonasxAlmacen(int idAlmacen,int tipo=-1) { List<TipoZona> lstZonas=new List<TipoZona>();; db.cmd.CommandText = "SELECT A.*,B.nombre nombreZona,C.codHex color,C.codHex FROM ZonaxAlmacen A " + "JOIN TipoZona B ON (A.idTipoZona=B.idTipoZona) " + " JOIN Color C ON (B.idColor=C.idColor) " + " WHERE A.idAlmacen=@idAlmacen"; db.cmd.Parameters.AddWithValue("@idAlmacen", idAlmacen); try { db.conn.Open(); SqlDataReader reader = db.cmd.ExecuteReader(); while (reader.Read()) { TipoZona tz = new TipoZona(); tz.IdTipoZona = int.Parse(reader["idTipoZona"].ToString()); tz.Nombre = reader["nombreZona"].ToString(); tz.Color = reader["color"].ToString(); tz.NroBloquesDisp = reader.IsDBNull(reader.GetOrdinal("nroBloquesDisp"))? -1:int.Parse(reader["nroBloquesDisp"].ToString()); tz.NroBloquesTotal= reader.IsDBNull(reader.GetOrdinal("nroBloquesTotal"))? -1:int.Parse(reader["nroBloquesTotal"].ToString()); lstZonas.Add(tz); } db.conn.Close(); reader.Close(); db.cmd.Parameters.Clear(); } catch (SqlException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e.StackTrace.ToString()); } UbicacionSQL uSQL = new UbicacionSQL(); for (int i = 0; i < lstZonas.Count; i++) { lstZonas[i].LstUbicaciones = uSQL.ObtenerUbicaciones(idAlmacen, lstZonas[i].IdTipoZona); } SectorSQL sSQL = new SectorSQL(); if (tipo == 2) { for (int i = 0; i < lstZonas.Count; i++) { lstZonas[i].LstSectores = sSQL.ObtenerSectores(idAlmacen, lstZonas[i].IdTipoZona); if (lstZonas[i].LstSectores == null) { lstZonas[i].LstSectores = new List<Sector>(); } } } return lstZonas; }