Пример #1
0
        private void btnNextQuestion_Click(object sender, EventArgs e)
        {
            ExamEntities db = new ExamEntities();

            Answer answer = new Answer();

            answer.QuestionId = ObjectPasser.QuestionList[nextClick].Id;
            answer.UserId     = ObjectPasser.UserLoggedIn.Id;
            Choice choice = new Choice();

            if (rbAns1.Checked)
            {
                answer.ChoiceId = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(0).Id;
            }
            else if (rbAns2.Checked)
            {
                answer.ChoiceId = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(1).Id;
            }
            else if (rbAns3.Checked)
            {
                answer.ChoiceId = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(2).Id;
            }
            else if (rbAns4.Checked)
            {
                answer.ChoiceId = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(3).Id;
            }

            db.Answers.Add(answer);
            db.SaveChanges();
            nextClick++;
            if (nextClick == 7 && ObjectPasser.QuestionList[nextClick] == null)
            {
                MessageBox.Show("Testi bitirdiniz Tebrikler");
                this.Close();
                StudentPanel i = new StudentPanel();
                i.Show();
                ObjectPasser.QuestionList = null;
            }
            else if (ObjectPasser.QuestionList.Count > nextClick)
            {
                lblQuestion.Text = ObjectPasser.QuestionList[nextClick].Question1;
                rbAns1.Text      = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(0).Choice1;
                rbAns2.Text      = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(1).Choice1;
                rbAns3.Text      = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(2).Choice1;
                rbAns4.Text      = ObjectPasser.QuestionList[nextClick].Choices.ElementAt(3).Choice1;
            }
        }
Пример #2
0
        private void btnUserDelete_Click(object sender, EventArgs e)
        {
            using (ExamEntities db = new ExamEntities())
            {
                if (dgwUsers.SelectedCells.Count > 0)
                {
                    User            user             = new User();
                    int             selectedrowindex = dgwUsers.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow      = dgwUsers.Rows[selectedrowindex];
                    int             id = Convert.ToInt32(Convert.ToString(selectedRow.Cells["Id"].Value));
                    user = db.Users.Where(x => x.Id == id).FirstOrDefault();

                    db.Users.Remove(user);
                    db.SaveChanges();
                    dgwUsers.DataSource = (from em in db.Users
                                           select new { em.Id, em.Username, em.UserType }).ToList();
                }
            }
        }
Пример #3
0
        public static bool AddOrUpdateQuestion(string questiontext, string cata, string trueAns, string ans2, string ans3, string ans4)
        {
            ExamEntities db = new ExamEntities();

            Random   rnd      = new Random();
            Question question = new Question();

            List <Choice> choices = new List <Choice>();
            Choice        choice1 = new Choice();
            Choice        choice2 = new Choice();
            Choice        choice3 = new Choice();
            Choice        choice4 = new Choice();

            question.Question1 = questiontext;
            question.CatId     = db.Catagories.Where(x => x.Name == cata).FirstOrDefault().Id;
            db.Questions.Add(question);

            choice1.Choice1   = trueAns;
            choice1.IsCorrect = true;
            choices.Add(choice1);

            choice2.Choice1 = ans2;
            choices.Add(choice2);

            choice3.Choice1 = ans3;
            choices.Add(choice3);

            choice4.Choice1 = ans4;
            choices.Add(choice4);

            choices = choices.OrderBy(item => rnd.Next()).ToList();
            foreach (var item in choices)
            {
                item.QuestionId = question.Id;
                db.Choices.AddOrUpdate(item);
            }
            int i = db.SaveChanges();

            System.Windows.MessageBox.Show("Soru kaydedildi");

            return(Convert.ToBoolean(i));
        }
Пример #4
0
        private void btnQuestionDelete_Click(object sender, EventArgs e)
        {
            using (ExamEntities db = new ExamEntities())
            {
                if (dgwQuestions.SelectedCells.Count > 0)
                {
                    Question        question         = new Question();
                    int             selectedrowindex = dgwQuestions.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow      = dgwQuestions.Rows[selectedrowindex];
                    int             id = Convert.ToInt32(Convert.ToString(selectedRow.Cells["Id"].Value));
                    question = db.Questions.Where(x => x.Id == id).FirstOrDefault();

                    db.Questions.Remove(question);
                    db.SaveChanges();
                    dgwQuestions.DataSource = (from em in db.Questions
                                               select new { em.Id, em.Question1, em.CatId }).ToList();
                    MessageBox.Show("Soru başarıyla silindi");
                }
            }
        }
Пример #5
0
        public static bool AddOrUpdateUser(string username, string password, string usertype)
        {
            ExamEntities db = new ExamEntities();

            User user = new User();

            user.Username = username;
            user.Password = password;
            if (usertype == "Ogrenci")
            {
                user.UserType = 2;
            }
            else
            {
                user.UserType = 1;
            }
            db.Users.AddOrUpdate(user);
            int i = db.SaveChanges();

            System.Windows.MessageBox.Show("Kullanıcı kaydedildi");

            return(Convert.ToBoolean(i));
        }