public async Task GetFilesAsync() { PlanFiles.Clear(); PlanFileSearchResult SearchResult = await DataPlanFileRepository.ReadFiles(SearchCondition); if (SearchResult == null) { return; } SearchCondition.RecordCount = SearchResult.SearchCondition.RecordCount; if (SearchResult.RecordList != null && SearchResult.RecordList.Count > 0) { SearchResult.RecordList.ToList().ForEach(e => { PlanFiles.Add(e); }); } if (SearchCondition.PageCount > 1) { CanVisible = "Visible"; } else { CanVisible = "Collapsed"; } }
/// <summary> /// 更新文件信息(文件名及文件描述) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_SaveChange(object sender, RoutedEventArgs e) { ExcuteResult JsonResult = await DataPlanFileRepository.UpdateFileInfo(_CurUCViewModel.CurFile); if (JsonResult.State == 0) { AppFuns.SetStateBarText(JsonResult.Msg); } AppFuns.ShowMessage(JsonResult.Msg, "消息"); }
/// <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); } }
private async void BtnUploadFile_ClickAsync(object sender, RoutedEventArgs e) { try { ExcuteResult JsonResult = new ExcuteResult(); if (_CurWinViewModel.EntityFile.ContentType == null) { AppFuns.ShowMessage("请选择文件内容类型!", Caption: "警告"); return; } _CurWinViewModel.EntityFile.CanReadUserIds = _CurWinViewModel.GetSelectUserIds(); if (!_CurWinViewModel.EntityFile.CanReadUserIds.Contains(AppSet.LoginUser.Id)) { if (!AppFuns.ShowMessage("你本人没有读取该文件的权限?", Caption: "确认", showYesNo: true)) { return; } } BtnUpFile.IsEnabled = false; ProgressMessageHandler progress = new ProgressMessageHandler(); progress.HttpSendProgress += (object sender, HttpProgressEventArgs e) => { _CurWinViewModel.EntityFile.UpIntProgress = e.ProgressPercentage; }; JsonResult = await DataPlanFileRepository.UpLoadFileInfo(_CurWinViewModel.EntityFile, _CurWinViewModel.UpFileInfo.OpenRead(), "upfilekey", "upfilename", progress); if (JsonResult != null && JsonResult.State == 0) { _CurWinViewModel.EntityFile.Id = JsonResult.Tag; _CurWinViewModel.EntityFile.UpIntProgress = 100; _CurWinViewModel.EntityFile.DownIntProgress = 0; _CallBackFunc(_CurWinViewModel.EntityFile); this.Close(); } else { AppFuns.ShowMessage(JsonResult.Msg, Caption: "错误", isErr: true); BtnUpFile.IsEnabled = true; } } catch (Exception ex) { AppFuns.ShowMessage(ex.Message, Caption: "错误", isErr: true); } }
/// <summary> /// 删除该文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_DeleteFileAsync(object sender, RoutedEventArgs e) { if (AppFuns.ShowMessage($"确定要删除[{_CurUCViewModel.CurFile.Name}]文件吗?", Caption: "确认", showYesNo: true)) { ExcuteResult JsonResult = await DataPlanFileRepository.DeleteFileInfo(_CurUCViewModel.CurFile); if (JsonResult.State == 0) { _DelFileCallBackFun?.Invoke(_CurUCViewModel.CurFile); AppFuns.SetStateBarText(JsonResult.Msg); } else { AppFuns.ShowMessage(JsonResult.Msg, "消息"); } } }
/// <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); } }
public async Task Init_PlanInfoVMAsync(Lib.PlanEntity P_Entity) { CurPlan = P_Entity; if (PlanFiles.Count < 1) { //如果该计划的附件文件没有读取则读取之。 PlanFileSearch mSearchFile = new PlanFileSearch() { PlanId = P_Entity.Id, UserId = AppSet.LoginUser.Id }; PlanFileSearchResult planFileSearchResult = await DataPlanFileRepository.ReadFiles(mSearchFile); if (planFileSearchResult != null && planFileSearchResult.RecordList != null) { planFileSearchResult.RecordList.ToList().ForEach(e => { e.UpIntProgress = 100; PlanFiles.Add(e); }); } } if (CurPlan.CreateUserId != null) { CurPlanCreateUserName = AppSet.SysUsers.Where(e => CurPlan.CreateUserId.Equals(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name).FirstOrDefault()?.Trim(); } if (CurPlan.ResponsiblePerson != null) { CurPlanResponsibleName = AppSet.SysUsers.Where(e => CurPlan.ResponsiblePerson.Equals(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name).FirstOrDefault()?.Trim(); } if (CurPlan.ReadGrant != null) { CurPlanHasGrantNames = string.Join(",", AppSet.SysUsers.Where(e => CurPlan.ReadGrant.Contains(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name)?.ToArray()); } if (CurPlan.Helpers != null) { CurPlanHelperNames = string.Join(",", AppSet.SysUsers.Where(e => CurPlan.Helpers.Contains(e.Id, System.StringComparison.Ordinal)).Select(x => x.Name)?.ToArray()); } }
/// <summary> /// 打开该文件,如本地不存在则下载之。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_OpenFileAsync(object sender, RoutedEventArgs e) { Button V_Button = sender as Button; V_Button.IsEnabled = false; ProgressMessageHandler progress = new System.Net.Http.Handlers.ProgressMessageHandler(); progress.HttpReceiveProgress += (object sender, System.Net.Http.Handlers.HttpProgressEventArgs e) => { _CurUCViewModel.CurFile.DownIntProgress = e.ProgressPercentage;// (double)(e.BytesTransferred / e.TotalBytes) * 100; }; string theDownFileName = await DataPlanFileRepository.DownloadFile(_CurUCViewModel.CurFile, false, progress); if (theDownFileName == null) { AppFuns.ShowMessage("文件下载失败,可能已被删除!", "警告"); V_Button.IsEnabled = true; return; } _CurUCViewModel.CurFile.DownIntProgress = 100; DataPlanFileRepository.OpenFileInfo(theDownFileName); V_Button.IsEnabled = true; }