コード例 #1
0
        private static TreeNode ClassToTreeNode(Class cl)
        {
            TreeNode node = new TreeNode(cl.name);
            foreach (Questions qs in cl.questions)
                node.Nodes.Add(SectionToTreeNode(qs));

            return node;
        }
コード例 #2
0
        /// <summary>
        /// Adds the Class to the database.
        /// </summary>
        /// <param name="c">The Class you want to add.</param>
        /// <param name="omitQuestionSets">Whether you want to add the Questions sets too.</param>
        /// <param name="omitQuestions">Whether you want to add the Question objects too.</param>
        public static void AddClass(Class c, bool omitQuestionSets = false, bool omitQuestions = false)
        {
            string text = "insert into dbo.Class values ('" + c.Id + "', '" + c.name + "');";
            StudyToolSql.RunSql(text);

            if (!omitQuestionSets)
                c.questions.ForEach(qs => StudyToolSql.AddQuestionSet(qs, c.Id, omitQuestions));
        }
コード例 #3
0
        public EditQuestionForm(Class c)
        {
            InitializeComponent();

            this.Canceled = true;
            this.c = c;

            this.treeViewQuestions.Nodes.Add(ClassToTreeNode(this.c));
            this.treeViewQuestions.ExpandAll();

            this.groupBoxEditor.Enabled = false;
            this.buttonAddQuestion.Enabled = false;
        }
コード例 #4
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (openFileDialogImport.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    this.filepath = openFileDialogImport.FileName;
                    Class c = new Class(this.filepath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error While Importing File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
                return;

            this.Close();
        }
コード例 #5
0
        private void buttonCreate_Click(object sender, EventArgs e)
        {
            CreateClass cc = new CreateClass();
            cc.ShowDialog();
            string[] splits = cc.filepath.Split('\\');
            string name = splits[splits.Length - 1];
            name = name.Substring(0, name.Length - 4);
            ClassData cd;
            cd.name = name;
            cd.path = cc.filepath;

            Properties.Settings.Default.FilePath.Add(cc.filepath);
            Properties.Settings.Default.Classes.Add(name);
            Properties.Settings.Default.Save();
            this.classes.Add(cd);
            this.comboBoxClass.Items.Add(cd);
            this.comboBoxClass.Refresh();

            Class ctemp = new Class(cd.path);
            ctemp.Save();

            return;
        }
コード例 #6
0
        /// <summary>
        /// Updates the Class in the database.
        /// </summary>
        /// <param name="c">The Class you want to update.</param>
        /// <param name="omitQuestionSets">Whether you want to update the Questions sets too.</param>
        /// <param name="omitQuestions">Whether you want to update the Question objects too.</param>
        public static void UpdateClass(Class c, bool omitQuestionSets = false, bool omitQuestions = false)
        {
            string text = "update dbo.Class set name = '" + c.name + "' where Id = '" + c.Id.ToString() + "';";
            StudyToolSql.RunSql(text);

            if (!omitQuestionSets)
                c.questions.ForEach(qs => StudyToolSql.UpdateQuestionSet(qs, c.Id, omitQuestions));
        }
コード例 #7
0
        /// <summary>
        /// Gets the Class object from the database matching the given id.
        /// </summary>
        /// <param name="id">Id of the Class you want to find.</param>
        /// <param name="omitQuestionSets">Wether you want to get the Questions object sets or not.</param>
        /// <param name="omitQuestions">Wether you want to get the Question objects or not.</param>
        /// <returns>Class object found in the database.</returns>
        public static Class GetClass(Guid id, bool omitQuestionSets = false, bool omitQuestions = false)
        {
            Class c;
            using (SqlConnection conn = new SqlConnection(StudyToolSql.connString))
            {
                conn.Open();
                string text = "select * from dbo.Class where Id = '" + id.ToString() + "';";
                SqlCommand cmd = new SqlCommand(text, conn);
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                c = new Class()
                {
                    Id = reader.GetGuid(0),
                    name = reader.GetString(1),
                };
                reader.Close();
                conn.Close();
            }

            if (!omitQuestionSets)
                c.questions = StudyToolSql.GetQuestionSets(c.Id, omitQuestions);

            return c;
        }
コード例 #8
0
        private void buttonSelect_Click(object sender, EventArgs e)
        {
            if (this.comboBoxClass.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a class", "Select a Class", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                string path = Properties.Settings.Default.FilePath[this.comboBoxClass.SelectedIndex];
                this.selectedClass = new Class(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading Class: " + ex.Message, "Error Loading Class", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.Canceled = false;
            this.Close();
        }