Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
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 }));
        }
Ejemplo n.º 4
0
        private void btn_ParamSet_Click(object sender, EventArgs e)
        {
            if (-1 == cbo_Param.SelectedIndex)
            {
                MessageBox.Show("Please Select Parameter", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbo_Param.Focus();
                return;
            }

            try
            {
                int paramValue = -1;
                switch (cbo_Param.SelectedIndex)
                {
                case 26:
                case 27:
                case 28:
                case 29:
                    if (false == ConvertObject.IsCorrenctIP(txt_ParamValue.Text.Trim()))
                    {
                        MessageBox.Show("Illegal IP address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txt_ParamValue.Focus();
                        return;
                    }
                    paramValue = ConvertObject.ConvertIPAddressToNumber(txt_ParamValue.Text.Trim());
                    break;

                default:
                    paramValue = Convert.ToInt32(txt_ParamValue.Text.Trim());
                    break;
                }

                object extraProperty = new object();
                object extraData     = new object();
                byte[] data          = new byte[8];
                Array.Copy(BitConverter.GetBytes(cbo_Param.SelectedIndex), 0, data, 0, 4);
                Array.Copy(BitConverter.GetBytes(paramValue), 0, data, 4, 4);
                extraData = data;
                bool result = deviceConnection.SetProperty(DeviceProperty.SysParam, extraProperty, device, extraData);
                if (result)
                {
                    MessageBox.Show("Set Parameter Success", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Set Parameter Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        private void btn_ParamSet_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[] data          = new byte[8];
                int    paramValue    = Convert.ToInt32(txt_ParamValue.Text.Trim());
                Array.Copy(BitConverter.GetBytes(cbo_ParamName.SelectedIndex + 32), 0, data, 0, 4);
                Array.Copy(BitConverter.GetBytes(paramValue), 0, data, 4, 4);
                extraData = data;
                bool result = deviceConnection.SetProperty(DeviceProperty.SysParam, extraProperty, device, extraData);
                if (result)
                {
                    MessageBox.Show("Set Access Control Parameter Success", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Set Access Control Parameter Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", 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));
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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));
        }