public static DataFrame convertToFrame(byte[] receiveBytes) { DataFrame dataFrame = new DataFrame(); dataFrame.sym = new byte[2]; dataFrame.sym[0] = receiveBytes[0]; dataFrame.sym[1] = receiveBytes[1]; dataFrame.desAddr = receiveBytes[2]; dataFrame.comFrameLen = receiveBytes[3]; dataFrame.srcAddr = receiveBytes[4]; dataFrame.protocol = receiveBytes[5]; dataFrame.seq = receiveBytes[6]; int dataFrameLength = receiveBytes.Length - 8; dataFrame.frameData = new byte[dataFrameLength]; for(int i = 0;i<dataFrameLength;i++) { dataFrame.frameData[i] = receiveBytes[7+i]; } dataFrame.checkSum = receiveBytes[receiveBytes.Length - 1]; return dataFrame; }
public int InsertMorningCheckInfo(DataFrame dataFrame) { int rowsAffected = 0; using(MorningCheckInfoDataAccess morningCheckInfoDataAccess = new MorningCheckInfoDataAccess()) { rowsAffected = morningCheckInfoDataAccess.InsertMorningCheckInfo(dataFrame); } return rowsAffected; }
private void SynchDate() { try { simpleButton_Date.Enabled = false; DataFrame controlFrame = new DataFrame(); controlFrame.sym = new byte[]{(byte)'@',(byte)'@'}; controlFrame.desAddr = Convert.ToByte(gridView5.GetDataRow(gridView5.GetSelectedRows()[0])["machine_address"]); controlFrame.comFrameLen = 15; controlFrame.srcAddr = 0; controlFrame.protocol = CPTT.SystemFramework.Util.TIME_SYNCH_TOKEN; controlFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; controlFrame.frameData = new byte[7]; controlFrame.frameData[0] = Convert.ToByte(DateTime.Now.Year%100); controlFrame.frameData[1] = Convert.ToByte((byte)DateTime.Now.Month); controlFrame.frameData[2] = Convert.ToByte((byte)DateTime.Now.Day); controlFrame.frameData[3] = Convert.ToByte((byte)(DateTime.Now.DayOfWeek+1)); controlFrame.frameData[4] = Convert.ToByte((byte)DateTime.Now.Hour); controlFrame.frameData[5] = Convert.ToByte((byte)DateTime.Now.Minute); controlFrame.frameData[6] = Convert.ToByte((byte)DateTime.Now.Second); controlFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(controlFrame.comFrameLen,controlFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } // Login.handleComClass.WriteSerialCmd(15,new byte[]{(byte)'@',(byte)'@',1,15,0,4,0, // 06,10,5,1,22,22,22,236}); //Monitor.Exit(Login.handleComClass); timer_SychnDate.Enabled = true; LoginForm.synchDateThread.Suspend(); // LoginForm.ResumeThread(); timer_SychnDate.Enabled = false; Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); msgForm.Close(); if ( isTimeSynSucceed ) MessageBox.Show("时间同步成功.","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); simpleButton_Date.Enabled = true; LoginForm.synchDateThread.Abort(); } catch { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); isTimeSynSucceed = false; msgForm.Close(); timer_SychnDate.Enabled = false; } }
private void ValidateCard() { simpleButton_BatchSendCheck.Enabled = false; DataSet machineAddrList = new MachineSystem().GetMachineAddrList(); DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.desAddr = 0; sendCardFrame.comFrameLen = 12; sendCardFrame.frameData = new byte[4]; sendCardFrame.protocol = CPTT.SystemFramework.Util.VALIDATE_CARD_TOKEN; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; sendCardFrame.desAddr = Convert.ToByte(machineAddrList.Tables[0].Rows[0]["machine_address"]); int stuCardNumber = 0; unchecked { stuCardNumber = (int)(Convert.ToInt64(textEdit3.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,-2); sendCardFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } Timer_ValidateCardOverTime.Enabled = true; LoginForm.validateCardThread.Suspend(); validateCardTryTime = 0; simpleButton_BatchSendCheck.Enabled = true; textEdit3.SelectAll(); Login.COM_PORT_IS_BUSY = false; // LoginForm.ResumeThread(); LoginForm.ResumeQueryThread(); LoginForm.validateCardThread.Abort(); }
private void LeaveSchool() { dataNavigator_CardLogout.Buttons.CancelEdit.Enabled = false; int stuNumber; if(leaveSearchStu) { stuNumber = Convert.ToInt32(gridView2.GetDataRow(gridView2.GetSelectedRows()[0])["info_stuNumber"]); } else { stuNumber = Convert.ToInt32(gridView2.GetDataRow(gridView2.GetSelectedRows()[0])["T_Number"]); } DataSet machineAddrList = new MachineSystem().GetMachineAddrList(); DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.desAddr = 0; sendCardFrame.comFrameLen = 10; sendCardFrame.frameData = new byte[2]; sendCardFrame.protocol = CPTT.SystemFramework.Util.LEAVE_SCHOOL_TOKEN; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; sendCardFrame.frameData[0] = (byte)(stuNumber % 100); int tmp = stuNumber / 100; int stuClassNum = tmp / 10; stuClassNum <<= 4; stuClassNum += tmp % 10; sendCardFrame.frameData[1] = (byte)stuClassNum; foreach(DataRow machineAddr in machineAddrList.Tables[0].Rows) { sendCardFrame.desAddr = Convert.ToByte(machineAddr["machine_address"]); sendCardFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送退学帧 } finally { Monitor.Exit(Login.syncRoot); } Timer_LeaveTime.Enabled = true; LoginForm.leaveCardThread.Suspend(); } if ( isLeaveSchoolSucceed ) { leaveCardTryTime = 0; dataNavigator_CardLogout.Buttons.CancelEdit.Enabled = true; Login.COM_PORT_IS_BUSY = false; CardInfoSystem cardInfoSystem = new CardInfoSystem(); string stuID = string.Empty; if(leaveSearchStu) { stuID = (gridView2.GetDataRow(gridView2.GetSelectedRows()[0])["info_stuID"]).ToString(); if(cardInfoSystem.StuLeaveSchool(stuID)>0) { gridView2.DeleteRow(gridView2.GetSelectedRows()[0]); } new CardInfoSystem().DeleteCardInfo(true,stuID); } else { stuID = (gridView2.GetDataRow(gridView2.GetSelectedRows()[0])["T_ID"]).ToString(); if(cardInfoSystem.TeaLeaveSchool(stuID)>0) { gridView2.DeleteRow(gridView2.GetSelectedRows()[0]); } new CardInfoSystem().DeleteCardInfo(false,stuID); } // LoginForm.ResumeThread(); LoginForm.ResumeQueryThread(); MessageBox.Show("操作成功.","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); LoginForm.leaveCardThread.Abort(); } }
private void LogoutCard(object state) { var context = state as SynchronizationContext; try { context.Send((_) => { dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = false; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = false; }, null); string stuID = string.Empty; int stuNumber; if(searchStu) { stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["info_stuID"]).ToString(); stuNumber = Convert.ToInt32(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["info_stuNumber"]); } else { stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_ID"]).ToString(); stuNumber = Convert.ToInt32(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_Number"]); } DataSet machineAddrList = new MachineSystem().GetMachineAddrList(); DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.desAddr = 0; sendCardFrame.comFrameLen = 30; sendCardFrame.frameData = new byte[22]; sendCardFrame.protocol = CPTT.SystemFramework.Util.SEND_CARD_SUCCESS_TOKEN; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; sendCardFrame.frameData[0] = (byte)(stuNumber % 100); int tmp = stuNumber / 100; int stuClassNum = tmp / 10; stuClassNum <<= 4; stuClassNum += tmp % 10; sendCardFrame.frameData[1] = (byte)stuClassNum; int stuCardNumber = 0; ArrayList cardLogout = new ArrayList(); if(!(SendCard1Number.Text.Trim().Equals(string.Empty))) { if(removeCard1.Checked) { CPTT.SystemFramework.Util.FillCard(sendCardFrame,0,0); cardLogout.Add(SendCard1Number.Text.Trim()); } else { unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard1Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,0); } } if(!(SendCard2Number.Text.Trim().Equals(string.Empty))) { if(removeCard2.Checked) { CPTT.SystemFramework.Util.FillCard(sendCardFrame,0,4); cardLogout.Add(SendCard2Number.Text.Trim()); } else { unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard2Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,4); } } if(!(SendCard3Number.Text.Trim().Equals(string.Empty))) { if(removeCard3.Checked) { CPTT.SystemFramework.Util.FillCard(sendCardFrame,0, 8); cardLogout.Add(SendCard3Number.Text.Trim()); } else { unchecked { stuCardNumber =(int)(Convert.ToInt64(SendCard3Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,8); } } if(!(SendCard4Number.Text.Trim().Equals(string.Empty))) { if(removeCard4.Checked) { CPTT.SystemFramework.Util.FillCard(sendCardFrame,0,12); cardLogout.Add(SendCard4Number.Text.Trim()); } else { unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard4Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,12); } } if(!(SendCard5Number.Text.Trim().Equals(string.Empty))) { if(removeCard5.Checked) { CPTT.SystemFramework.Util.FillCard(sendCardFrame,0,16); cardLogout.Add(SendCard5Number.Text.Trim()); } else { unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard5Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,16); } } foreach(DataRow machineAddr in machineAddrList.Tables[0].Rows) { cardTrace = Convert.ToInt32(machineAddr["machine_address"]); sendCardFrame.desAddr = Convert.ToByte(machineAddr["machine_address"]); sendCardFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } Timer_SendCardOverTime.Enabled = true; LoginForm.sendCardThread.Suspend(); } Thread.Sleep(300); Login.COM_PORT_IS_BUSY = false; if ( isCardLogOutSucceed ) { if (this.InvokeRequired) { this.Invoke(new logoutCardContextSyncDelegate(LogoutCardContextSync), new object[]{cardLogout, stuID}); } else { LogoutCardContextSync(cardLogout, stuID); } // LoginForm.ResumeThread(); // LoginForm.ResumeQueryThread(); // // dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; // dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; MessageBox.Show("销卡成功!!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); try { LoginForm.sendCardThread.Abort(); } catch { Thread.ResetAbort(); } } } catch(Exception ex) { CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); MessageBox.Show("销卡卡中发生错误,出现的原因可能是暂时无法连接远程设备,请重试!"); } finally { if(this.InvokeRequired) { this.Invoke(new enableCardButtonContextSyncDelegate(EnableCardButtonContextSyncDelegate)); } else { EnableCardButtonContextSyncDelegate(); } Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); if ( LoginForm.sendCardThread.IsAlive ) LoginForm.sendCardThread.Abort(); } }
//发卡 private void SendCard(object state) { var context = state as SynchronizationContext; try { FileStream fileStream = null; StreamReader streamReader = null; DataSet machineAddrList = new MachineSystem().GetMachineAddrList(); DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.desAddr = 0; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; if(!isBatchSendCard)//普通发卡 { sendCardFrame.protocol = CPTT.SystemFramework.Util.SEND_CARD_TOKEN; sendCardFrame.comFrameLen = 30; sendCardFrame.frameData = new byte[22]; string stuID = string.Empty; int stuNumber; if(searchStu) { stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["info_stuID"]).ToString(); stuNumber = Convert.ToInt32(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["info_stuNumber"]); } else { stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_ID"]).ToString(); stuNumber = Convert.ToInt32(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_Number"]); } sendCardFrame.frameData[0] = (byte)(stuNumber % 100); int tmp = stuNumber / 100; int stuClassNum = tmp / 10; stuClassNum <<= 4; stuClassNum += tmp % 10; sendCardFrame.frameData[1] = (byte)stuClassNum; int stuCardNumber = 0; if(!(SendCard1Number.Text.Trim().Equals(string.Empty))) { #if CardValidCheck try { bool findCard = false; fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = Convert.ToInt64(SendCard1Number.Text.Trim()) + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); MessageBox.Show("存在非法卡号,发卡失败!"); dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; return; } finally { fileStream.Close(); streamReader.Close(); } #endif unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard1Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,0); } if(!(SendCard2Number.Text.Trim().Equals(string.Empty))) { #if CardValidCheck try { bool findCard = false; fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = Convert.ToInt64(SendCard2Number.Text.Trim()) + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch(Exception ex) { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); MessageBox.Show("存在非法卡号,发卡失败!"); dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; return; } finally { fileStream.Close(); streamReader.Close(); } #endif unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard2Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,4); } if(!(SendCard3Number.Text.Trim().Equals(string.Empty))) { #if CardValidCheck try { bool findCard = false; fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = Convert.ToInt64(SendCard3Number.Text.Trim()) + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch(Exception ex) { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); MessageBox.Show("存在非法卡号,发卡失败!"); dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; return; } finally { fileStream.Close(); streamReader.Close(); } #endif unchecked { stuCardNumber =(int)(Convert.ToInt64(SendCard3Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,8); } if(!(SendCard4Number.Text.Trim().Equals(string.Empty))) { #if CardValidCheck try { bool findCard = false; fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = Convert.ToInt64(SendCard4Number.Text.Trim()) + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch(Exception ex) { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); MessageBox.Show("存在非法卡号,发卡失败!"); dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; return; } finally { fileStream.Close(); streamReader.Close(); } #endif unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard4Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,12); } if(!(SendCard5Number.Text.Trim().Equals(string.Empty))) { #if CardValidCheck try { bool findCard = false; fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = Convert.ToInt64(SendCard5Number.Text.Trim()) + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch(Exception ex) { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); MessageBox.Show("存在非法卡号,发卡失败!"); dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; return; } finally { fileStream.Close(); streamReader.Close(); } #endif unchecked { stuCardNumber = (int)(Convert.ToInt64(SendCard5Number.Text.Trim())); } CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,16); } foreach(DataRow machineAddr in machineAddrList.Tables[0].Rows) { cardTrace = Convert.ToInt32(machineAddr["machine_address"]); sendCardFrame.desAddr = Convert.ToByte(machineAddr["machine_address"]); sendCardFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } //Monitor.Exit(Login.handleComClass); Timer_SendCardOverTime.Enabled = true; LoginForm.sendCardThread.Suspend(); } Thread.Sleep(300); if (this.InvokeRequired) { this.Invoke(new getCardDetailsContextSyncDelegate(GetCardDetailsContextSyncDelegate), new object[]{stuID}); } else { GetCardDetailsContextSyncDelegate(stuID); } // if(searchStu) // { // cardDetails = new CardInfoSystem().GetStuCardByID(stuID); // } // else // { // cardDetails = new CardInfoSystem().GetTeaCardByID(stuID); // } // DisplayCardInfo(cardDetails); // // dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; // dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; } else//批量发卡 { try { sendCardFrame.protocol = CPTT.SystemFramework.Util.BATCH_SEND_CARD_TOKEN; sendCardFrame.comFrameLen = 15; sendCardFrame.frameData = new byte[7]; string stuID = string.Empty; int stuNumber = 0; while(gridView3.RowCount>0) { isCardSendSucceed = true; if(batchSearchStu) { stuID = (gridView3.GetDataRow(0)["info_stuID"]).ToString(); stuNumber = Convert.ToInt32(gridView3.GetDataRow(0)["info_stuNumber"]); } else { stuID = (gridView3.GetDataRow(0)["T_ID"]).ToString(); stuNumber = Convert.ToInt32(gridView3.GetDataRow(0)["T_Number"]); } sendCardFrame.frameData[0] = (byte)(stuNumber % 100); int tmp = stuNumber / 100; int stuClassNum = tmp / 10; stuClassNum <<= 4; stuClassNum += tmp % 10; sendCardFrame.frameData[1] = (byte)stuClassNum; #if CardValidCheck3 try { bool findCard = false; Int64 cardNumber = 0; if(batchSearchStu) { cardNumber = Convert.ToInt64(gridView3.GetDataRow(0)["info_stuCardNumber"]); } else { cardNumber = Convert.ToInt64(gridView3.GetDataRow(0)["info_teaCardNumber"]); } fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"encry.bin",FileMode.OpenOrCreate,FileAccess.Read); streamReader = new StreamReader(fileStream); long dataEncrypt = cardNumber + myBirthday; StringBuilder enryString = new StringBuilder(dataEncrypt.ToString()); for ( int i=0; i<enryString.Length; i++ ) { char newChar = (char)(((int)enryString[i])+i*(i-1)); enryString[i] = newChar; } while ( true ) { string readStr = streamReader.ReadLine(); if ( readStr != null ) { if ( readStr.Equals(enryString.ToString()) ) { findCard = true; break; } } else { if ( !findCard ) { Timer_SendCardOverTime.Enabled = false; LoginForm.sendCardThread.Abort(); throw new Exception(); } else break; } } } catch(Exception ex) { Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); simpleButton2.Enabled = true; MessageBox.Show("存在非法卡号,发卡失败!"); return; } finally { fileStream.Close(); streamReader.Close(); } #endif int stuCardNumber = 0; unchecked { if(batchSearchStu) { stuCardNumber = (int)(Convert.ToInt64(gridView3.GetDataRow(0)["info_stuCardNumber"])); } else { stuCardNumber = (int)(Convert.ToInt64(gridView3.GetDataRow(0)["info_teaCardNumber"])); } } foreach(DataRow machineAddr in machineAddrList.Tables[0].Rows) { cardTrace = Convert.ToInt32(machineAddr["machine_address"]); sendCardFrame.desAddr =Convert.ToByte(machineAddr["machine_address"]); CPTT.SystemFramework.Util.FillCard(sendCardFrame,stuCardNumber,0); if(batchSearchStu) { sendCardFrame.frameData[6] = Convert.ToByte(gridView3.GetDataRow(0)["info_stuCardSeq"]); } else { sendCardFrame.frameData[6] = Convert.ToByte(gridView3.GetDataRow(0)["info_teaCardSeq"]); } sendCardFrame.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } Timer_SendCardOverTime.Enabled = true; LoginForm.sendCardThread.Suspend(); } if ( isCardSendSucceed ) { CardInfoSystem cardInfoSystem = new CardInfoSystem(); if(batchSearchStu) { cardInfoSystem.UpdateCardState(gridView3.GetDataRow(0)["info_stuCardNumber"].ToString()); } else { cardInfoSystem.UpdateTeaCardState(gridView3.GetDataRow(0)["info_teaCardNumber"].ToString()); } context.Send((_) => gridView3.DeleteRow(0), null); } } context.Send((_) => simpleButton2.Enabled = true, null); } catch(ThreadAbortException taex) { if (taex.ExceptionState == null || taex.ExceptionState.GetType() != typeof(bool)) { if ((LoginForm.sendCardThread.ThreadState & ThreadState.Aborted) == ThreadState.Aborted || (LoginForm.sendCardThread.ThreadState & ThreadState.AbortRequested) == ThreadState.AbortRequested || (LoginForm.sendCardThread.ThreadState & ThreadState.Stopped) == ThreadState.Stopped || (LoginForm.sendCardThread.ThreadState & ThreadState.StopRequested) == ThreadState.StopRequested) { LoginForm.sendCardThread = new Thread(SendCard); LoginForm.sendCardThread.Start(SynchronizationContext.Current); } Thread.ResetAbort(); } return; } } Login.COM_PORT_IS_BUSY = false; reTryTime = 0; // LoginForm.ResumeThread(); LoginForm.ResumeQueryThread(); if ( isCardSendSucceed ) MessageBox.Show("发卡成功!!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); try { LoginForm.sendCardThread.Abort(); } catch { Thread.ResetAbort(); } } catch(Exception ex) { CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); MessageBox.Show("发卡中断,点击发卡重试!"); } finally { if (context != null) { context.Send((_) => { dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true; dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true; }, null); } Login.COM_PORT_IS_BUSY = false; LoginForm.ResumeQueryThread(); if (LoginForm.sendCardThread.IsAlive) { try { LoginForm.sendCardThread.Abort(); } catch (Exception) { } } } }
private void DoSendCustomButton(int stateID, string stateName) { foreach(DataRow row in new MachineSystem().GetMachineAddrList().Tables[0].Rows) { DataFrame data = new DataFrame(); data.sym = new byte[]{(byte)'@',(byte)'@'}; data.desAddr = Convert.ToByte(row[0]); data.srcAddr = 0; data.protocol = CPTT.SystemFramework.Util.SEND_CUSTOMBUTTON_TOKEN; data.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; byte[] nameBytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(stateName); data.comFrameLen = Convert.ToByte(11 + nameBytes.Length); data.frameData = new byte[3 + nameBytes.Length]; data.frameData[0] = (byte)stateID; data.frameData[1] = (byte)0x10; for(int i = 0; i < nameBytes.Length; i++) data.frameData[2 + i] = nameBytes[i]; data.frameData[data.frameData.Length - 1] = Convert.ToByte(nameBytes.Length); data.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(data.comFrameLen, data.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } syncCustomButtonTimer.Enabled = true; login.syncCustomButtonThread.Suspend(); } }
public int InsertMorningCheckInfo(DataFrame dataFrame) { return new MorningCheckInfoRules().InsertMorningCheckInfo(dataFrame); }
private void SendClassName() { if (currentMachineAddr == 0) { setVolumeFailed = true; login.setMachineVolumn.Resume(); MessageBox.Show(string.Format("对门口机{0}设定容量失败!", currentMachineAddr)); return; } DataFrame data = new DataFrame(); data.sym = new byte[]{(byte)'@',(byte)'@'}; data.desAddr = currentMachineAddr; data.srcAddr = 0; data.protocol = CPTT.SystemFramework.Util.SEND_CLASSNAME_TOKEN; data.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; ArrayList nameList = new ArrayList(); ArrayList numberList = new ArrayList(); int totalNameLength = 0; int classNumberTemp = 0; for(int i = 0;i < gridView2.DataRowCount;i ++) { int gradeNumber = Convert.ToInt32(gridView2.GetDataRow(i)["info_gradeNumber"]); if (currentGradeNumber != gradeNumber) { if (currentGradeNumber < gradeNumber) { currentGradeNumber = gradeNumber; break; } } else { byte[] nameBytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(gridView2.GetDataRow(i)["info_className"].ToString()); nameList.Add(nameBytes); totalNameLength += nameBytes.Length; classNumberTemp = Convert.ToInt32(gridView2.GetDataRow(i)["machine_address"]); int classNum = classNumberTemp; classNum = classNum/10*16 + classNum%10; numberList.Add(classNum); } if (i == gridView2.DataRowCount - 1) isLast = true; } if (nameList.Count != numberList.Count) { setVolumeFailed = true; login.setMachineVolumn.Resume(); MessageBox.Show(string.Format("对门口机{0}设定容量失败!", currentMachineAddr)); return; } //numberList.Count * 2 其中包括一个字节描述namebytes的长度 //1个字节描述年级 data.comFrameLen = Convert.ToByte(8 + 1 + numberList.Count * 2 + totalNameLength); data.frameData = new byte[1 + numberList.Count * 2 + totalNameLength]; DataSet gradeInfo = new GradeSystem().GetGradeInfo(classNumberTemp / 10); int gradeNumberMapping = 5; if (gradeInfo.Tables.Count > 0) { string gradeName = gradeInfo.Tables[0].Rows[0]["info_gradeName"].ToString(); switch(gradeName) { case "托班":gradeNumberMapping = 1; break; case "小班":gradeNumberMapping = 2; break; case "中班":gradeNumberMapping = 3; break; case "大班":gradeNumberMapping = 4; break; default:gradeNumberMapping = 5; break; } } data.frameData[0] = Convert.ToByte(gradeNumberMapping); int cursor = 1; for(int i = 0; i < nameList.Count; i++) { data.frameData[cursor++] = Convert.ToByte(numberList[i]); byte[] nameBytes = (byte[])nameList[i]; data.frameData[cursor++] = Convert.ToByte(nameBytes.Length); for(int j = 0; j < nameBytes.Length; j++) { data.frameData[cursor++] = nameBytes[j]; } } data.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(data.comFrameLen, data.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } }
private void SendHardWareAuthenticationToken() { while(true) { if ( _alUnAuthenticatedHardWare != null ) { if ( _alUnAuthenticatedHardWare.Count > 0 ) { for ( int i=0; i<_alUnAuthenticatedHardWare.Count; i++ ) { DataFrame authenticationToken = new DataFrame(); authenticationToken.sym = new byte[]{(byte)'@',(byte)'@'}; authenticationToken.srcAddr = 0; authenticationToken.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; authenticationToken.protocol = CPTT.SystemFramework.Util.HARDWARE_AUTHENTICATION; authenticationToken.comFrameLen = (byte)9; authenticationToken.frameData = new byte[1]; // need modify if ( _registerDays != -1 ) { if ( _registerDays >= 40 ) authenticationToken.frameData[0] = Convert.ToByte(254); else authenticationToken.frameData[0] = Convert.ToByte(_registerDays); } else continue; authenticationToken.desAddr = Convert.ToByte(_alUnAuthenticatedHardWare[i].ToString()); authenticationToken.computeCheckSum(); //Monitor.Enter(handleComClass); Monitor.Enter(syncRoot); try { handleComClass.WriteSerialCmd(authenticationToken.comFrameLen,authenticationToken.frameToBytes());//发送问询帧 } finally { Monitor.Exit(syncRoot); } Thread.Sleep(SystemFramework.Util.QUERY_AUTHENTICATION_INTERVAL); } } else Thread.Sleep(CPTT.SystemFramework.Util.QUERY_NULL_INTERVAL); } else { MessageBox.Show("数据库连接失败!"); break; } } }
private void SendUserName(byte destAddr, byte stuNumber, byte stuClassNum, string stuName, int month, int day) { DataFrame data = new DataFrame(); data.sym = new byte[]{(byte)'@',(byte)'@'}; data.desAddr = destAddr; data.srcAddr = 0; data.protocol = CPTT.SystemFramework.Util.SEND_USERNAME_TOKEN; data.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; byte[] nameBytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(stuName); data.comFrameLen = Convert.ToByte(13 + nameBytes.Length); data.frameData = new byte[5 + nameBytes.Length]; data.frameData[0] = stuNumber; data.frameData[1] = stuClassNum; for(int i = 0; i < nameBytes.Length; i++) data.frameData[2 + i] = nameBytes[i]; data.frameData[data.frameData.Length - 3] = Convert.ToByte(month); data.frameData[data.frameData.Length - 2] = Convert.ToByte(day); data.frameData[data.frameData.Length - 1] = Convert.ToByte(nameBytes.Length + 2); data.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(data.comFrameLen, data.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } Timer_SendCardOverTime.Enabled = true; LoginForm.sendCardThread.Suspend(); }
//新协议 // public int InsertMorningCheckInfo(DataFrame dataFrame) // { // int rowsAffected = 0; // // try // { // if(dataFrame.frameData.Length == 13)//确认为晨检应答帧 // { // Int16 classNumber = (Int16)(((dataFrame.frameData[1]/16)*10 + (dataFrame.frameData[1]%16))*100 // + dataFrame.frameData[0]);//计算学号 // // int year = dataFrame.frameData[2] == 0 ? DateTime.Now.Year : 2000 + (Int16)dataFrame.frameData[2]; // int month = dataFrame.frameData[3] == 0 ? DateTime.Now.Month : dataFrame.frameData[3]; // int day = dataFrame.frameData[4] == 0 ? DateTime.Now.Day :dataFrame.frameData[4]; // int hour = dataFrame.frameData[5] == 0 ? DateTime.Now.Hour : dataFrame.frameData[5]; // int minute = dataFrame.frameData[6] == 0 ? DateTime.Now.Minute : dataFrame.frameData[6]; // int second = dataFrame.frameData[7] == 0 ? DateTime.Now.Second : dataFrame.frameData[7]; // // DateTime checkTime = new DateTime(year, month, day, hour, minute, second); // // bool isManual = false; // // if(dataFrame.frameData[9] == 6) // { // isManual = true; // } // // DBCommandWrapper dbcommandWrapper = db.GetStoredProcCommandWrapper("FillCheckInfo"); // // dbcommandWrapper.AddInParameter("@getStuNumber",DbType.Int16,classNumber); // dbcommandWrapper.AddInParameter("@getTime",DbType.DateTime,checkTime); // dbcommandWrapper.AddInParameter("@getState",DbType.Int16,Convert.ToInt16(dataFrame.frameData[11])); // dbcommandWrapper.AddInParameter("@getCardSeq",DbType.Int16,Convert.ToInt16(dataFrame.frameData[9])); // dbcommandWrapper.AddInParameter("@fromMachine",DbType.Int16,Convert.ToInt16(dataFrame.srcAddr)); // dbcommandWrapper.AddInParameter("@isNightCheck",DbType.Boolean,Convert.ToBoolean(dataFrame.frameData[8])); // dbcommandWrapper.AddInParameter("@isManual",DbType.Boolean,isManual); // dbcommandWrapper.AddOutParameter("@rowsAffected",DbType.Int32,4); // // db.ExecuteNonQuery(dbcommandWrapper); // // rowsAffected = Convert.ToInt32(dbcommandWrapper.GetParameterValue("@rowsAffected")); // } // else // { // throw new Exception("通讯帧出错"); // } // } // catch(Exception ex) // { // throw ex; // } // // return rowsAffected; // } public int InsertMorningCheckInfo(DataFrame dataFrame) { int rowsAffected = 0; try { if(dataFrame.frameData.Length == 11)//确认为晨检应答帧 { Int16 classNumber = (Int16)(((dataFrame.frameData[1]/16)*10 + (dataFrame.frameData[1]%16))*100 + dataFrame.frameData[0]);//计算学号 DateTime checkTime = new DateTime(DateTime.Now.Year,DateTime.Now.Month, DateTime.Now.Day,dataFrame.frameData[2],dataFrame.frameData[3], dataFrame.frameData[4]); bool isManual = false; if(dataFrame.frameData[6]==6) { isManual = true; } CPTT.SystemFramework.Util.WriteLog(string.Format("number:{0}", classNumber),CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); DBCommandWrapper dbcommandWrapper = db.GetStoredProcCommandWrapper("FillCheckInfo"); dbcommandWrapper.AddInParameter("@getStuNumber",DbType.Int16,classNumber); dbcommandWrapper.AddInParameter("@getTime",DbType.DateTime,checkTime); dbcommandWrapper.AddInParameter("@getState",DbType.Int16,Convert.ToInt16(dataFrame.frameData[8])); dbcommandWrapper.AddInParameter("@getCardSeq",DbType.Int16,Convert.ToInt16(dataFrame.frameData[6])); dbcommandWrapper.AddInParameter("@fromMachine",DbType.Int16,Convert.ToInt16(dataFrame.srcAddr)); dbcommandWrapper.AddInParameter("@isNightCheck",DbType.Boolean,Convert.ToBoolean(dataFrame.frameData[5])); dbcommandWrapper.AddInParameter("@isManual",DbType.Boolean,isManual); dbcommandWrapper.AddOutParameter("@rowsAffected",DbType.Int32,4); db.ExecuteNonQuery(dbcommandWrapper); rowsAffected = Convert.ToInt32(dbcommandWrapper.GetParameterValue("@rowsAffected")); } else { throw new Exception("通讯帧出错"); } } catch(Exception ex) { throw ex; } return rowsAffected; }
//新协议 // public int InsertMorningCheckInfo(DataFrame dataFrame) // { // int rowsAffected = 0; // // try // { // if(dataFrame.frameData.Length == 13)//确认为晨检应答帧 // { // Int16 classNumber = (Int16)(((dataFrame.frameData[1]/16)*10 + (dataFrame.frameData[1]%16))*100 // + dataFrame.frameData[0]);//计算学号 // // int year = dataFrame.frameData[2] == 0 ? DateTime.Now.Year : 2000 + (Int16)dataFrame.frameData[2]; // int month = dataFrame.frameData[3] == 0 ? DateTime.Now.Month : dataFrame.frameData[3]; // int day = dataFrame.frameData[4] == 0 ? DateTime.Now.Day :dataFrame.frameData[4]; // int hour = dataFrame.frameData[5] == 0 ? DateTime.Now.Hour : dataFrame.frameData[5]; // int minute = dataFrame.frameData[6] == 0 ? DateTime.Now.Minute : dataFrame.frameData[6]; // int second = dataFrame.frameData[7] == 0 ? DateTime.Now.Second : dataFrame.frameData[7]; // // DateTime checkTime = new DateTime(year, month, day, hour, minute, second); // // bool isManual = false; // // if(dataFrame.frameData[9] == 6) // { // isManual = true; // } // // DBCommandWrapper dbcommandWrapper = db.GetStoredProcCommandWrapper("FillCheckInfo"); // // dbcommandWrapper.AddInParameter("@getStuNumber",DbType.Int16,classNumber); // dbcommandWrapper.AddInParameter("@getTime",DbType.DateTime,checkTime); // dbcommandWrapper.AddInParameter("@getState",DbType.Int16,Convert.ToInt16(dataFrame.frameData[11])); // dbcommandWrapper.AddInParameter("@getCardSeq",DbType.Int16,Convert.ToInt16(dataFrame.frameData[9])); // dbcommandWrapper.AddInParameter("@fromMachine",DbType.Int16,Convert.ToInt16(dataFrame.srcAddr)); // dbcommandWrapper.AddInParameter("@isNightCheck",DbType.Boolean,Convert.ToBoolean(dataFrame.frameData[8])); // dbcommandWrapper.AddInParameter("@isManual",DbType.Boolean,isManual); // dbcommandWrapper.AddOutParameter("@rowsAffected",DbType.Int32,4); // // db.ExecuteNonQuery(dbcommandWrapper); // // rowsAffected = Convert.ToInt32(dbcommandWrapper.GetParameterValue("@rowsAffected")); // } // else // { // throw new Exception("通讯帧出错"); // } // } // catch(Exception ex) // { // throw ex; // } // // return rowsAffected; // } public int InsertMorningCheckInfo(DataFrame dataFrame) { int rowsAffected = 0; try { if(dataFrame.frameData.Length == 11)//确认为晨检应答帧 { Int16 classNumber = (Int16)(((dataFrame.frameData[1]/16)*10 + (dataFrame.frameData[1]%16))*100 + dataFrame.frameData[0]);//计算学号 DateTime checkTime = new DateTime(DateTime.Now.Year,DateTime.Now.Month, DateTime.Now.Day,dataFrame.frameData[2],dataFrame.frameData[3], dataFrame.frameData[4]); bool isManual = false; if(dataFrame.frameData[6]==6) { isManual = true; } CPTT.SystemFramework.Util.WriteLog(string.Format("number:{0},", classNumber),CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); short state = Convert.ToInt16(dataFrame.frameData[8]); if (state > 15) return 0; //FD 健康+警示 //FE 观察+警示 //FF 服药+警示 if (state == 253) { rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 0, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 4, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); } else if (state == 254) { rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 0, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 2, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 4, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); } else if (state == 255) { rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 0, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 3, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, 4, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); } else { rowsAffected = DoInsertMorningCheckInfo( classNumber, checkTime, state, dataFrame.frameData[6], dataFrame.srcAddr, Convert.ToBoolean(dataFrame.frameData[5]), isManual); } } else { throw new Exception("通讯帧出错"); } } catch(Exception ex) { throw ex; } return rowsAffected; }
private void SetMachineVolumn() { simpleButton4.Enabled = false; int classCount = gridView2.DataRowCount; DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.srcAddr = 0; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; sendCardFrame.protocol = CPTT.SystemFramework.Util.SET_DOOR_VOLUME; sendCardFrame.comFrameLen = (byte)(8 + (classCount+2) *2); sendCardFrame.frameData = new byte[(classCount+2) * 2]; int machineVolumn = 0; int index = 0; for(int i = 0;i < classCount;i ++) { machineVolumn = Convert.ToInt32(gridView2.GetDataRow(i)["machine_volumn"]); if(machineVolumn>=0) { machineVolumn = machineVolumn; } else { machineVolumn = 0 - machineVolumn; } int classNum = Convert.ToInt32(gridView2.GetDataRow(i)["machine_address"]); classNum = classNum/10*16 + classNum%10; sendCardFrame.frameData[index++] = Convert.ToByte(classNum); sendCardFrame.frameData[index++] = Convert.ToByte(machineVolumn); } sendCardFrame.frameData[index] = Convert.ToByte((91/10*16 + 91%10)); sendCardFrame.frameData[index + 1] = Convert.ToByte(70); sendCardFrame.frameData[index + 2] = Convert.ToByte((92 / 10 * 16 + 92 % 10)); sendCardFrame.frameData[index + 3] = Convert.ToByte(70); if (classCount > 28) { MessageBox.Show("学生班级数量不能超过28,请重试.", "系统信息!", MessageBoxButtons.OK, MessageBoxIcon.Information); Login.COM_PORT_IS_BUSY = false; login.ResumeQueryThread(); simpleButton4.Enabled = true; return; } //special edition for people volume expanding //the last max volume is 1200 if (SystemFramework.Util.CardVersion == 5) { if ((classCount * machineVolumn + 140) > 1420) { MessageBox.Show("超出门口机容量,请重试.", "系统信息!", MessageBoxButtons.OK, MessageBoxIcon.Information); Login.COM_PORT_IS_BUSY = false; login.ResumeQueryThread(); simpleButton4.Enabled = true; return; } } if ( batchMode ) { foreach(DataRow machineAddr in MachineInfo.Tables[0].Rows) { sendCardFrame.desAddr = Convert.ToByte(machineAddr["machine_address"]); sendCardFrame.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } // timer_SetMachineVolumn.Enabled = true; login.setMachineVolumn.Suspend(); } } else { sendCardFrame.desAddr = Convert.ToByte(getMachineNo); sendCardFrame.computeCheckSum(); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } // timer_SetMachineVolumn.Enabled = true; login.setMachineVolumn.Suspend(); } if ( hasSetMachineVol ) { setVolumnTryTime = 0; simpleButton4.Enabled = true; Login.COM_PORT_IS_BUSY = false; login.ResumeQueryThread(); MessageBox.Show("容量设定成功.","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); login.setMachineVolumn.Abort(); } }
private void AssignAddress() { simpleButton2.Enabled = false; DataFrame sendCardFrame = new DataFrame(); sendCardFrame.sym = new byte[]{(byte)'@',(byte)'@'}; sendCardFrame.desAddr = originalAddr; sendCardFrame.srcAddr = 0; sendCardFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; sendCardFrame.protocol = CPTT.SystemFramework.Util.ASSIGN_DOOR_ADDRESS; sendCardFrame.comFrameLen = 9; sendCardFrame.frameData = new byte[1]; sendCardFrame.frameData[0] = currentAddr; sendCardFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); Monitor.Enter(Login.syncRoot); try { Login.handleComClass.WriteSerialCmd(sendCardFrame.comFrameLen,sendCardFrame.frameToBytes());//发送问询帧 } finally { Monitor.Exit(Login.syncRoot); } timer_AssignAddr.Enabled = true; login.assignAddress.Suspend(); if ( hasAssignedSucceed ) { if(originalAddr == 0xff) { int rowAffected = new MachineSystem().InsertMachine(Convert.ToInt32(currentAddr)); } else { int rowsAffected = new MachineSystem().UpdateMachine(Convert.ToInt32(originalAddr) ,Convert.ToInt32(currentAddr)); // if(rowsAffected==0) // { // MessageBox.Show("地址修改插入数据库失败,请重试.","系统信息!", // MessageBoxButtons.OK,MessageBoxIcon.Information); // } } MachineInfo = new MachineSystem().GetMachineAddrList(); DataTable dt = MachineInfo.Tables[0]; DataColumn dc = new DataColumn("machine_state",System.Type.GetType("System.String")); dt.Columns.Add(dc); gridControl1.DataSource = dt; login.ResumeQueryThread(); MessageBox.Show("分配地址成功.","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); login.assignAddress.Abort(); } }
private void SynchDate(object machineAddr) { try { DataFrame controlFrame = new DataFrame(); controlFrame.sym = new byte[]{(byte)'@',(byte)'@'}; controlFrame.desAddr = Convert.ToByte(machineAddr); controlFrame.comFrameLen = 15; controlFrame.srcAddr = 0; controlFrame.protocol = CPTT.SystemFramework.Util.TIME_SYNCH_TOKEN; controlFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; controlFrame.frameData = new byte[7]; controlFrame.frameData[0] = Convert.ToByte(DateTime.Now.Year%100); controlFrame.frameData[1] = Convert.ToByte((byte)DateTime.Now.Month); controlFrame.frameData[2] = Convert.ToByte((byte)DateTime.Now.Day); controlFrame.frameData[3] = Convert.ToByte((byte)(DateTime.Now.DayOfWeek+1)); controlFrame.frameData[4] = Convert.ToByte((byte)DateTime.Now.Hour); controlFrame.frameData[5] = Convert.ToByte((byte)DateTime.Now.Minute); controlFrame.frameData[6] = Convert.ToByte((byte)DateTime.Now.Second); controlFrame.computeCheckSum(); //Monitor.Enter(Login.handleComClass); handleComClass.WriteSerialCmd(controlFrame.comFrameLen,controlFrame.frameToBytes());//发送问询帧 // Login.handleComClass.WriteSerialCmd(15,new byte[]{(byte)'@',(byte)'@',1,15,0,4,0, // 06,10,5,1,22,22,22,236}); //Monitor.Exit(Login.handleComClass); Thread.Sleep((int)CPTT.SystemFramework.Util.SEND_CARD_TIMER_OVERTIME); } catch { } }
public static void FillCard(DataFrame cardFrame,int cardNumber,int cardIndex) { cardFrame.frameData[2+cardIndex] = (byte)((cardNumber & 0xff000000) >> 24); cardFrame.frameData[3+cardIndex] = (byte)((cardNumber & 0x00ff0000) >> 16); cardFrame.frameData[4+cardIndex] = (byte)((cardNumber & 0x0000ff00) >> 8); cardFrame.frameData[5+cardIndex] = (byte)(cardNumber & 0x000000ff); }