/// <summary> /// Crea un registro en almacen inventario lote, mandandole todos los parametros sin afectar la tabla Folio Lote Producto /// </summary> /// <param name="almacenInventarioLoteInfo"></param> /// <returns></returns> internal int CrearConTodosParametros(AlmacenInventarioLoteInfo almacenInventarioLoteInfo) { try { Logger.Info(); Dictionary <string, object> parameters = AuxAlmacenInventarioLoteDAL.ObtenerParametrosCrearConTodosParametros(almacenInventarioLoteInfo); int result = Create("AlmacenInventarioLote_CrearTodosParametros", parameters); return(result); } catch (SqlException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (DataException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene el almacen en base a la organizacion, el tipo de almacen , el producto y el numero de lote /// </summary> /// <param name="lote"></param> /// <param name="datosLotes"></param> /// <returns></returns> internal AlmacenInventarioLoteInfo ObtenerPorLoteTipoAlmacenProducto(int lote, ParametrosOrganizacionTipoAlmacenProductoActivo datosLotes) { AlmacenInventarioLoteInfo almacenInventarioLote = null; try { var listaInventariosLote = ObtenerListadoLotesPorOrganizacionTipoAlmacenProducto(datosLotes); if (listaInventariosLote != null && listaInventariosLote.Count > 0) { var listaAlmacenInventarioLote = (from inventarioLote in listaInventariosLote where inventarioLote.Lote == lote select inventarioLote); if (listaAlmacenInventarioLote != null && listaAlmacenInventarioLote.Count() > 0) { almacenInventarioLote = listaAlmacenInventarioLote.First(); } } } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
public static AlmacenInventarioLoteInfo ObtenerCantidadPiezas(int idInventarioLote) { AlmacenInventarioLoteInfo lote = null; try { SeguridadInfo seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo; if (seguridad != null) { var almacenPl = new AlmacenInventarioLotePL(); lote = almacenPl.ObtenerAlmacenInventarioLotePorId(idInventarioLote); } else { throw new ExcepcionServicio("SesionExpirada"); } } catch (ExcepcionServicio ex) { Logger.Error(ex); throw new ExcepcionServicio(ex.Message); } catch (Exception ex) { Logger.Error(ex); throw new Exception(ex.Message); } return(lote); }
/// <summary> /// Obtener lote /// </summary> /// <param name="filtro"></param> public void ObtenerLote(string filtro) { try { if (skAyudaLote.Clave != string.Empty) { if (ValidarLote(skAyudaLote.Info)) { almacenInventarioLote = skAyudaLote.Info; } else { skAyudaLote.Clave = string.Empty; skAyudaLote.Descripcion = string.Empty; } skAyudaLote.Info = new AlmacenInventarioLoteInfo { ProductoId = producto.ProductoId, OrganizacionId = pedido.Organizacion.OrganizacionID, TipoAlmacenId = (int)TipoAlmacenEnum.MateriasPrimas, Activo = EstatusEnum.Activo }; } } catch (Exception ex) { Logger.Error(ex); } }
/// <summary> /// Se obtiene lotes /// </summary> /// <param name="datosLote"></param> /// <returns></returns> internal IList <AlmacenInventarioLoteInfo> ObtenerLotesUso(AlmacenInventarioLoteInfo datosLote) { try { Dictionary <string, object> parameters = AuxAlmacenInventarioLoteDAL. ObtenerParametrosObtenerLotesUso(datosLote); DataSet ds = Retrieve("AlmacenInventarioLote_ObtenerLotesUso", parameters); IList <AlmacenInventarioLoteInfo> lista = null; if (ValidateDataSet(ds)) { lista = MapAlmacenInventarioLoteDAL.ObtenerListadoAlmacenInventarioLote(ds); } return(lista); } catch (SqlException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (DataException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene almaceninventariolote por folio /// </summary> /// <param name="almacenInventarioLote"></param> /// <returns></returns> internal AlmacenInventarioLoteInfo ObtenerAlmacenInventarioLoteAlmacenCodigo(AlmacenInventarioLoteInfo almacenInventarioLote) { try { var almacenDAL = new AlmacenInventarioLoteDAL(); almacenInventarioLote = almacenDAL.ObtenerAlmacenInventarioLoteAlmacenCodigo(almacenInventarioLote); if (almacenInventarioLote != null) { if (almacenInventarioLote.AlmacenInventario.AlmacenInventarioID > 0) { var almacenInventarioBl = new AlmacenInventarioBL(); almacenInventarioLote.AlmacenInventario = almacenInventarioBl.ObtenerAlmacenInventarioPorId( almacenInventarioLote.AlmacenInventario.AlmacenInventarioID); } } } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Obtiene los parametros para insertar un registro almacen inventario lote /// </summary> /// <param name="almacenInventarioLoteInfo"></param> /// <param name="almacenInventarioInfo"></param> /// <returns></returns> internal static Dictionary <string, object> ObtenerParametrosCrear(AlmacenInventarioLoteInfo almacenInventarioLoteInfo, AlmacenInventarioInfo almacenInventarioInfo) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@AlmacenInventarioID", almacenInventarioLoteInfo.AlmacenInventario.AlmacenInventarioID }, { "@Cantidad", almacenInventarioLoteInfo.Cantidad }, { "@PrecioPromedio", almacenInventarioLoteInfo.PrecioPromedio }, { "@Piezas", almacenInventarioLoteInfo.Piezas }, { "@Importe", almacenInventarioLoteInfo.Importe }, { "@Activo", almacenInventarioLoteInfo.Activo.GetHashCode() }, { "@UsuarioCreacionID", almacenInventarioLoteInfo.UsuarioCreacionId }, { "@AlmacenID", almacenInventarioInfo.AlmacenID }, { "@ProductoID", almacenInventarioInfo.ProductoID } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Validar lote /// </summary> /// <param name="lote"></param> /// <returns></returns> private bool ValidarLote(AlmacenInventarioLoteInfo lote) { if (Programacion == null) { if (detallePedido.ProgramacionMateriaPrima != null) { foreach (var programacionInfo in detallePedido.ProgramacionMateriaPrima) { if (programacionInfo.InventarioLoteOrigen != null) { if (lote.AlmacenInventarioLoteId == programacionInfo.InventarioLoteOrigen.AlmacenInventarioLoteId) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CrearProgramacionMateriaPrimaDialogo_MsgLoteCapturado, MessageBoxButton.OK, MessageImage.Warning); skAyudaLote.AsignarFoco(); return(false); } } } } } return(true); }
/// <summary> /// Actualiza la infomracion del inventario - lote cuando se genera un envio de alimento /// </summary> /// <param name="almacenInventarioLoteInfo">Información del almácen lote - inventari</param> internal void ActualizarInventarioLoteEnvioMercancia(AlmacenInventarioLoteInfo almacenInventarioLoteInfo) { try{ Dictionary <string, object> parametros = AuxAlmacenInventarioLoteDAL.ObtenerParametrosActualizarEnvioAlimento(almacenInventarioLoteInfo); Update("AlmacenInventarioLote_ActualizarEnvioAlimento", parametros); } catch (Exception ex) { throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Genera los registros para guardar el ajuste del almacen, en la tabla AlmacenInventario o AlmacenInventarioLote /// </summary> private void GenerarAjustesInventario(List <AlmacenInventarioLoteInfo> listaAlmacenInventarioLote, List <AlmacenInventarioInfo> listaAlmacenInventario, CierreDiaInventarioPAInfo cierreDiaInventarioPA) { var productosConLote = cierreDiaInventarioPA.ListaCierreDiaInventarioPADetalle.Where( prod => prod.ManejaLote && !prod.RequiereAutorizacion); var productosSinLote = cierreDiaInventarioPA.ListaCierreDiaInventarioPADetalle.Where( prod => !prod.ManejaLote && !prod.RequiereAutorizacion); listaAlmacenInventarioLote.AddRange((from lote in productosConLote let esEntrada = (lote.InventarioFisico - lote.InventarioTeorico > 0) select new AlmacenInventarioLoteInfo { AlmacenInventarioLoteId = lote.AlmacenInventarioLoteID, Cantidad = Math.Abs(lote.InventarioFisico - lote.InventarioTeorico), Piezas = Math.Abs(lote.PiezasFisicas - lote.PiezasTeoricas), UsuarioModificacionId = cierreDiaInventarioPA.UsuarioCreacionID, ProductoId = lote.ProductoID, EsEntrada = esEntrada }).ToList()); listaAlmacenInventario.AddRange((from producto in productosSinLote let esEntrada = (producto.InventarioFisico - producto.InventarioTeorico > 0) select new AlmacenInventarioInfo { AlmacenID = cierreDiaInventarioPA.AlmacenID, ProductoID = producto.ProductoID, Cantidad = Math.Abs(producto.InventarioFisico - producto.InventarioTeorico), UsuarioModificacionID = cierreDiaInventarioPA.UsuarioCreacionID, EsEntrada = esEntrada })); foreach (var almacenInventarioLoteInfo in listaAlmacenInventarioLote) { AlmacenInventarioLoteInfo info = almacenInventarioLoteInfo; if (!listaAlmacenInventario.Where(registro => registro.ProductoID == info.ProductoId).ToList().Any()) { var almacenInventario = new AlmacenInventarioInfo { AlmacenID = cierreDiaInventarioPA.AlmacenID, ProductoID = info.ProductoId, Cantidad = listaAlmacenInventarioLote.Where(registro => registro.ProductoId == info.ProductoId) .ToList() .Sum(registro => registro.Cantidad), UsuarioModificacionID = cierreDiaInventarioPA.UsuarioCreacionID }; listaAlmacenInventario.Add(almacenInventario); } } }
/// <summary> /// Actualiza la infomracion del inventario - lote cuando se genera un envio de alimento /// </summary> /// <param name="almacenInventarioLoteInfo">Información del almácen lote - inventari</param> internal void ActualizarEnvioAlimento(AlmacenInventarioLoteInfo almacenInventarioLote) { try { new AlmacenInventarioLoteDAL().ActualizarInventarioLoteEnvioMercancia(almacenInventarioLote); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Desactiva un lote /// </summary> /// <param name="almacenInventarioLote"></param> internal void DesactivarLote(AlmacenInventarioLoteInfo almacenInventarioLote) { try { var almacenInventarioLoteDAL = new AlmacenInventarioLoteDAL(); almacenInventarioLoteDAL.DesactivarLote(almacenInventarioLote); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
public static AlmacenInventarioLoteInfo ObtenerExistenciaInventario(int almacenInventarioLoteId) { var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo; AlmacenInventarioLoteInfo almacenInventarioLoteInfo = null; var almaceninventariolotepl = new AlmacenInventarioLotePL(); if (seguridad != null) { almacenInventarioLoteInfo = almaceninventariolotepl.ObtenerAlmacenInventarioLotePorId(almacenInventarioLoteId); } return(almacenInventarioLoteInfo); }
/// <summary> /// Actualiza un registro almacen inventario lote /// </summary> /// <returns></returns> internal void DesactivarLote(AlmacenInventarioLoteInfo almacenInventarioLote) { try { Dictionary <string, object> parametros = AuxAlmacenInventarioLoteDAL.ObtenerParametrosDesactivarLote(almacenInventarioLote); Update("AlmacenInventarioLote_DesactivarLote", parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Validar lote en uso /// </summary> /// <returns></returns> private bool ValidarLoteEnUso() { decimal cantidadProgramadaAux = 0; var datosLote = new AlmacenInventarioLoteInfo { ProductoId = producto.ProductoId, OrganizacionId = pedido.Organizacion.OrganizacionID, TipoAlmacenId = (int)TipoAlmacenEnum.MateriasPrimas, Activo = EstatusEnum.Activo }; var almacenInventarioLotePL = new AlmacenInventarioLotePL(); IList <AlmacenInventarioLoteInfo> resultado = almacenInventarioLotePL.ObtenerLotesUso(datosLote); if (resultado != null) { if (Convert.ToInt32(skAyudaLote.Clave) == resultado[0].Lote || Autorizado) { Autorizado = false; return(true); } if (Convert.ToInt32(skAyudaLote.Clave) == resultado[1].Lote) { var pedidoPL = new PedidosPL(); int cantidadProgramada = pedidoPL.ObtenerPedidosProgramadosPorLoteCantidadProgramada(resultado[0].Lote); if (detallePedido.ProgramacionMateriaPrima != null) { foreach ( var programacionMateriaPrimaInfo in detallePedido.ProgramacionMateriaPrima.Where( programacionMateriaPrimaInfo => programacionMateriaPrimaInfo.InventarioLoteOrigen.Lote == resultado[0].Lote)) { cantidadProgramadaAux = programacionMateriaPrimaInfo.CantidadProgramada; } } if ((resultado[0].Cantidad - (cantidadProgramada + cantidadProgramadaAux)) == 0) { return(true); } } loteEnUso = resultado[0].Lote; } SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], string.Format(Properties.Resources.SolicitudProgramacionMateriaPrima_RequiereAutorizacion, skAyudaLote.Clave), MessageBoxButton.OK, MessageImage.Warning); SolicitarAutorizacionLoteUso(); return(false); }
/// <summary> /// Existe solicitud autorizada para folio seleccionado /// </summary> private void ExisteSolicitudAutorizada() { bool loteProgramacion = false; var solicitudAutorizacionPl = new SolicitudAutorizacionPL(); var autorizacionInfo = new AutorizacionMateriaPrimaInfo { OrganizacionID = organizacionID, TipoAutorizacionID = TipoAutorizacionEnum.UsoLote.GetHashCode(), Folio = pedido.FolioPedido, EstatusID = Estatus.AMPAutoriz.GetHashCode() }; AutorizacionMateriaPrimaInfo resultado = solicitudAutorizacionPl.ObtenerDatosSolicitudAutorizada(autorizacionInfo); if (resultado != null) { if (detallePedido.ProgramacionMateriaPrima != null && detallePedido.ProgramacionMateriaPrima.Count > 0) { loteProgramacion = detallePedido.ProgramacionMateriaPrima.Any( programacionMateriaPrimaInfo => programacionMateriaPrimaInfo.InventarioLoteOrigen.Lote == resultado.Lote); } if (!loteProgramacion) { skAyudaLote.Clave = resultado.Lote.ToString(CultureInfo.InvariantCulture); skAyudaLote.Descripcion = resultado.Lote.ToString(CultureInfo.InvariantCulture); txtCantidadProgramada.Text = Convert.ToString(resultado.CantidadProgramada); var almacenInventarioLoteInfo = new AlmacenInventarioLoteInfo { ProductoId = producto.ProductoId, OrganizacionId = pedido.Organizacion.OrganizacionID, TipoAlmacenId = (int)TipoAlmacenEnum.MateriasPrimas, Activo = EstatusEnum.Activo, Lote = resultado.Lote }; var almacenInventarioLotePL = new AlmacenInventarioLotePL(); AlmacenInventarioLoteInfo resultadoInfo = almacenInventarioLotePL.ObtenerAlmacenInventarioLotePorFolio(almacenInventarioLoteInfo); almacenInventarioLote = resultadoInfo; almacenInventarioLote.ProductoId = almacenInventarioLoteInfo.ProductoId; almacenInventarioLote.OrganizacionId = almacenInventarioLoteInfo.OrganizacionId; almacenInventarioLote.TipoAlmacenId = almacenInventarioLoteInfo.TipoAlmacenId; almacenInventarioLote.Activo = almacenInventarioLoteInfo.Activo; almacenInventarioLote.Lote = almacenInventarioLoteInfo.Lote; skAyudaLote.Info = resultadoInfo; } } }
/// <summary> /// Obtiene el almacen en base al folio /// </summary> /// <param name="almacenInventarioLote"></param> /// <returns></returns> public AlmacenInventarioLoteInfo ObtenerAlmacenInventarioLotePorFolio(AlmacenInventarioLoteInfo almacenInventarioLote) { try { var almacenDAL = new AlmacenInventarioLoteBL(); almacenInventarioLote = almacenDAL.ObtenerAlmacenInventarioLotePorLote(almacenInventarioLote); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Obtiene almaceninventariolote por folio /// </summary> /// <param name="contrato"></param> /// <returns></returns> internal AlmacenInventarioLoteInfo ObtenerAlmacenInventarioLotePorContratoID(ContratoInfo contrato) { AlmacenInventarioLoteInfo almacenInventarioLote = null; try { var almacenDAL = new AlmacenInventarioLoteDAL(); almacenInventarioLote = almacenDAL.ObtenerAlmacenInventarioLotePorContratoID(contrato); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Obtiene una lista lotes para verificacion de lote en uso. /// </summary> /// <param name="datosLote"></param> /// <returns></returns> public IList <AlmacenInventarioLoteInfo> ObtenerLotesUso(AlmacenInventarioLoteInfo datosLote) { IList <AlmacenInventarioLoteInfo> listaLotes = null; try { var almacenBl = new AlmacenInventarioLoteBL(); listaLotes = almacenBl.ObtenerLotesUso(datosLote); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(listaLotes); }
public AlmacenInventarioLoteInfo CrearLotePorOrganizacionTipoAlmacenProducto(ParametrosOrganizacionTipoAlmacenProductoActivo parametro) { AlmacenInventarioLoteInfo almacenInventarioLote = null; try { var almacenBl = new AlmacenInventarioLoteBL(); almacenInventarioLote = almacenBl.CrearLotePorOrganizacionTipoAlmacenProducto(parametro); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Obtiene el almacen en base al lote,organizacion, el tipo de almacen y el producto /// </summary> /// <param name="lote"></param> /// <param name="datosLotes"></param> /// <returns></returns> public AlmacenInventarioLoteInfo ObtenerPorLoteOrganizacionTipoAlmacenProducto(int lote, ParametrosOrganizacionTipoAlmacenProductoActivo datosLotes) { AlmacenInventarioLoteInfo almacenInventarioLote = null; try { var almacenBl = new AlmacenInventarioLoteBL(); almacenInventarioLote = almacenBl.ObtenerPorLoteTipoAlmacenProducto(lote, datosLotes); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Crea un registro en almacen inventario lote. /// </summary> /// <param name="almacenInventarioLoteInfo"></param> /// <returns></returns> internal int CrearConTodosParametros(AlmacenInventarioLoteInfo almacenInventarioLoteInfo) { try { Logger.Info(); var almacenInventarioDal = new AlmacenInventarioLoteDAL(); int result = almacenInventarioDal.CrearConTodosParametros(almacenInventarioLoteInfo); return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene un almaceninventariolote por lote /// </summary> /// <param name="almacenInventarioLote"></param> /// <returns></returns> internal AlmacenInventarioLoteInfo ObtenerAlmacenInventarioLoteAlmacenCodigo(AlmacenInventarioLoteInfo almacenInventarioLote) { try { Dictionary <string, object> parametros = AuxAlmacenInventarioLoteDAL.ObtenerParametroObtenerAlmacenInventarioLoteAlmacenCodigo(almacenInventarioLote); DataSet ds = Retrieve("AlmacenInventarioLote_ObtenerPorAlmacenLote", parametros); almacenInventarioLote = null; if (ValidateDataSet(ds)) { almacenInventarioLote = MapAlmacenInventarioLoteDAL.ObtenerAlmacenInventarioLotePorLote(ds); } } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacenInventarioLote); }
/// <summary> /// Desactiva un lote /// </summary> /// <param name="almacenInventarioLoteInfo"></param> /// <returns></returns> internal static Dictionary <string, object> ObtenerParametrosDesactivarLote(AlmacenInventarioLoteInfo almacenInventarioLoteInfo) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@AlmacenInventarioLoteID", almacenInventarioLoteInfo.AlmacenInventarioLoteId }, { "@Activo", (int)EstatusEnum.Inactivo }, { "@UsuarioModificacionID", almacenInventarioLoteInfo.UsuarioModificacionId } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Inicializa los datos en pantalla /// </summary> private void InicializarDatos() { txtNombreProducto.Text = producto.ProductoDescripcion; txtIdProducto.Text = producto.ProductoId.ToString(CultureInfo.InvariantCulture); if (Programacion != null) { txtCantidadProgramada.Value = (int?)Programacion.CantidadProgramada; if (Programacion.InventarioLoteOrigen != null) { Programacion.InventarioLoteOrigen.ProductoId = producto.ProductoId; Programacion.InventarioLoteOrigen.OrganizacionId = pedido.Organizacion.OrganizacionID; almacenInventarioLote = Programacion.InventarioLoteOrigen; skAyudaLote.Info = Programacion.InventarioLoteOrigen; skAyudaLote.Clave = Programacion.InventarioLoteOrigen.Lote.ToString(); skAyudaLote.Descripcion = Programacion.InventarioLoteOrigen.Lote.ToString(); skAyudaLote.IsEnabled = false; } } }
/// <summary> /// Obtiene el almacen inventario lote indicado /// </summary> /// <returns></returns> internal AlmacenInventarioLoteInfo ObtenerAlmacenInventarioLotePorId(int almacenInventarioLoteId) { AlmacenInventarioLoteInfo almacen = null; try { Dictionary <string, object> parametros = AuxAlmacenInventarioLoteDAL.ObtenerParametrosObtenerAlmacenInventarioLotePorId(almacenInventarioLoteId); DataSet ds = Retrieve("AlmacenInventarioLote_ObtenerAlmacenPorId", parametros); if (ValidateDataSet(ds)) { almacen = MapAlmacenInventarioLoteDAL.ObtenerAlmacenInventarioLoteId(ds); } } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(almacen); }
/// <summary> /// Obtiene parametros de lote en uso /// </summary> /// <param name="datosLote"></param> /// <returns></returns> internal static Dictionary <string, object> ObtenerParametrosObtenerLotesUso(AlmacenInventarioLoteInfo datosLote) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@OrganizacionID", datosLote.OrganizacionId }, { "@TipoAlmacen", datosLote.TipoAlmacenId }, { "@ProductoId", datosLote.ProductoId }, { "@Activo", datosLote.Activo } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene los parametros para actualizar los datos del lote /// </summary> /// <returns></returns> internal static Dictionary <string, object> ObtenerParametrosActualizar(AlmacenInventarioLoteInfo almacenInventarioLote) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@AlmacenInventarioLoteID", almacenInventarioLote.AlmacenInventarioLoteId }, { "@Cantidad", almacenInventarioLote.Cantidad }, { "@PrecioPromedio", almacenInventarioLote.PrecioPromedio }, { "@Piezas", almacenInventarioLote.Piezas }, { "@Importe", almacenInventarioLote.Importe }, { "@UsuarioModificacionID", almacenInventarioLote.UsuarioModificacionId } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Crea un registro en almacen inventario lote id /// </summary> /// <param name="almacenInventarioLoteInfo"></param> /// <param name="almacenInventarioInfo"></param> /// <returns></returns> public int Crear(AlmacenInventarioLoteInfo almacenInventarioLoteInfo, AlmacenInventarioInfo almacenInventarioInfo) { try { Logger.Info(); var almcenInventarioLoteBl = new AlmacenInventarioLoteBL(); return(almcenInventarioLoteBl.Crear(almacenInventarioLoteInfo, almacenInventarioInfo)); } catch (SqlException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (DataException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
private void CargarArchivoImportar() { try { var almacenPL = new AlmacenPL(); var almacenInventarioPL = new AlmacenInventarioPL(); var almacenInventarioLotePL = new AlmacenInventarioLotePL(); var productoPL = new ProductoPL(); List <AlmacenInfo> almacenesOrganizacion = almacenPL.ObtenerAlmacenesPorOrganizacion(Contexto.Organizacion.OrganizacionID); List <ProductoInfo> productos = productoPL.ObtenerPorEstados(EstatusEnum.Activo); if (almacenesOrganizacion == null) { SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_SinAlmacenes, MessageBoxButton.OK, MessageImage.Warning); return; } IList <AlmacenInventarioInfo> almacenesInventario = almacenInventarioPL.ObtenerPorAlmacenXML(almacenesOrganizacion) ?? new List <AlmacenInventarioInfo>(); IList <AlmacenInventarioLoteInfo> almacenesInventarioLote = almacenInventarioLotePL.ObtenerLotesPorAlmacenInventarioXML(almacenesInventario.ToList()) ?? new List <AlmacenInventarioLoteInfo>(); var archivoCarga = new FileInfo(Contexto.Ruta); // Open and read the XlSX file. using (var excel = new ExcelPackage(archivoCarga)) { ExcelWorkbook libro = excel.Workbook; if (libro == null || libro.Worksheets.Count == 0) { SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_ArchivoSinDatos, MessageBoxButton.OK, MessageImage.Warning); return; } // Get the first worksheet ExcelWorksheet hojaExcel = libro.Worksheets.First(); if (!hojaExcel.Name.ToUpper().Equals(Properties.Resources.CargaMPPA_NombreHoja.ToUpper(), StringComparison.InvariantCultureIgnoreCase)) { SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_NombreIncorrectoHoja, MessageBoxButton.OK, MessageImage.Warning); return; } if (!ValidarEncabezado(hojaExcel)) { return; } for (int renglon = RenglonEncabezados + 1; renglon <= hojaExcel.Dimension.End.Row; renglon++) { var carga = new CargaMPPAModel(); object columnaVacia = hojaExcel.Cells[renglon, 1].Value; if (columnaVacia == null || string.IsNullOrWhiteSpace(columnaVacia.ToString())) { continue; } #region AsignarPropiedades var propiedades = carga.GetType().GetProperties(); foreach (var propInfo in propiedades) { dynamic customAttributes = carga.GetType().GetProperty(propInfo.Name).GetCustomAttributes(typeof(AtributoCargaMPPA), true); if (customAttributes.Length > 0) { for (var indexAtributos = 0; indexAtributos < customAttributes.Length; indexAtributos++) { var atributos = (AtributoCargaMPPA)customAttributes[indexAtributos]; int celdaArchivo = atributos.Celda; TypeCode tipoDato = atributos.TipoDato; bool aceptaVacio = atributos.AceptaVacio; object dato = hojaExcel.Cells[renglon, celdaArchivo].Value; switch (tipoDato) { case TypeCode.Int32: int valorInt; int.TryParse(dato == null ? "" : dato.ToString(), out valorInt); if (valorInt == 0) { if (aceptaVacio) { propInfo.SetValue(carga, 0, null); } else { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ErrorColumna, renglon, propInfo.Name); break; } } propInfo.SetValue(carga, valorInt, null); break; case TypeCode.Decimal: decimal valorDecimal; decimal.TryParse(dato == null ? "" : dato.ToString(), out valorDecimal); if (valorDecimal == 0) { if (aceptaVacio) { propInfo.SetValue(carga, 0, null); } else { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ErrorColumna, renglon, propInfo.Name); break; } } propInfo.SetValue(carga, valorDecimal, null); break; case TypeCode.DateTime: DateTime valorFecha; DateTime.TryParse(dato == null ? "" : dato.ToString(), out valorFecha); if (valorFecha == DateTime.MinValue) { if (aceptaVacio) { propInfo.SetValue(carga, DateTime.MinValue, null); } else { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ErrorColumna, renglon, propInfo.Name); break; } } propInfo.SetValue(carga, valorFecha, null); break; default: propInfo.SetValue(carga, null, null); break; } } } } #endregion AsignarPropiedades #region Validaciones AlmacenInfo almacenCarga = almacenesOrganizacion.FirstOrDefault(alm => alm.AlmacenID == carga.AlmacenID); ProductoInfo producto = productos.FirstOrDefault(pro => pro.ProductoId == carga.ProductoID); AlmacenInventarioInfo almacenInventario = almacenesInventario.FirstOrDefault( ai => ai.AlmacenID == carga.AlmacenID && ai.ProductoID == carga.ProductoID); if (almacenCarga == null) { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_NoExisteAlmacen, carga.AlmacenID, renglon); } carga.Almacen = almacenCarga; if (producto == null) { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_NoExisteProducto, carga.ProductoID, renglon); } carga.Producto = producto; if (almacenInventario != null && almacenInventario.Cantidad > 0) { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteInventario, carga.ProductoID, carga.AlmacenID, renglon); } carga.AlmacenInventario = almacenInventario; if (carga.AlmacenInventario != null && carga.AlmacenInventario.AlmacenInventarioID > 0) { List <AlmacenInventarioLoteInfo> lotesInventario = almacenesInventarioLote.Where( ail => ail.AlmacenInventario.AlmacenInventarioID == carga.AlmacenInventario.AlmacenInventarioID).ToList(); if (lotesInventario.Any()) { AlmacenInventarioLoteInfo lote = lotesInventario.FirstOrDefault(ail => ail.Lote == carga.Lote); if (lote != null) { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteLote, carga.Lote, carga.AlmacenID, renglon); } } } CargaMPPAModel cargaRepetida = listaInventariosValidos.FirstOrDefault(car => car.ProductoID == carga.ProductoID && car.AlmacenID == carga.AlmacenID && car.Lote == carga.Lote); if (cargaRepetida != null) { carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteRenglonRepetido, renglon); } if (!string.IsNullOrWhiteSpace(carga.MensajeAlerta)) { listaInventariosInvalidos.Add(carga); } else { listaInventariosValidos.Add(carga); } #endregion Validaciones } } if (listaInventariosInvalidos.Any()) { gridDatos.ItemsSource = listaInventariosInvalidos; btnGuardar.IsEnabled = false; SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], string.Format(Properties.Resources.CargaMPPA_RegistroProblemas, listaInventariosInvalidos.Count), MessageBoxButton.OK, MessageImage.Warning); return; } if (listaInventariosValidos.Any()) { SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], string.Format(Properties.Resources.CargaMPPA_RegistroSinProblemas, listaInventariosValidos.Count), MessageBoxButton.OK, MessageImage.Correct); } btnGuardar.IsEnabled = true; } catch (Exception ex) { SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_ErrorValidar, MessageBoxButton.OK, MessageImage.Error); Logger.Error(ex); } }