Beispiel #1
0
//		private void changeCardState(string cardNumber)
//		{
//
//		}
		#endregion

		#region 检验ID卡
		private void simpleButton_BatchSendCheck_Click(object sender, System.EventArgs e)
		{
			if(textEdit3.Text.Equals(string.Empty))
			{
				MessageBox.Show("请输入要检验的卡号!!","系统信息!",
					MessageBoxButtons.OK,MessageBoxIcon.Information);
				textEdit3.Focus();
				return;
			}

			string number = new CardInfoSystem().GetNumberByCard(textEdit3.Text.Trim().TrimStart('0'));
			if(number.Length == 0)
			{
				MessageBox.Show(textEdit3.Text+"不是本校的卡.","系统信息!",
					MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
			else
			{
				MessageBox.Show(textEdit3.Text+"是"+number.ToString()+"的卡.","系统信息!",
					MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
//
//			Login.COM_PORT_IS_BUSY = true;
//
//			LoginForm.SuspendAllThread();
//			LoginForm.validateCardThread = new Thread(new ThreadStart(ValidateCard));
//			LoginForm.validateCardThread.IsBackground = true;
//			LoginForm.validateCardThread.Priority = ThreadPriority.Normal;
//			LoginForm.validateCardThread.Start();
		}
Beispiel #2
0
		private bool CardSave()
		{
			FileStream fileStream = null;
			StreamReader streamReader = null;

			if(SendCard1Number.Text.Trim().Equals(string.Empty)&&
				SendCard2Number.Text.Trim().Equals(string.Empty)&&
				SendCard3Number.Text.Trim().Equals(string.Empty)&&
				SendCard4Number.Text.Trim().Equals(string.Empty)&&
				SendCard5Number.Text.Trim().Equals(string.Empty))
			{
				MessageBox.Show("卡号不能都为空!!","系统信息!",
					MessageBoxButtons.OK,MessageBoxIcon.Information);

				return false;
			}

			cardsHasSend.Clear();

			string stuID;
			string stuCardNumber = string.Empty;

			if(searchStu)
			{
				stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["info_stuID"]).ToString();
			}
			else
			{
				stuID = (gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_ID"]).ToString();
			}

			bool cardIsNotSend = true;
			CardInfoSystem cardInfoSystem = new CardInfoSystem();

			if(!(SendCard1Number.Text.Trim().Equals(string.Empty)))
			{

#if CardValidCheck2
				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 )
							{
								MessageBox.Show("存在非法卡号,卡操作失败!");
								return false;
							}
							else
								break;
						}
					}
				}
				catch(Exception ex)
				{	
					MessageBox.Show("卡号信息不准确,请重试!");
					return false;
				}
				finally
				{
					dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
					dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

					fileStream.Close();
					streamReader.Close();
				}
#endif
				if(searchStu)
				{
					if(SendCard1Holder.Text.Trim().Equals(string.Empty))
					{
						MessageBox.Show("卡1持卡人不能都为空!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);
						return false;
					}
				}

				stuCardNumber = SendCard1Number.Text.Trim();


				SystemFramework.CardInfo sendCardInfo = new CardInfo();
				sendCardInfo.StuID = stuID;
				sendCardInfo.CardNumber = stuCardNumber;
				sendCardInfo.CardHolder = SendCard1Holder.Text.Trim();
				sendCardInfo.CardSendDate = DateTime.Now;
				sendCardInfo.CardSequence = 1;
				sendCardInfo.CardState = cardIsNotSend;

				if(searchStu)
				{
					int retValue = cardInfoSystem.InsertCardInfo(sendCardInfo);
					
					if (retValue == -2)
					{
						return false;
					}
				}
				else
				{
					int retValue = cardInfoSystem.InsertTeaCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				cardsHasSend.Add(stuCardNumber);
				SendCard1Number.Enabled = false;
			}

			if(!(SendCard2Number.Text.Trim().Equals(string.Empty)))
			{

#if CardValidCheck2
				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 )
							{
								MessageBox.Show("存在非法卡号,卡操作失败!");
								return false;
							}
							else
								break;
						}
					}
				}
				catch(Exception ex)
				{	
					MessageBox.Show("卡号信息不准确,请重试!");
					return false;
				}
				finally
				{
					dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
					dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

					fileStream.Close();
					streamReader.Close();
				}
