private void WordTextBox_Click(object sender, RoutedEventArgs e)
        {
            WordToBeDeleted = WordList.Text;           //Sets the string value to whats entered in the text box

            WordListBox.DataContext = WordToBeDeleted; //Sets the data context for the Word List Box
            WordList.Clear();                          //Clears WordsList text box
        }
        /// <summary>
        /// Общий метод для всех способов открытия файла списка.
        /// </summary>
        /// <param name="file">Файл списка, который требуется открыть.</param>
        /// <param name="askSelectAction">Требуется ли запрашивать выбор действия.</param>
        private async void OpenList(StorageFile file, bool askSelectAction = true)
        {
            if (file == null)
            {
                return;
            }

            List <ListWordModel> data = new List <ListWordModel>();

            try
            {
                data = new XmlService().ReadList(await FileIO.ReadTextAsync(file), !askSelectAction);
                if (data == null)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Messages.OpenFileError(ex.Message);
                return;
            }

            if (askSelectAction && WordList.Count > 0)
            {
                MessageDialogResult result = await Messages.SelectOperationWithLoadedListFileAsync();

                switch (result)
                {
                case MessageDialogResult.Yes:
                    WordList.Clear();
                    new AppHelper().AddFileToMRU(file); break;

                case MessageDialogResult.No: break;

                case MessageDialogResult.Cancel: return;
                }
            }
            else
            {
                WordList.Clear();
            }

            ListFile = file;

            ObservableCollection <ListWordViewModel> readed
                = new ObservableCollection <ListWordViewModel>(data?.Select(e => new ListWordViewModel(e)));

            foreach (ListWordViewModel item in readed)
            {
                WordList.Add(item);
            }

            for (int i = 0; i < WordList.Count; i++)
            {
                WordList[i].ID = (ushort)i;
            }
        }
Пример #3
0
        private async Task LoadWordFileAsync()
        {
            ApplicationData.Current.LocalSettings.Values["IsPicking"] = true;
            FileOpenPicker picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".csv");
            _currentFile = await picker.PickSingleFileAsync();

            ApplicationData.Current.LocalSettings.Values["IsPicking"] = false;

            if (_currentFile == null)
            {
                throw new Exception("ファイルが選択されていません");
            }

            CurrentFileName = _currentFile.Name;
            var buff = await FileIO.ReadBufferAsync(_currentFile);

            DataReader reader = DataReader.FromBuffer(buff);

            byte[] dataBuff = new byte[buff.Length];
            reader.ReadBytes(dataBuff);

            string dataStr = Portable.Text.Encoding.GetEncoding("Shift-JIS").GetString(dataBuff, 0, dataBuff.Length);

            IList <string> lines = dataStr.Split('\n').ToList();

            WordList.Clear();

            foreach (string line in lines)
            {
                string tempLine = line.Replace("\r", "");

                if (string.IsNullOrEmpty(tempLine))
                {
                    continue;
                }

                string[] str  = tempLine.Split(',');
                WordItem item = null;
                if (str.Length == 4)
                {
                    int col2 = 0;
                    int.TryParse(str[2], out col2);
                    int col3 = 0;
                    int.TryParse(str[3], out col3);
                    item = new WordItem(str[0], str[1], col2, col3);
                }
                else
                {
                    item = new WordItem(str[0], str[1], 0, 0);
                }
                WordList.Add(item);
            }

            RaisePropertyChanged("MaxWordNum");
        }
 /// <summary>
 /// Выполняет создание файла.
 /// </summary>
 private async Task NewAsync()
 {
     if (await SaveTheChangesAsync() != null)
     {
         GridFile     = ListFile = null;
         IsNewEnabled = false;
         Items.Clear();
         WordList.Clear();
     }
 }
Пример #5
0
        private void SearchWord(string searchWord)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(searchWord))
                {
                    return;
                }

                searchWord = searchWord.TrimStart().TrimEnd().ToLower();

                if (temp == searchWord)
                {
                    return;
                }

                _Word = temp = searchWord;
                WordList?.Clear();

                if (!Regex.IsMatch(searchWord, @"[a-z]+[\-\']?[a-z]*"))
                {
                    WordList?.Add(new Word()
                    {
                        word = searchWord, translation = "无释义"
                    });
                    return;
                }

                string result = RestSharpService.Search(searchWord);
                Console.WriteLine(result);

                if (result == "[]")
                {
                    WordList?.Add(new Word()
                    {
                        word = searchWord, translation = "无释义"
                    });
                }
                else
                {
                    List <Word> list = JsonConvert.DeserializeObject <List <Word> >(result);

                    if (list?.Count > 0)
                    {
                        list.ForEach(item => WordList.Add(item));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #6
0
        public void InitStudy()
        {
            CurrentWordPosition = -1;
            IsStudying          = true;
            CurrentWord         = new WordItem("", "", 0, 0);
            List <WordItem> items = WordList.OrderBy(q => Guid.NewGuid()).ToList();

            WordList.Clear();
            foreach (WordItem item in items)
            {
                WordList.Add(item);
            }
        }
Пример #7
0
        /// <summary>
        /// Общий метод для всех способов открытия файла списка.
        /// </summary>
        /// <param name="file">Файл списка, который требуется открыть.</param>
        private async void OpenList(StorageFile file)
        {
            if (file == null)
            {
                return;
            }

            List <ListWordModel> data = new List <ListWordModel>();

            try
            {
                data = new XmlService().ReadList(await FileIO.ReadTextAsync(file), true);
                if (data == null)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Messages.OpenFileError(ex.Message);
                return;
            }

            WordList.Clear();

            ObservableCollection <ListWordViewModel> readed
                = new ObservableCollection <ListWordViewModel>(data?.Select(e => new ListWordViewModel(e)));

            for (int i = 1; i <= readed.Count; i++)
            {
                readed[i - 1].ID = (ushort)i;
            }

            foreach (ListWordViewModel item in readed)
            {
                WordList.Add(item);
            }
        }
Пример #8
0
 public void Clear()
 {
     words.Clear();
 }