Exemple #1
0
        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());
        }
Exemple #2
0
        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 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"));
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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 }));
        }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
        /// <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));
        }
        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));
        }