Ejemplo n.º 1
0
 private void buttonSave_Click(object sender, RoutedEventArgs e)
 {
     BdTools.DeleteWord(MyWord.WordId);
     initNewWord();
     if (wordSample != null)
     {
         int id = BdTools.AddNewWords(wordSample);
         wordButton.DataContext = id;
     }
     this.DialogResult = true;
 }
Ejemplo n.º 2
0
        private void buttonDelete_Click(object sender, RoutedEventArgs e)
        {
            Button but   = sender as Button;
            int    index = (int)but.DataContext;

            MyWord   wordDel  = BdTools.DeleteWord(index);
            FileInfo fileInfo = FIleTools.SearchFile(wordDel.SoundName, FIleTools.NameDirectoryAudio);

            collection.Remove(wordDel);
            try
            {
                File.Delete(fileInfo.FullName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + MethodBase.GetCurrentMethod().DeclaringType.FullName);
                return;
            }
        }
Ejemplo n.º 3
0
        private void DeleteWord(int wordId)
        {
            BdTools.DeleteWord(wordId);
            //MyWord myWord = collection.Where(n => n.WordId == wordId).Single();
            MyWord myWord = null;

            foreach (MyWord item in collection)
            {
                if (item.WordId == wordId)
                {
                    myWord = item;
                }
            }
            if (myWord == null)
            {
                MessageBox.Show("Слово не найдено!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            collection.Remove(myWord);
            FileInfo fileInfo = FIleTools.SearchFile(myWord.SoundName, FIleTools.NameDirectoryAudio);

            if (fileInfo != null)
            {
                fileInfo.IsReadOnly = false;
                try
                {
                    File.Delete(fileInfo.FullName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + MethodBase.GetCurrentMethod().DeclaringType.FullName, "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Файл отсутствует в папке SoundFiles", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }