/// <summary> /// Metodo que se invoca cuando la ayuda de seleccion de destino se des-selecciona /// </summary> /// <param name="sender">Objeto que invoco el evento</param> /// <param name="e">Parametros del evento</param> private void skAyudaDestino_LostFocus(object sender, RoutedEventArgs e) { OrganizacionInfo organizacionDestino = EnvioAlimento.Destino; if (organizacionDestino.OrganizacionID == 0) { organizacionDestino = (OrganizacionInfo)skAyudaDestino.DataContext; organizacionDestino.ListaTiposOrganizacion = this._tiposOrganizacionDestino; } if (organizacionDestino.OrganizacionID != 0 && organizacionDestino.TipoOrganizacion != null && (organizacionDestino.TipoOrganizacion.TipoOrganizacionID == TipoOrganizacion.Corporativo.GetHashCode() || organizacionDestino.TipoOrganizacion.TipoOrganizacionID == TipoOrganizacion.Ganadera.GetHashCode())) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.EnvioDeAlimento_MsgErrorTipoOrganizacion, MessageBoxButton.OK, MessageImage.Warning); skAyudaDestino.LimpiarCampos(); return; } //validar si la organizacion destino tiene un almacen if (organizacionDestino != null & organizacionDestino.OrganizacionID != 0) { AlmacenPL almacenPL = new AlmacenPL(); List <AlmacenInfo> almacenes = almacenPL.ObtenerAlmacenesPorOrganizacion(organizacionDestino.OrganizacionID); if (almacenes == null) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.EnvioAlimento_MsgDestinoNoTieneAlmacen, MessageBoxButton.OK, MessageImage.Stop); skAyudaDestino.LimpiarCampos(); skAyudaDestino.txtClave.Focus(); return; } } this.cmbSubFamilia.Focus(); }
public static IList <AlmacenInventarioLoteInfo> ObtenerLotes(FiltroAyudaLotes filtroLote) { IList <AlmacenInventarioLoteInfo> listaAlmacenInventarioLote = null; try { var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo; if (seguridad != null) { var almacenPL = new AlmacenPL(); List <AlmacenInfo> almacenesOrganizacion = almacenPL.ObtenerAlmacenesPorOrganizacion(seguridad.Usuario.Organizacion.OrganizacionID); AlmacenInfo almacenPlantaAlimentos = almacenesOrganizacion.FirstOrDefault( alm => alm.TipoAlmacenID == TipoAlmacenEnum.PlantaDeAlimentos.GetHashCode()); if (almacenPlantaAlimentos != null) { filtroLote.AlmacenID = almacenPlantaAlimentos.AlmacenID; } filtroLote.OrganizacionID = seguridad.Usuario.Organizacion.OrganizacionID; var almacenInventarioLotePL = new AlmacenInventarioLotePL(); listaAlmacenInventarioLote = almacenInventarioLotePL.ObtenerAlmacenInventarioLotePorLote(filtroLote); return(listaAlmacenInventarioLote); } } catch (ExcepcionDesconocida ex) { Logger.Error(ex); throw; } catch (Exception ex) { Logger.Error(ex); } return(listaAlmacenInventarioLote); }
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); } }