//NIP PARA DAR ENCONTRAR A LOS CUSTODIOS (AUSENTES)
        private async void CompararNIPAsistenciaCustodio(string nip)
        {
            try
            {
                ListResultadoCustodio = ListResultadoCustodio ?? new List <ResultadoBusquedaBiometricoCustodio>();
                if (BuscarNIP != string.Empty)
                {
                    long NIP = Convert.ToInt64(nip);
                    //Se busca el custodio por medio del ID obtenido
                    CustodioSelect = new cEmpleado().ObtenerEmpleadoPorDepartamento(NIP, (short)enumAreaTrabajo.COMANDANCIA);

                    if (CustodioSelect != null)
                    {
                        ListResultadoCustodio.Add(new ResultadoBusquedaBiometricoCustodio()
                        {
                            //Se muestra la información del custodio encontrado
                            Nombre     = string.IsNullOrEmpty(CustodioSelect.PERSONA.NOMBRE) ? string.Empty : CustodioSelect.PERSONA.NOMBRE.TrimEnd(),
                            CPaterno   = string.IsNullOrEmpty(CustodioSelect.PERSONA.PATERNO) ? string.Empty : CustodioSelect.PERSONA.PATERNO.TrimEnd(),
                            CMaterno   = string.IsNullOrEmpty(CustodioSelect.PERSONA.MATERNO) ? string.Empty : CustodioSelect.PERSONA.MATERNO.TrimEnd(),
                            IdPersona  = CustodioSelect.ID_EMPLEADO,
                            ENCONTRADO = true,
                            Persona    = CustodioSelect.PERSONA
                        });
                        ImagenCustodio = new cPersonaBiometrico().ObtenerTodos(CustodioSelect.ID_EMPLEADO, (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO).Any() ? new cPersonaBiometrico().ObtenerTodos(CustodioSelect.ID_EMPLEADO, (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO).FirstOrDefault().BIOMETRICO : new Imagenes().getImagenPerson();
                        //SE ENCONTRO CUSTODIO
                        CambiarMensajeNIP(enumMensajeNIP.ENCONTRADO);
                        NIPCapturaVisible = false;
                    }
                    else
                    {
                        //NO SE ENCONTRO CUSTODIO
                        CambiarMensajeNIP(enumMensajeNIP.NO_ENCONTRADO);
                    }
                }
                else
                {
                    //NIP VIENE VACIO
                    CambiarMensajeNIP(enumMensajeNIP.NO_ENCONTRADO);
                }
            }
            catch (Exception ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al obtener información.", ex);
            }
        }
        //HUELLA PARA LOS CUSTODIOS
        private Task <bool> CompararHuellaCustodio(byte[] Huella = null, enumTipoBiometrico?Finger = null)
        {
            try
            {
                var bytesHuella = FingerPrintData != null?FeatureExtraction.CreateFmdFromFid(FingerPrintData, Constants.Formats.Fmd.ANSI).Data.Bytes : null ?? Huella;

                var verifyFinger = Finger ?? (DD_DedoHuella.HasValue ? DD_DedoHuella.Value : enumTipoBiometrico.INDICE_DERECHO);
                ImagenCustodio                = null;
                ListResultadoCustodio         = null;
                TextoRegistroEdificioCustodio = null;

                if (bytesHuella == null)
                {
                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        if (Finger == null)
                        {
                            ScannerMessage = "Vuelve a capturar las huellas";
                        }
                        else
                        {
                            ScannerMessage = "Siguiente Huella";
                        }
                        FocusAceptarBusquedaHuella = true;
                        ColorMensaje = new SolidColorBrush(Colors.DarkOrange);
                        ShowLinea    = Visibility.Collapsed;
                    }));
                }
                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    ScannerMessage             = "Procesando...";
                    ColorMensaje               = new SolidColorBrush(System.Windows.Media.Color.FromRgb(51, 115, 242));
                    FocusAceptarBusquedaHuella = false;
                }));
                var Service = new BiometricoServiceClient();
                if (Service == null)
                {
                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        ScannerMessage             = "Error en el servicio de comparación";
                        FocusAceptarBusquedaHuella = true;
                        ColorMensaje = new SolidColorBrush(Colors.Red);
                        ShowLinea    = Visibility.Collapsed;
                    }));
                }
                var CompareResult = Service.CompararHuellaPersona(new ComparationRequest {
                    BIOMETRICO = bytesHuella, ID_TIPO_BIOMETRICO = verifyFinger, ID_TIPO_FORMATO = enumTipoFormato.FMTO_DP, ID_TIPO_PERSONA = enumTipoPersona.PERSONA_EMPLEADO, ID_CENTRO = GlobalVar.gCentro
                });
                //var CompareResult = Service.CompararHuellaPersona(new ComparationRequest { BIOMETRICO = bytesHuella, ID_TIPO_BIOMETRICO = verifyFinger, ID_TIPO_FORMATO = enumTipoFormato.FMTO_DP, ID_TIPO_PERSONA = enumTipoPersona.PERSONA_EMPLEADO });

                if (CompareResult.Identify)
                {
                    ListResultadoCustodio = ListResultadoCustodio ?? new List <ResultadoBusquedaBiometricoCustodio>();

                    if (CompareResult.Result.Count() > 1)
                    {
                        TextoRegistroEdificioCustodio = "NOTA: Se encontró más de una coincidencia, por favor intente de nuevo";
                        ScannerMessage = "";
                        return(TaskEx.FromResult(false));
                    }
                    else
                    {
                        foreach (var item in CompareResult.Result)
                        {
                            var custodio = new cPersonaBiometrico().GetData().Where(w => w.ID_PERSONA == item.ID_PERSONA && (w.ID_TIPO_BIOMETRICO == (DD_DedoHuella.HasValue ? (short)DD_DedoHuella.Value : (short)enumTipoBiometrico.INDICE_DERECHO) && w.ID_FORMATO == (short)enumTipoFormato.FMTO_DP)).OrderBy(o => o.ID_PERSONA).FirstOrDefault();

                            ShowContinue = Visibility.Collapsed;
                            if (custodio == null)
                            {
                                continue;
                            }

                            Application.Current.Dispatcher.Invoke((System.Action)(delegate
                            {
                                var custodio_biometrico = custodio.PERSONA;
                                var FotoBusquedaHuella  = new Imagenes().ConvertByteToBitmap(new Imagenes().getImagenPerson());

                                if (custodio_biometrico != null)
                                {
                                    if (custodio_biometrico.PERSONA_BIOMETRICO.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_SEGUIMIENTO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).Any())
                                    {
                                        FotoBusquedaHuella = new Imagenes().ConvertByteToBitmap(custodio_biometrico.PERSONA_BIOMETRICO.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_SEGUIMIENTO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).SingleOrDefault().BIOMETRICO);
                                    }
                                    else
                                    if (custodio_biometrico.PERSONA_BIOMETRICO.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).Any())
                                    {
                                        FotoBusquedaHuella = new Imagenes().ConvertByteToBitmap(custodio_biometrico.PERSONA_BIOMETRICO.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).SingleOrDefault().BIOMETRICO);
                                    }
                                }

                                ListResultadoCustodio.Add(new ResultadoBusquedaBiometricoCustodio()
                                {
                                    IdPersona  = custodio.PERSONA.ID_PERSONA,
                                    Nombre     = string.IsNullOrEmpty(custodio.PERSONA.NOMBRE) ? string.Empty : custodio.PERSONA.NOMBRE.TrimEnd(),
                                    CPaterno   = string.IsNullOrEmpty(custodio.PERSONA.PATERNO) ? string.Empty : custodio.PERSONA.PATERNO.TrimEnd(),
                                    CMaterno   = string.IsNullOrEmpty(custodio.PERSONA.MATERNO) ? string.Empty : custodio.PERSONA.MATERNO.TrimEnd(),
                                    ENCONTRADO = true,
                                    Persona    = custodio.PERSONA
                                });
                            }));
                            ImagenCustodio = new cPersonaBiometrico().ObtenerTodos(custodio.ID_PERSONA, (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO).Any() ? new cPersonaBiometrico().ObtenerTodos(custodio.ID_PERSONA, (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO).FirstOrDefault().BIOMETRICO : new Imagenes().getImagenPerson();
                        }
                    }

                    foreach (var llenar in ListResultadoCustodio)
                    {
                        var igual = ListaCustodio.Where(w => w.IdPersona == llenar.IdPersona).Count();

                        if (igual == 0)
                        {
                            ListaCustodio.Add(llenar);
                        }
                        else
                        {
                            llenar.ENCONTRADO = false;
                        }
                        ListResultadoCustodio = new List <ResultadoBusquedaBiometricoCustodio>(ListResultadoCustodio);
                        ShowContinue          = Visibility.Collapsed;

                        if (ListResultadoCustodio.Any())
                        {
                            Application.Current.Dispatcher.Invoke((System.Action)(delegate
                            {
                                if (igual > 0)
                                {
                                    ScannerMessage             = "Registro repetido";
                                    FocusAceptarBusquedaHuella = true;
                                    ColorMensaje = new SolidColorBrush(Colors.Orange);
                                }
                                else if (!CancelKeepSearching)
                                {
                                    ScannerMessage             = "Registro encontrado";
                                    FocusAceptarBusquedaHuella = true;
                                    ColorMensaje = new SolidColorBrush(Colors.Green);
                                }
                            }));
                            if (Finger != null)
                            {
                                Service.Close();
                            }

                            return(TaskEx.FromResult(false));
                        }
                    }
                }
                else
                {
                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        if (!CancelKeepSearching)
                        {
                            ScannerMessage             = "Huella no encontrada";
                            ColorMensaje               = new SolidColorBrush(Colors.Red);
                            FocusAceptarBusquedaHuella = true;
                            ImagenCustodio             = ImagenPlaceHolder.getImagenPerson();
                        }
                    }));
                    IsSucceded = false;
                    if (!CancelKeepSearching)
                    {
                        SelectedRegistroCustodio = null;
                    }
                    PropertyImage = null;
                }
                Service.Close();
                FingerPrintData = null;

                return(TaskEx.FromResult(true));
            }
            catch (System.ServiceModel.EndpointNotFoundException ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "No se pudo conectar al servidor de huellas", ex);
                return(TaskEx.FromResult(false));
            }
            catch (Exception ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al cargar búsqueda", ex);
                return(TaskEx.FromResult(false));
            }
        }
