Example #1
0
        //запис айди тесту
        void ChangeIDForTest()
        {
            using (ExamVceDB test = new ExamVceDB())
            {
                //var last = test.TestDBs.Last();
                TestDB last = null;
                foreach (var item in test.TestDBs)
                {
                    last = item;
                }
                var result = test.TestDBs.FirstOrDefault(i => i.ID == last.ID);

                var      serializer = new XmlSerializer(typeof(MakeTest));
                MakeTest desr;

                using (TextReader reader = new StringReader(result.Test))
                {
                    desr = (MakeTest)serializer.Deserialize(reader);
                }
                desr.IdTest = last.ID;
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(MakeTest));
                var           stringWriter  = new StringWriter();
                xmlSerializer.Serialize(stringWriter, desr);
                last.Test = stringWriter.ToString();
                test.SaveChanges();
            }
        }
Example #2
0
        //вибір дії
        private void comboBoxAct_SelectedIndexChanged(object sender, EventArgs e)
        {
            string act = comboBoxAct.SelectedItem.ToString();

            switch (act)
            {
            case "Add test to DB":
            {
                OpenFileDialog file = new OpenFileDialog();
                file.ShowDialog();

                string xmlTest = File.ReadAllText(file.FileName);
                var    time    = DateTime.Now;
                using (ExamVceDB test = new ExamVceDB())
                {
                    test.TestDBs.Add(new TestDB()
                        {
                            IdFromPerson = loginPerson.ID,
                            Test         = xmlTest,
                            DateLoad     = time,
                        });
                    test.SaveChanges();
                    MessageBox.Show("test was added");
                }
                ChangeIDForTest();
                break;
            }

            case "Send test to":
            {
                break;
            }

            case "Add student to DB":
            {
                AddStudentToDB addStudent = new AddStudentToDB();
                addStudent.ShowDialog();
                break;
            }

            case "Choose exam":
            {
                listBoxExam.Enabled = true;
                using (ExamVceDB exam = new ExamVceDB())
                {
                    foreach (var item in exam.TestDBs)
                    {
                        MakeTest subject = DeserialiseFromString(item.Test);
                        listBoxExam.Items.Add($"{item.ID}* {subject.Subject}");
                    }
                }

                break;
            }
            }

            if (comboBoxAct.SelectedItem.Equals("Add test to DB"))
            {
            }
        }
Example #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(textBoxName.Text) && !string.IsNullOrEmpty(textBoxLogin.Text) && !string.IsNullOrEmpty(textBoxPassword.Text) && !string.IsNullOrEmpty(textBoxCourse.Text) && !string.IsNullOrEmpty(textBoxGroup.Text) && !string.IsNullOrEmpty(textBoxSpecialisation.Text))
     {
         string password;
         using (MD5 md5Hash = MD5.Create())
         {
             password = GetMd5Hash(md5Hash, textBoxPassword.Text);
         }
         using (ExamVceDB student = new ExamVceDB())
         {
             try
             {
                 student.Students.Add(new Student()
                 {
                     Name           = textBoxName.Text,
                     Course         = textBoxCourse.Text,
                     Password       = password,
                     Login          = textBoxLogin.Text,
                     Specialisation = textBoxSpecialisation.Text,
                     GroupName      = textBoxGroup.Text
                 });
                 student.SaveChanges();
                 MessageBox.Show("Student was added");
                 textBoxCourse.Clear();
                 textBoxGroup.Clear();
                 textBoxLogin.Clear();
                 textBoxName.Clear();
                 textBoxPassword.Clear();
                 textBoxSpecialisation.Clear();
             } catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
     else
     {
         MessageBox.Show("Заповніть всі поля");
     }
 }
Example #4
0
        //вибір типу отриманого повідомлення
        void FunctionForSwich(TransferInfo info, string recive, User client)
        {
            switch (info.Type)
            {
            case MessageType.CheckLogIn:
            {
                User   reciveUser = JsonConvert.DeserializeObject <User>(recive);
                string passRecive;
                using (MD5 md5Hash = MD5.Create())
                {
                    passRecive = GetMd5Hash(md5Hash, reciveUser.Password);
                }
                using (ExamVceDB userLogin = new ExamVceDB())
                {
                    var student = userLogin.Students.Where(i => i.Login == reciveUser.Login).FirstOrDefault();

                    char[] login       = student.Login.ToCharArray();
                    var    password    = student.Password.ToCharArray();
                    int    endPosLogin = 0;
                    int    endPosPass  = 0;
                    while (true)
                    {
                        if (login[endPosLogin] == ' ' || endPosLogin > student.Login.Length - 1)
                        {
                            break;
                        }
                        endPosLogin++;
                    }
                    while (true)
                    {
                        if (password[endPosPass] == ' ' || endPosPass > student.Login.Length - 1)
                        {
                            break;
                        }
                        endPosPass++;
                    }
                    string log = new string(login, 0, endPosLogin);

                    string pass = new string(password, 0, endPosPass);


                    bool isCorrectMD5 = false;

                    if (reciveUser.Login.Equals(log) && passRecive.Equals(pass))
                    {
                        client.ID = student.ID;

                        SendAnswer(student.ID.ToString(), client, MessageType.GetAnswer);

                        return;
                    }
                    ;


                    SendAnswer("not correct", client, MessageType.GetAnswer);
                }

                break;
            }

            case MessageType.Test:
            {
                using (ExamVceDB test = new ExamVceDB())
                {
                    try
                    {
                        if (idChooseExam < 0)
                        {
                            new Exception();
                        }
                        SendAnswer(GetTestForSendStudent(idChooseExam), client, MessageType.Test);
                    }
                    catch  { SendAnswer("error xml", client, MessageType.Error); }
                }
                break;
            }

            case MessageType.CheckTestFromStudent:
            {
                MakeTest testFromUser = DeserialiseFromString(recive);
                int      mark         = 0;
                bool     isWriteToDB  = true;
                using (ExamVceDB test = new ExamVceDB())
                {
                    try
                    {
                        var      result      = test.TestDBs.FirstOrDefault(i => i.ID == testFromUser.IdTest);
                        MakeTest correctTest = DeserialiseFromString(result.Test);

                        for (int i = 0; i < correctTest.questions.Count; i++)
                        {
                            for (int j = 0; j < correctTest.questions[i].answers.Count; j++)
                            {
                                if (correctTest.questions[i].answers[j].IsCorrect)
                                {
                                    if (testFromUser.questions[i].answers[j].IsCorrect)
                                    {
                                        mark += correctTest.questions[i].Weight;
                                    }
                                }
                            }
                        }
                        //MessageBox.Show(mark.ToString());
                    }
                    catch
                    {
                        isWriteToDB = false;
                        MessageBox.Show("Test not foudn");
                    }
                }
                if (isWriteToDB)
                {
                    try
                    {
                        using (ExamVceDB passExam = new ExamVceDB())
                        {
                            passExam.PassExams.Add(new PassExam()
                                {
                                    Id_Sender  = loginPerson.ID,
                                    Id_Student = client.ID,
                                    Id_Test    = testFromUser.IdTest,
                                    Mark       = mark,
                                    Date_Pass  = DateTime.Now
                                });
                            passExam.SaveChanges();
                            MessageBox.Show("Test pass writed in DB");
                        }
                    }catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                SendAnswer($"Your mark is: {mark}", client, MessageType.SendMark);
                break;
            }
            }
        }