Skip to content

Commit f8ca155

Browse files
committed
添加完成文件列表显示,接下载准备实现文件删除和下载。
1 parent f44c0dc commit f8ca155

File tree

7 files changed

+300
-2
lines changed

7 files changed

+300
-2
lines changed

软件系统客户端Wpf/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
</Grid>
164164
</Grid>
165165

166+
<!--左侧的侧边栏预告-->
166167
<Grid Width="180" DockPanel.Dock="Left">
167168
<GroupBox Header="系统信息" Margin="0,0,0,0">
168169
<Grid>

软件系统客户端Wpf/MainWindow.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private void Button_Quit_Click(object sender, RoutedEventArgs e)
365365
private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
366366
{
367367
//点击了文件查看
368-
MessageBox.Show("点击了文件");
368+
SetShowRenderControl(UIControl_Files);
369369
}
370370

371371

@@ -645,7 +645,8 @@ private void AccountChip_Click(object sender, RoutedEventArgs e)
645645
private UserChat UIControls_Chat { get; set; }
646646

647647
private UserHome UIControl_Home { get; set; }
648-
648+
649+
private UserFileRender UIControl_Files { get; set; }
649650

650651
private UserPaletteSelector UIControl_Palette { get; set; }
651652

@@ -690,6 +691,8 @@ private void MainRenderInitialization()
690691
UIControl_Palette = new UserPaletteSelector() { DataContext = new PaletteSelectorViewModel() };
691692
all_main_render.Add(UIControl_Palette);
692693

694+
UIControl_Files = new UserFileRender();
695+
all_main_render.Add(UIControl_Files);
693696

