예제 #1
0
        public void ShowQuestion(Question question)
        {
            questionText.Text = question.Text;
                for (int i = 1; i <= answerPickers.Count(); i++)
                    answerPickers[i].Text = question.Answers[i];

                if (question is GraphicQuestion)
                {
                    // do some image data handling. NYI
                    questionImage.Image = ((GraphicQuestion)question).Image;
                    questionImage.Visible = true;
                }
                else
                {
                    questionImage.Visible = false;
                }
        }
예제 #2
0
파일: Admin.cs 프로젝트: alex67x/RomGeo
        private void button2_Click(object sender, EventArgs e)
        {
            String file = openFileDialog1.FileName;
            String text = richTextBox1.Text;
            String domainname = null;
            bool isGraphic = checkBox1.Checked;
            Domain domain = 0;
            Answers answers = new Answers();
            answers[1] = textBox1.Text;
            answers[2] = textBox2.Text;
            answers[3] = textBox3.Text;
            answers[4] = textBox4.Text;

            switch (comboBox1.SelectedIndex)
            {
                case 0: answers.CorrectAnswer = textBox1.Text;
                    break;
                case 1: answers.CorrectAnswer = textBox2.Text;
                    break;
                case 2: answers.CorrectAnswer = textBox3.Text;
                    break;
                case 3: answers.CorrectAnswer = textBox4.Text;
                    break;
                default:
                    answers.CorrectAnswer = textBox1.Text;
                    break;
            }

            foreach (Control c in this.Controls)
                if (c is RadioButton) if (((RadioButton)c).Checked == true) domainname = ((RadioButton)c).Text;

            switch (domainname)
            {
                case "hidro":
                    domain = Domain.Hidrografie;
                    break;
                case "rel":
                    domain = Domain.Relief;
                    break;
                case "res":
                    domain = Domain.Resurse;
                    break;
                case "admin":
                    domain = Domain.Administrativ;
                    break;
                default:
                    domain = Domain.None;
                    break;
            }

            Question question = new Question(0, text, domain, 0, answers);
            if (!String.IsNullOrEmpty(richTextBox1.Text) &&
                !String.IsNullOrEmpty(textBox1.Text) &&
                !String.IsNullOrEmpty(textBox2.Text) &&
                !String.IsNullOrEmpty(textBox3.Text) &&
                !String.IsNullOrEmpty(textBox4.Text))
            {
                if (isGraphic)
                    DatabaseAbstractionLayer.DAL.UploadQuestion(question, isGraphic, file);
                else DatabaseAbstractionLayer.DAL.UploadQuestion(question);
                MessageBox.Show("Intrebare adaugata!");
                this.Close();
            }
            else MessageBox.Show("Toate campurile trebuie completate!");
        }
예제 #3
0
파일: DAL.cs 프로젝트: poseamaria/RomGeo
        public static void MarkQueried(User user, Question question)
        {
            if (OpenConnection() == true)
            {
                // Create command and assign the query and connection from the constructor
                try
                {
                    using (var command = new MySqlCommand("MarkQueried", connection) { CommandType = CommandType.StoredProcedure })
                    {
                        command.Parameters.AddWithValue("@user", user);
                        command.Parameters.AddWithValue("@idQ", question.Id);
                        if (command.ExecuteNonQuery() > 0)
                        {
                            Debug.Log("Question " + question.Id + " marked as queried");
                        }
                    }
                }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
            }
        }
예제 #4
0
파일: DAL.cs 프로젝트: poseamaria/RomGeo
        // Added for question uploader (admin)
        public static void UploadQuestion(Question question, bool isGraphic=false, String fileName=null)
        {
            if (OpenConnection() == true)
            {
                try
                {
                    using (var command = new MySqlCommand("UploadQuestion", connection) { CommandType = CommandType.StoredProcedure })
                    {
                        if (fileName != null && fileName != "openFileDialog1")
                        {
                            Debug.Log(fileName);
                            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                            BinaryReader reader = new BinaryReader(fs);
                            byte[] imgData = reader.ReadBytes((int)fs.Length);

                            MySqlParameter mParm = new MySqlParameter("@data", MySqlDbType.LongBlob);
                            mParm.Size = imgData.Length;
                            mParm.Value = imgData;

                            command.Parameters.Add(mParm);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@data", null);
                        }

                        command.Parameters.AddWithValue("@text", question.Text);
                        command.Parameters.AddWithValue("@answer1", question.Answers[1]);
                        command.Parameters.AddWithValue("@answer2", question.Answers[2]);
                        command.Parameters.AddWithValue("@answer3", question.Answers[3]);
                        command.Parameters.AddWithValue("@answer4", question.Answers[4]);
                        command.Parameters.AddWithValue("@correctAnswer", question.CorrectAnswer);
                        command.Parameters.AddWithValue("@domain", Utils.Converters.DomainToString(question.Domain));
                        command.Parameters.AddWithValue("@graphic",isGraphic?1:0);

                        if (command.ExecuteNonQuery() > 0) Debug.Log("Question uploaded!");
                    }
                }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
            }
        }
예제 #5
0
파일: DAL.cs 프로젝트: poseamaria/RomGeo
        public static OneBasedArray<Question> GetQuestions()
        {
            OneBasedArray<Question> questionList = new OneBasedArray<Question>(30);
            int id = 0;
            int difficultyPercent = 0;
            bool isGraphic = false;
            string text = string.Empty;
            Domain domain = Domain.None;
            byte[] imageData;
            Image image = null;

            // Open connection
            if (OpenConnection() == true)
            {
                // Create command and assign the query and connection from the constructor
                try
                {
                        using (var command = new MySqlCommand("GetQuestions", connection) { CommandType = CommandType.StoredProcedure })
                        {
                            command.Parameters.AddWithValue("@user", PersistentData.user);
                            int j = 1;

                            MySqlDataReader myReader = command.ExecuteReader();
                            while (myReader.Read())
                            {
                                id = myReader.GetInt32(0);
                                text = myReader.GetString(1);
                                domain = myReader.GetDomain(2);
                                difficultyPercent = myReader.GetInt32(3);
                                isGraphic = myReader.GetBoolean(4);

                                if (isGraphic)
                                    imageData = (byte[])myReader[5];
                                else imageData = null;
                                image = Utils.Converters.ByteArrayToImage(imageData);
                                Answers answers = new Answers();
                                answers.CorrectAnswer = myReader.GetString(6);

                                int i = 1;
                                while (i <= PersistentData.MAX_ANSWERS)
                                {
                                    answers[i] = myReader.GetString(6 + i);
                                    i++;
                                }

                                if (!isGraphic)
                                    questionList[j] = new Question(id, text, domain, difficultyPercent, answers);
                                else
                                    questionList[j] = new GraphicQuestion(id, text, image, domain, difficultyPercent, answers);
                                j++;
                            }
                        }
                    }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
            }
            else Debug.ExitWithErrorMessage("Connection failed to open using DAL method.");
            return questionList;
        }