public frmShowStudentInfo(string studendID) { InitializeComponent(); this.lblID.Text = studendID; Person person = MemoryTable.getPersonByID(studendID); if (person != null) { this.lblName.Text = person.name; this.lblClass.Text = person.bj; this.lblEmail.Text = person.email; } else { this.lblName.Text = ""; this.lblID.Text = ""; this.lblClass.Text = ""; this.lblEmail.Text = ""; } }
static void OnReceiveLoginRequest(IAsyncResult ar) { //接收到客户端的登陆请求 //请求中带有客户端输入的学生ID,本服务端需要和学生信息进行匹配, //首先学号查找与学号对应的卡号,然后查找卡号是否已经读取到,如果已经读取到,则广播发送登陆信息给客户端 //如果卡号尚未读取到,则客户端可以等待,然后读取到卡号的时候会发送登陆信息 //接收到的数据格式 // [id,data,epc,data] 对应的正则表达式 \[id,(?<id>\w+),epc,(?<epc>\w{0,})\] 必须要求有ID存在 try { IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0); EndPoint epSender = (EndPoint)ipeSender; Login_ServerSocket.EndReceiveFrom(ar, ref epSender); string strReceived = Encoding.UTF8.GetString(byteData); Array.Clear(byteData, 0, byteData.Length); Debug.WriteLine("OnReceiveLoginRequest => " + strReceived); string strToBroadcast = string.Empty; Regex regex = new Regex(@"\[id,(?<id>\w+),epc,(?<epc>\w{0,})\]"); MatchCollection matches = regex.Matches(strReceived); foreach (Match mc in matches) { string epc_match = mc.Groups["epc"].Value; string id_match = mc.Groups["id"].Value; Debug.WriteLine(string.Format("Match => epc = {0} student ID = {1}", epc_match, id_match)); //根据接收到的id查找绑定的卡号 Person person = MemoryTable.getPersonByID(id_match); if (person != null) { string epc = person.epc; //查找是否已经读取到卡号 if (epcList.Contains(epc)) { string equipmentID = string.Empty; equipmentPosition ep = MemoryTable.getEquipmentInfoByEpc(epc); if (ep == null) { ep = MemoryTable.getEquipmentInfoNotUsed(); } if (ep != null) { equipmentID = ep.equipmentID; } strToBroadcast = string.Format("[id,{0},epc,{1},equipmentID,{2}]", person.id_num, epc, equipmentID); Broadcast(strToBroadcast); } } } //Start listening to the message send by the user Login_ServerSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnReceiveLoginRequest), epSender); } catch (Exception ex) { Debug.WriteLine("OnReceiveRFID => " + ex.Message); } }