Beispiel #1
0
        private void SearchWord(WordPad wordPad, string wordKey)
        {
            if (wordPad == null)
            {
                return;
            }

            if (wordKey == null || wordKey.Length == 0)
            {
                searchResultList.Hide();
                WordList.Show();

                UpdateWordCount();
                return;
            }

            ArrayList searchResult = new ArrayList();

            for (int i = 0; i < wordPad.Words.Count; i++)
            {
                NewWordItem word = (NewWordItem)wordPad.Words[i];
                if (word.Name.Contains(wordKey))
                {
                    searchResult.Add(wordPad.Words[i]);
                }
            }

            UpdateWordListByWordList(searchResultList, searchResult);

            searchResultList.Show();
            WordList.Hide();
        }
Beispiel #2
0
        private void PadTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            e.CancelEdit = false;
            if (e.Label == null)
            {
                e.CancelEdit = true;

                if (AddingNewPad)
                {
                    // 删掉刚加的节点
                    e.Node.Remove();
                    AddingNewPad = false;
                }

                return;
            }

            WordPad targetPad;

            if (m_wordPads.TryGetValue(e.Node.Text, out targetPad))
            {
                string preName = targetPad.Name;
                targetPad.Name = e.Label;
                m_wordPads.Add(targetPad.Name, targetPad);
                m_wordPads.Remove(preName);
            }
            else
            {
                if (AddingNewPad)
                {
                    WordPad newPad = new WordPad(e.Label);
                    m_wordPads.Add(e.Label, newPad);
                    e.Node.Tag   = newPad;
                    AddingNewPad = false;
                }
                else
                {
                    e.CancelEdit = true;
                }
            }
        }
Beispiel #3
0
        public bool AddNewWordPad(string name, bool switchTo)
        {
            if (m_wordPads.ContainsKey(name))
            {
                return(false);
            }

            WordPad newPad = new WordPad(name);

            m_wordPads.Add(name, newPad);
            TreeNode newNode = WordPadTree.TopNode.Nodes.Add(name);

            newNode.Tag = newPad;

            // 选中新加生词本
            if (switchTo)
            {
                newNode.Expand();
            }

            return(true);
        }
Beispiel #4
0
        public bool AddNewWord(WordPad wordPad, NewWordItem newWord)
        {
            if (wordPad == null)
            {
                return(false);
            }

            if (wordPad.FindWord(newWord.Name) != null)
            {
                MessageBox.Show("you already add this word!");
                return(false);
            }

            bool result = wordPad.AddWord(newWord);

            if (result)
            {
                AddWordItemToList(WordList, newWord);
            }

            return(result);
        }
Beispiel #5
0
        private void contextMenuWord_ItemClicked(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = null;

            if (sender.GetType() == typeof(ToolStripMenuItem))
            {
                menuItem = (ToolStripMenuItem)sender;
            }

            if (menuItem.Tag.GetType() == typeof(WordPad))
            {
                WordPad destWordPad = (WordPad)menuItem.Tag;
                if (destWordPad == null)
                {
                    return;
                }

                if (WordList.SelectedItems.Count > 0)
                {
                    if (CurWordPad == null)
                    {
                        AddNewWordPad("Default", true);
                    }

                    foreach (ListViewItem item in WordList.SelectedItems)
                    {
                        NewWordItem word = (NewWordItem)item.Tag;
                        destWordPad.AddWord(word);
                        CurWordPad.Words.Remove(word);
                    }

                    foreach (ListViewItem item in WordList.SelectedItems)
                    {
                        WordList.Items.Remove(item);
                    }
                }
            }
        }
