private void btn_DownloadHistory_Click(object sender, EventArgs e) { object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { List <DateTime> dtList = GetDateTimeList(); bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraProperty = false; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecordsCount, extraProperty, ref device, ref extraData); if (false == result) { MessageBox.Show("Get All Glog Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int recordCount = (int)extraData; if (0 == recordCount) {//为0时说明没有新日志记录 lvw_GLogList.Items.Clear(); return; } List <bool> boolList = new List <bool>(); boolList.Add(false); //所有日志 boolList.Add(chk_NewFlag.Checked); //清除新日志标记,false则不清除 extraProperty = boolList; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecords, extraProperty, ref device, ref extraData); if (result) { List <Record> recordList = (List <Record>)extraData; AddRecordToListView(recordList); } else { MessageBox.Show("Get All Glog Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); } }
private void btn_MessageGet_Click(object sender, EventArgs e) { if (-1 == cbo_MessageSN.SelectedIndex) { MessageBox.Show("Please select SN", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); cbo_MessageSN.Focus(); return; } object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraData = Zd2911Utils.DeviceMessage; result = deviceConnection.GetProperty(DeviceProperty.Message, extraProperty, ref device, ref extraData); if (result) { byte[] data = Encoding.Unicode.GetBytes((string)extraData); byte[] message = new byte[Zd2911Utils.MaxDeviceMessageLength]; Array.Copy(data, cbo_MessageSN.SelectedIndex * Zd2911Utils.MaxDeviceMessageLength, message, 0, message.Length); chk_MessageEnable.Checked = Convert.ToBoolean(message[0]); cbo_MessageType.SelectedIndex = message[1]; cbo_MessageSound.SelectedIndex = message[2]; dtp_MessageBeginDatetime.Value = new DateTime(message[6] + 2000, message[7], message[8], message[9], message[10], 0); dtp_MessageEndDatetime.Value = new DateTime(message[11] + 2000, message[12], message[13], message[14], message[15], 0); nud_MessageID.Value = BitConverter.ToUInt64(message, 16); txt_MessageContent.Text = Encoding.Unicode.GetString(message, 24, 30 * 2).Replace("\0", ""); } else { MessageBox.Show("Get Message Settings Fail.", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); } }
private void btn_ParamGet_Click(object sender, EventArgs e) { if (-1 == cbo_ParamName.SelectedIndex) { MessageBox.Show("Please Select Parameter", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); cbo_ParamName.Focus(); return; } try { object extraProperty = new object(); object extraData = new object(); byte[] paramIndex = BitConverter.GetBytes(cbo_ParamName.SelectedIndex + 32); extraData = paramIndex; bool result = deviceConnection.GetProperty(DeviceProperty.SysParam, extraProperty, ref device, ref extraData); if (result) { int paramValue = BitConverter.ToInt32((byte[])extraData, 0); txt_ParamValue.Text = paramValue.ToString(); } else { MessageBox.Show("Get Access Control Parameter Settings Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_AlarmGet_Click(object sender, EventArgs e) { if (-1 == cbo_AlarmDN.SelectedIndex) { MessageBox.Show("Please Select SN", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); cbo_AlarmDN.Focus(); return; } object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraData = Zd2911Utils.DeviceAlarmClock; result = deviceConnection.GetProperty(DeviceProperty.Bell, extraProperty, ref device, ref extraData); if (result) { string bellData = (string)extraData; byte[] dataBytes = Encoding.Unicode.GetBytes(bellData);//返回字节数组长度:192 byte[] bell = new byte[Zd2911Utils.BellLength]; Array.Copy(dataBytes, cbo_AlarmDN.SelectedIndex * Zd2911Utils.BellLength, bell, 0, bell.Length);//根据序号获取相应位置数据,每一组数据字节长度:8 cbo_AlarmHour.SelectedIndex = bell[0]; cbo_AlarmMinute.SelectedIndex = bell[1]; cbo_AlarmCycle.SelectedIndex = bell[2]; nud_AlarmDelay.Value = bell[3]; } else { MessageBox.Show("Get Alarm Settings Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); } }
/// <summary> /// 根据设备Id,找到设备中没有员工姓名的那些记录,根据他们的PhycisalCardNumber,从Staffs中找到对应的员工姓名,并写入到机器中 /// </summary> /// <param name="DeviceId"></param> /// <returns></returns> public ActionResult WriteUserToDevice(int DeviceId) { Device device = new Device(); DeviceConnection deviceConnection = this.createDeviceConnection(DeviceId, ref device); //设备连接成功 if (deviceConnection.Open() > 0) //连接设备成功 { try { object extraProperty = new object(); object extraData = new object(); extraProperty = (UInt64)0; bool result = deviceConnection.GetProperty(DeviceProperty.Enrolls, extraProperty, ref device, ref extraData); if (false == result) { return(RedirectToAction("ConnError")); } List <User> userList = (List <User>)extraData; foreach (User user in userList) //遍历所有的注册用户,获取其用户名,我也不知道为什么User这个对象里不存放用户名这个字段 { // Enroll enroll = user.Enrolls[0]; User u = user; // u.DIN = (UInt64)1; result = deviceConnection.GetProperty(UserProperty.UserName, extraProperty, ref u, ref extraData); string tmpPCN = u.DIN.ToString(); u.UserName = db.Staffs.Where(p => p.PhysicalCardNumber.Equals(tmpPCN)).ToList().First().Name; //将机器上的用户名称重置为员工档案中的名称 deviceConnection.SetProperty(UserProperty.UserName, extraProperty, user, extraData); } } catch (Exception e) { } } return(RedirectToAction("UserList", new { id = DeviceId })); }
/// <summary> /// 获取到硬件设备中的用户信息。同时要初始化以后硬件操作要用到的Device和DeviceConnection对象 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult UserList(int id) { ViewBag.DeviceId = id; List <DeviceUserViewModel> deviceUser = new List <DeviceUserViewModel>(); try { Device device = new Device(); DeviceConnection deviceConnection = this.createDeviceConnection(id, ref device); //设备连接成功 if (deviceConnection.Open() > 0) //连接设备成功 { object extraProperty = new object(); object extraData = new object(); try { // bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraProperty = (UInt64)0; bool result = deviceConnection.GetProperty(DeviceProperty.Enrolls, extraProperty, ref device, ref extraData); if (false == result) { return(RedirectToAction("ConnError")); } List <User> userList = (List <User>)extraData; foreach (User user in userList) //遍历所有的注册用户,获取其用户名,我也不知道为什么User这个对象里不存放用户名这个字段 { // Enroll enroll = user.Enrolls[0]; User u = user; result = deviceConnection.GetProperty(UserProperty.UserName, extraProperty, ref u, ref extraData); string tmpDIN = u.DIN.ToString(); var tmpDepts = db.Departments.Where(p => p.DepartmentId.Equals(tmpDIN)).ToList(); string deptName = null; if (tmpDepts.Count == 0) { deptName = "暂无部门"; } else { deptName = tmpDepts[0].Name; } if (result) { deviceUser.Add(new DeviceUserViewModel() { Name = u.UserName, PhysicalCardNumber = u.DIN.ToString(), DepartmentName = deptName }); } else { deviceUser.Add(new DeviceUserViewModel() { Name = "未设定", PhysicalCardNumber = u.DIN.ToString(), DepartmentName = deptName }); } } } catch (Exception e) { } } } catch (Exception ex) { return(View()); } return(View(deviceUser)); }
private void getAccessControlSettingsLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraData = Zd2911Utils.DeviceAccessControlSettings; result = deviceConnection.GetProperty(DeviceProperty.AccessControlSettings, extraProperty, ref device, ref extraData); if (result) { byte[] data = Encoding.Unicode.GetBytes((string)extraData); WiegandItem.SelectedIndex = data[0]; HijackOpenItem.SelectedIndex = data[1]; HijackAlarmItem.SelectedIndex = data[2]; AntiPassbackItem.SelectedIndex = data[3]; FireAlarmItem.SelectedIndex = data[4]; HijackFpNoItem.SelectedIndex = data[5]; AntiHijackEnableItem.SelectedIndex = data[6]; SecondLockItem.SelectedIndex = data[7]; StringBuilder pwd = new StringBuilder(); for (int i = 0; i < Zd2911Utils.PasswordLength; i++) { pwd.Append((char)data[8 + i]); } HijackPasswordItem.Text = pwd.ToString(); OpenDoor1TimeItem.Value = data[16]; CheckDoor1StatusItem.SelectedIndex = data[17]; OpenDoor1OvertimeAlarmItem.Value = data[18]; IllegalOpenDoor1TimeItem.Value = data[19]; OpenDoor2TimeItem.Value = data[20]; CheckDoor2StatusItem.SelectedIndex = data[21]; OpenDoor2OvertimeAlarmItem.Value = data[22]; IllegalOpenDoor2TimeItem.Value = data[23]; MultOpenEnableItem.SelectedIndex = data[24]; LinkageOpenItem.SelectedIndex = data[25]; LinkageAlarmItem.SelectedIndex = data[26]; AutoUnlock1PassGroupItem.Value = data[27]; AutoUnlock2PassGroupItem.Value = data[28]; EnableRealyAlarmItem.SelectedIndex = data[29]; } else { MessageBox.Show("Get Access control Settings Fail.", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); } }
public JsonResult DownloadAttendence(int DN, string Model, int ConnectionModel, string IpAddress, int IpPort, string FrmDt, string ToDt) { int Result = 0; int Result1 = 0; int UsrKy = HTNSession.UsrKy; int CKy = HTNSession.CKy; //string EnvironmentName = HTNSession.Environment; string EnvironmentName = ""; try { if (WebConfigurationManager.AppSettings["AttendenceInsertEnvNm"] != null && WebConfigurationManager.AppSettings["AttendenceInsertEnvNm"] != "") { EnvironmentName = WebConfigurationManager.AppSettings["AttendenceInsertEnvNm"]; } else { EnvironmentName = HTNSession.Environment; } } catch (Exception) { } //string EnvironmentName = WebConfigurationManager.AppSettings["AttendenceInsertEnvNm"]; device = new Riss.Devices.Device(); device.CommunicationType = CommunicationType.Tcp; device.DN = DN; device.IpAddress = IpAddress; device.Model = Model; device.ConnectionModel = ConnectionModel; device.IpPort = IpPort; deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { Result1 = 1; deviceEty = new DeviceCommEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; } else { return(Json(Result, JsonRequestBehavior.AllowGet)); } object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; if (Result1 == 1) { try { FrmDt = "01/01/2017"; ToDt = "31/12/2099"; List <DateTime> dtList = GetDateTimeList(FrmDt, ToDt); bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraProperty = false; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecordsCount, extraProperty, ref device, ref extraData); if (false == result) { return(Json(Result, JsonRequestBehavior.AllowGet)); } int recordCount = (int)extraData; if (0 == recordCount) { return(Json(Result, JsonRequestBehavior.AllowGet)); } List <bool> boolList = new List <bool>(); boolList.Add(false); boolList.Add(false); extraProperty = boolList; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecords, extraProperty, ref device, ref extraData); if (result) { List <Record> recordList = (List <Record>)extraData; List <AttendenceDownloadModel> AtnDownloadLst = new List <AttendenceDownloadModel>(); foreach (Record item in recordList) { AttendenceDownloadModel obj = new AttendenceDownloadModel(); obj.UsrKy = Convert.ToInt32(item.DIN); obj.ClkDt = item.Clock.ToString(); AtnDownloadLst.Add(obj); } var stringList = AtnDownloadLst.OfType <string>(); bool res = apiOpr.AtnClkDet_InsertWeb(CKy, UsrKy, AtnDownloadLst, EnvironmentName); if (res) { //bool clear = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); bool clear = deviceConnection.SetProperty(DeviceProperty.AttRecords, extraProperty, device, extraData); if (clear) { //lvw_GLogList.Items.Clear(); Result = 1; } } } else { return(Json(Result, JsonRequestBehavior.AllowGet)); } } #pragma warning disable CS0168 // The variable 'ex' is declared but never used catch (Exception ex) #pragma warning restore CS0168 // The variable 'ex' is declared but never used { return(Json(Result, JsonRequestBehavior.AllowGet)); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); deviceConnection.Close(); device = null; deviceConnection = null; deviceEty = null; } } return(Json(Result, JsonRequestBehavior.AllowGet)); }
private bool FetchData() { object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { if (GetLastEntryTime() == false) { Logger.log("Database exception : Abort fetching data"); return(false); } List <DateTime> dtList = GetDateTimeList(); bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); extraProperty = false; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecordsCount, extraProperty, ref device, ref extraData); if (false == result) { Logger.log("Get All Glog Fail"); return(false); } int recordCount = (int)extraData; if (0 == recordCount) { Logger.log("Get All Glog Fail : zero fetch count"); return(false); } List <bool> boolList = new List <bool>(); boolList.Add(false); boolList.Add(false);//清除新日志标记,false则不清除 extraProperty = boolList; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecords, extraProperty, ref device, ref extraData); if (result) { List <Record> recordList = (List <Record>)extraData; return(ProcessData(recordList)); } else { Logger.log("Get All Glog Fail"); } } catch (Exception ex) { Logger.log("Get All Glog Fail : Exception"); Logger.log(ex.Message); } finally { extraData = Global.DeviceIdle; deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); } return(false); }
public ActionResult DownloadDataBiometric() { //List<DownloadDataViewModel> list = new List<DownloadDataViewModel>(); //------------------------------------------ BINUGO CODE device = new Device(); device.DN = 1; device.Model = "A-C030"; device.ConnectionModel = 5; device.IpAddress = "192.168.005.001"; device.IpPort = 123; device.CommunicationType = CommunicationType.Tcp; deviceConnection = DeviceConnection.CreateConnection(ref device); System.Diagnostics.Debug.WriteLine(deviceConnection.Open()); deviceEty = new DeviceComEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; //----------------------------------------- object extraProperty = new object(); object extraData = new object(); extraData = Global.DeviceBusy; try { List <DateTime> dtList = new List <DateTime>(); bool result = deviceConnection.SetProperty(DeviceProperty.Enable, extraProperty, device, extraData); //------------------------------------------ BINUGO CODE dtList.Add(Convert.ToDateTime("08/01/2017")); dtList.Add(DateTime.Now); //----------------------------------------- //dtList.Add(model.TO.Date); //dtList.Add(model.TO.Date); extraProperty = false; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecordsCount, extraProperty, ref device, ref extraData); if (false == result) { TempData["msg"] = "<script>alert('Download Failed');</script>"; } int recordCount = (int)extraData; if (0 == recordCount) {//为0时说明没有新日志记录 ListDownloadData.Clear(); } List <bool> boolList = new List <bool>(); //----------------------------------------- BINUGO CODE boolList.Add(false); //所有日志 boolList.Add(false); //清除新日志标记,false则不清除 //----------------------------------------- extraProperty = boolList; extraData = dtList; result = deviceConnection.GetProperty(DeviceProperty.AttRecords, extraProperty, ref device, ref extraData); if (result) { int i = 1; int y = 0; List <Record> recordList = (List <Record>)extraData; ListDownloadData.Clear(); foreach (Record record in recordList) { ListDownloadData.Add(new DownloadDataViewModel { SN = i.ToString(), DN = record.DN.ToString(), DIN = record.DIN.ToString(), Type = ConvertObject.GLogType(record.Verify), mode = ConvertObject.IOMode(record.Action), Clock = record.Clock.ToString("yyyy-MM-dd HH:mm:ss") }); i++; } Session["SessionName"] = ListDownloadData; } else { TempData["msg"] = "<script>alert('Download Failed');</script>"; } } catch (Exception) { TempData["msg"] = "<script>alert('Download Failed');</script>"; } return(View("ConnectBiometric", ListDownloadData)); }