#endif
				if(searchStu)
				{
					if(SendCard2Holder.Text.Trim().Equals(string.Empty))
					{
						MessageBox.Show("卡2持卡人不能都为空!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);
						return false;
					}
				}


				stuCardNumber = SendCard2Number.Text.Trim();

				SystemFramework.CardInfo sendCardInfo = new CardInfo();
				sendCardInfo.StuID = stuID;
				sendCardInfo.CardNumber = stuCardNumber;
				sendCardInfo.CardHolder = SendCard2Holder.Text.Trim();
				sendCardInfo.CardSendDate = DateTime.Now;
				sendCardInfo.CardSequence = 2;
				sendCardInfo.CardState = cardIsNotSend;

				if(searchStu)
				{
					int retValue = cardInfoSystem.InsertCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				else
				{
					int retValue = cardInfoSystem.InsertTeaCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				cardsHasSend.Add(stuCardNumber);
				SendCard2Number.Enabled = false;
			}

			if(!(SendCard3Number.Text.Trim().Equals(string.Empty)))
			{

#if CardValidCheck2
				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 )
							{
								MessageBox.Show("存在非法卡号,卡操作失败!");
								return false;
							}
							else
								break;
						}
					}
				}
				catch(Exception ex)
				{	
					MessageBox.Show("卡号信息不准确,请重试!");
					return false;
				}
				finally
				{
					dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
					dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

					fileStream.Close();
					streamReader.Close();
				}
#endif
				if(searchStu)
				{
					if(SendCard3Holder.Text.Trim().Equals(string.Empty))
					{
						MessageBox.Show("卡3持卡人不能都为空!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);
						return false;
					}
				}


				stuCardNumber = SendCard3Number.Text.Trim();

				SystemFramework.CardInfo sendCardInfo = new CardInfo();
				sendCardInfo.StuID = stuID;
				sendCardInfo.CardNumber = stuCardNumber;
				sendCardInfo.CardHolder = SendCard3Holder.Text.Trim();
				sendCardInfo.CardSendDate = DateTime.Now;
				sendCardInfo.CardSequence = 3;
				sendCardInfo.CardState = cardIsNotSend;

				if(searchStu)
				{
					int retValue = cardInfoSystem.InsertCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				else
				{
					int retValue = cardInfoSystem.InsertTeaCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				cardsHasSend.Add(stuCardNumber);
				SendCard3Number.Enabled = false;
			}

			if(!(SendCard4Number.Text.Trim().Equals(string.Empty)))
			{

#if CardValidCheck2
				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 )
							{
								MessageBox.Show("存在非法卡号,卡操作失败!");
								return false;
							}
							else
								break;
						}
					}
				}
				catch(Exception ex)
				{	
					MessageBox.Show("卡号信息不准确,请重试!");
					return false;
				}
				finally
				{
					dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
					dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

					fileStream.Close();
					streamReader.Close();
				}
#endif
				if(searchStu)
				{
					if(SendCard4Holder.Text.Trim().Equals(string.Empty))
					{
						MessageBox.Show("卡4持卡人不能都为空!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);
						return false;
					}
				}


				stuCardNumber = SendCard4Number.Text.Trim();

				SystemFramework.CardInfo sendCardInfo = new CardInfo();
				sendCardInfo.StuID = stuID;
				sendCardInfo.CardNumber = stuCardNumber;
				sendCardInfo.CardHolder = SendCard4Holder.Text.Trim();
				sendCardInfo.CardSendDate = DateTime.Now;
				sendCardInfo.CardSequence = 4;
				sendCardInfo.CardState = cardIsNotSend;

				if(searchStu)
				{
					int retValue = cardInfoSystem.InsertCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				else
				{
					int retValue = cardInfoSystem.InsertTeaCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				cardsHasSend.Add(stuCardNumber);
				SendCard4Number.Enabled = false;
			}

			if(!(SendCard5Number.Text.Trim().Equals(string.Empty)))
			{

#if CardValidCheck2
				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 )
							{
								MessageBox.Show("存在非法卡号,卡操作失败!");
								return false;
							}
							else
								break;
						}
					}
				}
				catch(Exception ex)
				{	
					MessageBox.Show("卡号信息不准确,请重试!");
					return false;
				}
				finally
				{
					dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
					dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

					fileStream.Close();
					streamReader.Close();
				}