Beispiel #6
0
        /**
         * @param proficiency 表示只选择这个熟练度以下(包括当前)的,当取ProficiencyCount时表示不限熟练度
         * @param bAllTime 选取全部时间范围的词
         */
        public bool InitQuiz(ArrayList wordPads, QuizType type, int testWordCount, NewWordItem.ProficiencyLevel proficiency, DateTime starDate, DateTime endDate, bool bAllTime = true)
        {
            HashSet <int> alreadyChoosedWordIndice = new HashSet <int>();
            ArrayList     totalWords          = new ArrayList();
            ArrayList     totalWordsForOption = new ArrayList(); //不考虑时间的所有词,作为选项候选

            int totalWordCount = 0;

            System.Collections.IEnumerator iterator = wordPads.GetEnumerator();

            DateTime earliestTime = new DateTime(8000, 12, 31);
            DateTime latestTime   = new DateTime(1000, 1, 1);

            while (iterator.MoveNext())
            {
                WordPad wordPad = iterator.Current as WordPad;

                totalWordsForOption.AddRange(wordPad.Words);

                if (bAllTime)
                {
                    totalWordCount += wordPad.Words.Count;
                    totalWords.AddRange(wordPad.Words);
                }
                else
                {
                    ArrayList wordsWithinTimeRange = wordPad.GetWordsByTimeRange(starDate, endDate);
                    totalWordCount += wordsWithinTimeRange.Count;
                    totalWords.AddRange(wordsWithinTimeRange);

                    if (earliestTime.CompareTo(wordPad.EarliestAddTime) > 0)
                    {
                        earliestTime = wordPad.EarliestAddTime;
                    }

                    if (latestTime.CompareTo(wordPad.LatestAddTime) < 0)
                    {
                        latestTime = wordPad.LatestAddTime;
                    }
                }
            }

            if (!bAllTime &&
                (starDate.CompareTo(latestTime) > 0 || // not in time range
                 endDate.CompareTo(earliestTime) < 0)
                )
            {
                MessageBox.Show("specified time range exceed all the words' total time range!");
                return(false);
            }

            if (totalWords.Count <= 3)
            {
                MessageBox.Show("Not sufficient words for a valid test!");
                return(false);
            }

            if (testWordCount > totalWords.Count)
            {
                testWordCount = totalWords.Count;
                MessageBox.Show("test word count is more than word count in all selected wordpads, so clamp to the actual count: " + totalWords.Count);
            }

            Random randGenerator = new Random(Convert.ToInt32(DateTime.Now.Millisecond));

            for (int i = 0; i < testWordCount; i++)
            {
                int         globalIndex   = randGenerator.Next(0, totalWordCount);
                NewWordItem candidateWord = (NewWordItem)totalWords[globalIndex];

                // exclude words not fit condition
                while (alreadyChoosedWordIndice.Contains(globalIndex) ||
                       candidateWord.Meaning == "" ||
                       candidateWord.Proficiency > proficiency ||
                       (!bAllTime &&
                        (candidateWord.AddTime.CompareTo(starDate) < 0 ||  // not in time range
                         candidateWord.AddTime.CompareTo(endDate) > 0)
                       )
                       )
                {
                    globalIndex   = randGenerator.Next(0, totalWordCount);
                    candidateWord = (NewWordItem)totalWords[globalIndex];
                }

                // add test word
                m_testWords.Add(totalWords[globalIndex]);

                // add meaning options for words
                HashSet <int> optionsChoosedForCurWord = new HashSet <int>();
                optionsChoosedForCurWord.Add(globalIndex);

                ArrayList optionWords = new ArrayList();
                for (int j = 0; j < 3; j++)
                {
                    int optionWordIndex = randGenerator.Next(0, totalWordsForOption.Count);
                    while (optionsChoosedForCurWord.Contains(optionWordIndex) ||
                           ((NewWordItem)totalWordsForOption[optionWordIndex]).Meaning == "")
                    {
                        optionWordIndex = randGenerator.Next(0, totalWordsForOption.Count);
                    }

                    optionWords.Add(totalWordsForOption[optionWordIndex]);
                    optionsChoosedForCurWord.Add(optionWordIndex);
                }

                // insert correct word option
                int insertPos = randGenerator.Next(0, 3);
                optionWords.Insert(insertPos, totalWords[globalIndex]);

                m_wordToOptionMap.Add(((NewWordItem)totalWords[globalIndex]).Name, optionWords);
                alreadyChoosedWordIndice.Add(globalIndex);
            }

            m_curTestWordIndex = 0;
            m_startTime        = DateTime.Now;
            UpdateWordUI();
            return(true);
        }
