Пример #1
0
        private void MenuAdd_Click(object sender, EventArgs e)
        {
            if (selectedBox.Tag.ToString() == "Quest")
            {
                string getkeysql = "analyze table quest_def; ";
                globalDB.ExeQuery(getkeysql);
                getkeysql = "SELECT `AUTO_INCREMENT` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA`= 'edu' AND`TABLE_NAME`= 'quest_def';";
                int newKeyIdx = globalDB.ReadDB <int>(getkeysql)[0];

                formAdd = new FormQuestAdd("增加问题");
                if (formAdd.ShowDialog() == DialogResult.OK)
                {
                    string questName    = formAdd.QuestName;
                    string questDetail  = formAdd.QuestDetail;
                    string questPath    = formAdd.QuestPath;
                    string answerDetail = formAdd.AnswerDetail;
                    string answerPath   = formAdd.AnswerPath;
                    string sqlcmd       = string.Format("INSERT INTO quest_def (`caption`,`detail`,`file_path`,`answer_text`,`answer_picture`) " +
                                                        "VALUES ('{0}','{1}','{2}' ,'{3}','{4}');"
                                                        , questName, questDetail, questPath, answerDetail, answerPath);
                    if (globalDB.ExeUpdate(sqlcmd.Replace("\\", "\\\\")) == 0)
                    {
                        MessageBox.Show("insert fail!");
                    }

                    foreach (var item in formAdd.listId_selectTagId_map)
                    {
                        string tagsql = string.Format("INSERT INTO quest_tag_map (`quest_id`, `tag_id`) VALUES ({0}, {1});", newKeyIdx, item.Value);
                        if (globalDB.ExeUpdate(tagsql) == 0)
                        {
                            MessageBox.Show("insert fail!");
                        }
                    }


                    LoadListBox();
                    formAdd.Close();
                }
            }
            //else
            //{
            //    formOpt = new FormTagAdd("增添标签", false);
            //    if (formOpt.ShowDialog() == DialogResult.OK)
            //    {
            //        int tagSeletIdx = listTags.SelectedIndex;
            //        string newTag = formOpt.textString;
            //        string questName = listQuest.SelectedItem.ToString();
            //        int questId = listId_id_map[tagSeletIdx];

            //      //  int group_id = cap_map_tag_group[questName].id;
            //        //string sqlcmd = string.Format("INSERT INTO tag_def (`caption`, `group_id`) VALUES ('{0}', {1} );", newTag, group_id);
            //        //if (globalDB.ExeUpdate(sqlcmd) == 0)
            //          //  MessageBox.Show("insert fail!");
            //       // LoadListBox();
            //       // ListBoxTagGroup.SelectedIndex = tagSeletIdx;
            //    }

            //}
        }
Пример #2
0
        private void MenuModify_Click(object sender, EventArgs e)
        {
            if (selectedBox.Tag.ToString() == "Quest")
            {
                int questId = listId_id_map[selectedBox.SelectedIndex];
                formAdd = new FormQuestAdd("编辑问题", questId);
                if (formAdd.ShowDialog() == DialogResult.OK)
                {
                    string questName    = formAdd.QuestName;
                    string questDetail  = formAdd.QuestDetail;
                    string questPath    = formAdd.QuestPath;
                    string answerDetail = formAdd.AnswerDetail;
                    string answerPath   = formAdd.AnswerPath;

                    //string getkeysql = "analyze table tag_group_def; ";
                    //globalDB.ExeQuery(getkeysql);
                    //getkeysql = "SELECT `AUTO_INCREMENT` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA`= 'edu' AND`TABLE_NAME`= 'quest_def';";
                    //int newKeyIdx = globalDB.ReadDB<int>(getkeysql)[0];

                    string sqlcmd = string.Format("UPDATE quest_def SET `caption`='{0}' ,`detail` ='{1}',`file_path` = '{2}' ,`answer_text` ='{3}',`answer_picture` ='{4}' WHERE id = {5}"
                                                  , questName, questDetail, questPath, answerDetail, answerPath, questId);
                    if (globalDB.ExeUpdate(sqlcmd.Replace("\\", "\\\\")) == 0)
                    {
                        MessageBox.Show("update fail!");
                    }

                    string delsql = "DELETE FROM quest_tag_map WHERE quest_id = " + questId.ToString();
                    if (globalDB.ExeUpdate(delsql) == 0)
                    {
                        MessageBox.Show("delete fail!");
                    }


                    foreach (var item in formAdd.listId_selectTagId_map)
                    {
                        string tagsql = string.Format("INSERT INTO quest_tag_map (`quest_id`, `tag_id`) VALUES ({0}, {1});", questId, item.Value);
                        if (globalDB.ExeUpdate(tagsql) == 0)
                        {
                            MessageBox.Show("insert fail!");
                        }
                    }

                    LoadListBox();
                }
                formAdd.Close();
            }
        }