Ejemplo n.º 1
0
 /// <summary> 
 /// 查询集合 
 /// </summary> 
 /// <returns></returns> 
 public IList<ExamQuestion> GetList(String exam_sequence)
 {
     string sql = "SELECT sequence,exam_sequence,questionType,answer,question,option1,option2,option3,option4,option5,option6,option7,option8 FROM tb_exam_question WHERE exam_sequence=@exam_sequence";
     
     using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
     {
         mycn.Open();
         MySqlCommand command = new MySqlCommand(sql, mycn);
         command.Parameters.AddWithValue("@exam_sequence", exam_sequence);
         MySqlDataReader reader = command.ExecuteReader();
         IList<ExamQuestion> list = new List<ExamQuestion>();
         ExamQuestion examQuestion = null;
         while (reader.Read())
         {
             examQuestion = new ExamQuestion();
             examQuestion.sequence = reader["sequence"] == DBNull.Value ? null : reader["sequence"].ToString();
             examQuestion.exam_sequence = reader["exam_sequence"] == DBNull.Value ? null : reader["exam_sequence"].ToString();
             examQuestion.questionType = reader["questionType"] == DBNull.Value ? null : reader["questionType"].ToString();
             examQuestion.answer = reader["answer"] == DBNull.Value ? null : reader["answer"].ToString();
             examQuestion.question = reader["question"] == DBNull.Value ? null : reader["question"].ToString();
             examQuestion.option1 = reader["option1"] == DBNull.Value ? null : reader["option1"].ToString();
             examQuestion.option2 = reader["option2"] == DBNull.Value ? null : reader["option2"].ToString();
             examQuestion.option3 = reader["option3"] == DBNull.Value ? null : reader["option3"].ToString();
             examQuestion.option4 = reader["option4"] == DBNull.Value ? null : reader["option4"].ToString();
             examQuestion.option5 = reader["option5"] == DBNull.Value ? null : reader["option5"].ToString();
             examQuestion.option6 = reader["option6"] == DBNull.Value ? null : reader["option6"].ToString();
             examQuestion.option7 = reader["option7"] == DBNull.Value ? null : reader["option7"].ToString();
             examQuestion.option8 = reader["option8"] == DBNull.Value ? null : reader["option8"].ToString();
             list.Add(examQuestion);
         }
         mycn.Close();
         return list;
     }
 }
