예제 #1
0
 //Если пользователя с данным логином нет в базе - предлагается его создать
 // Если данный логин есть в базе, но под другим паролем, выводится сообщение об ошибке
 private void button1_Click(object sender, EventArgs e)
 {
     using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext())
     {
         var users = db.Users.Where(i => i.Name == textBox1.Text && i.Password == textBox2.Text).FirstOrDefault();
         if (users != null)
         {
             form.UserId = users.Id;
         }
         else
         {
             var users2 = db.Users.Where(i => i.Name == textBox1.Text && i.Password != textBox2.Text).FirstOrDefault();
             if (users2 != null)
             {
                 MessageBox.Show("Пароль пользователя введен неверно");
                 return;
             }
             else
             {
                 DialogResult result = MessageBox.Show("Вы хотите создать нового пользователя?", "Создание нового пользователя", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if (result == DialogResult.Yes)
                 {
                     TestAppLibrary.User user = new TestAppLibrary.User {
                         Name = textBox1.Text, Password = textBox2.Text
                     };
                     db.Users.Add(user);
                     db.SaveChanges();
                 }
                 return;
             }
         }
     }
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
예제 #2
0
 //При загрузке формы, создается коллекция вопросов, связанная с данным экзаменом и выводится первый вопрос на форму
 private void FormUserAnswer_Load(object sender, EventArgs e)
 {
     try
     {
         using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext())
         {
             q    = db.Questions.Where(i => i.Exam.Id == idExam).ToList();
             ex   = db.Exams.Where(i => i.Id == idExam).FirstOrDefault();
             user = db.Users.Where(i => i.Id == idUser).FirstOrDefault();
             TestAppLibrary.Question quest = q[count++];
             textBox1.Text = quest.Challenge;
             Control ctrl;
             textBox1.ReadOnly = true;
             table             = new TableLayoutPanel();
             table.Parent      = splitContainer2.Panel1;
             table.Dock        = DockStyle.Fill;
             table.ColumnCount = 2;
             table.Padding     = new Padding(20, 10, 10, 20);
             table.AutoScroll  = true;
             int k = 0;
             ans = db.Answers.Where(i => i.Question.Id == quest.Id).ToList();
             for (int j = 0; j < quest.AnswersNumber && j < ans.Count; j++)
             {
                 if (quest.MultiChoice == false)
                 {
                     ctrl = new RadioButton();
                 }
                 else
                 {
                     ctrl = new CheckBox();
                 }
                 ctrl.Parent = table;
                 TextBox t = new TextBox();
                 t.Parent    = table;
                 t.Multiline = true;
                 t.WordWrap  = true;
                 t.Size      = new Size {
                     Width = 250, Height = 50
                 };
                 t.Text = ans[k++].Challenge;
             }
             table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20));
             //Инициализация и запуск таймера
             t          = new Timer();
             t.Interval = 1000;
             t.Tick    += OnTimer;
             time       = new TimeSpan(ex.TimeToPass / 60, ex.TimeToPass % 60, 0);
             t.Start();
         }
     }
     catch (Exception e1)
     {
         MessageBox.Show(e1.Message);
     }
 }
예제 #3
0
 private void FormTestPass_Load(object sender, EventArgs e)
 {
     using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext())
     {
         q    = db.Questions.Where(i => i.Exam.Id == idExam).ToList();
         ex   = db.Exams.Where(i => i.Id == idExam).FirstOrDefault();
         user = db.Users.Where(i => i.Id == idUser).FirstOrDefault();
     }
     textBox1.Text = ex.Name;
     textBox2.Text = ex.QuestionNumber.ToString();
     textBox3.Text = new TimeSpan(ex.TimeToPass / 60, ex.TimeToPass % 60, 0).ToString();
 }