public void InitPropValus(Lib.PlanFile PFile) { if (PFile == null) { return; } CurFile = PFile; if (PFile.CanReadUserIds != null) { CurFileHasGrantNames = string.Join(",", AppSet.SysUsers.Where(e => PFile.CanReadUserIds.Contains(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name)?.ToArray()); } if (PFile.UserId != null) { CurFileCreateUserName = string.Join(",", AppSet.SysUsers.Where(e => PFile.UserId.Equals(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name)?.ToArray()); } if (AppSet.LoginUser.Post.Equals("管理员")) { CanRead = CanUpdate = CanDelete = "Visible"; return; } if (CurFile.UserId.Equals(AppSet.LoginUser.Id, System.StringComparison.Ordinal)) { CanRead = CanDelete = CanUpdate = "Visible"; return; } if (CurFile.CanReadUserIds.Contains(AppSet.LoginUser.Id, System.StringComparison.Ordinal)) { CanRead = "Visible"; } }
/// <summary> /// 初始化视图模型属性值。 /// </summary> /// <param name="P_File">待修改、删除的文件对象</param> /// <param name="P_DelFileCallBackFun">删除文件后回调的函数</param> public void Init_FileInfo(Lib.PlanFile P_File, Action <Lib.PlanFile> P_DelFileCallBackFun = null) { _CurUCViewModel = new CurUCViewModel(); _CurUCViewModel.InitPropValus(P_File); _DelFileCallBackFun = P_DelFileCallBackFun; DataContext = _CurUCViewModel; }
/// <summary> /// 从服务器删除文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Image_Delete_MouseLeftButtonUpAsync(object sender, System.Windows.Input.MouseButtonEventArgs e) { Lib.PlanFile SelectFile = LB_FileList.SelectedItem as Lib.PlanFile; if (!AppFuns.ShowMessage($"删除文件《{SelectFile.Name}》?", "确认", showYesNo: true)) { return; } ExcuteResult delResult = await DataPlanFileRepository.DeleteFileInfo(SelectFile); if (delResult.State == 0) { _UCPlanInfoVM.PlanFiles.Remove(SelectFile); } }
/// <summary> /// 转到文件夹 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MenuItem_ToFolder_ClickAsync(object sender, RoutedEventArgs e) { Lib.PlanFile SelectFile = LB_FileList.SelectedItem as Lib.PlanFile; string theDownFileName = await DownLoadFile(SelectFile, false); if (theDownFileName != null) { System.Diagnostics.Process.Start("Explorer", "/select," + theDownFileName); } else { AppFuns.ShowMessage("文件下载失败,可能该文件已被删除!", "警告"); } }
/// <summary> /// 拷贝文件到剪贴板 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MenuItem_CopyFile_ClickAsync(object sender, RoutedEventArgs e) { Lib.PlanFile SelectFile = LB_FileList.SelectedItem as Lib.PlanFile; string theDownFileName = await DownLoadFile(SelectFile, false); if (theDownFileName != null) { System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection(); files.Add(theDownFileName); Clipboard.SetFileDropList(files); } else { AppFuns.ShowMessage("文件下载失败,可能该文件已被删除!", "警告"); } }
/// <summary> /// 重新下载并打开文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MenuItem_ReDwonLoad_ClickAsync(object sender, RoutedEventArgs e) { MenuItem curMenuItem = sender as MenuItem; curMenuItem.IsEnabled = false; Lib.PlanFile SelectFile = LB_FileList.SelectedItem as Lib.PlanFile; string theDownFileName = await DownLoadFile(SelectFile, true); if (theDownFileName != null) { FileOperation.UseDefaultAppOpenFile(theDownFileName); } else { AppFuns.ShowMessage("文件下载失败,可能该文件已被删除!", "警告"); } curMenuItem.IsEnabled = true; }
/// <summary> /// 打开所选文件。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void TB_OpenFile_MouseLeftButtonUpAsync(object sender, System.Windows.Input.MouseButtonEventArgs e) { TextBlock curTextBlock = sender as TextBlock; curTextBlock.IsEnabled = false; Lib.PlanFile SelectFile = LB_FileList.SelectedItem as Lib.PlanFile; string theDownFileName = await DownLoadFile(SelectFile, false); if (theDownFileName != null) { FileOperation.UseDefaultAppOpenFile(theDownFileName); } else { AppFuns.ShowMessage("文件下载失败,可能该文件已被删除!", "警告"); } curTextBlock.IsEnabled = true; }
public CurWinViewModel(FileInfo P_FileInfo, string P_OwnerType, string P_PlanId, string P_OwnerContentType) { UpFileInfo = P_FileInfo; EntityFile = new Lib.PlanFile { ContentType = P_OwnerContentType, PlanId = P_PlanId, Name = UpFileInfo.Name.Substring(0, P_FileInfo.Name.LastIndexOf('.')), UserId = AppSet.LoginUser.Id, Length = UpFileInfo.Length, ExtendName = UpFileInfo.Extension, UpIntProgress = 0, DownIntProgress = 100, Pubdate = System.DateTime.Now, UpDateTime = System.DateTime.Now, Describe = "", }; InitUserList(); }
/// <summary> /// 下载文件,成功返回带路径的文件名,失败返回Null /// </summary> /// <param name="WillDownFile"></param> /// <param name="ReDownLoad"></param> /// <returns></returns> private async Task <string> DownLoadFile(Lib.PlanFile WillDownFile, bool ReDownLoad = false) { ProgressMessageHandler progress = new ProgressMessageHandler(); progress.HttpReceiveProgress += (object sender, HttpProgressEventArgs e) => { WillDownFile.DownIntProgress = e.ProgressPercentage; }; string theDownFileName = await DataPlanFileRepository.DownloadFile(WillDownFile, false, progress); if (theDownFileName != null) { WillDownFile.DownIntProgress = 100; return(theDownFileName); } else { return(null); } }