/// <summary> /// 开关门 信息显示 和记录 /// </summary> private void OnOffDoorInfoRecord(WgDoorType doorOrBox, string strDoorName, DoorsState state, string strOpenType, string strGroup, string strUser, DateTime timeOpen, string strArea) { EventType eventType = EventType.门禁; if (doorOrBox == WgDoorType.门禁) { if (state == DoorsState.开门) { commonCls.NewDoorInOut(state, strOpenType, strDoorName, strGroup, strUser, ""); } else if (state == DoorsState.关门) { TimeSpan timeSpan = DateTime.Now - timeOpen;//listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor; string strSpan = clsCommon.CalculateTime(timeSpan); commonCls.NewDoorInOut(state, "", "", "", "", strSpan); } } else if (doorOrBox == WgDoorType.工具柜) { eventType = EventType.工具柜; commonCls.BoxOnOffRecord(strArea, strDoorName, state, strOpenType, strGroup, strUser); } if (NewEventShowEvent != null) { NewEventShowEvent(new NewEventEventArgs(eventType, strDoorName, state.ToString(), strUser, strOpenType, DateTime.Now)); } }
/// <summary> /// 控制器 通信 异常 显示 和记录 /// </summary> private void NetErrInfoAndRecord(WgDoorType doorType, int iIndex, string strContent) { EventType eventType = EventType.门禁; if (doorType == WgDoorType.工具柜) { eventType = EventType.工具柜; } string strWgName = listWg[iIndex].StrNameOfWg;; //微耕控制器名称 //异常记录 commonCls.NewErrRecord(eventType.ToString(), strWgName, strContent, ""); if (NewAlarmShowEvent != null) { NewAlarmShowEvent(new NewEventEventArgs(eventType, strWgName, strContent, "", "", DateTime.Now)); } }
/// <summary> /// 定时读取 门禁控制器状态 /// </summary> private void updateControllerStatus() { try { if (watching != null) { int iCount = listWg.Count; for (int iIndex = 0; iIndex < iCount; iIndex++) { if (listWg[iIndex] != null) { // 门的类型 大门 或 工具柜门 WgDoorType doorOrBox = listWg[iIndex].DoorOrBoxDoor; #region 网络通信 状态 及校时 //网络连接错误 30S 后继续连接 bool blAgain = false; if (listWg[iIndex].StateOfNet == CommuniState.未连接) { TimeSpan span = DateTime.Now - listWg[iIndex].TimeErrNet; if (span.TotalSeconds > 30) { blAgain = true; lock (listWg) { listWg[iIndex].TimeErrNet = DateTime.Now; } } } if (listWg[iIndex].StateOfNet == CommuniState.已连接 || blAgain) { wgMjControllerRunInformation conRunInfo = null; int commStatus; int iSn = (int)listWg[iIndex].IntSn; commStatus = watching.CheckControllerCommStatus(iSn, ref conRunInfo); if (commStatus == -1) { if (listWg[iIndex].StateOfNet != CommuniState.未连接) { lock (listWg) { listWg[iIndex].StateOfNet = CommuniState.未连接; listWg[iIndex].TimeErrNet = DateTime.Now; } //通信 异常信息 及记录 NetErrInfoAndRecord(doorOrBox, iIndex, ErrorContent.通信异常.ToString()); #region //string strErrType = DoorOrBoxDoor.ToString(); //string strWgName = "";//微耕控制器名称 //if (DoorOrBoxDoor == EventType.工具柜) //{ // strWgName = listWg[iIndex].StrNameOfWg; //} //string strContent = ErrorContent.通信异常.ToString(); ////异常记录 //commonCls.NewErrRecord(strErrType, strWgName, strContent, ""); //if (NewAlarmShowEvent != null) //{ // NewAlarmShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strWgName, strContent, "", "", DateTime.Now)); //} #endregion } } else if (commStatus == 1) { if (listWg[iIndex].StateOfNet != CommuniState.已连接) { lock (listWg) { listWg[iIndex].StateOfNet = CommuniState.已连接; } //通信恢复 正常 记录及主界面显示 NetErrInfoAndRecord(doorOrBox, iIndex, ErrorContent.通信恢复正常.ToString()); #region 通信恢复 正常 记录及主界面显示 //string strErrType = DoorOrBoxDoor.ToString(); //string strWgName = "";//微耕控制器名称 //if (DoorOrBoxDoor == EventType.工具柜) //{ // strWgName = listWg[iIndex].StrNameOfWg; //} //string strContent = ErrorContent.通信恢复正常.ToString(); //commonCls.NewErrRecord(strErrType, strWgName, strContent, ""); //if (NewAlarmShowEvent != null) //{ // NewAlarmShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strWgName, strContent, "", "", DateTime.Now)); //} #endregion #region 校时 DateTime time = conRunInfo.dtNow; TimeSpan ts = DateTime.Now - time;//记录历史温湿度数据间隔 if (ts.TotalSeconds >= 59 || ts.TotalSeconds <= -59) { wgController.AdjustTimeIP(DateTime.Now); } #endregion } } } #endregion #region 门状态 if (listWg[iIndex].StateOfNet == CommuniState.已连接) { if (listWg[iIndex].listDoor != null) { string strArea = listWg[iIndex].StrArea; int iCountDoor = listWg[iIndex].listDoor.Count; for (int iIndexDoor = 0; iIndexDoor < iCountDoor; iIndexDoor++) { //门名称 string strDoorName = ""; if (listWg[iIndex].listDoor[iIndexDoor].StrDoorName != null) { strDoorName = listWg[iIndex].listDoor[iIndexDoor].StrDoorName; } int iDoorIndex = listWg[iIndex].listDoor[iIndexDoor].IntDoorIndex; DoorsState getDoorState = listWg[iIndex].GetDoorState(iDoorIndex); if (listWg[iIndex].listDoor[iIndexDoor].StateOfDoor != getDoorState) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].StateOfDoor = getDoorState; } if (getDoorState == DoorsState.开门) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor = DateTime.Now; } if (listWg[iIndex].listDoor[iIndexDoor].IsOfRfid == DeviceUsing.启用) { clsRfidRead.strOpenUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; } //开门 string strOpenType = listWg[iIndex].listDoor[iIndexDoor].StrOpenType; string strGroup = listWg[iIndex].listDoor[iIndexDoor].StrGroup; string strUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; OnOffDoorInfoRecord(doorOrBox, strDoorName, DoorsState.开门, strOpenType, strGroup, strUser, DateTime.Now, strArea); #region //string strOpenType = listWg[iIndex].listDoor[iIndexDoor].StrOpenType; //string strGroup = listWg[iIndex].listDoor[iIndexDoor].StrGroup; //string strUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; //if (DoorOrBoxDoor == EventType.门禁) //{ // commonCls.NewDoorInOut(DoorsState.开门, strOpenType, strDoorName, strGroup, strUser, ""); //} //else if (DoorOrBoxDoor == EventType.工具柜) //{ //} //if (NewEventShowEvent != null) //{ // NewEventShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strDoorName, DoorsState.开门.ToString(), strUser, strOpenType, DateTime.Now)); //} #endregion } else if (getDoorState == DoorsState.关门) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].ClearOpenInfo(); } if (listWg[iIndex].listDoor[iIndexDoor].IsOfRfid == DeviceUsing.启用) { clsRfidRead.strOpenUser = ""; } //关门 DateTime timeOpen = listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor; OnOffDoorInfoRecord(doorOrBox, strDoorName, DoorsState.关门, "", "", "", timeOpen, strArea); #region //TimeSpan timeSpan = DateTime.Now - listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor; //string strSpan = clsCommon.CalculateTime(timeSpan); //if (DoorOrBoxDoor == EventType.门禁) //{ // commonCls.NewDoorInOut(DoorsState.关门, "", "", "", "", strSpan); //} //else if (DoorOrBoxDoor == EventType.工具柜) //{ //} //if (NewEventShowEvent != null) //{ // NewEventShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strDoorName, DoorsState.开门.ToString(), "", "", DateTime.Now)); //} #endregion } } } } } #endregion } } } } catch (Exception ex) { if (frmMain.blDebug) { MessageUtil.ShowTips(ex.Message); } } }