private void simpleButton1_Click(object sender, System.EventArgs e) { int rtnState = new MachineSystem().CreateClassMachine(); if (rtnState > 0) { ClassMachineInfo = new MachineSystem().GetClassMachineAddrList(); gridControl2.DataSource = ClassMachineInfo.Tables[0]; } else { MessageBox.Show("班级生成失败,请重试!"); } }
/// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// </summary> private void InitializeComponent() { this.timerTimeSynch = new System.Timers.Timer(); this.timer_ReceiveReply = new System.Timers.Timer(); ((System.ComponentModel.ISupportInitialize)(this.timerTimeSynch)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.timer_ReceiveReply)).BeginInit(); // // timerTimeSynch // timerTimeSynch.Interval = CPTT.SystemFramework.Util.TIMESYNCH_TIMER_INTERVAL;//设置时间同步timer this.timerTimeSynch.Elapsed += new System.Timers.ElapsedEventHandler(this.timerTimeSynch_Elapsed); // // timer_ReceiveReply // this.timer_ReceiveReply.Enabled = false; this.timer_ReceiveReply.Interval = 40000; this.timer_ReceiveReply.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReceiveReply_Elapsed); // // AutoService // this.CanPauseAndContinue = true; this.CanShutdown = true; this.ServiceName = "CPTT4.0AutoService"; ((System.ComponentModel.ISupportInitialize)(this.timerTimeSynch)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.timer_ReceiveReply)).EndInit(); handleComClass = new HandleComClass(); handleComClass.Start(CPTT.SystemFramework.Util.COM1_PORT_NUMBER,CPTT.SystemFramework.Util.COM_BAUD_RATE,1); handleComClass.DataArrived += new _IHandleComEvents_DataArrivedEventHandler(handleComClass_DataArrived); machineSystem = new MachineSystem(); responseFrame = new ControlFrame(); responseFrame.sym = new byte[]{(byte)'*',(byte)'*'}; responseFrame.srcAddr = 0; responseFrame.response = CPTT.SystemFramework.Util.RECEIVE_SUCCESS_TOKEN; responseFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; handleComData = new HandleComData(this.InsertMorningCheckData); }
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 simpleButton_GetMobile_Click(object sender, System.EventArgs e) { DataSet machineAddrList = new MachineSystem().GetMachineAddrList(); gridControl_DeviceView.DataSource = machineAddrList.Tables[0]; }
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 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 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) { } } } }
//delete private void simpleButton5_Click(object sender, System.EventArgs e) { if(gridView1.RowCount <= 1) { MessageBox.Show("至少应该保证有一台门口机处于工作状态,删除失败!"); return; } if(DialogResult.Yes != MessageBox.Show("确定删除?","系统信息!", MessageBoxButtons.YesNo,MessageBoxIcon.Information)) { return; } // if(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["machine_state"].ToString().Equals("待分配") // ||gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["machine_state"].ToString().Equals("待修改")) // { // MessageBox.Show("只有状态不为待修改和待分配的记录才能进行删除,请选择正确的行记录.","系统信息!", // MessageBoxButtons.OK,MessageBoxIcon.Information); // // return; // } int machineAddr = Convert.ToInt32(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["machine_address"]); int rowsAffected = new MachineSystem().DeleteMachine(machineAddr); gridView1.DeleteRow(gridView1.GetSelectedRows()[0]); // if(rowsAffected>0) // { // gridView1.DeleteRow(gridView1.GetSelectedRows()[0]); // } // else // { // MessageBox.Show("删除失败,请重试.","系统信息!", // MessageBoxButtons.OK,MessageBoxIcon.Information); // } }
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(); } }
public OptionsForm(Login loginForm) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // option = new Option(); if(!Thread.CurrentPrincipal.IsInRole("园长") &&!Thread.CurrentPrincipal.IsInRole("保健") &&Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { xtraTabPage_ComPortSet.PageVisible = false; } if(Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { xtraTabPage_AutoSendSmsTimeSet.PageVisible = false; } if(Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { xtraTabPage2.PageVisible = false; } if(Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { xtraTabPage3.PageVisible = false; } if(Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { xtraTabPage_BatchCreate.PageVisible = false; } if(!Thread.CurrentPrincipal.IsInRole("园长") &&Thread.CurrentPrincipal.Identity.Name.ToLower()!="admin") { xtraTabPage_TerminalServ.PageVisible = false; } if(!Thread.CurrentPrincipal.IsInRole("园长") &&Thread.CurrentPrincipal.Identity.Name.ToLower()!="admin") { xtraTabPage4.PageVisible = false; } if (Thread.CurrentPrincipal.Identity.Name.ToLower() != "admin") { comboBoxEdit_BatchCreate_Load.Properties.Items.Remove("学生信息表(复杂)"); } loadUserStyleProfile(); this.loginForm = loginForm; this.tbxUploadUrl.Text = "http://xdd.xindoudou.cn/2/partner/sync"; optionSystem = new OptionSystem(); gridControl1.DataSource = new CameraSystem().GetCameraInfo(); var machineSet = new MachineSystem().GetMachineAddrList(); if (machineSet != null && machineSet.Tables.Count >= 1) { foreach (DataRow item in machineSet.Tables[0].Rows) { repositoryItemComboBox4.Items.Add(string.Format("{0}号门口机", item["machine_address"])); } } }
public Login() { utilSystem = new UtilSystem(); #if MaxClients int maxClients = utilSystem.GetMaxClients(); if ( maxClients != -1 ) CPTT.SystemFramework.Util.MaxClients = maxClients; else { MessageBox.Show("初始化服务器会话状态时发生严重错误,请与供应商联系!"); return; } #endif _alUnAuthenticatedHardWare = HardWareAuthentication.GetUnAuthorizedHardWare(); _alAuthenticatedHardWare = HardWareAuthentication.GetAuthorizedHardWare(); _registerDays = HardWareAuthentication.GetDaysValid; //显示Splash // Splash splash = new Splash(); // splash.StartPosition = FormStartPosition.CenterScreen; // splash.Show(); //初始化LoginForm InitializeComponent(); userSystem = new UserSystem(); ArrayList settings = ConfigurationManager.GetConfiguration("CustomizeSettings") as ArrayList; isAutoShutDown = Convert.ToBoolean((settings[2] as XmlNode[])[1].InnerText); // shutDownTime = Convert.ToDateTime((settings[3] as XmlNode[])[1].InnerText); if(isAutoShutDown) { timer_AutoShutDown.Enabled = true; } // appUpdater_ForCTPP.UpdateUrl = CPTT.SystemFramework.Util.AUTO_UPDATE_ADDRESS; prepareForCheckThread = new Thread(new ThreadStart(PrepareForCheck)); prepareForCheckThread.IsBackground = true; prepareForCheckThread.Priority = ThreadPriority.Normal; prepareForCheckThread.Start(); //splash.Close(); //初始化查询线程 if(!COM_PORT_IS_BUSY) { handleComClass = new HandleCom(); handleComClass.Start(CPTT.SystemFramework.Util.COM1_PORT_NUMBER,CPTT.SystemFramework.Util.COM_BAUD_RATE,1); handleComClass.DataArrived += new _IHandleComEvents_DataArrivedEventHandler(handleComClass_DataArrived); machineSystem = new MachineSystem(); queryThread = new Thread(new ThreadStart(SendQuery)); queryThread.IsBackground = true; queryThread.Priority = ThreadPriority.Normal; queryThread.Start(); // queryThread = new Thread(new ThreadStart(SendHardWareAuthenticationToken)); // queryThread.IsBackground = true; // queryThread.Priority = ThreadPriority.Normal; // queryThread.Start(); controlFrame = new ControlFrame(); responseFrame = new ControlFrame(); responseFrame.sym = new byte[]{(byte)'*',(byte)'*'}; // responseFrame.desAddr = 1; responseFrame.srcAddr = 0; responseFrame.response = CPTT.SystemFramework.Util.RECEIVE_SUCCESS_TOKEN; responseFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE; handleComData = new HandleComData(this.InsertMorningCheckData); } this.StartPosition = FormStartPosition.CenterScreen; // this.Opacity = 0.0; // Activate(); // Refresh(); // fadeTimer.Start(); // Refresh(); textEdit_UserLoginID.Text=""; textEdit_UserLoginPwd.Text=""; }