Ejemplo n.º 1
0
        private void build()
        {
            this.PackStart(new Label {
                Markup = "<b><big>" + m_Category + "</big></b>", UseMarkup = true
            }, false, false, 35);

            int buttonCount = 0;


            using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
                var provider = new QuestionProvider(connection);
                var levels   = provider.FetchAll().Where(q => q.HowOftenAsk == 0 && q.Category == m_Category).Select(q => q.DifficultyLevel).Distinct().ToList();
                levels.Sort();

                foreach (var level in levels)
                {
                    var questions = provider.FetchAll().Where(q => q.HowOftenAsk == 0 && q.DifficultyLevel == level && q.Category == m_Category);

                    if (generateButton(questions))
                    {
                        buttonCount++;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void HandleCreateDbButtonClicked(object sender, EventArgs e)
        {
            string file = newDbButton.Filename;

            if (string.IsNullOrEmpty(file))
            {
                dbLoadLabel.Text = "richtigen Pfad angeben";
                this.ShowAll();
                return;
            }
            try {
                QuizParser qp = new QuizParser(file);

                using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
                    var provider  = new QuestionProvider(connection);
                    var questions = qp.Questions.ToList();
                    foreach (var quest in questions)
                    {
                        provider.Save(quest);
                    }
                }
                dbLoadLabel.Text = "erstellen erfolgreich";
                this.ShowAll();
            } catch (Exception exc) {
                dbLoadLabel.Text = exc.Message;
                this.ShowAll();
            }
            dbInfoLabel.Text = string.Format("Exestiert die Datenbank: {0}", System.IO.File.Exists(QuestionProvider.dbPath));
        }
Ejemplo n.º 3
0
 void HowOftenAskFill()
 {
     using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
         var provider = new QuestionProvider(connection);
         var cmd      = new HyenaSqliteCommand("UPDATE ? SET HowOftenAsk = 1 WHERE Id = ?;", provider.TableName, bus.CurrentQuestion.Id);
         connection.Execute(cmd);
     }
 }
Ejemplo n.º 4
0
 void ButtonAddClicked(object sender, EventArgs e)
 {
     using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
         var      provider = new QuestionProvider(connection);
         Question question = new Question("Frage", "Antwort", "Nothing", 0, 0);
         provider.Save(question);
         qnv.QuestionNodeView.NodeStore.AddNode(new QuestionNode(question));
     }
 }
Ejemplo n.º 5
0
        void ButtonRemoveClicked(object sender, EventArgs e)
        {
            if (qnv.QuestionNodeView.NodeSelection.SelectedNode == null)
            {
                return;
            }
            var questionNode = (QuestionNode)qnv.QuestionNodeView.NodeSelection.SelectedNode;
            var question     = questionNode.GetQuestion();

            qnv.QuestionNodeView.NodeStore.RemoveNode(questionNode);
            using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
                var provider = new QuestionProvider(connection);
                provider.Delete(question);
            }
        }
Ejemplo n.º 6
0
        /* many thinks not implement
         * public void CreateDB ()
         * {
         *      var db = new QuestionTable (connectionString);
         *      if (db.DatabaseExists ()) {
         *              //Console.WriteLine ("Deleting old database...");
         *              db.DeleteDatabase ();
         *      }
         *      db.CreateDatabase ();
         * }
         */
        public void CreateProvider()
        {
            using (var conn = new HyenaSqliteConnection(path)) {
                var qp = new QuestionProvider(conn);

                /*
                 * dbConn.Open ();
                 *
                 * using (var dbCommand = dbConn.CreateCommand ()) {
                 *      dbCommand.CommandText = @"CREATE TABLE question (id INTEGER PRIMARY KEY, question TEXT, answer TEXT, category TEXT, howOftenAsk INTEGER);";
                 *      dbCommand.ExecuteNonQuery ();
                 * }
                 */
            }
        }
Ejemplo n.º 7
0
        void build()
        {
            using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
                var provider = new QuestionProvider(connection);

                var questions            = provider.FetchAll();
                var questCategories      = questions.Where(q => q.HowOftenAsk == 0).Select(q => q.Category).Distinct().ToList();
                int questCategoriesCount = questCategories.Count();
                var categories           = new List <string> ();

                if (questCategoriesCount > 3)
                {
                    do
                    {
                        var rand = new Random(DateTime.Now.Millisecond);
                        int r    = 0;

                        if (questCategoriesCount > 1)
                        {
                            r = rand.Next(0, questCategoriesCount);
                        }
                        categories.Add(questCategories [r]);
                        categories = categories.Distinct().ToList();
                    } while (categories.Count < 3);
                }
                else
                {
                    categories = questCategories.ToList();
                }

                foreach (var cat in categories)
                {
                    this.Add(new DifficultLevelButtons(cat));
                }

                if (questCategoriesCount == 0)
                {
                    this.Add(new Label("Keine Fragen mehr vorhanden"));
                }
            }
        }
Ejemplo n.º 8
0
        void build()
        {
            this.Title = "Einstellungen";

            var mainBox = new VBox();

            dbInfoLabel = new Label();

            dbInfoLabel.Text = string.Format("Exestiert die Datenbank: {0}", System.IO.File.Exists(QuestionProvider.dbPath));
            mainBox.Add(dbInfoLabel);

            newDbButton = new FileChooserButton("Question File Open", FileChooserAction.Open);
            mainBox.Add(newDbButton);

            dbLoadLabel = new Label();
            mainBox.Add(dbLoadLabel);

            var createDbButton = new Button(new Label("Datenbank erstellen"));

            createDbButton.Clicked += HandleCreateDbButtonClicked;
            mainBox.Add(createDbButton);

            var removeDbButton = new Button(new Label("Datenbank löschen"));

            removeDbButton.Clicked += delegate {
                QuestionProvider.RemoveDb();
                dbInfoLabel.Text = string.Format("Exestiert die Datenbank: {0}", System.IO.File.Exists(QuestionProvider.dbPath));
            };
            mainBox.Add(removeDbButton);

            this.VBox.Add(mainBox);

            this.AddButton("Schließen", ResponseType.Close);

            this.ShowAll();
        }
Ejemplo n.º 9
0
        protected override void OnEdited(string path, string new_text)
        {
            using (var connection = new HyenaSqliteConnection(QuestionProvider.dbPath)) {
                var node  = (QuestionNode)m_Store.GetNode(new TreePath(path));
                var quest = node.GetQuestion();
                switch (m_Column)
                {
                case Question.Constants.Quest:
                    quest.Quest = new_text;
                    break;

                case Question.Constants.Answer:
                    quest.Answer = new_text;
                    break;

                case Question.Constants.Category:
                    quest.Category = new_text;
                    break;

                case Question.Constants.HowOftenAsk:
                    quest.HowOftenAsk = Convert.ToInt32(new_text);
                    break;

                case Question.Constants.DifficultyLevel:
                    quest.DifficultyLevel = Convert.ToInt32(new_text);
                    break;

                default:
                    throw new ApplicationException("falscher Spaltenname");
                }
                var provider = new QuestionProvider(connection);
                var cmd      = new HyenaSqliteCommand("UPDATE ? SET ? = ? WHERE Id = ?;", provider.TableName, m_Column, new_text, quest.Id);
                connection.Execute(cmd);
            }
            base.OnEdited(path, new_text);
        }