Example #1
0
        //对应菜单项删除考生事件处理
        public void Menu_del(int devnum, string zkzhm)
        {
            CStudent stu = model.devmanager.GetStudent(devnum, zkzhm);

            if (stu != null)
            {
                DisplayStrings.DeleteString(stu.DisplayString(devnum));
            }
            model.devmanager.DeleteStudent(devnum, zkzhm);
            mainform.UpdateStudentlist(devnum, (CStuDevlist)model.devmanager.DevList[devnum]);
            CStudent stu2and3;

            for (int i = 1; i < 3; i++)
            {
                stu2and3 = model.devmanager.GetStudent(devnum, i);
                if (stu2and3 != null)
                {
                    DisplayStrings.AddString(stu2and3.DisplayString(devnum), "排队");
                }
                else
                {
                    break;
                }
            }
            //displaycomm.ShowText(DisplayStrings.GetAllStrings());

            //删除对应的远端设备列表中的排队考生
            CNetData tmpdata = new CNetData();

            tmpdata.cmdCommand = Command.DeleteStudent;
            tmpdata.intDevnum  = devnum;
            tmpdata.strZjbh    = zkzhm;
            Server.SendData(devnum, tmpdata);
        }
Example #2
0
        //public void OnSend(IAsyncResult ar)
        //{
        //    try
        //    {
        //        Socket client = (Socket)ar.AsyncState;
        //        client.EndSend(ar);
        //    }
        //    catch (Exception ex)
        //    {
        //        System.Windows.Forms.MessageBox.Show(ex.Message, "CNetServer_OnSend",
        //             System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
        //    }
        //}


        public void SendData(int pintdevnum, CNetData datasend)
        {
            foreach (ClientInfo client in clientList)
            {
                if (client.intDevnum == pintdevnum)
                {
                    byte[] b = datasend.ToByte();
                    client.socket.Send(b, 0, b.Length, SocketFlags.None);
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
Example #3
0
        //对应菜单项清除所有考生事件处理
        public void Menu_clear(int devnum)
        {
            for (int i = 0; i < ((CStuDevlist)(model.devmanager.DevList[devnum])).Stumum; i++)
            {
                CStudent stu = model.devmanager.GetStudent(devnum, i);
                if (stu != null)
                {
                    DisplayStrings.DeleteString(stu.DisplayString(devnum));
                }
            }
            //displaycomm.ShowText(DisplayStrings.GetAllStrings());
            model.devmanager.ClearStudent(devnum);
            mainform.UpdateStudentlist(devnum, (CStuDevlist)model.devmanager.DevList[devnum]);
            //清除对应的远端设备列表中的排队考生
            CNetData tmpdata = new CNetData();

            tmpdata.cmdCommand = Command.ClearStudent;
            tmpdata.intDevnum  = devnum;
            Server.SendData(devnum, tmpdata);
        }
Example #4
0
        private void UpdateRemoteListview(int devnum)
        {
            CNetData tmpdata = new CNetData();

            //发送清除列表命令
            tmpdata.cmdCommand = Command.ClearStudent;
            tmpdata.intDevnum  = devnum;
            Server.SendData(devnum, tmpdata);
            tmpdata.Clear();
            System.Threading.Thread.Sleep(5);

            for (int i = 0; i < ((CStuDevlist)model.devmanager.DevList[devnum]).StudentList.Count; i++)
            {
                tmpdata.cmdCommand = Command.AddStudent;
                tmpdata.strZjbh    = ((CStudent)((CStuDevlist)model.devmanager.DevList[devnum]).StudentList[i]).zkzmbh;
                tmpdata.Xm         = ((CStudent)((CStuDevlist)model.devmanager.DevList[devnum]).StudentList[i]).xm;
                tmpdata.intDevnum  = devnum;
                Server.SendData(devnum, tmpdata);
                tmpdata.Clear();
                System.Threading.Thread.Sleep(20);
            }
        }
Example #5
0
        private void buttonX1_Click_1(object sender, EventArgs e)
        {
            int redevnum = model.devmanager.FindStudent(Inputstudent.zkzmbh);

            if (redevnum > 0)
            {
                MessageBox.Show("考生(" + Inputstudent.xm + ")已经在设备" + redevnum.ToString() + "中排队了!");
                initlabel();
                Inputstudent     = null;
                buttonX1.Enabled = false;
                comboBox1.Text   = model.devmanager.GetMinnum().ToString();
                return;
            }


            //给devmanager设备列表增加考生
            ((CStuDevlist)model.devmanager.DevList[int.Parse(comboBox1.Text)]).AddStudent(Inputstudent);
            ViewManage.UpdateStudentlist(int.Parse(comboBox1.Text), ((CStuDevlist)model.devmanager.DevList[int.Parse(comboBox1.Text)]));
            model.SaveStudent(Inputstudent);

            //************************************
            CNetData tmpdata = new CNetData();

            tmpdata.cmdCommand = Command.AddStudent;
            tmpdata.intDevnum  = int.Parse(comboBox1.Text);
            tmpdata.strZjbh    = Inputstudent.zkzmbh;
            tmpdata.Xm         = Inputstudent.xm;
            ctrl.Server.SendData(int.Parse(comboBox1.Text), tmpdata);
            //************************************

            initlabel();
            Inputstudent     = null;
            buttonX1.Enabled = false;
            comboBox1.Text   = model.devmanager.GetMinnum().ToString();
            textBoxX1.Focus();
        }
Example #6
0
        private void Server_Event_Devnetdata(CNetData data)
        {
            CNetData tmpdata = new CNetData();

            switch (data.cmdCommand)
            {
            case Command.GetStudent:

                CStudent stu = model.devmanager.GetStudent(data.intDevnum);
                if (stu != null)
                {
                    tmpdata.Clear();
                    tmpdata.cmdCommand = Command.Zkzhm;
                    tmpdata.strZjbh    = stu.zkzmbh;
                    Server.SendData(data.intDevnum, tmpdata);
                    mainform.ChangeDevStatus(data.intDevnum, DevStatus.身份验证);
                    mainform.UpdateStuColor(data.intDevnum);
                    if (DisplayStrings.GetValue(stu.DisplayString(data.intDevnum)) == null)
                    {
                        DisplayStrings.AddString(stu.DisplayString(data.intDevnum), "考试");
                    }
                    else
                    {
                        DisplayStrings.UpdateString(stu.DisplayString(data.intDevnum), "考试");
                    }
                    CVoice.Play(stu.DisplayString(data.intDevnum) + "考试。");
                    CStudent stu2 = model.devmanager.GetStudent(data.intDevnum, 1);
                    if (stu2 != null)
                    {
                        DisplayStrings.AddString(stu2.DisplayString(data.intDevnum), "排队");
                        //CVoice.Play(stu2.DisplayString(data.intDevnum) + "排队。");
                    }
                    //displaycomm.ShowText(DisplayStrings.GetAllStrings());
                }
                break;

            case Command.Ksks:
                if (mainform.GetDeviceStatus(data.intDevnum) != DevStatus.正在考试)
                {
                    mainform.ChangeDevStatus(data.intDevnum, DevStatus.正在考试);
                    //把设备列表中第一个考生显示颜色改为红色,表示正在考试
                    mainform.UpdateStuColor(data.intDevnum);
                    CStudent stu1 = model.devmanager.GetStudent(data.intDevnum, 0);
                    if (stu1 != null)
                    {
                        DisplayStrings.DeleteString(stu1.DisplayString(data.intDevnum));
                    }
                    CStudent stu2and3;
                    for (int i = 1; i < 3; i++)
                    {
                        stu2and3 = model.devmanager.GetStudent(data.intDevnum, i);
                        if (stu2and3 != null)
                        {
                            DisplayStrings.AddString(stu2and3.DisplayString(data.intDevnum), "排队");
                        }
                        else
                        {
                            break;
                        }
                    }
                    //displaycomm.ShowText(DisplayStrings.GetAllStrings());
                }
                break;

            case Command.Kswc:
                mainform.ChangeDevStatus(data.intDevnum, DevStatus.设备就绪);
                mainform.ReUpdateStuColor(data.intDevnum);
                //把设备列表中第一个考生删除掉
                mainform.DeleteFirstStudent(data.intDevnum);
                tmpdata.Clear();
                tmpdata.cmdCommand = Command.DeleteStudent;
                tmpdata.intDevnum  = data.intDevnum;
                tmpdata.strZjbh    = data.strZjbh;
                Server.SendData(data.intDevnum, tmpdata);
                break;

            case Command.Jjks:
                System.Windows.Forms.MessageBox.Show("考生" + ((CStudent)(model.devmanager.GetStudent(data.intDevnum))).zkzmbh + "被" + data.intDevnum.ToString() + "号考库拒绝!");
                mainform.ReUpdateStuColor(data.intDevnum);
                CStudent stu3 = model.devmanager.GetStudent(data.intDevnum, 0);
                if (stu3 != null)
                {
                    DisplayStrings.UpdateString(stu3.DisplayString(data.intDevnum), "排队");
                }
                //displaycomm.ShowText(DisplayStrings.GetAllStrings());
                mainform.ChangeDevStatus(data.intDevnum, DevStatus.设备就绪);
                ////把设备列表中第一个考生删除掉
                //mainform.DeleteFirstStudent(data.intDevnum);
                ////删除对应的远端设备列表中的排队考生
                //tmpdata.Clear();
                //tmpdata.cmdCommand = Command.DeleteStudent;
                //tmpdata.intDevnum = data.intDevnum;
                //tmpdata.strZjbh = data.strZjbh;
                //Server.SendData(data.intDevnum, tmpdata);
                break;

            case Command.Updatelist:
                //同步更新远程设备排队考生列表
                UpdateRemoteListview(data.intDevnum);
                break;
            }
        }
Example #7
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                clientSocket.EndReceive(ar);

                //Transform the array of bytes received from the user into an
                //intelligent form of object Data
                CNetData msgReceived = new CNetData(byteData);


                //创建接收到数据的事件处理
                switch (msgReceived.cmdCommand)
                {
                case Command.Login:
                    ClientInfo clientInfo = new ClientInfo();
                    clientInfo.socket    = clientSocket;
                    clientInfo.intDevnum = msgReceived.intDevnum;
                    clientList.Add(clientInfo);
                    if (_event_devlogin != null)
                    {
                        _event_devlogin(msgReceived.intDevnum);    //发送login事件
                    }
                    break;

                case Command.Logout:
                    int nIndex    = 0;
                    int tmpdevnum = 0;
                    foreach (ClientInfo client in clientList)
                    {
                        if (client.socket == clientSocket)
                        {
                            tmpdevnum = client.intDevnum;
                            clientList.RemoveAt(nIndex);
                            break;
                        }
                        ++nIndex;
                    }
                    clientSocket.Close();
                    if (_event_devlogout != null)
                    {
                        _event_devlogout(tmpdevnum);    //发送logout事件
                    }
                    break;

                default:
                    if (_event_devnetdata != null)
                    {
                        _event_devnetdata(msgReceived);    //发送其他事件
                    }
                    break;
                }

                if (msgReceived.cmdCommand != Command.Logout)
                {
                    //Start listening to the message send by the user
                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), clientSocket);
                }
            }
            catch
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                int    nIndex       = 0;
                int    tmpdevnum    = 0;
                foreach (ClientInfo client in clientList)
                {
                    if (client.socket == clientSocket)
                    {
                        tmpdevnum = client.intDevnum;
                        clientList.RemoveAt(nIndex);
                        break;
                    }
                    ++nIndex;
                }
                clientSocket.Close();
                if (_event_devlogout != null)
                {
                    _event_devlogout(tmpdevnum);//发送logout事件
                }
                //System.Windows.Forms.MessageBox.Show(ex.Message, "CNetServer_OnReceive",
                //  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                System.Windows.Forms.MessageBox.Show("设备" + tmpdevnum.ToString() + "强行断开网络!", "点名中心提示");
            }
        }