|
| 1 | +using ClientsLibrary; |
| 2 | +using CommonLibrary; |
| 3 | +using HslCommunication; |
| 4 | +using HslCommunication.Enthernet; |
| 5 | +using Newtonsoft.Json.Linq; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Linq; |
| 9 | +using System.Text; |
| 10 | +using System.Threading.Tasks; |
| 11 | +using System.Windows; |
| 12 | +using System.Windows.Controls; |
| 13 | +using System.Windows.Data; |
| 14 | +using System.Windows.Documents; |
| 15 | +using System.Windows.Input; |
| 16 | +using System.Windows.Media; |
| 17 | +using System.Windows.Media.Imaging; |
| 18 | +using System.Windows.Navigation; |
| 19 | +using System.Windows.Shapes; |
| 20 | + |
| 21 | +namespace 软件系统客户端Wpf.Views |
| 22 | +{ |
| 23 | + /// <summary> |
| 24 | + /// UserFileRender.xaml 的交互逻辑 |
| 25 | + /// </summary> |
| 26 | + public partial class UserFileRender : UserControl |
| 27 | + { |
| 28 | + public UserFileRender() |
| 29 | + { |
| 30 | + InitializeComponent(); |
| 31 | + } |
| 32 | + |
| 33 | + private void FileSearchFilter_TextChanged(object sender, TextChangedEventArgs e) |
| 34 | + { |
| 35 | + //搜索时触发的数据 |
| 36 | + if (!string.IsNullOrEmpty(FileSearchFilter.Text)) |
| 37 | + { |
| 38 | + string pattern = FileSearchFilter.Text; |
| 39 | + SetFilesShow(Cache_Files.Where(f => |
| 40 | + f.FileName.Contains(pattern) || |
| 41 | + f.FileNote.Contains(pattern) || |
| 42 | + f.UploadName.Contains(pattern)).ToList()); |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + SetFilesShow(Cache_Files); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private void Button_FileUpload_Click(object sender, RoutedEventArgs e) |
| 51 | + { |
| 52 | + //上传数据,先对权限进行验证 |
| 53 | + if (UserClient.UserAccount.Grade < AccountGrade.Technology) |
| 54 | + { |
| 55 | + MessageBox.Show("权限不够!"); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + using (FormSimplyFileUpload upload = new FormSimplyFileUpload( |
| 60 | + UserClient.ServerIp, |
| 61 | + CommonLibrary.CommonLibrary.Port_Share_File, |
| 62 | + UserClient.UserAccount.UserName)) |
| 63 | + { |
| 64 | + upload.ShowDialog(); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private void Button_FileRefresh_Click(object sender, RoutedEventArgs e) |
| 69 | + { |
| 70 | + //向服务器请求数据 |
| 71 | + OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.请求文件); |
| 72 | + if (result.IsSuccess) |
| 73 | + { |
| 74 | + Cache_Files = JArray.Parse(result.Content).ToObject<List<HslSoftFile>>(); |
| 75 | + SetFilesShow(Cache_Files); |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + MessageBox.Show(result.ToMessageShowString()); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + public void UpdateFiles() |
| 85 | + { |
| 86 | + Button_FileRefresh_Click(null, new RoutedEventArgs()); |
| 87 | + } |
| 88 | + |
| 89 | + private void ClearControls() |
| 90 | + { |
| 91 | + FileListControl.Children.Clear(); |
| 92 | + //while (FilesControls.Count > 0) |
| 93 | + //{ |
| 94 | + // FilesControls.Pop().Dispose(); |
| 95 | + //} |
| 96 | + } |
| 97 | + |
| 98 | + private void SetFilesShow(List<HslSoftFile> files) |
| 99 | + { |
| 100 | + //清楚缓存 |
| 101 | + ClearControls(); |
| 102 | + if (files?.Count > 0 && FileListControl.ActualWidth > 20) |
| 103 | + { |
| 104 | + //添加子控件 |
| 105 | + foreach (var m in files) |
| 106 | + { |
| 107 | + UserFileRenderItem item = new UserFileRenderItem(); |
| 108 | + FileListControl.Children.Add(item); |
| 109 | + item.SetFile(m); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// 所有文件信息的缓存,以支持直接的搜索 |
| 116 | + /// </summary> |
| 117 | + private List<HslSoftFile> Cache_Files { get; set; } = new List<HslSoftFile>(); |
| 118 | + /// <summary> |
| 119 | + /// 文件控件的缓存列表,方便清除垃圾 |
| 120 | + /// </summary> |
| 121 | + private Stack<IDisposable> FilesControls = new Stack<IDisposable>(); |
| 122 | + |
| 123 | + } |
| 124 | +} |
0 commit comments