Beispiel #1
0
        private void addQuestionButton_Click(object sender, EventArgs e)
        {
            if (questionTbox.Text != null && questionTbox.Text != "" && replyTBox.Text != "" && replyTBox.Text != null && categoryTypeCombo.SelectedItem != null && replyTBox1.Text != "" && replyTBox1.Text != null && replyTBox2.Text != "" && replyTBox2.Text != null && replyTBox3.Text != "" && replyTBox3.Text != null && replyTBox4.Text != "" && replyTBox4.Text != null && validationReturn())
            {
                questionName = DateTime.Now.ToString().Trim().Replace(" ", string.Empty).Trim().Replace(":", string.Empty).Trim().Replace("/", string.Empty);
                Classes.questionClass ques = new Classes.questionClass();
                if (oldFileLoc != "")
                {
                    File.Copy(oldFileLoc, @"images\\" + questionName + ".jpg");
                }
                questionTbox.SaveFile(@"question\\" + questionName + ".rtf");
                //soru oluşturma

                question newQuest = new question();
                newQuest.questionText = questionTbox.Text;
                newQuest.questionName = questionName;
                newQuest.reply        = replyTBox.Text;
                newQuest.reply1       = replyTBox1.Text;
                newQuest.reply2       = replyTBox2.Text;
                newQuest.reply3       = replyTBox3.Text;
                newQuest.reply4       = replyTBox4.Text;
                newQuest.categoryID   = (int)categoryTypeCombo.SelectedValue;
                bool ret = quizOP.addQuestion(newQuest);
                if (ret)
                {
                    MessageBox.Show("Sorunuz başarılı bir şekilde eklendi.");
                    qListe();
                    clearForms();
                }
            }
            else
            {
                MessageBox.Show("Lütfen bilgileri doğru ve eksiksiz giriniz.");
            }
        }
        public List <questionClass> getQuestion(string searchType, int catID, int questRate)
        {
            List <questionClass> questions = new List <questionClass>();

            try
            {
                mainConnect();
                MySqlCommand qSearchCommand = new MySqlCommand();
                if (searchType != null)
                {
                    qSearchCommand = new MySqlCommand("Select * from question WHERE categoryID='" + catID + "'" + " ORDER BY RAND() LIMIT " + (questRate * 2).ToString(), mainDatabeseConn);
                }
                else
                {
                    qSearchCommand = new MySqlCommand("Select * from question", mainDatabeseConn);
                }

                MySqlDataReader reader = qSearchCommand.ExecuteReader();
                while (reader.Read())
                {
                    questionClass quest = new questionClass();
                    quest.id       = reader.GetInt32("id");
                    quest.quesText = reader.GetString("questionText").Trim().Replace("\n", " ");
                    quest.quesName = reader.GetString("questionName");
                    quest.reply    = reader.GetString("reply");
                    quest.reply1   = reader.GetString("reply1");
                    quest.reply2   = reader.GetString("reply2");
                    quest.reply3   = reader.GetString("reply3");
                    quest.reply4   = reader.GetString("reply4");
                    quest.cat      = reader.GetInt32("categoryID");
                    questions.Add(quest);
                }
                mainConnect();
            }
            catch (Exception e)
            {
                MessageBox.Show("İşlem sırasında bir hata meydana geldi." + e);
                mainConnect();
            }

            return(questions);
        }