private void MainForm_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length != 1) { return; } string filename = files[0]; if (filename.Contains(".mdf") == false) { MessageBox.Show("外链失败,请拖拽mdf文件。", "外链数据库", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } database.OpenConnection(filename); MessageBox.Show("外链数据库文件成功。", "已使用新的数据库"); }
/// <summary> /// 后台线程执行函数。只负责打开数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dbBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { database.OpenConnection(); this.dbBackgroundWorker.ReportProgress(100); //报告执行完毕,执行RunWorkerCompleted } catch (Exception ex) { ExceptionForm.ShowDialog(ex); } }