private void renameButton_Click(object sender, EventArgs e)
        {
            try
            {
                NamePaser paser = new NamePaser();
                paser.Address = Path.GetDirectoryName(openFileDialog.FileName);
                paser.Ext = Path.GetExtension(openFileDialog.FileName);
                paser.Speaker = this.speakerTextBox.Text;
                paser.Category = this.categoryTextBox.Text;
                paser.Word = this.wordTextBox.Text;
                paser.Label = this.labelTextBox.Text;

                File.Move(openFileDialog.FileName, paser.SingleFile);

                if (File.Exists(paser.SingleFile))
                {
                    this.filenameTextBox.Text = paser.FullName;
                    this.openFileDialog.FileName = paser.SingleFile;
                }
            }
            catch (Exception exp)
            {
                if (exp.GetType() == typeof(FileNotFoundException))
                {
                    MessageBox.Show(exp.Message, "No such file!");
                }
                else if (exp.GetType() == typeof(IOException))
                {
                    MessageBox.Show(exp.Message, "Destination file already exists!");
                }
            }
        }
        private void toDBButton_Click(object sender, EventArgs e)
        {
            try
            {
                var DBContext = MainForm.self.DBModel;
                foreach (KeyValuePair<string, string> item in mediaLocalListBox.SelectedItems)
                {
                    String filename = item.Key.ToString();
                    NamePaser paser = new NamePaser();
                    paser.FullName = filename;
                    if (paser.MediaFormat == "audio") paser.Address = Properties.Settings.Default.AudioFolder;
                    else if (paser.MediaFormat == "video") paser.Address = Properties.Settings.Default.VideoFolder;

                    DBContext.AddOrUpdateRecordingFile(paser.SingleFile);

                    string existingFile = item.Value + "\\" + item.Key;
                    string newFile = paser.Address + "\\" + item.Key;
                    //avoid writing itslef
                    if (!existingFile.Equals(newFile))
                    {
                        File.Copy(existingFile, newFile, true);
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
                MessageBox.Show("Fail to update!");
            }
        }
        private void toLocalButton_Click(object sender, EventArgs e)
        {
            try
            {
                var DBContext = MainForm.self.DBModel;
                for (int i = onDBListBox.SelectedItems.Count - 1; i >= 0; i--)
                {
                    SingleFile sf = onDBListBox.SelectedItems[i] as MPAid.Models.SingleFile;
                    Recording rd = null;
                    NamePaser paser = new NamePaser();
                    paser.FullName = sf.Name;
                    if (paser.MediaFormat == "audio") rd = sf.Audio;
                    else if (paser.MediaFormat == "video") rd = sf.Video;
                    Speaker spk = rd.Speaker;
                    Word word = rd.Word;
                    Category cty = word.Category;
                    string existingFile = sf.Address + "\\" + sf.Name;
                    if (File.Exists(existingFile))
                    {
                        File.Delete(existingFile);
                    }
                    DBContext.SingleFile.Remove(sf);

                    if(rd.Audios.Count == 0 && rd.Video == null) DBContext.Recording.Remove(rd);
                    if (spk.Recordings.Count == 0) DBContext.Speaker.Remove(spk);
                    if (word.Recordings.Count == 0) DBContext.Word.Remove(word);
                    if (cty.Words.Count == 0) DBContext.Category.Remove(cty);
                }
                MainForm.self.DBModel.SaveChanges();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Fail to delete!");
            }
        }