Example #1
0
        protected void BtnDescargar_Click(object sender, EventArgs e)
        {
            log.Info(String.Format("El usuario [{0}] presiono el boton para descargar la plantilla del Control de Acceso con ID: [{1}]", UsuarioActual.Nombre, txtControlAcceso.SelectedValue));

            // Validar si se selecciono un control de acceso
            if (!ValidarObjeto(txtControlAcceso.SelectedValue))
            {
                MostrarAdvertencia(Constantes.MENSAJE_CAMPO_REQUERIDO_TITULO, "Por favor seleccione un control del listado");
                return;
            }

            ControlAcceso control = null;

            try
            {
                control = controlAccesoDao.GetById(Int32.Parse(txtControlAcceso.SelectedValue));
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso de Conexion con el control. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }

            if (control == null)
            {
                MostrarAdvertencia("Control de Acceso No Encontrado", String.Format("No fue Posible encontrar el Control de Acceso con identificador [0]", txtControlAcceso.SelectedValue));
                return;
            }


            // Variables de cajon
            int    iMachineNumber  = 1;
            string sdwEnrollNumber = Constantes.TEXTO_BLANCO;
            string sName           = Constantes.TEXTO_BLANCO;
            string sPassword       = Constantes.TEXTO_BLANCO;
            int    iPrivilege      = 0;
            bool   bEnabled        = false;
            int    idwErrorCode    = 0;

            int    idwFingerIndex;
            string sTmpData   = Constantes.TEXTO_BLANCO;
            int    iTmpLength = 0;
            int    iFlag      = 0;


            try
            {
                log.Info(String.Format("Se Intentará conectar con el control de acceso con ID: [{0}]. El control tiene la direccion ip: [{1}] y el puerto: [{2}]", txtControlAcceso.SelectedValue, control.DireccionIp, control.Puerto));

                CZKEMClass _control = new CZKEMClass();
                if (_control.Connect_Net(control.DireccionIp, Int32.Parse(control.Puerto.Value.ToString())))
                {
                    log.Info(String.Format("Se logro correctamente la conexion con el control con direccion ip: [{0}] y el puerto: [{1}]", control.DireccionIp, control.Puerto));

                    _control.EnableDevice(iMachineNumber, false);
                    _control.ReadAllUserID(iMachineNumber);   //read all the user information to the memory
                    _control.ReadAllTemplate(iMachineNumber); //read all the users' fingerprint templates to the memory


                    while (_control.SSR_GetAllUserInfo(iMachineNumber, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled))//get all the users' information from the memory
                    {
                        log.Info(String.Format("Se obtienen los datos iMachineNumber: [{0}], sdwEnrollNumber: [{1}], sName: [{2}], sPassword: [{3}], iPrivilege: [{4}], bEnabled: [{5}]", iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled));

                        for (idwFingerIndex = 0; idwFingerIndex < 10; idwFingerIndex++)
                        {
                            if (_control.GetUserTmpExStr(iMachineNumber, sdwEnrollNumber, idwFingerIndex, out iFlag, out sTmpData, out iTmpLength))//get the corresponding templates string and length from the memory
                            {
                                log.Info(String.Format("Se obtienen los datos idwFingerIndex: [{0}], iFlag: [{1}], sTmpData: [{2}], iTmpLength: [{3}]", idwFingerIndex, iFlag, sTmpData, iTmpLength));


                                try
                                {
                                    DbDominio.Plantilla planti = plantillaDao.GetByControlAccesoEnrollNumberFingerIndex(control, sdwEnrollNumber, idwFingerIndex);

                                    if (planti == null)
                                    {
                                        planti = new DbDominio.Plantilla();
                                        planti.ControlAcceso      = control;
                                        planti.Usuario_creado_por = UsuarioActual;
                                        log.Info("Se creará una plantilla nueva a partir de estos datos");
                                    }
                                    else
                                    {
                                        log.Info("Esta es una plantilla nueva que se insertara");
                                    }

                                    planti.FechaModificacion      = DateTime.Now;
                                    planti.Usuario_modificado_por = UsuarioActual;
                                    planti.Enabled           = bEnabled;
                                    planti.Enrollnumber      = sdwEnrollNumber;
                                    planti.Fingerindex       = idwFingerIndex;
                                    planti.Flag              = iFlag;
                                    planti.IpControlTemplate = control.DireccionIp;
                                    planti.Nombre            = sName;
                                    planti.Password          = sPassword;
                                    planti.Privilege         = iPrivilege;
                                    planti.Status            = true;
                                    planti.Tmpdata           = sTmpData;
                                    plantillaDao.SaveOrUpdate(planti);

                                    try
                                    {
                                        Empleado empleado = empleadoDao.GetByNumeroEmpleado(Int32.Parse(sdwEnrollNumber));
                                        if (empleado != null && control != null)
                                        {
                                            EmpleadoControlAcceso eca = empleadoControlAccesoDao.GetByControlAcceso(control, empleado);
                                            if (eca == null)
                                            {
                                                eca = new EmpleadoControlAcceso();
                                            }
                                            eca.CveEmpleado      = empleado.CveEmpleado;
                                            eca.CveControlAcceso = control.CveControlAcceso;
                                            eca.ControlAcceso    = control;
                                            eca.Empleado         = empleado;

                                            empleadoControlAccesoDao.SaveOrUpdate(eca);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Error(String.Format("Error en el Proceso Guardar Empleado Control de Acceso en la base de Datos. Mensaje: [{0}]", ex.Message));
                                        log.Error(ex);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error(String.Format("Error en el Proceso Guardar Plantilla en la base de Datos. Mensaje: [{0}]", ex.Message));
                                    log.Error(ex);
                                }
                            }
                        }
                    }

                    _control.Disconnect();
                    MostrarExito("Proceso Completo", "Se completo el proceso exitosamente");
                }
                else
                {
                    _control.GetLastError(ref idwErrorCode);
                    log.Error(String.Format("Error en el Proceso de Conexion al control con ID [{0}], Direccion IP [{1}] y Puerto [{2}]. Codigo de Error [{3}]", control.IdControl, control.DireccionIp, control.Puerto, idwErrorCode));
                    MostrarExcepcion("Conexion Invalida", String.Format("Error en el Proceso de Conexion con el Control con Direccion IP: {0} y Puerto {1}", control.DireccionIp, control.Puerto));
                }
            }

            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso de Conexion con el control. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }
        }
Example #2
0
        protected void BtnAceptar_Click(object sender, EventArgs e)
        {
            // Validamos que se haya seleccionado un control fuente
            if (!ValidarObjeto(txtPlantilla.SelectedValue))
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_REQUERIDO_TITULO, "Es requerido Seleccionar la plantilla fuente");
                return;
            }

            // Validamos que se haya seleccionado un control de destino
            if (!ValidarObjeto(txtControlDestino.SelectedValue))
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_REQUERIDO_TITULO, "Es requerido Seleccionar el Control de Acceso de destino");
                return;
            }

            // Validamos que el control de destino no sea el mismo que el seleccionado en la fuente
            if (txtControlDestino.SelectedValue.Equals(txtPlantilla.SelectedValue))
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_CON_ERROR_TITULO, "El Control de Acceso de Destino es el Mismo que el de la fuente de Datos");
            }

            // Obtenemos y validamos el control fuente
            ControlAcceso controlFuente = null;

            try
            {
                controlFuente = controlAccesoDao.GetById(Int32.Parse(txtPlantilla.SelectedValue));
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso Obtener Control Fuente. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }

            if (controlFuente == null)
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_CON_ERROR_TITULO, "El control fuente es nulo");
                return;
            }

            // Obtenemos y validamos el control de destino
            ControlAcceso controlDestino = null;

            try
            {
                controlDestino = controlAccesoDao.GetById(Int32.Parse(txtControlDestino.SelectedValue));
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso Obtener Control Destino. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }

            if (controlDestino == null)
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_CON_ERROR_TITULO, "El control de destino es nulo");
                return;
            }

            // Obtenemos y validamos la lista de plantillas a cargar
            List <DbDominio.Plantilla> listaPlantilla = null;

            try
            {
                listaPlantilla = plantillaDao.GetListado(null, controlFuente);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso Obtener La plantilla desde el Control Fuente. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }

            if (listaPlantilla == null || listaPlantilla.Count == 0)
            {
                MostrarExcepcion(Constantes.MENSAJE_CAMPO_CON_ERROR_TITULO, "La plantilla seleccionada es nula o vacia");
                return;
            }


            // Al parecer todo va bien, iniciarmos el proceso
            int    idwErrorCode    = 0;
            string sdwEnrollNumber = Constantes.TEXTO_BLANCO;
            string sName           = Constantes.TEXTO_BLANCO;
            int    idwFingerIndex  = 0;
            string sTmpData        = Constantes.TEXTO_BLANCO;
            int    iPrivilege      = 0;
            string sPassword       = Constantes.TEXTO_BLANCO;
            bool   bEnabled        = false;
            int    iFlag           = 1;
            int    iUpdateFlag     = 1;
            int    iMachineNumber  = 1;

            try
            {
                log.Info(String.Format("Se Intentará conectar con el control de acceso con ID: [{0}]. El control tiene la direccion ip: [{1}] y el puerto: [{2}]", txtControlDestino.SelectedValue, controlDestino.DireccionIp, controlDestino.Puerto));

                CZKEMClass _control = new CZKEMClass();
                // _control.PullMode = 1;

                if (_control.Connect_Net(controlDestino.DireccionIp, Int32.Parse(controlDestino.Puerto.Value.ToString())))
                {
                    log.Info(String.Format("Se logro correctamente la conexion con el control con direccion ip: [{0}] y el puerto: [{1}]", controlDestino.DireccionIp, controlDestino.Puerto));

                    _control.RegEvent(iMachineNumber, 65535);
                    _control.EnableDevice(iMachineNumber, false);

                    if (_control.BeginBatchUpdate(iMachineNumber, iUpdateFlag))//create memory space for batching data
                    {
                        log.Info(String.Format("Inicia el Proceso BeginBatchUpdate Con ImachineNumber : [{0}] iUpdateFlag: [{1}]", iMachineNumber, iUpdateFlag));

                        string sLastEnrollNumber = "";//the former enrollnumber you have upload(define original value as 0)

                        foreach (DbDominio.Plantilla planti in listaPlantilla)
                        {
                            sdwEnrollNumber = planti.Enrollnumber;
                            sName           = planti.Nombre;
                            idwFingerIndex  = planti.Fingerindex != null ? planti.Fingerindex.Value : 0;
                            sTmpData        = planti.Tmpdata;
                            iPrivilege      = planti.Privilege != null ? planti.Privilege.Value : 0;
                            sPassword       = planti.Password;
                            bEnabled        = planti.Enabled != null ? planti.Enabled.Value : false;
                            iFlag           = planti.Flag != null ? planti.Flag.Value : 1;

                            log.Info(String.Format("Se Carga la Siguiente sdwEnrollNumber: [{0}] sName: [{1}], idwFingerIndex: [{2}], sTmpData: [{3}], iPrivilege : [{4}], sPassword : [{5}], bEnabled : [{6}], iFlag: [{7}]", sdwEnrollNumber, sName, idwFingerIndex, sTmpData, iPrivilege, sPassword, bEnabled, iFlag));

                            if (sdwEnrollNumber != sLastEnrollNumber)                                                                  //identify whether the user information(except fingerprint templates) has been uploaded
                            {
                                if (_control.SSR_SetUserInfo(iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled)) //upload user information to the memory
                                {
                                    log.Info(String.Format("Se Completa El ProcesoS SR_SetUserInfo con la siguiente Informacion_ iMachineNumber [{0}] sdwEnrollNumber: [{1}] sName: [{2}], sPassword: [{3}], iPrivilege : [{4}], bEnabled: [{5}]", iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled));

                                    _control.SetUserTmpExStr(iMachineNumber, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData);//upload templates information to the memory

                                    log.Info(String.Format("Se Completa El Proceso SetUserTmpExStr con la siguiente Informacion_ iMachineNumber [{0}] sdwEnrollNumber: [{1}] idwFingerIndex: [{2}], iFlag: [{3}], sTmpData : [{4}]", iMachineNumber, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData));
                                }
                                else
                                {
                                    _control.GetLastError(ref idwErrorCode);
                                    _control.EnableDevice(iMachineNumber, true);

                                    log.Error(String.Format("Error en el Proceso Distribuir  La plantilla Al Control de Destino. Codigo de Error: [{0}]", idwErrorCode));
                                    MostrarExcepcion("Error en el proceso", String.Format("Error en el Proceso Distribuir  La plantilla Al Control de Destino. Codigo de Error: [{0}]", idwErrorCode));
                                    return;
                                }
                            }
                            else
                            {
                                _control.SetUserTmpExStr(iMachineNumber, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData);
                                log.Info(String.Format("Se Completa El Proceso SetUserTmpExStr (sdwEnrollNumber != sLastEnrollNumber) con la siguiente Informacion_ iMachineNumber [{0}] sdwEnrollNumber: [{1}] idwFingerIndex: [{2}], iFlag: [{3}], sTmpData : [{4}]", iMachineNumber, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData));
                            }
                            sLastEnrollNumber = sdwEnrollNumber;

                            try
                            {
                                Empleado empleado = empleadoDao.GetByNumeroEmpleado(Int32.Parse(sdwEnrollNumber));
                                if (empleado != null && controlDestino != null)
                                {
                                    EmpleadoControlAcceso eca = empleadoControlAccesoDao.GetByControlAcceso(controlDestino, empleado);
                                    if (eca == null)
                                    {
                                        eca = new EmpleadoControlAcceso();
                                    }
                                    eca.ControlAcceso = controlDestino;
                                    eca.Empleado      = empleado;
                                    empleadoControlAccesoDao.SaveOrUpdate(eca);
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error(String.Format("Error en el Proceso Guardar Empleado Control de Acceso en la base de Datos. Mensaje: [{0}]", ex.Message));
                                log.Error(ex);
                            }
                        }
                    }
                    _control.BatchUpdate(iMachineNumber); //upload all the information in the memory
                    _control.RefreshData(iMachineNumber); //the data in the device should be refreshed
                    _control.EnableDevice(iMachineNumber, true);
                    _control.Disconnect();
                    MostrarExito("Proceso Completo", "Se completo el proceso exitosamente");
                }
                else
                {
                    _control.GetLastError(ref idwErrorCode);
                    log.Error(String.Format("Error en el Proceso de Conexion al control con ID [{0}], Direccion IP [{1}] y Puerto [{2}]. Codigo de Error [{3}]", controlDestino.IdControl, controlDestino.DireccionIp, controlDestino.Puerto, idwErrorCode));
                    MostrarExcepcion("Conexion Invalida", String.Format("Error en el Proceso de Conexion con el Control con Direccion IP: {0} y Puerto {1}", controlDestino.DireccionIp, controlDestino.Puerto));
                }
            }

            catch (Exception ex)
            {
                log.Error(String.Format("Error en el Proceso de Conexion con el control. Mensaje: [{0}]", ex.Message));
                ManejarExcepcion(ex);
            }
        }