public void Write(int enrollNumber, string name, string password, int privilege, bool enabled, int fingerIndex) { const int updateFlag = 1; if (!_isConnected) { return; } Service.EnableDevice(MachineNumber, false); if (Service.BeginBatchUpdate(MachineNumber, updateFlag)) { var result = Service.SSR_SetUserInfo(MachineNumber, enrollNumber.ToString(), name, null, privilege, enabled); if (result) { if (!Service.BatchUpdate(MachineNumber)) { ViewError(); } } else { ViewError(); } } Service.RefreshData(MachineNumber);//the data in the device should be refreshed Service.EnableDevice(MachineNumber, true); }
private void CrearUsers(HttpWebResponse respuestaHTTP, int privilegio) { File.AppendAllText(@"C:\logger.log", "Inicio envio de huellas..." + DateTime.Now + Environment.NewLine); var userList = new List <Usuario>(); using (var streamReader = new StreamReader(respuestaHTTP.GetResponseStream())) { var json = streamReader.ReadToEnd(); userList = JsonConvert.DeserializeObject <List <Usuario> >(json); //Convierto el json contenedor de los usuarios a una List<User>, con "User" objeto definido en la clase } //Comienzo el grabado de datos bool batchUpdate = terminalZK.BeginBatchUpdate(idMaquina, 1); for (int i = 0; i < userList.Count; i++) { //Registro las tarjetas(tags) por usuario if (!string.IsNullOrEmpty(userList[i].tag)) { terminalZK.SetStrCardNumber(userList[i].tag); } //Primero debo registrar los datos del usuario if (terminalZK.SSR_SetUserInfo(idMaquina, userList[i].credencial.ToString(), userList[i].nombre, string.Empty, privilegio, true)) { //Segundo grabo las huellas de cada usuario if (userList[i].huellas != null) { foreach (var h in userList[i].huellas) { terminalZK.SetUserTmpExStr(idMaquina, userList[i].credencial.ToString(), h.id, 0, h.codigo); } } } else { File.AppendAllText(@"C:\logger.log", DateTime.Now + " ERROR de carga usuario" + Environment.NewLine); } //if (userList[i].credencial == 2 || userList[i].credencial == 3) // dispositivo.EmptyCard(idMaquina); } //Envio los datos if (batchUpdate) { terminalZK.BatchUpdate(idMaquina); } terminalZK.RefreshData(idMaquina); //Actualizo el dispositivo para que las huellas queden activas File.AppendAllText(@"C:\logger.log", "Fin envio de huellas..." + DateTime.Now + Environment.NewLine); }
private void UploadKeMesin(string id = null) { bool bIsConnected = false; int iMachineNumber = 1; int idwErrorCode = 0; var mesin = fp.mesins.ToList(); int no = 1; foreach (var msn in mesin) { bIsConnected = axCZKEM1.Connect_Net(msn.mesin_ip.Trim(), Convert.ToInt32(msn.mesin_key.Trim())); if (bIsConnected == false) { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error"); } else { iMachineNumber = no; axCZKEM1.RegEvent(iMachineNumber, 65535); int iUpdateFlag = 1; axCZKEM1.EnableDevice(iMachineNumber, false); if (axCZKEM1.BeginBatchUpdate(iMachineNumber, iUpdateFlag)) { if (!axCZKEM1.SSR_SetUserInfo(iMachineNumber, txtID.Text, txtPanggilan.Text, txtSandi.Text, (cbHakAkses.SelectedIndex == 0 ? 3 : 0), true)) { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Operation failed,ErrorCode=" + idwErrorCode.ToString(), "Error"); } else { var pegawai = fp.pegawais.Where(x => x.pegawai_id.Equals(id == null? pegawai_id: id)).FirstOrDefault(); pegawai.upload = true; fp.SaveChanges(); } } axCZKEM1.BatchUpdate(iMachineNumber); axCZKEM1.RefreshData(iMachineNumber); } no += 1; axCZKEM1.EnableDevice(iMachineNumber, true); axCZKEM1.Disconnect(); } }
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); } }
private void bwPosting_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { bool bIsConnected = false; int idwErrorCode = 0; lblProses.Invoke(new Action(() => lblProses.Text = "Mengambil data mesin")); var mesin = fp.mesins.ToList(); int no = 1; int jumlah = 0; foreach (var msn in mesin) { progressBar.Value = 0; bwDownload.ReportProgress(0); lblProses.Invoke(new Action(() => lblProses.Text = "Melakukan koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key)); bIsConnected = axCZKEM1.Connect_Net(msn.mesin_ip, Convert.ToInt32(msn.mesin_key)); if (bIsConnected == false) { axCZKEM1.GetLastError(ref idwErrorCode); lblProses.Invoke(new Action(() => lblProses.Text = "Koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key + " GAGAL " + idwErrorCode.ToString())); gagal.Add("gagal"); } else { iMachineNumber = no; axCZKEM1.RegEvent(iMachineNumber, 65535); int iUpdateFlag = 1; axCZKEM1.EnableDevice(iMachineNumber, false); if (axCZKEM1.BeginBatchUpdate(iMachineNumber, iUpdateFlag))//create memory space for batching data { string sdwEnrollNumber = ""; string nip = ""; string sName = ""; int idwFingerIndex = 0; string sTmpData = ""; int iPrivilege = 0; string sPassword = ""; bool bEnabled = true; int iFlag = 1; lblProses.Invoke(new Action(() => lblProses.Text = "Mengambil data pegawai")); var pegawai = fp.pegawais.ToList(); string sLastEnrollNumber = "";//the former enrollnumber you have upload(define original value as 0) var nomor = 1; int iValue = pegawai.Count(); foreach (var row in pegawai) { sdwEnrollNumber = row.pegawai_id.ToString(); sName = row.pegawai_panggilan; nip = row.pegawai_nip; iPrivilege = row.pegawai_izin == "0" ? 3 : 0; sPassword = row.pegawai_sandi; if (axCZKEM1.SSR_SetUserInfo(iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled)) { lblProses.Invoke(new Action(() => lblProses.Text = "Mengupload data pegawai " + nip)); var data = fp.pegawais.Where(x => x.pegawai_id.Equals(sdwEnrollNumber)).FirstOrDefault(); data.upload = true; fp.SaveChanges(); jumlah += 1; } else { axCZKEM1.GetLastError(ref idwErrorCode); lblProses.Invoke(new Action(() => lblProses.Text = "Operation failed,ErrorCode=" + idwErrorCode.ToString())); gagal.Add("ID " + sdwEnrollNumber + ", nip " + nip); } int percentage = nomor * 100 / iValue; nomor++; bwDownload.ReportProgress(percentage); } } axCZKEM1.BatchUpdate(iMachineNumber); //upload all the information in the memory axCZKEM1.RefreshData(iMachineNumber); //the data in the device should be refreshed axCZKEM1.EnableDevice(iMachineNumber, true); } no += 1; axCZKEM1.EnableDevice(iMachineNumber, true); axCZKEM1.Disconnect(); } if (gagal.Count > 0) { lblProses.Invoke(new Action(() => lblProses.Text = "Gagal mengupload " + gagal.Count + " data pegawai")); MessageBox.Show("Gagal mendownload " + gagal.Count + " data pegawai"); e.Cancel = true; } else { lblProses.Invoke(new Action(() => lblProses.Text = "Berhasil mengupload " + jumlah.ToString() + " data pegawai ke mesin")); MessageBox.Show("Berhasil mengupload " + jumlah.ToString() + " data pegawai ke mesin"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }