//重命名 private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e) { if (!string.IsNullOrEmpty(e.Label)) { ListViewItem myItem = lvFiles.Items[e.Item]; if (myItem != null) { ListViewItem existItem = FindItemByName(e.Label); if (existItem != null) { MessageBox.Show("该文件夹名已存在!"); e.CancelEdit = true; } else { FileInfoModel myFile = myItem.Tag as FileInfoModel; bool result = client.MakeDir(CurrentPath + e.Label + "/"); if (!result) { e.CancelEdit = true; MessageBox.Show("文件夹重命名失败!"); } else { LoadFileStatus(CurrentPath); } } } } }
//双击进入 private void lvFiles_MouseDoubleClick(object sender, MouseEventArgs e) { FileInfoModel fs = lvFiles.SelectedItems[0].Tag as FileInfoModel; if (fs != null && fs.Isdir) { LoadFileStatus(tbAddress.Text.Trim() + lvFiles.SelectedItems[0].Text + "/"); } }
//回车进入 private void lvFiles_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && lvFiles.SelectedItems.Count > 0) { FileInfoModel fs = lvFiles.SelectedItems[0].Tag as FileInfoModel; if (fs != null && fs.Isdir) { LoadFileStatus(tbAddress.Text.Trim() + lvFiles.SelectedItems[0].Text + "/"); } } }
//下载 private void btDownLoad_Click(object sender, EventArgs e) { if (lvFiles.SelectedItems.Count > 0) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.ShowNewFolderButton = true; //选择保存文件夹 if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { worker.DoWork += new DoWorkEventHandler(DoDownLoadWork); worker.ProgressChanged += new ProgressChangedEventHandler(ProgessChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteDownLoadWork); List <FileInfoModel> fileList = new List <FileInfoModel>(); List <string> fileNameList = new List <string>(); foreach (ListViewItem item in lvFiles.SelectedItems) { if (item.Text.Contains(".")) { fileNameList.Add(item.Text.Split('.')[0]); } else { fileNameList.Add(item.Text); } } foreach (ListViewItem item in lvFiles.SelectedItems) { FileInfoModel myfile = item.Tag as FileInfoModel; if (myfile != null) { string filename = item.Text; if (item.Text.Contains(".")) { filename = item.Text.Split('.')[0]; } fileList.Add(myfile); } } worker.RunWorkerAsync(new DownloadArgs() { FileList = fileList, SavePath = fbd.SelectedPath, OutFileType = 0 }); } } }
//剪切 private void MenuItemCut_Click(object sender, EventArgs e) { if (lvFiles.SelectedItems.Count > 0) { pasterTemp.Clear(); foreach (ListViewItem item in lvFiles.SelectedItems) { FileInfoModel myfile = item.Tag as FileInfoModel; if (myfile != null) { pasterTemp.Add(myfile.Path); } } } }
//右键菜单 private void listView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { listMenu.Show(lvFiles, e.X, e.Y); if (lvFiles.SelectedItems.Count > 0) { FileInfoModel filestatu = lvFiles.SelectedItems[0].Tag as FileInfoModel; if (filestatu != null) { if (filestatu.Isdir) { menuNewFolder.Enabled = false; menuUpload.Enabled = false; MenuItemUploadFloder.Enabled = false; menuDelete.Enabled = true; menuDownload.Enabled = false; MenuItemCut.Enabled = true; MenuItemPaste.Enabled = false; } else { menuNewFolder.Enabled = false; menuUpload.Enabled = false; MenuItemUploadFloder.Enabled = false; menuDelete.Enabled = true; menuDownload.Enabled = true; MenuItemCut.Enabled = true; MenuItemPaste.Enabled = false; } } } else { menuNewFolder.Enabled = true; menuUpload.Enabled = true; MenuItemUploadFloder.Enabled = true; menuDelete.Enabled = false; menuDownload.Enabled = false; MenuItemCut.Enabled = false; MenuItemPaste.Enabled = pasterTemp.Count > 0; } } }
//根据导入列表下载 public void DownLoadFile(List <string> pathList) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.ShowNewFolderButton = true; fbd.Description = "请选择一个文件夹存放导出的视频文件。"; //选择保存文件夹 if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { worker.DoWork += new DoWorkEventHandler(DoDownLoadWork); worker.ProgressChanged += new ProgressChangedEventHandler(ProgessChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteDownLoadWork); List <FileInfoModel> fileList = new List <FileInfoModel>(); List <string> noFound = new List <string>(); foreach (string filePath in pathList) { var myfile = new FileInfoModel() { FileName = filePath, Path = CurrentPath.TrimStart('/') + filePath }; if (client.Exist(myfile.Path)) { fileList.Add(myfile); } else { noFound.Add(filePath); } } string nofoundTitle = string.Format("以下{0}个文件没有找到,请核实:\r\n{1}\r\n===结束===", noFound.Count, string.Join("\r\n", noFound.ToArray())); File.WriteAllText(fbd.SelectedPath + "/NoFound.txt", nofoundTitle); worker.RunWorkerAsync(new DownloadArgs() { FileList = fileList, SavePath = fbd.SelectedPath, OutFileType = 0 }); } }
//识别文件类型 private string MkFileType(FileInfoModel fs) { string typeString = "未知类型"; if (fs.Isdir) { typeString = "文件夹"; } else { string ext = System.IO.Path.GetExtension(fs.Path); if (!string.IsNullOrEmpty(ext)) { typeString = ext; } } return(typeString); }
/// <summary> /// 根据订单 或右键下载 /// </summary> /// <param name="pathList">key:文件名,value:主题名</param> /// <param name="outFamate">导出格式</param> /// <param name="fileType">以什么为文件名,0文件名,1主题名,2主题文件夹</param> public void DownLoadFile(Dictionary <string, string> pathList, string outFamate, int fileType) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.ShowNewFolderButton = true; fbd.Description = "请选择一个文件夹存放导出的视频文件。"; //选择保存文件夹 if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { worker.DoWork += new DoWorkEventHandler(DoDownLoadWork); worker.ProgressChanged += new ProgressChangedEventHandler(ProgessChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteDownLoadWork); List <FileInfoModel> fileList = new List <FileInfoModel>(); List <string> noFound = new List <string>(); foreach (string filePath in pathList.Keys) { FileInfoModel myfile = client.GetFileStatus(ConfigHelper.HdfsRoot + "/" + CurrentPath + "/" + filePath + outFamate); if (myfile != null) { myfile.FileName = pathList[filePath] + outFamate; fileList.Add(myfile); } else { noFound.Add(filePath); } } string nofoundTitle = string.Format("以下{0}个文件没有找到,请核实:\r\n{1}\r\n===结束===", noFound.Count, string.Join("\r\n", noFound.ToArray())); File.WriteAllText(fbd.SelectedPath + "/NoFound.txt", nofoundTitle); worker.RunWorkerAsync(new DownloadArgs() { FileList = fileList, SavePath = fbd.SelectedPath, OutFileType = fileType }); } }
//删除选中 private void btDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("确定删除选中的文件或文件夹?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { if (lvFiles.SelectedItems.Count > 0) { foreach (ListViewItem item in lvFiles.SelectedItems) { FileInfoModel myfile = item.Tag as FileInfoModel; if (myfile != null) { bool result = client.Delete(myfile.Path, true); string msg = string.Format("{2}:{0} 删除{1}", Path.GetFileName(myfile.Path), result ? "成功" : "失败", myfile.Isdir ? "文件夹" : "文件"); lbProgressTxt.Text = msg; } Application.DoEvents(); } //重新加载 LoadFileStatus(CurrentPath); } } }