Ejemplo n.º 1
0
        /// <summary>
        /// 发送串口命令
        /// </summary>
        /// <param name="SendData">发送数据</param>
        /// <param name="ReceiveData">接收数据</param>
        /// <param name="Overtime">重复次数</param>
        /// <returns></returns>
        public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime)
        {
            int ret = 0;

            try
            {
                if (!(comPort.IsOpen))
                {
                    comPort.Open();
                }
                ReceiveEventFlag = true;        //关闭接收事件
                comPort.ReadExisting();
                comPort.Write(SendData, 0, SendData.Length);
                System.Threading.Thread.Sleep(Overtime);
                if (comPort.BytesToRead >= ReceiveData.Length)
                {
                    ret = comPort.Read(ReceiveData, 0, ReceiveData.Length);
                }
                ReceiveEventFlag = false;       //打开事件
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 只连接 不绑定 事件
        /// </summary>
        public bool OnlyConnect()
        {
            bool blRet = false;

            try
            {
                if (string.IsNullOrEmpty(strIp))
                {
                    MessageUtil.ShowTips("指纹门禁IP为空");
                    return(blRet);
                }
                if (iPort == 0)
                {
                    MessageUtil.ShowTips(strIp + "-指纹门禁端口号未设置");
                    return(blRet);
                }
                blRet = axCZKEM1.Connect_Net(strIp, iPort);
                if (blRet == true)
                {
                    blConnoct = true;
                }
                else
                {
                    blRet = false;
                }
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(blRet);
        }
Ejemplo n.º 3
0
        public bool GetDoorState(ref DoorsState state)
        {
            bool blRet = false;

            try
            {
                int iState = 0;
                if (axCZKEM1.GetDoorState(iMachineNumber, ref iState))
                {
                    blRet = true;
                    if (iState == 0)
                    {
                        state = DoorsState.开门;
                    }
                    else if (iState == 1)
                    {
                        state = DoorsState.关门;
                    }
                }
                else
                {
                    blRet = false;
                }
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(blRet);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 打开端口
        /// </summary>
        /// <returns></returns>
        public void OpenPort()
        {
            try
            {
                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                comPort.PortName = _portName;
                comPort.BaudRate = (int)_baudRate;
                comPort.Parity   = _parity;
                comPort.DataBits = (int)_dataBits;
                comPort.StopBits = _stopBits;

                comPort.Open();
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
        }
Ejemplo n.º 5
0
 private void timerWg_Execute()
 {
     try
     {
         if (watching != null)
         {
             updateControllerStatus();
             if (QueRecText.Count > 0)
             {
                 txtInfoHaveNewInfoEntry();
             }
             Application.DoEvents();//2010-8-1 09:09:06 显示
         }
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
         if (watching != null)
         {
             timerWg.Start();//下次执行
             System.Threading.Interlocked.Exchange(ref dealingTxt, 0);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 连接控制器
        /// </summary>
        /// <returns></returns>
        public async Task <bool> ConnectZk()
        {
            bool blRet = false;
            await Task.Factory.StartNew(() => {
                try
                {
                    if (string.IsNullOrEmpty(strIp))
                    {
                        MessageUtil.ShowTips("指纹门禁 IP 为空");
                        return(blRet);
                    }
                    if (iPort == 0)
                    {
                        MessageUtil.ShowTips("指纹门禁 端口号 未设置");
                        return(blRet);
                    }
                    blRet = axCZKEM1.Connect_Net(strIp, iPort);
                    if (blRet == true)
                    {                           //连接成功
                        blConnoct          = true;
                        int iMachineNumber = 1; //In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                        if (axCZKEM1.RegEvent(iMachineNumber, 65535))
                        {
                            blRet = true;
                            //当验证通过时触发该事件
                            this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                            this.axCZKEM1.OnDoor             += new zkemkeeper._IZKEMEvents_OnDoorEventHandler(axCZKEM1_OnDoor);
                            this.axCZKEM1.OnAlarm            += new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(axCZKEM1_OnAlarm);
                            this.axCZKEM1.OnDisConnected     += new zkemkeeper._IZKEMEvents_OnDisConnectedEventHandler(axCZKEM1_OnDisConnected);
                        }
                        else
                        {
                            blRet = false;
                            //axCZKEM1.GetLastError(ref idwErrorCode);
                            //lbRTShow.Items.Add("连接设备失败,错误码: " + idwErrorCode.ToString());
                        }
                    }
                    else
                    {
                        blRet = false;
                        //axCZKEM1.GetLastError(ref idwErrorCode);
                        //lbRTShow.Items.Add("连接设备失败,错误码: " + idwErrorCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    if (frmMain.blDebug)
                    {
                        MessageUtil.ShowTips(ex.Message);
                    }
                }
                return(blRet);
            });

            return(blRet);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载所有工具柜
        /// </summary>
        //public void LoadBox()
        //{
        //    try
        //    {
        //        #region  工具柜门禁

        //        if (boxDoorWatching != null)
        //        {
        //            boxDoorWatching.PauseWatch();
        //            if (clsWgWatchingBox.listWg.Count > 0)
        //            {
        //                lock (clsWgWatchingBox.listWg)
        //                {
        //                    clsWgWatchingBox.listWg.Clear();
        //                }
        //            }
        //        }

        //        string strSql = "select tvChildId,AreaName,PlaceName,DoorIp,DoorSn,BoxHasRfid,BoxRfidMain from tb_Tools where  " +
        //                        "IsArea='" + ToolAreaType.工具柜.ToString() + "' and HasDoor='" + DeviceUsing.启用.ToString() + "'  ";
        //        DataTable dt = datalogic.GetDataTable(strSql);
        //        foreach (DataRow datarow in dt.Rows)
        //        {
        //            string strChildId = datarow["tvChildId"].ToString();
        //            string strArea = datarow["AreaName"].ToString();
        //            string strName = datarow["PlaceName"].ToString();
        //            string strIp = datarow["DoorIp"].ToString();
        //            string strSn = datarow["DoorSn"].ToString();
        //            string strHasRfid = datarow["BoxHasRfid"].ToString();
        //            string strRfidMain = datarow["BoxRfidMain"].ToString();
        //            uint iSn = 0;
        //            if (!string.IsNullOrEmpty(strSn))
        //            {
        //                iSn = Convert.ToUInt32 (strSn);
        //            }
        //            else
        //            {
        //                MessageUtil.ShowTips(strName + " 工具柜门禁SN为空");
        //            }

        //            clsDoorBox boxDoor = new clsDoorBox(strIp, iSn, strName, strArea);
        //            boxDoor.StrChildId = strChildId;
        //            boxDoor.StrHasRfid = strHasRfid;
        //            boxDoor.StrRfidMain = strRfidMain;
        //            lock (clsWgWatchingBox.listWg)
        //            {
        //                clsWgWatchingBox.listWg.Add(boxDoor);
        //            }
        //        }

        //        if (clsWgWatchingBox.listWg.Count > 0)
        //        {
        //            if (boxDoorWatching == null)
        //            {
        //                boxDoorWatching = new clsWgWatchingBox();
        //            }
        //            boxDoorWatching.StartWatch();
        //            frmMain.UsingBox = DeviceUsing.启用;
        //        }
        //        else
        //        {
        //            frmMain.UsingBox = DeviceUsing.未启用;
        //            if (boxDoorWatching != null)
        //            {
        //                boxDoorWatching.StopWatch();
        //                boxDoorWatching = null;
        //            }
        //        }

        //        #endregion

        //        #region

        //        //#region 工具柜RFID

        //        //if (listBoxRfid.Count > 0)
        //        //{
        //        //    lock (listBoxRfid)
        //        //    {
        //        //        for (int iIndexRfid = 0; iIndexRfid < listBoxRfid.Count; iIndexRfid++)
        //        //        {
        //        //            if (listBoxRfid[iIndexRfid] != null)
        //        //            {
        //        //                if (listBoxRfid[iIndexRfid].StateMainRead != BoxRfidState.不读)
        //        //                    listBoxRfid[iIndexRfid].StateMainRead = BoxRfidState.不读;
        //        //                if (listBoxRfid[iIndexRfid].StateSlaveRead != BoxRfidState.不读)
        //        //                    listBoxRfid[iIndexRfid].StateSlaveRead = BoxRfidState.不读;
        //        //                if (listBoxRfid[iIndexRfid].timerRfidFast.State == TimerState.Running)
        //        //                    listBoxRfid[iIndexRfid].StopRead();
        //        //                if (listBoxRfid[iIndexRfid].BlConnent)
        //        //                {
        //        //                    listBoxRfid[iIndexRfid].CloseNetPort();
        //        //                }
        //        //                if (listBoxRfid[iIndexRfid].timerRfidFast != null)
        //        //                    listBoxRfid[iIndexRfid].timerRfidFast = null;
        //        //                listBoxRfid[iIndexRfid] = null;
        //        //            }
        //        //        }
        //        //        listBoxRfid.Clear();
        //        //    }
        //        //}

        //        //strSql = "select tvChildId,AreaName,PlaceName,BoxRfidIp,BoxRfidPort,BoxRfidMain,BoxRfidAnt1,BoxRfidAnt2,BoxRfidAnt3,BoxRfidAnt4 from tb_Tools where " +
        //        //         "IsArea='" + ToolAreaType.工具柜.ToString() + "' and BoxHasRfid='" + DeviceUsing.启用.ToString() + "'  ";
        //        //dt = datalogic.GetDataTable(strSql);
        //        //foreach (DataRow datarow in dt.Rows)
        //        //{
        //        //    string strId = datarow["tvChildId"].ToString();
        //        //    string strArea = datarow["AreaName"].ToString();
        //        //    string strName = datarow["PlaceName"].ToString();
        //        //    string strIp = datarow["BoxRfidIp"].ToString();
        //        //    string strPort = datarow["BoxRfidPort"].ToString();
        //        //    string strMain = datarow["BoxRfidMain"].ToString();

        //        //    #region 天线

        //        //    DeviceUsing ant1 = DeviceUsing.未启用;
        //        //    DeviceUsing ant2 = DeviceUsing.未启用;
        //        //    DeviceUsing ant3 = DeviceUsing.未启用;
        //        //    DeviceUsing ant4 = DeviceUsing.未启用;

        //        //    string strAnt = datarow["BoxRfidAnt1"].ToString();
        //        //    if (strAnt == DeviceUsing.启用.ToString())
        //        //        ant1 = DeviceUsing.启用;
        //        //    else
        //        //        ant1 = DeviceUsing.未启用;
        //        //    strAnt = datarow["BoxRfidAnt2"].ToString();
        //        //    if (strAnt == DeviceUsing.启用.ToString())
        //        //        ant2 = DeviceUsing.启用;
        //        //    else
        //        //        ant2 = DeviceUsing.未启用;
        //        //    strAnt = datarow["BoxRfidAnt3"].ToString();
        //        //    if (strAnt == DeviceUsing.启用.ToString())
        //        //        ant3 = DeviceUsing.启用;
        //        //    else
        //        //        ant3 = DeviceUsing.未启用;
        //        //    strAnt = datarow["BoxRfidAnt4"].ToString();
        //        //    if (strAnt == DeviceUsing.启用.ToString())
        //        //        ant4 = DeviceUsing.启用;
        //        //    else
        //        //        ant4 = DeviceUsing.未启用;

        //        //    #endregion

        //        //    bool blHas = false;

        //        //    int iPort = 0;
        //        //    if (!string.IsNullOrEmpty(strPort))
        //        //    {
        //        //        iPort = Convert.ToInt32(strPort);
        //        //    }
        //        //    else
        //        //    {
        //        //        MessageUtil.ShowTips(strName + " 工具柜RFID端口号为空");
        //        //    }

        //        //    #region  已有

        //        //    if (listBoxRfid.Count > 0)
        //        //    {
        //        //        int iCount = listBoxRfid.Count;
        //        //        for (int iIndex = 0; iIndex < iCount; iIndex++)
        //        //        {
        //        //            if (listBoxRfid[iIndex].StrIp == strIp && listBoxRfid[iIndex].IPort == iPort)
        //        //            {
        //        //                blHas = true;
        //        //                if (listBoxRfid[iIndex].StrChildIdMain == null)
        //        //                {
        //        //                    listBoxRfid[iIndex].StrChildIdMain = strId;
        //        //                    listBoxRfid[iIndex].StrNameMain = strName;
        //        //                    listBoxRfid[iIndex].AntMain1 = ant1;
        //        //                    listBoxRfid[iIndex].AntMain2 = ant2;
        //        //                }
        //        //                else if (listBoxRfid[iIndex].StrChildIdSlave == null)
        //        //                {
        //        //                    listBoxRfid[iIndex].StrChildIdSlave = strId;
        //        //                    listBoxRfid[iIndex].StrNameSlave = strName;
        //        //                    listBoxRfid[iIndex].AntSlave1 = ant3;
        //        //                    listBoxRfid[iIndex].AntSlave2 = ant4;
        //        //                }
        //        //            }
        //        //        }
        //        //    }

        //        //    #endregion

        //        //    #region  无,添加

        //        //    if (blHas == false)
        //        //    {
        //        //        RfidReadBox rfidRead = new RfidReadBox();
        //        //        rfidRead.StrIp = strIp;
        //        //        rfidRead.IPort = iPort;
        //        //        if (strMain == BoxRfidMain.主机.ToString())
        //        //        {
        //        //            rfidRead.StrChildIdMain = strId;
        //        //            rfidRead.StrNameMain = strName;
        //        //            rfidRead.AntMain1 = ant1;
        //        //            rfidRead.AntMain2 = ant2;
        //        //        }
        //        //        else if (strMain == BoxRfidMain.从机.ToString())
        //        //        {
        //        //            rfidRead.StrChildIdSlave = strId;
        //        //            rfidRead.StrNameSlave = strName;
        //        //            rfidRead.AntSlave1 = ant3;
        //        //            rfidRead.AntSlave2 = ant4;
        //        //        }
        //        //        lock (listBoxRfid)
        //        //        {
        //        //            listBoxRfid.Add(rfidRead);
        //        //        }
        //        //    }

        //        //    #endregion

        //        //}
        //        ////设置工具柜RFID天线



        //        ////for (int iIndex = 0; iIndex < listBoxRfid.Count; iIndex++)
        //        ////{
        //        ////    DeviceUsing ant1 = listBoxRfid[iIndex].AntMain1;
        //        ////    DeviceUsing ant2 = listBoxRfid[iIndex].AntMain2;
        //        ////    DeviceUsing ant3 = listBoxRfid[iIndex].AntSlave1;
        //        ////    DeviceUsing ant4 = listBoxRfid[iIndex].AntSlave2;
        //        ////}

        //        ////if (listBoxDoor.Count > 0)
        //        ////{
        //        ////    //timerBoxDoor.Start();
        //        ////}
        //        ////else
        //        ////{
        //        ////    //timerBoxDoor.Stop();
        //        ////}

        //        //#endregion

        //        #endregion
        //    }
        //    catch (Exception ex)
        //    {
        //        if (frmMain.blDebug)
        //            MessageUtil.ShowTips(ex.Message);
        //    }
        //}

        /// <summary>
        /// 加载 所有工具
        /// </summary>
        public void LoadAllTools()
        {
            try
            {
                #region 加载所有工器具

                string strSql = "select tvParent,ToolID,RFIDCoding,BorrowReturnTime,IsInStore,ToolType,ToolName,BorrowPeople,StoragePlace" +
                                " from tb_Tools where IsArea='" + ToolAreaType.工具.ToString() + "' and RFIDCoding <> '' ";
                DataTable dt = datalogic.GetDataTable(strSql);
                listTools.Clear();
                if (dicTools != null && dicTools.Count > 0)
                {
                    dicTools.Clear();
                }
                foreach (DataRow dr in dt.Rows)//dtTools ToolID  RfidCoding ToolBR TimeBR ToolType ToolName
                {
                    string     strType     = dr["ToolType"].ToString();
                    string     strName     = dr["ToolName"].ToString();
                    string     strId       = dr["ToolID"].ToString();
                    string     strRfid     = dr["RFIDCoding"].ToString();
                    string     strTime     = dr["BorrowReturnTime"].ToString();
                    string     strState    = dr["IsInStore"].ToString();
                    string     strPeo      = dr["BorrowPeople"].ToString();
                    string     strTimeBorr = dr["BorrowReturnTime"].ToString();
                    string     strParent   = dr["tvParent"].ToString();
                    string     strStation  = dr["StoragePlace"].ToString();
                    ToolsState state       = (ToolsState)Enum.Parse(typeof(ToolsState), strState);
                    DateTime   dtime       = DateTime.Now;
                    if (!string.IsNullOrEmpty(strTime))
                    {
                        dtime = Convert.ToDateTime(strTime);
                    }
                    ToolInfo toolsInfo = new ToolInfo(strId, strType, strName, strRfid, state, dtime, strPeo, "", strParent, strStation);
                    listTools.Add(toolsInfo);
                    if (!dicTools.ContainsKey(strRfid))
                    {
                        dicTools.Add(strRfid, toolsInfo);
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 只断开连接  不注销事件
 /// </summary>
 public void OnlyDisConnect()
 {
     try
     {
         axCZKEM1.Disconnect();
         blConnoct = false;
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
Ejemplo n.º 9
0
        public bool DeleteUserInfo(string strId)
        {
            bool blRet = false;

            try
            {
                blRet = axCZKEM1.SSR_DeleteEnrollData(iMachineNumber, strId, 12);
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(blRet);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 写入数据
 /// </summary>
 /// <param name="msg">包含要写入端口的字节数组</param>
 /// <param name="offset">参数从0字节开始的字节偏移量</param>
 /// <param name="count">要写入的字节数</param>
 public void WriteData(byte[] msg, int offset, int count)
 {
     try
     {
         if (!(comPort.IsOpen))
         {
             comPort.Open();
         }
         comPort.Write(msg, offset, count);
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 写入数据
 /// </summary>
 /// <param name="msg">写入端口的字节数组</param>
 public void WriteData(byte[] msg)
 {
     try
     {
         if (!(comPort.IsOpen))
         {
             comPort.Open();
         }
         comPort.Write(msg, 0, msg.Length);
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 写入数据
 /// </summary>
 /// <param name="msg"></param>
 public void WriteData(string msg)
 {
     try
     {
         if (!(comPort.IsOpen))
         {
             comPort.Open();
         }
         comPort.ReadExisting();
         comPort.Write(msg);
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 添加或修改 用户信息
        /// </summary>
        /// <param name="strUserNo"></param>
        /// <param name="strName"></param>
        /// <param name="strPsw"></param>
        /// <param name="iPrivilege"></param>
        /// <returns></returns>
        public bool SetUserInfo(string strUserNo, string strName, string strPsw, int iPrivilege)
        {
            bool blRet = false;

            try
            {
                axCZKEM1.EnableDevice(iMachineNumber, false);
                blRet = axCZKEM1.SSR_SetUserInfo(iMachineNumber, strUserNo, strName, strPsw, iPrivilege, true);
                axCZKEM1.EnableDevice(iMachineNumber, true);
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(blRet);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 断开连接
 /// </summary>
 public void DisConnect()
 {
     try
     {
         axCZKEM1.Disconnect();
         blConnoct = false;
         //当验证通过时触发该事件
         this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
         this.axCZKEM1.OnDoor             -= new zkemkeeper._IZKEMEvents_OnDoorEventHandler(axCZKEM1_OnDoor);
         this.axCZKEM1.OnAlarm            -= new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(axCZKEM1_OnAlarm);
         this.axCZKEM1.OnDisConnected     -= new zkemkeeper._IZKEMEvents_OnDisConnectedEventHandler(axCZKEM1_OnDisConnected);
     }
     catch (Exception ex)
     {
         if (frmMain.blDebug)
         {
             MessageUtil.ShowTips(ex.Message);
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 发送string数据命令
        /// </summary>
        /// <param name="strSend"></param>
        /// <param name="Overtime"></param>
        /// <returns></returns>
        //public string SendReceStr(string strSend, int Overtime)
        //{
        //    string strRece="";
        //    try
        //    {
        //        if (!(comPort.IsOpen)) comPort.Open();
        //        comPort.ReadExisting();
        //        comPort.Write(strSend);
        //        System.Threading.Thread.Sleep(Overtime);
        //        strRece = comPort.ReadExisting();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (frmMain.blDebug)
        //            MessageUtil.ShowTips(ex.Message);
        //    }
        //    return strRece;
        //}

        public string SendReceStr(string strSend, int Overtime, IsWait isWait)
        {
            string strRece = "";

            try
            {
                if (!(comPort.IsOpen))
                {
                    comPort.Open();
                }
                comPort.ReadExisting();
                comPort.Write(strSend);
                for (int i = 0; i < Overtime; i++)
                {
                    if (isWait == IsWait.OnlyWait)
                    {
                        Thread.Sleep(100);
                    }
                    else if (isWait == IsWait.CanStop)
                    {
                        if (clsEnvirControl.blAskAir)
                        {
                            Thread.Sleep(100);
                        }
                        else
                        {
                            i = Overtime;
                        }
                    }
                }
                strRece = comPort.ReadExisting();
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(strRece);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 加载房间设备 一个房间对应的温湿度、烟感、空调控制器地址等
        /// </summary>
        public void LoadRooms()
        {
            clsEnvirControl.listRoom.Clear();
            //string strSql = "select ID,RoomName,WsdAddr1,WsdAddr2,FireAddr1,FireAddr2,RelayAddr,AirAddr,AirFactory,AirAddr2,AirFactory2 from tb_RoomInfo ";
            //DataTable dtRoom = datalogic.GetDataTable(strSql);
            IList <TbRoominfo> list = TbRoominfo.FindAll("", "ID ASC", "", 0, 0);

            if (list != null && list.Count > 0)
            {
                foreach (TbRoominfo roominfo in list)
                {
                    try
                    {
                        int       iWsd1  = 0;
                        int       iWsd2  = 0;
                        int       iAir1  = 0;
                        int       iAir2  = 0;
                        int       iRelay = 0;
                        RoomClass room   = new RoomClass(roominfo.RoomName);
                        room.YGCount    = roominfo.YGCount;
                        room.WSDCount   = roominfo.WSDCount;
                        room.KTCount    = roominfo.KTCount;
                        room.IsExistCSJ = roominfo.IsExistCsj == DeviceUsing.启用.ToString() ? true : false;
                        room.IsExistJDQ = roominfo.IsExistRealy == DeviceUsing.启用.ToString() ? true : false;
                        room.IsExistJRQ = roominfo.IsExistJrq == DeviceUsing.启用.ToString() ? true : false;
                        room.IsExistXF  = roominfo.IsExistXf == DeviceUsing.启用.ToString() ? true : false;
                        //温湿度
                        if (!string.IsNullOrEmpty(roominfo.WsdAddr1))
                        {
                            iWsd1 = Convert.ToInt32(roominfo.WsdAddr1);
                        }
                        if (!string.IsNullOrEmpty(roominfo.WsdAddr2))
                        {
                            iWsd2 = Convert.ToInt32(roominfo.WsdAddr2);
                        }
                        if (roominfo.WSDCount > 0)
                        {
                            if (iWsd1 != 0)
                            {
                                clsWsd wsd = new clsWsd(iWsd1);
                                room.listWsd.Add(wsd);
                            }
                            if (iWsd2 != 0)
                            {
                                clsWsd wsd = new clsWsd(iWsd2);
                                room.listWsd.Add(wsd);
                            }
                        }

                        //烟感
                        if (!string.IsNullOrEmpty(roominfo.FireAddr1))
                        {
                            clsFire fire = new clsFire(roominfo.FireAddr1);
                            room.listFire.Add(fire);
                        }
                        if (!string.IsNullOrEmpty(roominfo.FireAddr2))
                        {
                            clsFire fire = new clsFire(roominfo.FireAddr2);
                            room.listFire.Add(fire);
                        }
                        //空调控制器
                        if (roominfo.KTCount >= 2)
                        {//2个空调
                            if (!string.IsNullOrEmpty(roominfo.AirAddr))
                            {
                                iAir1 = Convert.ToInt32(roominfo.AirAddr);
                            }
                            if (!string.IsNullOrEmpty(roominfo.AirAddr2))
                            {
                                iAir2 = Convert.ToInt32(roominfo.AirAddr2);
                            }
                            if (iAir1 != 0)
                            {
                                AirFactoryType airType = AirFactoryType.大金;
                                if (roominfo.AirFactory != "大金")
                                {
                                    airType = AirFactoryType.其他;
                                }
                                clsAir air = new clsAir(iAir1, airType);
                                room.listAir.Add(air);
                            }
                            if (iAir2 != 0)
                            {
                                AirFactoryType airType = AirFactoryType.大金;
                                if (roominfo.AirFactory2 != "大金")
                                {
                                    airType = AirFactoryType.其他;
                                }
                                clsAir air = new clsAir(iAir2, airType);
                                room.listAir.Add(air);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(roominfo.AirAddr))
                            {
                                iAir1 = Convert.ToInt32(roominfo.AirAddr);
                            }
                            if (iAir1 != 0)
                            {
                                AirFactoryType airType = AirFactoryType.大金;
                                if (roominfo.AirFactory != "大金")
                                {
                                    airType = AirFactoryType.其他;
                                }
                                clsAir air = new clsAir(iAir1, airType);
                                room.listAir.Add(air);
                            }
                        }

                        //继电器板
                        if (!string.IsNullOrEmpty(roominfo.RelayAddr))
                        {
                            iRelay = Convert.ToInt32(roominfo.RelayAddr);
                        }
                        if (iRelay != 0)
                        {
                            room.roomRelay = new clsRelay(iRelay);
                        }
                        clsEnvirControl.listRoom.Add(room);
                    }
                    catch (Exception ex)
                    {
                        if (frmMain.blDebug)
                        {
                            MessageUtil.ShowTips(ex.Message);
                        }
                    }
                }
                RoomClass roomrelay = clsEnvirControl.listRoom.Find(p => p.roomRelay != null);
                foreach (RoomClass room in clsEnvirControl.listRoom)
                {
                    if (room.roomRelay == null)
                    {
                        room.roomRelay = roomrelay.roomRelay;
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void timerMain_Execute()
        {
            try
            {
                #region 报语音

                if (listVoice.Count > 0)
                {
                    TimeSpan span = DateTime.Now - timeLastVoice;
                    if (span.TotalSeconds > iVoiceLen)
                    {
                        string strVoice = listVoice[0];
                        timeLastVoice = DateTime.Now;
                        iVoiceLen     = (int)(strVoice.Length * 0.42);
                        bool blRet = serialVoice.SendVoice(strVoice);
                        if (blRet)
                        {
                            lock (listVoice)
                            {
                                listVoice.RemoveAt(0);
                            }
                        }
                    }
                }

                if (blVoiceOpenDoor)
                {
                    TimeSpan ts = DateTime.Now - timeLastVoice;// TotalSeconds
                    if (ts.TotalMinutes >= ciIntervalVoice)
                    {
                        string statu = SoundPlayerHelper.Status;
                        {
                            if (statu != VoiceState.播放.ToString())
                            {
                                string str = Application.StartupPath + "\\Voice\\欢迎.WAV";
                                SoundPlayerHelper.Play(str, false);
                                blVoiceOpenDoor = false;
                                timeLastVoice   = DateTime.Now;
                                blVoiceBorrOver = true;
                            }
                        }
                    }
                }

                #endregion

                if (infoOfSystem.usingBorrOver == DeviceUsing.启用)
                {
                    #region  开门后 报外借超时

                    if (blVoiceBorrOver)
                    {
                        bool blHasOver = false;//是否有外借超时
                        for (int iToos = 0; iToos < listTools.Count; iToos++)
                        {
                            if (listTools[iToos].ToolState == ToolsState.外借超时)
                            {
                                blHasOver = true;
                                break;
                            }
                        }
                        if (blHasOver)
                        {
                            TimeSpan ts = DateTime.Now - timeLastVoice;// TotalSeconds
                            if (ts.TotalMinutes >= ciIntervalVoice)
                            {
                                string statu = SoundPlayerHelper.Status;
                                {
                                    if (statu != VoiceState.播放.ToString())
                                    {
                                        string str = Application.StartupPath + "\\Voice\\工器具借出超时.WAV";
                                        SoundPlayerHelper.Play(str, false);
                                        timeLastVoice   = DateTime.Now;
                                        blVoiceBorrOver = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            blVoiceBorrOver = false;
                        }
                    }

                    #endregion

                    #region  判读借出超时 一天判断一次

                    TimeSpan tsOver = DateTime.Now - timeBorrOver;// TotalSeconds
                    if (tsOver.TotalDays >= 1)
                    {
                        timeBorrOver = DateTime.Now;

                        for (int iToos = 0; iToos < listTools.Count; iToos++)
                        {
                            if (listTools[iToos].ToolState == ToolsState.借出 || listTools[iToos].ToolState == ToolsState.外借超时)
                            {
                                DateTime timeBorr = listTools[iToos].TimeBorrRet;
                                TimeSpan ts       = DateTime.Now - timeBorr;
                                if (ts.TotalDays >= infoOfSystem.iOverDayBorr)
                                {
                                    string strId       = listTools[iToos].StrToolId;
                                    string strPeople   = listTools[iToos].StrPeopel;
                                    string strTimeBorr = listTools[iToos].TimeBorrRet.ToString("yyyy-MM-dd");
                                    ts = DateTime.Now - listTools[iToos].TimeBorrRet;
                                    string strDuration = clsCommon.CalculateTime(ts);
                                    string strType     = AlarmsType.外借超时.ToString();
                                    string strContent  = strTimeBorr + "借出,借出时长:" + strDuration;
                                    string strTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                    string strRfid     = listTools[iToos].StrRfidCode;

                                    DataRow dr = dtNewAlarm.NewRow();
                                    dr["Type"]    = strType;
                                    dr["Point"]   = strId;
                                    dr["Content"] = strContent;
                                    dr["People"]  = strPeople;
                                    dr["Time"]    = strTime;
                                    dtNewAlarm.Rows.Add(dr);
                                    //tb_AlarmEvent Type Point EventContent People Time
                                    string strSql = "insert into tb_AlarmEvent (Type,Point,EventContent,People,Time)" +
                                                    "values ('" + strType + "','" + strId + "','" + strContent + "','" + strPeople + "','" + strTime + "')";
                                    datalogic.SqlComNonQuery(strSql);

                                    strSql = "update tb_Tools set IsInStore='" + ToolsState.外借超时.ToString() + "' where RFIDCoding='" + strRfid + "' ";
                                    datalogic.SqlComNonQuery(strSql);

                                    lock (listTools)
                                    {
                                        listTools[iToos].ToolState = ToolsState.外借超时;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
        }
Ejemplo n.º 18
0
        public bool AddPower(string strIcNo)
        {
            bool blRet = false;

            #region  添加 权限 发送
            bSendDoor[1] = MainControl.bDoorAddrL;
            bSendDoor[2] = MainControl.bDoorAddrH;
            bSendDoor[3] = 0x07;
            bSendDoor[4] = 0x11;
            bSendDoor[5] = 0x00;
            bSendDoor[6] = 0x00;
            //IC卡号
            try
            {
                string strTemp = strIcNo.Substring(3, 5);
                int    iTemp   = Convert.ToInt32(strTemp);
                bSendDoor[7] = (byte)(iTemp & 0xff);
                bSendDoor[8] = (byte)((iTemp >> 8) & 0xff);
                strTemp      = strIcNo.Substring(0, 3);
                bSendDoor[9] = Convert.ToByte(strTemp);
            }
            catch (Exception ex)
            {
                MessageUtil.ShowTips(ex.Message);
            }
            //门号
            bSendDoor[10] = 0x01;
            //起始年月 2000年01月01
            bSendDoor[11] = 0x21;
            bSendDoor[12] = 0x00;
            //终止年月 2050年12月31
            bSendDoor[13] = 0x9F;
            bSendDoor[14] = 0x65;
            //时段
            bSendDoor[15] = 0x01;
            //密码  40 E2 01
            bSendDoor[16] = 0x40;
            bSendDoor[17] = 0xE2;
            bSendDoor[18] = 0x01;
            for (int i = 19; i < 31; i++)
            {
                bSendDoor[i] = 0;
            }
            int iCheckSun = 0;
            for (int i = 1; i < 31; i++)
            {
                iCheckSun += bSendDoor[i];
            }
            bSendDoor[31] = (byte)(iCheckSun & 0x00ff);
            bSendDoor[32] = (byte)(iCheckSun >> 8);

            //txt 发送
            string strContent = SerialPortUtil.ByteToHex(bSendDoor);
            txtLog.WriteTxt("Door.txt", "AddPower Send", strContent, false);

            byte[] bRece   = new byte[34];
            int    iLength = doorSerial.SendReceByte(bSendDoor, ref bRece, 500);

            //txt 接受
            if (iLength > 0)
            {
                strContent = SerialPortUtil.ByteToHex(bRece);
                txtLog.WriteTxt("Door.txt", "AddPower Rece", strContent, true);//01 01 01 0F 11 8C
            }

            #endregion

            #region  接受 判断

            if (iLength == 34)
            {
                iCheckSun = 0;
                for (int i = 1; i < 31; i++)
                {
                    iCheckSun += bRece[i];
                }
                byte bL = (byte)(iCheckSun & 0x00ff);
                byte bH = (byte)(iCheckSun >> 8);
                if (bRece[0] == 0x7E && bRece[1] == MainControl.bDoorAddrL && bRece[2] == MainControl.bDoorAddrH && bRece[3] == 0x07 && bRece[4] == 0x11 &&
                    bRece[31] == bL && bRece[32] == bH && bRece[33] == 0x0D)
                {
                    if (bRece[5] == 0x01)
                    {
                        blRet = true;
                    }
                    else
                    {
                        blRet = false;
                    }
                }
                else
                {
                    blRet = false;
                }
            }
            else
            {
                blRet = false;
            }
            #endregion

            return(blRet);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 判断时间 误差大于1分钟 校时
        /// </summary>
        /// <param name="ReceBuff"></param>
        private void JudgeDatetime(byte[] ReceBuff)
        {
            int iYear = ConvertBCDToInt(ReceBuff[5]);

            iYear += 2000;
            int      iMonth  = ConvertBCDToInt(ReceBuff[6]);
            int      iDay    = ConvertBCDToInt(ReceBuff[7]);
            int      iHour   = ConvertBCDToInt(ReceBuff[9]);
            int      iMinute = ConvertBCDToInt(ReceBuff[10]);
            int      iSecond = ConvertBCDToInt(ReceBuff[11]);
            DateTime dtRece  = new DateTime(iYear, iMonth, iDay, iHour, iMinute, iSecond);
            TimeSpan ts      = DateTime.Now - dtRece;//记录历史温湿度数据间隔

            if (ts.TotalSeconds >= 59 || ts.TotalSeconds <= -59)
            {
                DateTime dtNow = DateTime.Now;
                bSendDoor[1] = MainControl.bDoorAddrL;
                bSendDoor[2] = MainControl.bDoorAddrH;
                bSendDoor[3] = 0x8B;
                bSendDoor[4] = 0x10;
                int i = dtNow.Year;
                if (i >= 2000)
                {
                    i -= 2000;
                }
                bSendDoor[5] = ConvertBCD((byte)i);
                bSendDoor[6] = ConvertBCD((byte)(dtNow.Month));
                bSendDoor[7] = ConvertBCD((byte)(dtNow.Day));
                byte b = ConverWeekToInt(dtNow.DayOfWeek.ToString());
                bSendDoor[8]  = ConvertBCD(b);//周
                bSendDoor[9]  = ConvertBCD((byte)(dtNow.Hour));
                bSendDoor[10] = ConvertBCD((byte)(dtNow.Minute));
                bSendDoor[11] = ConvertBCD((byte)(dtNow.Second));

                int iCheckSun = 0;
                for (i = 1; i < 31; i++)
                {
                    iCheckSun += bSendDoor[i];
                }
                bSendDoor[31] = (byte)(iCheckSun & 0x00ff);
                bSendDoor[32] = (byte)(iCheckSun >> 8);

                //txt 发送
                string strContent = SerialPortUtil.ByteToHex(bSendDoor);
                txtLog.WriteTxt("Door.txt", "Time Send", strContent, false);

                byte[] bRece   = new byte[34];
                int    iLength = doorSerial.SendReceByte(bSendDoor, ref bRece, 500);

                //txt 接受
                if (iLength > 0)
                {
                    strContent = SerialPortUtil.ByteToHex(bRece);
                    txtLog.WriteTxt("Door.txt", "Time Rece", strContent, true);//01 01 01 0F 11 8C
                }

                if (iLength == 34)
                {
                    iCheckSun = 0;
                    for (i = 1; i < 31; i++)
                    {
                        iCheckSun += ReceBuff[i];
                    }
                    byte bL = (byte)(iCheckSun & 0x00ff);
                    byte bH = (byte)(iCheckSun >> 8);
                    if (ReceBuff[0] == 0x7E && bRece[1] == MainControl.bDoorAddrL && bRece[2] == MainControl.bDoorAddrH && ReceBuff[3] == 0x8B && ReceBuff[4] == 0x10 &&
                        ReceBuff[31] == bL && ReceBuff[32] == bH && ReceBuff[33] == 0x0D)
                    {
                        if (frmMain.blDebug)
                        {
                            string str = "校时成功";
                            MessageUtil.ShowTips(str);
                        }
                    }
                }
            }
        }