예제 #1
0
        // conexion y checadas BlackWhite
        private Modelos.Response checadasBW(string ip, int puerto, DateTime ultFecha)
        {
            Modelos.Response result = new Modelos.Response();

            try
            {
                // conexion por ip y puerto al checador
                int idwErrorCode = 0;

                // estableciendo conexion con el checador
                this.agregarDetalle("Estableciendo conexión con el checador");

                this._bIsConnected = axCZKEM1.Connect_Net(ip, puerto);
                if (this._bIsConnected)
                {
                    this.agregarDetalle("Conexión Exitosa!!!");

                    iMachineNumber = 1;                       //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                    axCZKEM1.RegEvent(iMachineNumber, 65535); //Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                }
                else
                {
                    axCZKEM1.GetLastError(ref idwErrorCode);
                    throw new Exception("No se puede conectar, ErrorCode=" + idwErrorCode.ToString());
                }

                // inicializa clase de conexion a la base de datos
                this._consultasNegocio = new ConsultasNegocio();

                // obtiene checadas
                this.agregarDetalle("Obteniendo los registros del checador");
                List <Modelos.AttLogs> resultado = this.obtieneChecadas();
                List <Modelos.AttLogs> traspaso  = resultado.FindAll(fl => fl.fecha >= ultFecha);

                foreach (Modelos.AttLogs res in traspaso)
                {
                    try
                    {
                        res.noChecador = Modelos.ConectionString.numCh;

                        // ingresa un usuario como pendiente en caso de no tenerlo registrado
                        this._consultasNegocio.insertaNuevo(res.enrolIdNumber);

                        this._consultasNegocio.insertaRegistro(res);

                        // imprime mensajes en pantalla
                        this.agregarDetalle("Registro Agregado: IdInterno: " + res.enrolIdNumber + "\tFecha: " + res.fecha.ToString("yyyy-MM-dd HH:mm"));
                    }
                    catch (Exception EX)
                    {
                        if (EX.Message.ToLower().Contains("duplicate entry"))
                        {
                            this.agregarDetalle(string.Format("El registro con IdInteno: {0} y FechaHora: {1} ya existe.", res.enrolIdNumber, res.fecha.ToString("yyyy-MM-dd HH:mm")));
                            Application.DoEvents();
                            continue;
                        }

                        throw new Exception(EX.Message);
                    }
                }

                // desconectar checador
                this.agregarDetalle("Cerrando conexión con el checador");
                axCZKEM1.Disconnect();
                this._bIsConnected = false;

                result.status = Modelos.Estatus.OK;
            }
            catch (Exception Ex)
            {
                Cursor        = Cursors.Default;
                result.error  = Ex.Message;
                result.status = Modelos.Estatus.ERROR;
            }

            return(result);
        }
예제 #2
0
        // conexion y checadas TFT
        private Modelos.Response checadasTFT(string ip, int puerto, DateTime ultFecha)
        {
            Modelos.Response result = new Modelos.Response();

            try
            {
                // estableciendo conexion con el checador
                this.agregarDetalle("Estableciendo conexión con el checador");
                var respuesta = TFT.TFT.conectar(ip, puerto);

                if (respuesta.status == TFT.Estatus.ERROR)
                {
                    throw new Exception(respuesta.error);
                }

                this.agregarDetalle("Conexión Exitosa!!!");

                // inicializa clase de conexion a la base de datos
                this._consultasNegocio = new ConsultasNegocio();

                // obtiene checadas
                this.agregarDetalle("Obteniendo los registros del checador");
                List <TFT.AttLogs> resultado = TFT.TFT.obtieneChecadas();
                List <TFT.AttLogs> traspaso  = resultado.FindAll(fl => fl.fecha >= ultFecha);

                Modelos.AttLogs ent;

                foreach (TFT.AttLogs res in traspaso)
                {
                    try
                    {
                        ent = new Modelos.AttLogs();
                        ent.enrolIdNumber = res.enrolIdNumber;
                        ent.fecha         = res.fecha;
                        ent.noChecador    = Modelos.ConectionString.numCh;

                        // ingresa un usuario como pendiente en caso de no tenerlo registrado
                        this._consultasNegocio.insertaNuevo(res.enrolIdNumber);

                        // inserta los registros a la base de datos
                        this._consultasNegocio.insertaRegistro(ent);

                        // imprime mensajes en pantalla
                        this.agregarDetalle("Registro Agregado: IdInterno: " + res.enrolIdNumber + "\tFecha: " + res.fecha.ToString("yyyy-MM-dd HH:mm"));
                    }
                    catch (Exception EX)
                    {
                        if (EX.Message.ToLower().Contains("duplicate entry"))
                        {
                            this.agregarDetalle(string.Format("El registro con IdInteno: {0} y FechaHora: {1} ya existe.", res.enrolIdNumber, res.fecha.ToString("yyyy-MM-dd HH:mm")));
                            Application.DoEvents();
                            continue;
                        }

                        throw new Exception(EX.Message);
                    }
                }

                // desconectar checador
                this.agregarDetalle("Cerrando conexión con el checador");
                TFT.TFT.desConectar();

                result.status = Modelos.Estatus.OK;
            }
            catch (Exception Ex)
            {
                TFT.TFT.desConectar();
                Cursor        = Cursors.Default;
                result.error  = Ex.Message;
                result.status = Modelos.Estatus.ERROR;
            }

            return(result);
        }
예제 #3
0
        private void btnDescargarChecadas_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._comEx)
                {
                    throw new Exception("Problemas con la conexión al checador");
                }

                if (!string.IsNullOrEmpty(this.tbResultados.Text))
                {
                    this.tbResultados.Clear(); this.tbResultados.Refresh();
                }

                if (string.IsNullOrEmpty(Modelos.ConectionString.ip) ||
                    string.IsNullOrEmpty(Modelos.ConectionString.puerto))
                {
                    throw new Exception("No se han definido los parámetros de conexión del Checador");
                }

                if (string.IsNullOrEmpty(Modelos.ConectionString.conn))
                {
                    throw new Exception("No se ha definido la cadena de conexión a la base de datos");
                }

                string ip     = Modelos.ConectionString.ip;
                int    puerto = Convert.ToInt32(Modelos.ConectionString.puerto);
                string tipoCh = Modelos.ConectionString.tipoCh;
                int    numCh  = Modelos.ConectionString.numCh;

                Cursor = Cursors.WaitCursor;

                // inicializa clase de conexion a la base de datos
                this._consultasNegocio = new ConsultasNegocio();

                // conectando con la base de datos
                this.agregarDetalle("Conectando con la base de datos");
                bool conectaBd = this._consultasNegocio.conectaBase();

                if (conectaBd)
                {
                    this.agregarDetalle("Conexión Exitosa!!!");
                }
                else
                {
                    throw new Exception("Problemas al conectar con la base de datos");
                }

                // obtener la ultmia checada
                this.agregarDetalle("Obteniendo la última fecha de registro");
                DateTime ultFecha = this._consultasNegocio.obtUltimaFecha(numCh);
                this.agregarDetalle("Fecha: " + ultFecha.ToString("yyyy-MM-dd HH:mm"));

                this.agregarDetalle("Tipo de Checador Seleccionado '" + tipoCh + "'");

                Modelos.Response respuesta = new Modelos.Response();

                switch (tipoCh)
                {
                case "TFT":

                    respuesta = this.checadasTFT(ip, puerto, ultFecha);

                    break;

                case "BlackWhite":

                    respuesta = this.checadasBW(ip, puerto, ultFecha);

                    break;

                default:

                    break;
                }

                if (respuesta.status == Modelos.Estatus.OK)
                {
                    // proceso concluido
                    this.agregarDetalle("Proceso Concluido");
                }

                if (respuesta.status == Modelos.Estatus.ERROR)
                {
                    throw new Exception(respuesta.error);
                }

                Cursor = Cursors.Default;
            }
            catch (Exception Ex)
            {
                Cursor = Cursors.Default;
                this.agregarDetalle("Error:" + Ex.Message);
                MessageBox.Show(Ex.Message, "Descarga Checadores", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }