private void btn_uplaod_Click(object sender, RoutedEventArgs e) { if (ismanager) { userfilename = file.fileName; } else { //注意: //如果是学生上传答卷 //请在这里定义上传文件的新名称,规则是添加时间戳+学号前缀,比如:20170227_2014309010124_ userfilename = DateTime.Now.ToString("yyyyMMdd") + "_" + StaticInform.Num + "_" + file.fileName; } if (btn_uplaod.Content.ToString() == "上传") { btn_uplaod.Content = "撤销"; upPro = new DownLoadProcess(FTP, file, "", userfilename); upPro.OnUpLoadComplete += new DownLoadProcess.DownloadStatusChangeHandle(upPro_OnUpLoadComplete); upPro.StartUpLoad(); } else { btn_uplaod.Content = "上传"; if (userfilename != null || userfilename != "") { file.complete = 0; FTP.Delete(userfilename); } } }
//下载状态发生变化 void dp_OnDownloadStatusChanged(object sender) { DownLoadProcess dp = sender as DownLoadProcess; if (dp.DownLoadStatus == "Canceled") { dp.downloadFile.complete = 0; dp.downloadFile.DownLoadStatus = "下载"; } else if (dp.DownLoadStatus == "Finished") { dp.downloadFile.DownLoadStatus = "打开"; } }
private void btn_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button; fileInfo file = btn.Tag as fileInfo; if (file.DownLoadStatus == "下载") { //这里可以设置是否打开文件存储路径,取消注释就会出现路径选择窗口 //FolderBrowserDialog dia = new FolderBrowserDialog(); //DialogResult result = dia.ShowDialog(); //if (result == System.Windows.Forms.DialogResult.Cancel) //{ return; } //path = dia.SelectedPath; DownLoadProcess dp = new DownLoadProcess(FTP, file, path); this.OnDownLoadList.Add(dp); dp.StartDownLoad();//开始下载 dp.OnDownloadStatusChanged += new DownLoadProcess.DownloadStatusChangeHandle(dp_OnDownloadStatusChanged); } //取消下载 else if (file.DownLoadStatus == "打开") { try { System.Diagnostics.Process.Start(path + "//" + file.fileName); } catch { System.Windows.MessageBox.Show("文件已丢失,请重新下载!"); } } else { foreach (DownLoadProcess d in OnDownLoadList) { if (d.downloadFile == file) { d.StopDownload(); OnDownLoadList.Remove(d); System.Windows.MessageBox.Show("已取消"); break; } } } }