Beispiel #7
0
        private void startBtn_Click(object sender, EventArgs e)
        {
            int wordCount = Decimal.ToInt32(wordCountSpin.Value);

            if (wordCount <= 0)
            {
                MessageBox.Show("Must choose at least one word for test!");
                return;
            }

            int testType   = this.quizTypeCombo.SelectedIndex;
            int familarity = this.familarityCombo.SelectedIndex;

            ArrayList candidateWordPads = new ArrayList();

            foreach (string wordPadName in wordPadsCheckedListBox.CheckedItems)
            {
                WordPad wordPad = MainDlg.Instance.GetWordPadByName(wordPadName);
                candidateWordPads.Add(wordPad);
            }

            DateTime startDate = DateTime.Now;
            DateTime endDate   = DateTime.Now;

            if (!checkBoxAllTime.Checked)
            {
                if (checkBoxRelativeMode.Checked)
                {
                    int daysBefore = Convert.ToInt32(comboBoxRelDays.Text);
                    startDate = endDate.AddDays(Math.Min(0, -daysBefore));
                }
                else
                {
                    startDate = startDateTimePicker.Value;
                    endDate   = endDateTimePicker.Value;

                    if (startDate.CompareTo(endDate) > 0)
                    {
                        startDate = new DateTime(endDate.Year, endDate.Month, endDate.Day);
                    }
                }
            }

            TimeSpan tp = new TimeSpan(startDate.Hour, startDate.Minute, startDate.Second);

            startDate = startDate.Subtract(tp);
            tp        = new TimeSpan(endDate.Hour, endDate.Minute, endDate.Second);
            endDate   = endDate.Subtract(tp);

            QuizMain quizDlg = new QuizMain();

            if (!quizDlg.InitQuiz(candidateWordPads, (QuizMain.QuizType)testType, wordCount,
                                  (NewWordItem.ProficiencyLevel)familarity,
                                  startDate, endDate, checkBoxAllTime.Checked))
            {
                return;
            }
            Hide();
            this.Close();
            quizDlg.ShowDialog(MainDlg.Instance);
        }
Beispiel #8
0
 protected void UpdateWordListFromWordPad(WordPad wp)
 {
     UpdateWordListByWordList(WordList, wp.Words);
     statusStripCurWordPad.Text = "Current word pad: " + wp.Name;
 }
Beispiel #9
0
        public MainDlg()
        {
            WordPadSavePath = Directory.GetCurrentDirectory() + "./WordPads/";
            if (!Directory.Exists(WordPadSavePath))
            {
                Directory.CreateDirectory(WordPadSavePath);
            }

            InitializeComponent();

            WordPadTree.TopNode = WordPadTree.Nodes.Add("All WordPad");

            // 加载生词本
            string[] fileNames = Directory.GetFiles(WordPadSavePath, "*" + WordPadExtesion);

            string strErrMsg = "";

            foreach (string fileName in fileNames)
            {
                // 很遗憾, .pad2 也会被.pad匹配
                if (Path.GetExtension(fileName) != WordPadExtesion)
                {
                    continue;
                }

                string rawFileName = Path.GetFileNameWithoutExtension(fileName);
                if (m_wordPads.ContainsKey(rawFileName))
                {
                    strErrMsg += "same name word pad of " + rawFileName + " already exists! errfile: " + fileName + "\n";
                    continue;
                }

                WordPad wp = new WordPad(rawFileName);

                if (wp.Load(fileName))
                {
                    m_wordPads.Add(wp.Name, wp);
                    WordPadTree.TopNode.Nodes.Add(wp.Name);

                    ListView wordList = new ListView();

                    m_wordLists.Add(wp.Name, WordList);
                }
            }

            if (strErrMsg != "")
            {
                MessageBox.Show(strErrMsg);
            }

            if (m_wordPads.Count == 0)
            {
                AddNewWordPad("Default", true);
            }

            WordPadTree.TopNode.Expand();

            WordPad firstWordPad;

            if (m_wordPads.TryGetValue(WordPadTree.TopNode.FirstNode.Text, out firstWordPad))
            {
                UpdateWordListFromWordPad(firstWordPad);
            }

            if (_instance == null)
            {
                _instance = this;
            }

            WordListComparer sorter = new WordListComparer();

            sorter.Ascending            = true;
            sorter.SortKey              = WordSortKeyType.WordSortKeyAddTime;
            WordList.ListViewItemSorter = (IComparer)sorter;

            // timer to save all words every little while
            timerSaveAll.Enabled = true;

            int relX = WordList.Bounds.Location.X - Bounds.Location.X;
            int relY = WordList.Bounds.Location.Y - Bounds.Location.Y;

            m_iniWordListRelativeLocation = new Point(relX, relY);

            m_iniWordListMargin        = new Size();
            m_iniWordListMargin.Width  = Bounds.Right - WordList.Bounds.Right;
            m_iniWordListMargin.Height = Bounds.Bottom - WordList.Bounds.Bottom;
        }