예제 #1
0
        public List<Question> findQuestion(string usernameF,Subject subject, Department department)
        {
            logger.Debug("findQuestion()");

            List<Question> questionList = new List<Question>();
            string query = "";

            if(usernameF != "all")
                query = "select Q.id as question_id,Q.question,Q.create_date,A.id as user_id,Q.level_range,A.username from question Q " +
                           "inner join account A on A.id = Q.account_id " +
                           "inner join subject_department SD on Q.subject_department_id = SD.id where SD.subject_id = " + subject.Id + " and SD.department_id = " + department.Id + " and A.username = '******'; ";
            else
                query = "select Q.id as question_id,Q.question,Q.create_date,A.id as user_id,Q.level_range,A.username from question Q " +
                          "inner join account A on A.id = Q.account_id " +
                          "inner join subject_department SD on Q.subject_department_id = SD.id where SD.subject_id = " + subject.Id + " and SD.department_id = " + department.Id + " ; ";

            MysqlConnector mysql = new MysqlConnector(CurrentUserInfo.USERNAME,
               CurrentUserInfo.PASSWORD,
               CurrentUserInfo.HOSTNAME,
               CurrentUserInfo.PORT,
               CurrentUserInfo.DATABASE);

            mysql.initializeConnection();
            mysql.openMysqlConnection();

            //Question Fields
            int question_id;
            string question_descr;
            int level_question;
            DateTime date_question;

            //Account Fields
            int account_id;
            string username;

            //Questions
            using (MySqlCommand cmd = new MySqlCommand(query, mysql.MysqlConnection))
            {
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            question_id = reader.GetInt32(0);
                            question_descr = reader.GetString(1);
                            date_question = reader.GetDateTime(2).Date;

                            Debug.Write("NOWWWWWWWWWW");
                            Debug.Write(date_question.ToString("MM/dd/yyyy"));

                            account_id = reader.GetInt32(3);
                            level_question = reader.GetInt32(4);
                            username = reader.GetString(5);

                            questionList.Add(new Question() { Id = question_id, Question_descr = question_descr, Account = new Account() { Username = username }, Subject = subject, Department = department, Level = level_question, Date = date_question });
                        }
                    }
                } // reader closed and disposed up here

            } // command disposed here
            mysql.closeMysqlConnection();

            //Answer of Above Questions

            if (questionList.Any())
            {
                mysql.openMysqlConnection();
                setAnsersForIndividualQuestion(questionList, mysql);
                mysql.closeMysqlConnection();
            }

            //Debug
            foreach (Question question in questionList)
            {
                Debug.WriteLine(question.Question_descr);
                foreach (Answer answer in question.AnswerList)
                    Debug.WriteLine(answer.Answer_descr);
            }

            return questionList;
        }
예제 #2
0
        private List<Question> loadQuestionData(string username, Subject subject, Department department)
        {
            List<Question> questionList;
            IQuestionDao questionDao = new QuestionDaoImpl();

            questionList = questionDao.findQuestion(username, subject, department);

            return questionList;
        }
예제 #3
0
 public List<Question> findQuestion(Account account, Subject subject, Department department)
 {
     throw new NotImplementedException();
 }