Ejemplo n.º 1
0
        public void OnComplete(object Capture, string ReaderSerialNumber, Sample Sample)
        {
            this.Invoke(new Function(delegate() { this.imgDigital.Enabled = true; }));
            this.Invoke(new Function(delegate() { this.Cursor = Cursors.WaitCursor; }));
            sp.ConvertToPicture(Sample, ref img);
            FuncionarioService funServ = new FuncionarioService(context);

            funcionarios = new List <Funcionario>();
            funcionarios = funServ.GetFuncionarios();
            byte[] bytes = Sample.Bytes;
            Process(Sample);

            if (impressaoLocalizada)
            {
                if (funcionario != null)
                {
                    if (funcionario.Id == 0)
                    {
                        return;
                    }

                    if ((impressaoLocalizada) &&
                        (funcionarioAnterior != null))
                    {
                        if (funcionarioAnterior.Id == 0)
                        {
                            impressaoLocalizada = false;
                        }

                        if (funcionario.Id == funcionarioAnterior.Id)
                        {
                            HorarioExpediente horarioExpediente = new HorarioExpediente();
                            HorarioService    serviceHorario    = new HorarioService(context);
                            horarioExpediente.Data = DateTime.Now.Date;
                            HorarioExpediente ultimoHorario = serviceHorario.GetLastHorario(funcionario.Id);
                            horarioExpediente.Funcionario = funcionario;

                            if (ultimoHorario == null)
                            {
                                horarioExpediente.Entrada = DateTime.Now;
                                horarioExpediente.Saida   = new DateTime();
                                serviceHorario.Insert(horarioExpediente);
                                updateStatus("Horário de entrada lançado com sucesso...");
                            }
                            else
                            {
                                if ((ultimoHorario.Entrada != DateTime.MinValue) &&
                                    (ultimoHorario.Saida == DateTime.MinValue))
                                {
                                    ultimoHorario.Saida = DateTime.Now;
                                    serviceHorario.Update(ultimoHorario);
                                    updateStatus("Horário de saída lançado com sucesso...");
                                }
                                else
                                {
                                    horarioExpediente.Entrada = DateTime.Now;
                                    horarioExpediente.Saida   = new DateTime();
                                    serviceHorario.Insert(horarioExpediente);
                                    updateStatus("Horário de entrada lançado com sucesso...");
                                }
                            }

                            funcionario         = new Funcionario();
                            funcionarioAnterior = funcionario;
                            this.Invoke(new Function(delegate() { limparTela(); }));
                            cp.StopCapture();
                            cp = new DPFP.Capture.Capture();
                            cp.StartCapture();
                            cp.EventHandler = this;
                        }
                    }
                    if ((impressaoLocalizada == false) ||
                        (funcionarioAnterior == null))
                    {
                        PreencherTela();
                        updateStatus("Impressão digital localizada. \nPara efetuar o lançamento do ponto e coloque novamente o mesmo dedo no leitor.");
                        funcionarioAnterior = funcionario;
                        impressaoLocalizada = true;
                    }
                    else
                    {
                        impressaoLocalizada = false;
                    }
                }
                else
                {
                    updateStatus("Impressão digital não localizada. \nTente novamente.");
                    funcionarioAnterior = null;
                    impressaoLocalizada = false;
                }
            }
            else
            {
                funcionario         = new Funcionario();
                funcionarioAnterior = funcionario;
                this.Invoke(new Function(delegate() { limparTela(); }));
                cp.StopCapture();
                cp = new DPFP.Capture.Capture();
                cp.StartCapture();
                cp.EventHandler = this;
                this.Invoke(new Function(delegate() { limparTela(); }));
            }
            this.Invoke(new Function(delegate() { this.Cursor = Cursors.Default; }));

            this.Invoke(new Function(delegate() { this.imgDigital.Enabled = false; }));
        }