#endif
				if(searchStu)
				{
					if(SendCard5Holder.Text.Trim().Equals(string.Empty))
					{
						MessageBox.Show("卡5持卡人不能都为空!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);
						return false;
					}
				}


				stuCardNumber = SendCard5Number.Text.Trim();

				SystemFramework.CardInfo sendCardInfo = new CardInfo();
				sendCardInfo.StuID = stuID;
				sendCardInfo.CardNumber = stuCardNumber;
				sendCardInfo.CardHolder = SendCard5Holder.Text.Trim();
				sendCardInfo.CardSendDate = DateTime.Now;
				sendCardInfo.CardSequence = 5;
				sendCardInfo.CardState = cardIsNotSend;

				if(searchStu)
				{
					int retValue = cardInfoSystem.InsertCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				else
				{
					int retValue = cardInfoSystem.InsertTeaCardInfo(sendCardInfo);

					if (retValue == -2)
					{
						return false;
					}
				}
				cardsHasSend.Add(stuCardNumber);
				SendCard5Number.Enabled = false;
			}
			return true;
		}
Beispiel #3
0
		private bool isCardExist(string cardNumber)
		{
			int cardCount = new CardInfoSystem().GetCardCount(cardNumber);

			if(cardCount>0)
				return true;
			else
				return false;
		}
Beispiel #4
0
		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();
			}
		}
Beispiel #5
0
		//卡操作成功后触发时间
		private void loginForm_SendCardSuccessed()
		{
			Timer_SendCardOverTime.Enabled = false;

			CardInfoSystem cardInfoSystem = new CardInfoSystem();
			if(isBatchSendCard&&gridView3.RowCount>0)
			{
				if(batchSearchStu)
				{
					//cardInfoSystem.UpdateCardState(gridView3.GetDataRow(0)["info_stuCardNumber"].ToString());
				}
				else
				{
					cardInfoSystem.UpdateTeaCardState(gridView3.GetDataRow(0)["info_teaCardNumber"].ToString());
				}
			}
			
//			if(!isBatchSendCard&&isSendCard)
//			{
//				foreach(string cardNumber in cardsHasSend)
//				{
//					if(searchStu)
//					{
//						cardInfoSystem.UpdateCardState(cardNumber);
//					}
//					else
//					{
//						cardInfoSystem.UpdateTeaCardState(cardNumber);
//					}
//				}
//			}

			isCardLogOutSucceed = true;
			isCardSendSucceed = true;
			
			//Login.COM_PORT_IS_BUSY = false;
			try
			{
				LoginForm.sendCardThread.Resume();
			}
			catch{}
		}
Beispiel #6
0
		private void LogoutCardContextSync(ArrayList cardLogout, string stuID)
		{
			dataNavigator_CardSent.Buttons.CustomButtons[0].Enabled = true;
			dataNavigator_CardSent.Buttons.CustomButtons[1].Enabled = true;

			reTryTime = 0;

			CardInfoSystem cardInfoSystem = new CardInfoSystem();
			foreach(string logoutCard in cardLogout)
			{
				if(searchStu)
				{
					cardInfoSystem.DeleteCardInfo(logoutCard);
				}
				else
				{
					cardInfoSystem.DeleteTeaCardInfo(logoutCard);
				}
			}

			GetCardDetailsContextSyncDelegate(stuID);
		}
Beispiel #7
0
		//发卡
		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)
                    {

                    }
                }

			}
		}