Ejemplo n.º 2
0
        public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
        /// <summary> 
        /// 添加数据 
        /// </summary> 
        /// <returns></returns> 
        public int Add(ExamQuestion entity)
        {


            string sql = "INSERT INTO tb_exam_question (exam_sequence,questionType,answer,question,option1,option2,option3,option4,option5,option6,option7,option8)";
            sql = sql + " VALUE (@exam_sequence,@questionType,@answer,@question,@option1,@option2,@option3,@option4,@option5,@option6,@option7,@option8)";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@exam_sequence", entity.exam_sequence);
                command.Parameters.AddWithValue("@questionType", entity.questionType);
                command.Parameters.AddWithValue("@answer", entity.answer);
                command.Parameters.AddWithValue("@question", entity.question);
                command.Parameters.AddWithValue("@option1", entity.option1);
                command.Parameters.AddWithValue("@option2", entity.option2);
                command.Parameters.AddWithValue("@option3", entity.option3);
                command.Parameters.AddWithValue("@option4", entity.option4);
                command.Parameters.AddWithValue("@option5", entity.option5);
                command.Parameters.AddWithValue("@option6", entity.option6);
                command.Parameters.AddWithValue("@option7", entity.option7);
                command.Parameters.AddWithValue("@option8", entity.option8);

                int i = command.ExecuteNonQuery();
                mycn.Close();
                mycn.Dispose();
                return i;
            }
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {

            if (String.IsNullOrEmpty(this.txtExamName.Text.Trim()))
            {
                MessageBox.Show("名称不能为空");
                txtExamName.Focus();
                return;
            }
            if (this.dtEndDate.Value.CompareTo(this.dtStartDate.Value) <= 0)
            {
                MessageBox.Show("有效期结束时间必须大于开始时间");

                return;
            }
            this.Cursor = Cursors.WaitCursor;

            Exam exam = new Exam();
            if (rdoExam.Checked)
            {
                exam.type = "Exam";
            }
            if (rdoSurvey.Checked)
            {
                exam.type = "Survey";
            }
            if (String.IsNullOrEmpty(exam.type))
            {
                MessageBox.Show("请选择试题类型");

                return;
            }
            exam.subject = this.txtExamName.Text;
            //exam.type = "Exam";
            exam.validateStartTime = this.dtStartDate.Value.ToString("yyyy-MM-dd");
            exam.validateEndTime = this.dtEndDate.Value.ToString("yyyy-MM-dd");
            exam.creatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");            
            exam.isValidate = "Y";
            exam.agentType = this.cboAgentType.Text;

            ExamDao examDao = new ExamDao();
            examDao.Add(exam);

            exam = examDao.GetByName(exam.subject);
            if (exam != null)
            {
                ExamQuestionDao examQuestionDao = new ExamQuestionDao();

                for (int i = 0; i < this.dgExamSingleChoice.RowCount; i++)
                {
                    ExamQuestion examQuestion = new ExamQuestion();
                    examQuestion.question = dgExamSingleChoice[0, i].Value.ToString();
                    examQuestion.answer = dgExamSingleChoice[1, i].Value.ToString();
                    examQuestion.option1 = dgExamSingleChoice[2, i].Value.ToString();
                    examQuestion.option2 = dgExamSingleChoice[3, i].Value.ToString();
                    examQuestion.option3 = dgExamSingleChoice[4, i].Value.ToString();
                    examQuestion.option4 = dgExamSingleChoice[5, i].Value.ToString();
                    examQuestion.option5 = dgExamSingleChoice[6, i].Value.ToString();
                    examQuestion.option6 = dgExamSingleChoice[7, i].Value.ToString();
                    examQuestion.option7 = dgExamSingleChoice[8, i].Value.ToString();
                   // examQuestion.option8 = dgExamSingleChoice[9, i].Value.ToString();
                    examQuestion.questionType = "Single";
                    examQuestion.exam_sequence = exam.sequence;
                    examQuestionDao.Add(examQuestion);

                }

                for (int i = 0; i < this.dgExamMultiChoice.RowCount; i++)
                {
                    ExamQuestion examQuestion = new ExamQuestion();
                    examQuestion.question = dgExamMultiChoice[0, i].Value.ToString();
                    examQuestion.answer = dgExamMultiChoice[1, i].Value.ToString();
                    examQuestion.option1 = dgExamMultiChoice[2, i].Value.ToString();
                    examQuestion.option2 = dgExamMultiChoice[3, i].Value.ToString();
                    examQuestion.option3 = dgExamMultiChoice[4, i].Value.ToString();
                    examQuestion.option4 = dgExamMultiChoice[5, i].Value.ToString();
                    examQuestion.option5 = dgExamMultiChoice[6, i].Value.ToString();
                    examQuestion.option6 = dgExamMultiChoice[7, i].Value.ToString();
                    examQuestion.option7 = dgExamMultiChoice[8, i].Value.ToString();
                  //  examQuestion.option8 = dgExamMultiChoice[9, i].Value.ToString();
                    examQuestion.questionType = "Multi";
                    examQuestion.exam_sequence = exam.sequence;
                    examQuestionDao.Add(examQuestion);

                }

                for (int i = 0; i < this.dgExamJugement.RowCount; i++)
                {
                    ExamQuestion examQuestion = new ExamQuestion();
                    examQuestion.question = dgExamJugement[0, i].Value.ToString();
                    examQuestion.answer = dgExamJugement[1, i].Value.ToString();
                    examQuestion.exam_sequence = exam.sequence;

                    examQuestion.questionType = "Jugement";

                    examQuestionDao.Add(examQuestion);

                }

                ExamReceiverDao examReceiverDao = new ChinaUnion_DataAccess.ExamReceiverDao();
                examReceiverDao.Delete(exam.sequence);


                for (int i = 0; i < lstAgentType.Items.Count; i++)
                {
                    if (lstAgentType.GetItemChecked(i))
                    {
                        ExamReceiver examReceiver = new ExamReceiver();
                        examReceiver.examSequence = exam.sequence;
                        examReceiver.receiver = lstAgentType.Items[i].ToString();
                        examReceiver.type = "渠道类型";
                        examReceiverDao.Add(examReceiver);
                    }
                }


                for (int i = 0; i < lstGroup.Items.Count; i++)
                {
                    if (lstGroup.GetItemChecked(i))
                    {
                        ExamReceiver examReceiver = new ExamReceiver();
                        examReceiver.examSequence = exam.sequence;
                        examReceiver.receiver = lstGroup.Items[i].ToString();
                        examReceiver.type = "自定义组";
                        examReceiverDao.Add(examReceiver);
                    }
                }
            }



            MessageBox.Show("操作完毕");

            this.Cursor = Cursors.Default;
        }
