Example #1
0
 /// <summary> 
 /// 删除数据 
 /// </summary> 
 /// <param name="entity"></param> 
 /// <returns></returns> 
 public int Delete(ExamReceiver entity)
 {
     string sql = "DELETE FROM tb_exam_receiver WHERE exam_sequence=@exam_sequence and receiver=@receiver and type=@type";
     using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
     {
         mycn.Open();
         MySqlCommand command = new MySqlCommand(sql, mycn);
         command.Parameters.AddWithValue("@exam_sequence", entity.examSequence);
         command.Parameters.AddWithValue("@receiver", entity.receiver);
         command.Parameters.AddWithValue("@type", entity.type);
         int i = command.ExecuteNonQuery();
         mycn.Close();
         mycn.Dispose();
         return i;
     }
 }
Example #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(ExamReceiver entity)
 {
     string sql = "INSERT INTO tb_exam_receiver (exam_sequence,receiver,type) VALUE (@exam_sequence,@receiver,@type)";
     using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
     {
         mycn.Open();
         MySqlCommand command = new MySqlCommand(sql, mycn);
         command.Parameters.AddWithValue("@exam_sequence", entity.examSequence);
         command.Parameters.AddWithValue("@receiver", entity.receiver);
         command.Parameters.AddWithValue("@type", entity.type);
         int i = command.ExecuteNonQuery();
         mycn.Close();
         mycn.Dispose();
         return i;
     }
 }
Example #3
0
        /// <summary> 
        /// 修改数据 
        /// </summary> 
        /// <param name="entity"></param> 
        /// <returns></returns> 
        public int Update(ExamReceiver entity)
        {
            string sql = "UPDATE  tb_exam_receiver SET exam_sequence=@exam_sequence,receiver=@receiver where exam_sequence=@exam_sequence  and type=@type";

            //string sql = "UPDATE cimuser SET userNickName=@userNickName WHERE userid=@userid";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@exam_sequence", entity.examSequence);
                command.Parameters.AddWithValue("@receiver", entity.receiver);
                command.Parameters.AddWithValue("@type", entity.type);
                int i = command.ExecuteNonQuery();
                mycn.Close();
                mycn.Dispose();
                return i;
            }
        }
Example #4
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;
        }
Example #5
0
        /// <summary> 
        /// 根据主键查询 
        /// </summary> 
        /// <param name="primaryKey"></param> 
        /// <returns></returns> 
        //public Agent Get(int primaryKey)
        //{
        //    string sql = "SELECT userid,userNickName FROM cimuser where userid=@userid";
        //    using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
        //    {
        //        mycn.Open();
        //        MySqlCommand command = new MySqlCommand(sql, mycn);
        //        command.Parameters.AddWithValue("@userid", primaryKey);
        //        MySqlDataReader reader = command.ExecuteReader();
        //        Agent userBase = null;
        //        if (reader.Read())
        //        {
        //            userBase = new Agent();
        //            userBase.UserId = Convert.ToInt32(reader["userid"]);
        //            userBase.UserNickName = reader["userNickName"] == DBNull.Value ? null : reader["userNickName"].ToString();
        //        }
        //        return userBase;
        //    }
        //}
        /// <summary> 
        /// 查询集合 
        /// </summary> 
        /// <returns></returns> 
        public IList<ExamReceiver> GetList(String examSequence)
        {
            string sql = "SELECT exam_sequence,receiver,type FROM tb_exam_receiver where exam_Sequence=@exam_Sequence";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@exam_Sequence", examSequence);
                MySqlDataReader reader = command.ExecuteReader();
                IList<ExamReceiver> list = new List<ExamReceiver>();
                ExamReceiver examReceiver = null;
                while (reader.Read())
                {
                    examReceiver = new ExamReceiver();

                    examReceiver.examSequence = reader["exam_sequence"] == DBNull.Value ? null : reader["exam_sequence"].ToString();
                    examReceiver.receiver = reader["receiver"] == DBNull.Value ? null : reader["receiver"].ToString();
                    examReceiver.type = reader["type"] == DBNull.Value ? null : reader["type"].ToString();

                    list.Add(examReceiver);
                }
                mycn.Close();
                return list;
            }
        }