Esempio n. 3
0
        private Task <bool> ComparePersona(byte[] Huella = null, enumTipoBiometrico?Finger = null)
        {
            var bytesHuella = FingerPrintData != null?FeatureExtraction.CreateFmdFromFid(FingerPrintData, Constants.Formats.Fmd.ANSI).Data.Bytes : null ?? Huella;

            var verifyFinger = Finger ?? (DD_Dedo.HasValue ? DD_Dedo.Value : enumTipoBiometrico.INDICE_DERECHO);

            if (bytesHuella == null)
            {
                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    if (Finger == null)
                    {
                        ScannerMessage = "Vuelve a capturar las huellas";
                    }
                    else
                    {
                        ScannerMessage = "Siguiente Huella";
                    }
                    AceptarBusquedaHuellaFocus = true;
                    ColorMessage = new SolidColorBrush(Colors.DarkOrange);
                    ShowLine     = Visibility.Collapsed;
                }));
            }
            Application.Current.Dispatcher.Invoke((System.Action)(delegate
            {
                ScannerMessage             = "Procesando...";
                ColorMessage               = new SolidColorBrush(System.Windows.Media.Color.FromRgb(51, 115, 242));
                AceptarBusquedaHuellaFocus = false;
            }));

            var Service = new BiometricoServiceClient();

            if (Service == null)
            {
                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    ScannerMessage             = "Error en el servicio de comparacion";
                    AceptarBusquedaHuellaFocus = true;
                    ColorMessage = new SolidColorBrush(Colors.Red);
                    ShowLine     = Visibility.Collapsed;
                }));
            }

            var CompareResult = Service.CompararHuellaPersona(new ComparationRequest
            {
                BIOMETRICO         = bytesHuella,
                ID_TIPO_BIOMETRICO = verifyFinger,
                ID_TIPO_FORMATO    = enumTipoFormato.FMTO_DP,
                ID_TIPO_PERSONA    = BuscarPor == enumTipoPersona.PERSONA_TODOS ? new Nullable <enumTipoPersona>() : BuscarPor
            });

            if (CompareResult.Identify)
            {
                ListResultado = ListResultado ?? new List <ResultadoBusquedaBiometrico>();

                foreach (var item in CompareResult.Result)
                {
                    var persona = new cPersonaBiometrico().GetData().Where(w => w.ID_PERSONA == item.ID_PERSONA && (w.ID_TIPO_BIOMETRICO == (DD_Dedo.HasValue ? (short)DD_Dedo.Value : (short)enumTipoBiometrico.INDICE_DERECHO)) && w.ID_FORMATO == (short)enumTipoFormato.FMTO_DP).FirstOrDefault();

                    ShowContinuar = Visibility.Collapsed;
                    if (persona == null)
                    {
                        continue;
                    }

                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        var perosonabiometrico = new cPersonaBiometrico().GetData().Where(w => w.ID_PERSONA == persona.ID_PERSONA).ToList();
                        var FotoBusquedaHuella = new Imagenes().ConvertByteToBitmap(new Imagenes().getImagenPerson());

                        if (perosonabiometrico != null)
                        {
                            if (perosonabiometrico.Any())
                            {
                                if (perosonabiometrico.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_SEGUIMIENTO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).Any())
                                {
                                    FotoBusquedaHuella = new Imagenes().ConvertByteToBitmap(perosonabiometrico.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_SEGUIMIENTO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).SingleOrDefault().BIOMETRICO);
                                }
                                else
                                if (perosonabiometrico.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).Any())
                                {
                                    FotoBusquedaHuella = new Imagenes().ConvertByteToBitmap(perosonabiometrico.Where(w => w.ID_TIPO_BIOMETRICO == (short)enumTipoBiometrico.FOTO_FRENTE_REGISTRO && w.ID_FORMATO == (short)enumTipoFormato.FMTO_JPG).SingleOrDefault().BIOMETRICO);
                                }
                            }
                        }

                        ListResultado.Add(new ResultadoBusquedaBiometrico()
                        {
                            Nombre     = persona.PERSONA.NOMBRE,
                            APaterno   = persona.PERSONA.PATERNO,
                            AMaterno   = persona.PERSONA.MATERNO,
                            Expediente = persona.PERSONA.ID_PERSONA.ToString(),
                            NIP        = persona.PERSONA.PERSONA_NIP.Where(w => w.ID_CENTRO == GlobalVar.gCentro).Any() ?
                                         persona.PERSONA.PERSONA_NIP.Where(w => w.ID_CENTRO == GlobalVar.gCentro).FirstOrDefault().NIP.HasValue
                                    ? persona.PERSONA.PERSONA_NIP.Where(w => w.ID_CENTRO == GlobalVar.gCentro).FirstOrDefault().NIP.Value.ToString()
                                        : string.Empty : string.Empty,
                            Foto    = FotoBusquedaHuella,
                            Persona = persona.PERSONA
                        });
                    }));
                }

                ListResultado = new List <ResultadoBusquedaBiometrico>(ListResultado);

                ShowContinuar = Visibility.Collapsed;

                if (ListResultado.Any())
                {
                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        if (!CancelKeepSearching)
                        {
                            ScannerMessage             = "Registro encontrado";
                            AceptarBusquedaHuellaFocus = true;
                            ColorMessage = new SolidColorBrush(Colors.Green);
                        }
                    }));

                    if (Finger != null)
                    {
                        Service.Close();
                    }

                    return(TaskEx.FromResult(false));
                }
                else
                {
                    Application.Current.Dispatcher.Invoke((System.Action)(delegate
                    {
                        if (!CancelKeepSearching)
                        {
                            ScannerMessage             = "Registro no encontrado";
                            AceptarBusquedaHuellaFocus = true;
                            ColorMessage = new SolidColorBrush(Colors.Red);
                        }
                    }));
                }
            }
            else
            {
                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    if (!CancelKeepSearching)
                    {
                        ScannerMessage             = "Huella no encontrada";
                        ColorMessage               = new SolidColorBrush(Colors.Red);
                        AceptarBusquedaHuellaFocus = true;
                    }
                }));
                _IsSucceed = false;
                if (!CancelKeepSearching)
                {
                    _SelectRegistro = null;
                }
                PropertyImage = null;
            }

            Service.Close();
            FingerPrintData = null;

            return(TaskEx.FromResult(true));
        }