Ejemplo n.º 4
0
        /// <summary> 
        /// 查询集合 
        /// </summary> 
        /// <returns></returns> 
        public IList<ExamQuestion> GetUserExamQuestion(String exam_sequence, String userId)
        {
            string sql = "SELECT t1.sequence,t1.exam_sequence,t1.questionType,t1.answer as standardAnswer,t2.answer as userAnswer,question,option1,option2,option3,option4,option5,option6,option7,option8 FROM tb_exam_question t1 left join tb_agent_exam_score t2 ";
            sql = sql + " on t1.sequence = t2.question_sequence and t1.exam_sequence=t2.exam_sequence where t1.exam_sequence=@exam_sequence and t2.userId = @userId";

            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@exam_sequence", exam_sequence);
                command.Parameters.AddWithValue("@userId", userId);
                MySqlDataReader reader = command.ExecuteReader();
                IList<ExamQuestion> list = new List<ExamQuestion>();
                ExamQuestion examQuestion = null;
                while (reader.Read())
                {
                    examQuestion = new ExamQuestion();
                    examQuestion.sequence = reader["sequence"] == DBNull.Value ? null : reader["sequence"].ToString();
                    examQuestion.exam_sequence = reader["exam_sequence"] == DBNull.Value ? null : reader["exam_sequence"].ToString();
                    examQuestion.questionType = reader["questionType"] == DBNull.Value ? null : reader["questionType"].ToString();
                    examQuestion.answer = reader["userAnswer"] == DBNull.Value ? null : reader["userAnswer"].ToString();
                    examQuestion.standardAnswer = reader["standardAnswer"] == DBNull.Value ? null : reader["standardAnswer"].ToString();
                    examQuestion.question = reader["question"] == DBNull.Value ? null : reader["question"].ToString();
                    examQuestion.option1 = reader["option1"] == DBNull.Value ? null : reader["option1"].ToString();
                    examQuestion.option2 = reader["option2"] == DBNull.Value ? null : reader["option2"].ToString();
                    examQuestion.option3 = reader["option3"] == DBNull.Value ? null : reader["option3"].ToString();
                    examQuestion.option4 = reader["option4"] == DBNull.Value ? null : reader["option4"].ToString();
                    examQuestion.option5 = reader["option5"] == DBNull.Value ? null : reader["option5"].ToString();
                    examQuestion.option6 = reader["option6"] == DBNull.Value ? null : reader["option6"].ToString();
                    examQuestion.option7 = reader["option7"] == DBNull.Value ? null : reader["option7"].ToString();
                    examQuestion.option8 = reader["option8"] == DBNull.Value ? null : reader["option8"].ToString();
                    list.Add(examQuestion);
                }
                mycn.Close();
                return list;
            }
        }