Beispiel #1
0
        private void Exam_Load(object sender, EventArgs e)
        {
            List <Question> lastQuestions = new List <Question>();;
            var             rnd           = new Random();
            List <Question> questions     = new List <Question>();

            MessageBox.Show("Sınav süresi 60 dakika başarılar");
            timer1.Start();
            ExamEntities  db      = new ExamEntities();
            List <Choice> choices = new List <Choice>();
            var           questionsAnsweredByMe = db.Answers.Where(x => x.UserId == ObjectPasser.UserLoggedIn.Id).Select(y => y.QuestionId).ToList();
            var           _availableQuestions   = db.Questions.Where(x => !questionsAnsweredByMe.Contains(x.Id)).ToList();

            if (db.VW_UserFalseCountByCategory.Where(x => x.UserId == ObjectPasser.UserLoggedIn.Id).OrderByDescending(y => y.FalseCount).Take(1).FirstOrDefault() != null)
            {
                int             catId      = db.VW_UserFalseCountByCategory.Where(x => x.UserId == ObjectPasser.UserLoggedIn.Id).OrderByDescending(y => y.FalseCount).Take(1).FirstOrDefault().CategoryId;
                List <Question> secondhalf = _availableQuestions.Where(x => x.CatId == catId).Take(4).ToList();
                var             Firsthalf  = _availableQuestions.Where(x => x.CatId != catId).Take(8 - (secondhalf.Count)).ToList();
                lastQuestions = Firsthalf.Concat(secondhalf).ToList();
            }
            lastQuestions = _availableQuestions;


            lastQuestions = lastQuestions.OrderBy(item => rnd.Next()).ToList();

            lblQuestion.Text          = lastQuestions[0].Question1;
            rbAns1.Text               = lastQuestions[0].Choices.ElementAt(0).Choice1;
            rbAns2.Text               = lastQuestions[0].Choices.ElementAt(1).Choice1;
            rbAns3.Text               = lastQuestions[0].Choices.ElementAt(2).Choice1;
            rbAns4.Text               = lastQuestions[0].Choices.ElementAt(3).Choice1;
            ObjectPasser.QuestionList = lastQuestions;
        }
Beispiel #2
0
        private void QuestinAdd_Load(object sender, EventArgs e)
        {
            using (ExamEntities db = new ExamEntities())
            {
                foreach (var item in db.Catagories)
                {
                    cbCatagory.Items.Add(item.Name.ToString());
                }

                if (ObjectPasser.Question != null)
                {
                    List <Choice> choices = new List <Choice>();
                    Catagory      cat     = new Catagory();
                    choices = db.Choices.Where(x => x.QuestionId == ObjectPasser.Question.Id).OrderByDescending(x => x.IsCorrect).ToList();
                    if (choices.Count != 0)
                    {
                        txtChoice1.Text = choices[0].Choice1;
                        txtChoice2.Text = choices[1].Choice1;
                        txtChoice3.Text = choices[2].Choice1;
                        txtChoice4.Text = choices[3].Choice1;
                    }
                    txtQuestion.Text = ObjectPasser.Question.Question1;
                }
            }
        }
Beispiel #3
0
        public static int GetInside(string username, string password)
        {
            int          usertype = -1;
            ExamEntities db       = new ExamEntities();


            var user = db.Users.Where(x => x.Username == username).FirstOrDefault();

            if (user != null)
            {
                if (user.Password == password)
                {
                    ObjectPasser.UserLoggedIn = user;
                    usertype = user.UserType;
                }
                else
                {
                    System.Windows.MessageBox.Show("Geçersiz şifre");
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Yanlış kullanıcı adı veya şifre girdiniz");
            }

            return(usertype);
        }
Beispiel #4
0
 public AdminPanel()
 {
     InitializeComponent();
     using (ExamEntities db = new ExamEntities())
     {
         dgwQuestions.DataSource = (from em in db.Questions
                                    select new { em.Id, em.Question1, em.CatId }).ToList();
         dgwUsers.DataSource = (from em in db.Users
                                select new { em.Id, em.Username, em.UserType }).ToList();
     }
 }
Beispiel #5
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;
            }
        }
Beispiel #6
0
        public Statistics()
        {
            InitializeComponent();
            ExamEntities db = new ExamEntities();

            var seriesArray = db.VW_UserFalseCountByCategory.Where(x => x.UserId == ObjectPasser.UserLoggedIn.Id).Select(x => x.Category).ToList();
            var pointsArray = db.VW_UserFalseCountByCategory.Where(x => x.UserId == ObjectPasser.UserLoggedIn.Id).Select(x => x.FalseCount).ToList();

            Series series = this.testChart.Series.Add("İstatistik");

            series.ChartType = SeriesChartType.Pie;


            for (int i = 0; i < seriesArray.Count; i++)
            {
                series.Points.AddXY(seriesArray[i], Convert.ToInt32(pointsArray[i]));
            }
        }
Beispiel #7
0
 private void btnQuestionUpdate_Click(object sender, EventArgs e)
 {
     using (ExamEntities db = new ExamEntities())
     {
         if (dgwQuestions.SelectedCells.Count > 0)
         {
             this.Hide();
             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();
             ObjectPasser.Question = question;
             QuestionAdd qa = new QuestionAdd();
             qa.Show();
         }
     }
 }
Beispiel #8
0
 private void btnUserUpdate_Click(object sender, EventArgs e)
 {
     using (ExamEntities db = new ExamEntities())
     {
         if (dgwUsers.SelectedCells.Count > 0)
         {
             this.Hide();
             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();
             ObjectPasser.User = user;
             UserAdd ua = new UserAdd();
             ua.Show();
         }
     }
 }
Beispiel #9
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();
                }
            }
        }
Beispiel #10
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));
        }
Beispiel #11
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");
                }
            }
        }
Beispiel #12
0
        private void Login_Click(object sender, EventArgs e)
        {
            using (ExamEntities db = new ExamEntities())
            {
                switch (GetIn.GetInside(txtUserName.Text, txtPassword.Text))
                {
                case 0:
                {
                    //TODO: Admin Login
                    this.Hide();
                    AdminPanel ap = new AdminPanel();
                    ap.Show();
                    break;
                }

                case 1:
                {
                    //TODO: Teacher Login
                    this.Hide();
                    QuestionAdd qa = new QuestionAdd();
                    qa.Show();
                    break;
                }

                case 2:
                {
                    //TODO: Student Login
                    this.Hide();
                    StudentPanel sp = new StudentPanel();
                    sp.Show();
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
Beispiel #13
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));
        }