694697
}
695698

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<UserControl x:Class="软件系统客户端Wpf.Views.UserFileRender"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:软件系统客户端Wpf.Views"
7+
mc:Ignorable="d"
8+
d:DesignHeight="400" d:DesignWidth="800">
9+
<Grid>
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="auto"></RowDefinition>
12+
<RowDefinition Height="*"></RowDefinition>
13+
</Grid.RowDefinitions>
14+
15+
<Grid Grid.Row="0">
16+
<Grid.ColumnDefinitions>
17+
<ColumnDefinition Width="auto"></ColumnDefinition>
18+
<ColumnDefinition Width="auto"></ColumnDefinition>
19+
<ColumnDefinition Width="*"></ColumnDefinition>
20+
<ColumnDefinition Width="auto"></ColumnDefinition>
21+
<ColumnDefinition Width="auto"></ColumnDefinition>
22+
</Grid.ColumnDefinitions>
23+
24+
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Margin="0,0, 5 5" Width="100"
25+
x:Name="Button_FileUpload" Click="Button_FileUpload_Click">
26+
上传
27+
</Button>
28+
<Button Grid.Column="1" Style="{StaticResource MaterialDesignRaisedLightButton}" Margin="0,0, 5 5" Width="100"
29+
x:Name="Button_FileRefresh" Click="Button_FileRefresh_Click">
30+
刷新
31+
</Button>
32+
33+
<TextBlock Grid.Column="3" VerticalAlignment="Center" FontSize="15">搜索:</TextBlock>
34+
<TextBox Grid.Column="4" Width="200" x:Name="FileSearchFilter" TextChanged="FileSearchFilter_TextChanged"></TextBox>
35+
</Grid>
36+
37+
<Border Grid.Row="1" BorderThickness="0,1,0,0" Margin="0,5,0,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
38+
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
39+
<StackPanel Margin="0,5,5,0" x:Name="FileListControl" ScrollViewer.VerticalScrollBarVisibility="Auto">
40+
41+
</StackPanel>
42+
</ScrollViewer>
43+
</Border>
44+
</Grid>
45+
</UserControl>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<UserControl x:Class="软件系统客户端Wpf.Views.UserFileRenderItem"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:软件系统客户端Wpf.Views"
7+
mc:Ignorable="d"
8+
d:DesignHeight="100" d:DesignWidth="400" BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}"
9+
Margin="0,0,0,3" MinWidth="400">
10+
<Grid Margin="3">
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="auto"></RowDefinition>
13+
<RowDefinition Height="auto"></RowDefinition>
14+
</Grid.RowDefinitions>
15+
<Grid.ColumnDefinitions>
16+
<ColumnDefinition Width="30"></ColumnDefinition>
17+
<ColumnDefinition></ColumnDefinition>
18+
<ColumnDefinition Width="120"></ColumnDefinition>
19+
<ColumnDefinition Width="130"></ColumnDefinition>
20+
<ColumnDefinition Width="60"></ColumnDefinition>
21+
</Grid.ColumnDefinitions>
22+
<Image x:Name="FileIcon" Grid.RowSpan="2" Width="18" Height="18" VerticalAlignment="Top" Margin="3,6,3,3"></Image>
23+
24+
<TextBlock x:Name="FileName" Grid.Column="1" VerticalAlignment="Center">文件名称:</TextBlock>
25+
<TextBlock x:Name="FileSize" Grid.Column="2" VerticalAlignment="Center">大小:</TextBlock>
26+
<TextBlock x:Name="FileDate" Grid.Column="3" VerticalAlignment="Center">日期:</TextBlock>
27+
28+
<TextBlock x:Name="FileDeleteButton" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
29+
Background="{DynamicResource PrimaryHueLightBrush}" Padding="6,3,6,3">删除</TextBlock>
30+
31+
<TextBlock x:Name="FileDescription" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">文件备注:</TextBlock>
32+
<TextBlock x:Name="FilePeople" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center">上传人:</TextBlock>
33+
<TextBlock x:Name="FileDownloadTimes" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center">下载次数:</TextBlock>
34+
<TextBlock x:Name="FileDownloadButton" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
35+
Background="{DynamicResource PrimaryHueLightBrush}" Padding="6,3,6,3">下载</TextBlock>
36+
</Grid>
37+
</UserControl>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using ClientsLibrary;
2+
using HslCommunication.Enthernet;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace 软件系统客户端Wpf.Views
19+
{
20+
/// <summary>
21+
/// UserFileRenderItem.xaml 的交互逻辑
22+
/// </summary>
23+
public partial class UserFileRenderItem : UserControl
24+
{
25+
public UserFileRenderItem()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
31+
{
32+
BitmapImage bitmapImage = new BitmapImage();
33+
34+
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
35+
{
36+
bitmap.Save(ms, bitmap.RawFormat);
37+
bitmapImage.BeginInit();
38+
bitmapImage.StreamSource = ms;
39+
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
40+
bitmapImage.EndInit();
41+
bitmapImage.Freeze();
42+
}
43+
44+
return bitmapImage;
45+
}
46+
47+
private HslSoftFile Hufile { get; set; } = null;
48+
/// <summary>
49+
/// 设置文件数据
50+
/// </summary>
51+
/// <param name="file">文件的信息对象</param>
52+
/// <param name="deleteEnable">删除控件的使能委托</param>
53+
public void SetFile(HslSoftFile file)
54+
{
55+
Hufile = file;
56+
//获取后缀名
57+
int dotIndex = Hufile.FileName.LastIndexOf('.');
58+
if (dotIndex >= 0)
59+
{
60+
FileIcon.Source = BitmapToBitmapImage(Hufile.GetFileIcon());
61+
}
62+
63+
FileName.Text = "文件名称:" + file.FileName;
64+
FileSize.Text = "大小:" + file.GetTextFromFileSize();
65+
FileDate.Text = "日期:" + file.UploadDate.ToString("yyyy-MM-dd");
66+
FileDescription.Text = "文件备注:" + file.FileNote;
67+
FilePeople.Text = "上传人:" + file.UploadName;
68+
FileDownloadTimes.Text = "下载数:" + file.FileDownloadTimes;
69+
70+
FileDeleteButton.IsEnabled = file.UploadName == UserClient.UserAccount.UserName;
71+
FileDownloadButton.IsEnabled = true;
72+
}
73+
}
74+
}

软件系统客户端Wpf/软件系统客户端Wpf.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
<Compile Include="Views\UserChat.xaml.cs">
8282
<DependentUpon>UserChat.xaml</DependentUpon>
8383
</Compile>
84+
<Compile Include="Views\UserFileRender.xaml.cs">
85+
<DependentUpon>UserFileRender.xaml</DependentUpon>
86+
</Compile>
87+
<Compile Include="Views\UserFileRenderItem.xaml.cs">
88+
<DependentUpon>UserFileRenderItem.xaml</DependentUpon>
89+
</Compile>
8490
<Compile Include="Views\UserHome.xaml.cs">
8591
<DependentUpon>UserHome.xaml</DependentUpon>
8692
</Compile>
@@ -114,6 +120,14 @@
114120
<SubType>Designer</SubType>
115121
<Generator>MSBuild:Compile</Generator>
116122
</Page>
123+
<Page Include="Views\UserFileRender.xaml">
124+
<SubType>Designer</SubType>
125+
<Generator>MSBuild:Compile</Generator>
126+
</Page>
127+
<Page Include="Views\UserFileRenderItem.xaml">
128+
<SubType>Designer</SubType>
129+
<Generator>MSBuild:Compile</Generator>
130+
</Page>
117131
<Page Include="Views\UserHome.xaml">
118132
<SubType>Designer</SubType>
119133
<Generator>MSBuild:Compile</Generator>

0 commit comments

Comments
 (0)