public MainWindow()
        {
            InitializeComponent();
            DirectoryInfo rootDirectory = new DirectoryInfo($"{DebugOrReleasePath}\\WordData");

            rootDirectory.Create();//目錄已存在不作用
            updataList();
            Local_OldWord = string.Empty;

            WordBuilder.Instance().LocalDataChanged += MainWindow_LocalDataChanged;
            Local_WordListBox.SelectionChanged += Local_WordListBox_SelectionChanged;
        }
示例#2
0
        private void YesButton_Click(object sender, RoutedEventArgs e)
        {
            var       builder = WordBuilder.Instance();
            AddResult status  = builder.CreateWord(wordStr);

            if (status == AddResult.SearchFail)
            {
                MessageBox.Show($"{wordStr}新增失敗,請再試一次。");
            }
            else
            {
                Close();
            }
        }
 private void Local_RemoveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var builder = WordBuilder.Instance();
         builder.RemoveWord(Local_WordListBox.SelectedValue.ToString());
         updataList();
         Local_WordListBox.SelectedIndex = 0;
         Local_OldWord = string.Empty;
     }
     catch (Exception e2)
     {
         MessageBox.Show("錯誤,無選取單字", e2.Message);
     }
 }
        private async void Download_Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            button.Content   = "Downloading, please wait!";
            button.IsEnabled = false;

            var builder = WordBuilder.Instance();

            builder.ProgressChanged += Builder_ProgressChanged;
            string[] words = Download_TextBox.Text.Split(new char[] { '\n' }); //TextBox文字以\n劃分各單字
            words = words.Select(x => x.Replace("\r", "")).Where(x => x != string.Empty).ToArray();
            var message   = new StringBuilder();
            var newText   = new StringBuilder(); //讓成功新增的單字在Textbox上除去
            var addResult = await Task.Factory.StartNew(() => builder.CreateWords(words));

            for (int i = 0; i < words.Length; i++)
            {
                switch (addResult[i])
                {
                case AddResult.HaveWord:
                    message.Append($"{words[i]}失敗,已有此單字資料\n");
                    newText.Append($"{words[i]}\r\n");
                    break;

                case AddResult.SearchFail:
                    if (!words[i].Equals(String.Empty))
                    {
                        message.Append($"{words[i]}失敗,查無此單字\n");
                        newText.Append($"{words[i]}\r\n");
                    }
                    break;

                default:
                    break;
                }
            }
            if (!message.ToString().Equals(String.Empty))
            {
                MessageBox.Show(message.ToString(), "新增失敗");
            }
            //if (!newText.ToString().Equals(String.Empty))
            Download_TextBox.Text = newText.ToString();

            button.Content   = "_Download";
            button.IsEnabled = true;
            updataList();
        }
        public bool SetDictionarySwitchTabControl(string wordStr, Grid grid)
        {
            wordStr = wordStr.ToLower();
            var builder = WordBuilder.Instance();
            var word    = builder.GetWord(wordStr);

            if (word == null)
            {
                MessageBox.Show("查無此單字");
                return(false);
            }

            var yahooGrid     = new Grid();
            var cambridgeGrid = new Grid();
            var helper        = new WordHelper();

            try
            {
                (string Name, string URL)[] wordPaths = null;