Пример #1
0
        private void ReadExamInfo(byte[] buffer)
        {
            int index = 0;

            examID = GetIntFromMessage(buffer, index);
            index += sizeof(int);

            memberID = GetIntFromMessage(buffer, index);
            index   += sizeof(int);

            studentCount = GetIntFromMessage(buffer, index);

            bool needStudents = false;

            if (File.Exists(students_xml))
            {
                ExamInfo examInfo = XMLFileManager.GetExamInfo(students_xml);
                if (examInfo.examId != examID || examInfo.studentCount != studentCount)
                {
                    needStudents = true;
                }
            }
            else
            {
                needStudents = true;
            }

            if (needStudents)
            {
                List <byte> message = new List <byte>();
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(AssistantProtocol.OpcodeNeedStudents)));
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(0)));

                byte[] msg = message.ToArray();
                SendMessage(msg);
            }
            else
            {
                XMLFileManager.SaveMemberId(students_xml, memberID);
                students = XMLFileManager.GetStudentList(students_xml);
            }

            if (!File.Exists(cards_xml))
            {
                List <byte> message = new List <byte>();
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(AssistantProtocol.OpcodeNeedCards)));
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(0)));

                byte[] msg = message.ToArray();
                SendMessage(msg);
            }
            else
            {
                cards = XMLFileManager.GetCardList(cards_xml);
            }
        }
Пример #2
0
        private void ReadExamInfo(byte[] buffer)
        {
            int index = 0;

            examID = GetIntFromMessage(buffer, index);
            index += sizeof(int);

            memberID = GetIntFromMessage(buffer, index);
            index   += sizeof(int);

            studentCount = GetIntFromMessage(buffer, index);
            index       += sizeof(int);

            studentID = GetIntFromMessage(buffer, index);

            bool needStudents = false;

            if (File.Exists(students_xml))
            {
                ExamInfo examInfo = XMLFileManager.GetExamInfo(students_xml);
                if (examInfo.examId != examID || examInfo.studentCount != studentCount)
                {
                    needStudents = true;
                }
            }
            else
            {
                needStudents = true;
            }

            if (needStudents)
            {
                List <byte> message = new List <byte>();
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(AssistantProtocol.OpcodeNeedStudents)));
                message.AddRange(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(0)));

                byte[] msg = message.ToArray();
                SendMessage(msg);
            }
            else
            {
                XMLFileManager.SaveMemberId(students_xml, memberID);
                students = XMLFileManager.GetStudentList(students_xml);
                parentForm.Invoke(new FillStudentResultsEventHandler(parentForm.FillStudentResults), new Object[] { students });

                if (studentID != -1)
                {
                    Student.StudentUpdate stUpd = new Student.StudentUpdate();
                    stUpd.student = Student.GetStudentById(students, studentID);
                    parentForm.Invoke(new UpdateStudentEventHandler(parentForm.UpdateStudentInfo), new Object[] { stUpd.student });
                }
            }
        }
Пример #3
0
        public static ExamInfo GetExamInfo(string fileName)
        {
            ExamInfo    exam = new ExamInfo();
            XmlDocument doc  = new XmlDocument();

            try
            {
                doc.Load(fileName);
                XmlNode root = doc.DocumentElement;

                exam.examType     = root.Attributes["examType"].Value;
                exam.examId       = Convert.ToInt32(root.Attributes["examId"].Value);
                exam.memberId     = Convert.ToInt32(root.Attributes["memberId"].Value);
                exam.studentCount = Convert.ToInt32(root.Attributes["studentCount"].Value);
            }
            catch (Exception err)
            {
                Console.WriteLine("Ошибка чтения XML: " + err);
            }

            return(exam);
        }