/// <summary> /// /// if vocab index changed reinit affected data (vocab,pic,sound,btns) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VocabSelectBox_SelectedIndexChanged(object sender, EventArgs e) { if (VocabSelectBox.Text == "Add...") { QuestionTextBox.Clear(); AnswerTextBox.Clear(); PicBox.Image = null; AddChangePictureBtn.Enabled = true; AddChangeSoundBtn.Enabled = true; DeleteVocabBtn.Enabled = false; NextSaveButton.Text = "Save"; } else { Vocab = (db.GetVocabs((GroupSelectBox.SelectedIndex + 1), db.getuserid("admin")))[VocabSelectBox.SelectedIndex]; //load vocab QuestionTextBox.Text = Vocab.german; AnswerTextBox.Text = Vocab.english; if (Vocab.picturepath != "") //load picture { PicBox.Image = Image.FromFile(Vocab.picturepath); //picbox load image PicBox.SizeMode = PictureBoxSizeMode.Zoom; //autosize AddChangePictureBtn.Text = "Change"; DeletePictureBtn.Enabled = true; } else { PicBox.Image = null; AddChangePictureBtn.Text = "Add"; DeletePictureBtn.Enabled = false; } if (Vocab.soundpath != "") //load sound { WMPLib.IWMPMedia media = WMPbox.newMedia(Vocab.soundpath); WMPbox.currentPlaylist.appendItem(media); AddChangeSoundBtn.Text = "Change"; DeleteSoundBtn.Enabled = true; } else { WMPbox.close(); //clear soundbox AddChangeSoundBtn.Text = "Add"; DeleteSoundBtn.Enabled = false; //set btns } NextSaveButton.Text = "Next"; AddChangePictureBtn.Enabled = true; AddChangeSoundBtn.Enabled = true; DeleteVocabBtn.Enabled = true; } if (VocabSelectBox.SelectedIndex == 0) //set to previous btn { PrevBtn.Enabled = false; } else { PrevBtn.Enabled = true; } toolStripStatusLabel1.Text = ""; //refresh tooltip }
/// <summary> /// delete sound from filesystem and db, set btns and reset picturebox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteSoundBtn_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Delete " + Vocab.soundpath; //set tooltip WMPbox.close(); //clear soundbox WMPbox.Dispose(); if (!Utility.FileDelete(Vocab.soundpath)) { MessageBox.Show("Unable to delete File (invalid path or file not found)!", "Vocabulator", MessageBoxButtons.OK, MessageBoxIcon.Error); } db.DeleteSound(Vocab); //delete path from db Vocab.soundpath = ""; DeleteSoundBtn.Enabled = false; //set btns AddChangeSoundBtn.Text = "Add"; toolStripStatusLabel1.Text = ""; //refresh tooltip }
/// <summary> /// opens file dialog for import of soundfile, copy/rename the file to root directory, save path into db /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddChangeSoundBtn_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); //openfiledialog dialog.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpg|all files|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { Path.GetExtension(dialog.FileName); string sourcefilepath = Path.GetDirectoryName(dialog.FileName) + @"/" + Path.GetFileName(dialog.FileName); Vocab.soundpath = Environment.CurrentDirectory + "/data/audio/" + (db.getunitid(UnitSelectBox.Text)) + db.getgroupid(GroupSelectBox.Text) + Vocab.id + ".Sound"; Utility.Filecopy(sourcefilepath, Vocab.soundpath); //filecopy function from Util.cs WMPbox.URL = dialog.FileName; //media load sound WMPLib.IWMPMedia media = WMPbox.newMedia(Path.GetFileName(dialog.FileName)); WMPbox.currentPlaylist.appendItem(media); toolStripStatusLabel1.Text = ""; //refresh tooltip if (NextSaveButton.Text != "Save") //check if new vocab { db.SetSoundPath(Vocab.id, Vocab.soundpath); //save path to db } } }
/// <summary> /// fill window with data from db /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TeacherForm_Load(object sender, EventArgs e) { Utility = new Util(); //io helper, filecopy function from Util.cs --> this maybe go online on server fileupload, for sync Vocab = new Vocab(); //Vocab obj try { db = new Database(); //database init } catch { MessageBox.Show("Unable to load database.", "Vocabulator", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } UnitSelectBox.Items.Clear(); //setup design specific, Lessons foreach (string unit in db.getunits()) { UnitSelectBox.Items.Add(unit); //add from db } UnitSelectBox.Items.Add("Add..."); //add last entry UnitSelectBox.SelectedIndex = 0; // set first entry GroupSelectBox.Items.Clear(); //Groups foreach (string group in db.getgroups(UnitSelectBox.SelectedIndex + 1)) { GroupSelectBox.Items.Add(group); //add from db } VocabSelectBox.Items.Add("Add..."); //add last entry GroupSelectBox.SelectedIndex = 0; // set to first entry VocabSelectBox.Items.Clear(); //Vocab foreach (Vocab German in db.GetVocabs((GroupSelectBox.SelectedIndex + 1), db.getuserid("admin"))) { VocabSelectBox.Items.Add(German.german); //add from db } VocabSelectBox.Items.Add("Add..."); //add last entry VocabSelectBox.SelectedIndex = 0; //set to first entry Vocab = (db.GetVocabs((GroupSelectBox.SelectedIndex + 1), //load Vocab db.getuserid("admin")))[VocabSelectBox.SelectedIndex]; QuestionTextBox.Text = Vocab.german; //set Vocab atttib AnswerTextBox.Text = Vocab.english; if (Vocab.picturepath != "") //Picturebox init { PicBox.Image = Image.FromFile(Vocab.picturepath); //picbox load image PicBox.SizeMode = PictureBoxSizeMode.Zoom; //autosize AddChangePictureBtn.Text = "Change"; DeletePictureBtn.Enabled = true; } else { PicBox.Image = null; AddChangePictureBtn.Text = "Add"; DeletePictureBtn.Enabled = false; } if (Vocab.soundpath != "") //Soundbox init, load sound { WMPLib.IWMPMedia media = WMPbox.newMedia(Vocab.soundpath); WMPbox.currentPlaylist.appendItem(media); AddChangeSoundBtn.Text = "Change"; DeleteSoundBtn.Enabled = true; } else { WMPbox.close(); //clear soundbox AddChangeSoundBtn.Text = "Add"; //set btns DeleteSoundBtn.Enabled = false; } }