From f8ca155e9fac5283221df05588b7e8f50e71b52d Mon Sep 17 00:00:00 2001 From: dathlin Date: Tue, 18 Jul 2017 10:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=8C=E6=88=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=EF=BC=8C=E6=8E=A5?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=87=86=E5=A4=87=E5=AE=9E=E7=8E=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E5=92=8C=E4=B8=8B=E8=BD=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 软件系统客户端Wpf/MainWindow.xaml | 1 + 软件系统客户端Wpf/MainWindow.xaml.cs | 7 +- 软件系统客户端Wpf/Views/UserFileRender.xaml | 45 +++++++ .../Views/UserFileRender.xaml.cs | 124 ++++++++++++++++++ .../Views/UserFileRenderItem.xaml | 37 ++++++ .../Views/UserFileRenderItem.xaml.cs | 74 +++++++++++ 软件系统客户端Wpf/软件系统客户端Wpf.csproj | 14 ++ 7 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 软件系统客户端Wpf/Views/UserFileRender.xaml create mode 100644 软件系统客户端Wpf/Views/UserFileRender.xaml.cs create mode 100644 软件系统客户端Wpf/Views/UserFileRenderItem.xaml create mode 100644 软件系统客户端Wpf/Views/UserFileRenderItem.xaml.cs diff --git a/软件系统客户端Wpf/MainWindow.xaml b/软件系统客户端Wpf/MainWindow.xaml index 16f1fd8..4bfc178 100644 --- a/软件系统客户端Wpf/MainWindow.xaml +++ b/软件系统客户端Wpf/MainWindow.xaml @@ -163,6 +163,7 @@ + diff --git a/软件系统客户端Wpf/MainWindow.xaml.cs b/软件系统客户端Wpf/MainWindow.xaml.cs index 8831d7b..44f1bef 100644 --- a/软件系统客户端Wpf/MainWindow.xaml.cs +++ b/软件系统客户端Wpf/MainWindow.xaml.cs @@ -365,7 +365,7 @@ namespace 软件系统客户端Wpf private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //点击了文件查看 - MessageBox.Show("点击了文件"); + SetShowRenderControl(UIControl_Files); } @@ -645,7 +645,8 @@ namespace 软件系统客户端Wpf private UserChat UIControls_Chat { get; set; } private UserHome UIControl_Home { get; set; } - + + private UserFileRender UIControl_Files { get; set; } private UserPaletteSelector UIControl_Palette { get; set; } @@ -690,6 +691,8 @@ namespace 软件系统客户端Wpf UIControl_Palette = new UserPaletteSelector() { DataContext = new PaletteSelectorViewModel() }; all_main_render.Add(UIControl_Palette); + UIControl_Files = new UserFileRender(); + all_main_render.Add(UIControl_Files); } diff --git a/软件系统客户端Wpf/Views/UserFileRender.xaml b/软件系统客户端Wpf/Views/UserFileRender.xaml new file mode 100644 index 0000000..b7e2939 --- /dev/null +++ b/软件系统客户端Wpf/Views/UserFileRender.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + 搜索: + + + + + + + + + + + + diff --git a/软件系统客户端Wpf/Views/UserFileRender.xaml.cs b/软件系统客户端Wpf/Views/UserFileRender.xaml.cs new file mode 100644 index 0000000..b522577 --- /dev/null +++ b/软件系统客户端Wpf/Views/UserFileRender.xaml.cs @@ -0,0 +1,124 @@ +using ClientsLibrary; +using CommonLibrary; +using HslCommunication; +using HslCommunication.Enthernet; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace 软件系统客户端Wpf.Views +{ + /// + /// UserFileRender.xaml 的交互逻辑 + /// + public partial class UserFileRender : UserControl + { + public UserFileRender() + { + InitializeComponent(); + } + + private void FileSearchFilter_TextChanged(object sender, TextChangedEventArgs e) + { + //搜索时触发的数据 + if (!string.IsNullOrEmpty(FileSearchFilter.Text)) + { + string pattern = FileSearchFilter.Text; + SetFilesShow(Cache_Files.Where(f => + f.FileName.Contains(pattern) || + f.FileNote.Contains(pattern) || + f.UploadName.Contains(pattern)).ToList()); + } + else + { + SetFilesShow(Cache_Files); + } + } + + private void Button_FileUpload_Click(object sender, RoutedEventArgs e) + { + //上传数据,先对权限进行验证 + if (UserClient.UserAccount.Grade < AccountGrade.Technology) + { + MessageBox.Show("权限不够!"); + return; + } + + using (FormSimplyFileUpload upload = new FormSimplyFileUpload( + UserClient.ServerIp, + CommonLibrary.CommonLibrary.Port_Share_File, + UserClient.UserAccount.UserName)) + { + upload.ShowDialog(); + } + } + + private void Button_FileRefresh_Click(object sender, RoutedEventArgs e) + { + //向服务器请求数据 + OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.请求文件); + if (result.IsSuccess) + { + Cache_Files = JArray.Parse(result.Content).ToObject>(); + SetFilesShow(Cache_Files); + } + else + { + MessageBox.Show(result.ToMessageShowString()); + } + } + + + public void UpdateFiles() + { + Button_FileRefresh_Click(null, new RoutedEventArgs()); + } + + private void ClearControls() + { + FileListControl.Children.Clear(); + //while (FilesControls.Count > 0) + //{ + // FilesControls.Pop().Dispose(); + //} + } + + private void SetFilesShow(List files) + { + //清楚缓存 + ClearControls(); + if (files?.Count > 0 && FileListControl.ActualWidth > 20) + { + //添加子控件 + foreach (var m in files) + { + UserFileRenderItem item = new UserFileRenderItem(); + FileListControl.Children.Add(item); + item.SetFile(m); + } + } + } + + /// + /// 所有文件信息的缓存,以支持直接的搜索 + /// + private List Cache_Files { get; set; } = new List(); + /// + /// 文件控件的缓存列表,方便清除垃圾 + /// + private Stack FilesControls = new Stack(); + + } +} diff --git a/软件系统客户端Wpf/Views/UserFileRenderItem.xaml b/软件系统客户端Wpf/Views/UserFileRenderItem.xaml new file mode 100644 index 0000000..d17a163 --- /dev/null +++ b/软件系统客户端Wpf/Views/UserFileRenderItem.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + 文件名称: + 大小: + 日期: + + 删除 + + 文件备注: + 上传人: + 下载次数: + 下载 + + diff --git a/软件系统客户端Wpf/Views/UserFileRenderItem.xaml.cs b/软件系统客户端Wpf/Views/UserFileRenderItem.xaml.cs new file mode 100644 index 0000000..11a893a --- /dev/null +++ b/软件系统客户端Wpf/Views/UserFileRenderItem.xaml.cs @@ -0,0 +1,74 @@ +using ClientsLibrary; +using HslCommunication.Enthernet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace 软件系统客户端Wpf.Views +{ + /// + /// UserFileRenderItem.xaml 的交互逻辑 + /// + public partial class UserFileRenderItem : UserControl + { + public UserFileRenderItem() + { + InitializeComponent(); + } + + private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) + { + BitmapImage bitmapImage = new BitmapImage(); + + using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) + { + bitmap.Save(ms, bitmap.RawFormat); + bitmapImage.BeginInit(); + bitmapImage.StreamSource = ms; + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.EndInit(); + bitmapImage.Freeze(); + } + + return bitmapImage; + } + + private HslSoftFile Hufile { get; set; } = null; + /// + /// 设置文件数据 + /// + /// 文件的信息对象 + /// 删除控件的使能委托 + public void SetFile(HslSoftFile file) + { + Hufile = file; + //获取后缀名 + int dotIndex = Hufile.FileName.LastIndexOf('.'); + if (dotIndex >= 0) + { + FileIcon.Source = BitmapToBitmapImage(Hufile.GetFileIcon()); + } + + FileName.Text = "文件名称:" + file.FileName; + FileSize.Text = "大小:" + file.GetTextFromFileSize(); + FileDate.Text = "日期:" + file.UploadDate.ToString("yyyy-MM-dd"); + FileDescription.Text = "文件备注:" + file.FileNote; + FilePeople.Text = "上传人:" + file.UploadName; + FileDownloadTimes.Text = "下载数:" + file.FileDownloadTimes; + + FileDeleteButton.IsEnabled = file.UploadName == UserClient.UserAccount.UserName; + FileDownloadButton.IsEnabled = true; + } + } +} diff --git a/软件系统客户端Wpf/软件系统客户端Wpf.csproj b/软件系统客户端Wpf/软件系统客户端Wpf.csproj index 3ee61a8..c6347f6 100644 --- a/软件系统客户端Wpf/软件系统客户端Wpf.csproj +++ b/软件系统客户端Wpf/软件系统客户端Wpf.csproj @@ -81,6 +81,12 @@ UserChat.xaml + + UserFileRender.xaml + + + UserFileRenderItem.xaml + UserHome.xaml @@ -114,6 +120,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile