private void EditSong_Click(object sender, RoutedEventArgs args) { if (SongName.Text != "" && SongName.Text != null && !MainWindow.Songs.Exists((f) => f.Name == SongName.Text)) { name = SongName.Text; } if (MainWindow.Songs.Exists((f) => f.Name == SongName.Text)) { MessageBox.Show("Назва використана", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if ((SongNumber.Text != "" && SongNumber.Text != null) || IsHasNumber.IsChecked.Value) { if (!IsHasNumber.IsChecked.Value) { number = Convert.ToInt16(SongNumber.Text); } else { number = 0; } } if ((SongCategory.Text != "" || SongCategory.Text != null) || (string)SongCategoryList.SelectedItem != "") { if ((bool)NewCategory.IsChecked) { category = SongCategory.Text; } else { category = (string)SongCategoryList.SelectedItem; } } if (path != null) { if (path.EndsWith(".mp3")) { MP3 = System.IO.File.ReadAllBytes(path); } else if (path.EndsWith(".mp4")) { try { string lpath = Environment.CurrentDirectory + "\\file.mp3"; Interaction.Shell($"ffmpeg.exe -i \"{path}\" \"{lpath}\"", AppWinStyle.Hide, true, -1); MP3 = System.IO.File.ReadAllBytes(lpath); System.IO.File.Delete(lpath); MessageBox.Show("Конвертація завершена"); } catch (Exception e) { Log.Error(e.StackTrace + " => " + e.Message); } } else if (path.EndsWith(".m4a")) { try { string temp = Environment.CurrentDirectory + @"\Data\Temp\file.wav"; string mp3 = Environment.CurrentDirectory + @"\Data\Temp\file.mp3"; Interaction.Shell($"faad.exe -o \"{temp}\" \"{path}\"", AppWinStyle.Hide, true, -1); Interaction.Shell($"lame.exe --preset standard \"{temp}\" \"{mp3}\"", AppWinStyle.Hide, true, -1); MP3 = System.IO.File.ReadAllBytes(mp3); System.IO.File.Delete(temp); System.IO.File.Delete(mp3); MessageBox.Show("Конвертація завершена"); } catch (Exception e) { Log.Error(e.StackTrace + " => " + e.Message); } } } lang = (string)SongLang.SelectedValue; if (name != null && name != "" && !DataBaseHelper.NameExist(name)) { DataBaseHelper.Edit(B_name, "Name", name); ok = true; } if (number != -1) { DataBaseHelper.Edit(B_name, "Number", number); ok = true; } if (category != null && category != "") { DataBaseHelper.Edit(B_name, "Category", category); ok = true; } if (lang != null && lang != B_lang) { DataBaseHelper.Edit(B_name, "Lang", lang); ok = true; } if (MP3 != null) { DataBaseHelper.Edit(B_name, "MP3", MP3); ok = true; } Close(); }
private void AddSong_Click(object sender, RoutedEventArgs args) { string error_text = ""; name = SongName.Text; if ((SongNumber.Text != "" && SongNumber.Text != null && SongNumber.Text.Length < 5) || IsHasNumber.IsChecked.Value) { if (!IsHasNumber.IsChecked.Value) { number = Convert.ToInt16(SongNumber.Text); } else { number = 0; } } if ((SongCategory.Text != null && SongCategory.Text != "") || (string)SongCategoryList.SelectedItem != "") { if ((bool)NewCategory.IsChecked) { category = SongCategory.Text; } else { category = (string)SongCategoryList.SelectedItem; } } if (path != null) { if (path.EndsWith(".mp3")) { MP3 = System.IO.File.ReadAllBytes(path); } else if (path.EndsWith(".mp4")) { try { string lpath = Environment.CurrentDirectory + "\\file.mp3"; Interaction.Shell($"ffmpeg.exe -i \"{path}\" \"{lpath}\"", AppWinStyle.Hide, true, -1); MP3 = System.IO.File.ReadAllBytes(lpath); System.IO.File.Delete(lpath); MessageBox.Show("Конвертація завершена"); } catch (Exception e) { Log.Error(e.StackTrace + " => " + e.Message); } } else if (path.EndsWith(".m4a")) { try { string temp = Environment.CurrentDirectory + @"\Data\Temp\file.wav"; string mp3 = Environment.CurrentDirectory + @"\Data\Temp\file.mp3"; Interaction.Shell($"faad.exe -o \"{temp}\" \"{path}\"", AppWinStyle.Hide, true, -1); Interaction.Shell($"lame.exe --preset standard \"{temp}\" \"{mp3}\"", AppWinStyle.Hide, true, -1); MP3 = System.IO.File.ReadAllBytes(mp3); System.IO.File.Delete(temp); System.IO.File.Delete(mp3); MessageBox.Show("Конвертація завершена"); } catch (Exception e) { Log.Error(e.StackTrace + " => " + e.Message); } } } lang = (string)SongLang.SelectedValue; if (name != "" && name != null && !DataBaseHelper.NameExist(name) && category != "" && category != null && ((SongNumber.Text != "" && SongNumber.Text != null) || IsHasNumber.IsChecked.Value) && lang != "" && MP3 != null) { DataBaseHelper.Add(name, lang, number, category, MP3); ok = !ok; Close(); } else { if (name == "") { error_text += "Назву не вказано" + "\n"; } if (DataBaseHelper.NameExist(name) && name != "") { error_text += "Назва використана" + "\n"; } if (category == null || category == "") { error_text += "Категорію не вказано" + "\n"; } if ((number == 0 || number < 0) && !IsHasNumber.IsChecked.Value) { error_text += "Номер не вказано" + "\n"; } if (path == null || path == "") { error_text += "Файл не вказано" + "\n"; } MessageBox.Show(error_text, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }