public ActionResult ConnectBiometric(DownloadDataViewModel model) { device = new Device(); device.DN = 1; device.Model = "A-C071"; device.ConnectionModel = 5; device.IpAddress = model.IpAddress; device.IpPort = int.Parse(model.Port); device.CommunicationType = CommunicationType.Tcp; deviceConnection = DeviceConnection.CreateConnection(ref device); System.Diagnostics.Debug.WriteLine(deviceConnection.Open()); if (deviceConnection.Open() > 0) { deviceEty = new DeviceComEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; } else { } return(View()); }
private void btnConnect_Click(object sender, EventArgs e) { try { device = new Device(); device.DN = 1; device.Password = "******"; device.Model = "A-C030"; device.ConnectionModel = 5;//等于5时才能正确加载ZD2911通讯模块 if (rdb_Network.Checked == true) { //ip address if (string.IsNullOrEmpty(txt_IP.Text.Trim())) { MessageBox.Show("Please Input IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } if (false == ConvertObject.IsCorrenctIP(txt_IP.Text.Trim())) { MessageBox.Show("Illegal IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } device.IpAddress = txt_IP.Text.Trim(); device.IpPort = int.Parse(txt_Port.Text); device.CommunicationType = CommunicationType.Tcp; } else { device.CommunicationType = CommunicationType.Usb; } deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { deviceEty = new DeviceComEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; MessageBox.Show("Device successfully connected", "System", MessageBoxButtons.OK, MessageBoxIcon.Information); btnBiometricData.Enabled = true; btnDisconnect.Enabled = true; btnConnect.Enabled = false; } else { MessageBox.Show("Failed to Connect to Device", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public DeviceConnection createDeviceConnection(int id, ref Device mydevice) { Devices dbDevice = db.Devices.Find(id); Device device = new Device(); device.DN = dbDevice.DeviceID; //deviceID; device.Password = dbDevice.CommKey; //this.CommKey; device.Model = dbDevice.DeviceType; device.ConnectionModel = 5; //等于5时才能正确加载ZD2911通讯模块 device.IpAddress = dbDevice.IP; //this.IP; //txt_IP.Text.Trim(); device.IpPort = dbDevice.Port; //this.Port; //(int)nud_Port.Value; device.CommunicationType = CommunicationType.Tcp; mydevice = device; return(DeviceConnection.CreateConnection(ref device)); }
public ActionResult ConnectBiometric(ConnectViewModel model) //this is one page bale localhost:portnum/DownloadData/ConnectBiometric << pwde kani localhost:portnum/DownloadData/Index { bool x = false; try { device = new Device(); device.DN = 1; device.Model = "A-C030"; device.ConnectionModel = 5; device.IpAddress = model.IpAddress; device.IpPort = int.Parse(model.Port); device.CommunicationType = CommunicationType.Tcp; deviceConnection = DeviceConnection.CreateConnection(ref device); System.Diagnostics.Debug.WriteLine(deviceConnection.Open()); if (deviceConnection.Open() > 0) { deviceEty = new DeviceComEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; x = true; } else { TempData["msg"] = "<script>alert('Connection Failed');</script>"; x = false; } } catch (Exception ex) { TempData["msg"] = "<script>alert('ex');</script>"; } if (x == true) { return(View()); } else { return(View("Index")); } }
private bool OpenConnection() { try { device = new Device(); device.DN = DN; device.Password = Password; device.Model = Model; device.ConnectionModel = ConnectionModel; device.IpAddress = IPAddress; device.IpPort = IPPort; device.CommunicationType = CommType; deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { deviceEty = new DeviceCommEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; Logger.log("Connection successful"); return(true); } else { Logger.log("Cannot open device connection"); return(false); //MessageBox.Show("Connect Device Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Logger.log("Cannot create connection"); Logger.log(ex.Message); return(false); //MessageBox.Show(ex.Message, "Error1", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 针对具体设备的测视连接方法 /// </summary> /// <returns></returns> public override bool TestConnection() { //调用特定设备的测试连接的函数 try { Device device = new Device(); device.DN = this.DeviceID; device.Password = this.CommKey; device.Model = "ZDC2911"; device.ConnectionModel = 5; //等于5时才能正确加载ZD2911通讯模块 device.IpAddress = this.IP; //txt_IP.Text.Trim(); device.IpPort = this.Port; //(int)nud_Port.Value; device.CommunicationType = CommunicationType.Tcp; DeviceConnection deviceConnection = DeviceConnection.CreateConnection(ref device); //设备连接成功 if (deviceConnection.Open() > 0) { // DeviceCommEty deviceEty = new DeviceCommEty(); // deviceEty.Device = device; // deviceEty.DeviceConnection = deviceConnection; // btn_CloseDevice.Enabled = true; // SetButtonEnabled(true); // btn_OpenDevice.Enabled = false; } else { return(false); } } catch (Exception ex) { return(false); } return(true); }
private void btn_OpenDevice_Click(object sender, EventArgs e) { try { device = new Device(); device.DN = (int)nud_DN.Value; device.Password = nud_Pwd.Value.ToString(); device.Model = "ZDC2911"; device.ConnectionModel = 5;//等于5时才能正确加载ZD2911通讯模块 if (rdb_USB.Checked) { device.CommunicationType = CommunicationType.Usb; } else if (rdb_TCP.Checked) { if (string.IsNullOrEmpty(txt_IP.Text.Trim())) { MessageBox.Show("Please Input IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } if (false == ConvertObject.IsCorrenctIP(txt_IP.Text.Trim())) { MessageBox.Show("Illegal IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } device.IpAddress = txt_IP.Text.Trim(); device.IpPort = (int)nud_Port.Value; device.CommunicationType = CommunicationType.Tcp; } else if (rdb_COMM.Checked) { device.SerialPort = Convert.ToInt32(cbo_COMM.SelectedItem.ToString().Replace("COM", string.Empty)); device.Baudrate = Convert.ToInt32(cbo_BaudRate.SelectedItem); device.CommunicationType = CommunicationType.Serial; } else if (p2pRadioButton.Checked) { device.CommunicationType = CommunicationType.P2P; device.SerialNumber = p2pAddrTextBox.Text.Trim(); //20130819 Riss.Devices.P2pUtils.SetP2pServerIpAddress(p2pServerTextBox.Text.Trim()); } deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { deviceEty = new DeviceCommEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; btn_CloseDevice.Enabled = true; SetButtonEnabled(true); btn_OpenDevice.Enabled = false; } else { MessageBox.Show("Connect Device Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error1", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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)); }
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)); }