Skip to content

Commit 4f66ccc

Browse files
committed
wpf客户端实现文件上传下载。
1 parent f8ca155 commit 4f66ccc

File tree

8 files changed

+148
-32
lines changed

8 files changed

+148
-32
lines changed

Public/HslCommunication.dll

512 Bytes
Binary file not shown.

Public/HslCommunication.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public LoginWindow()
3232
{
3333
InitializeComponent();
3434

35-
UserClient.JsonSettings.FileSavePath = AppDomain.CurrentDomain.BaseDirectory + @"\JsonSettings.txt";
35+
UserClient.JsonSettings.FileSavePath = AppDomain.CurrentDomain.BaseDirectory + @"JsonSettings.txt";
3636
UserClient.JsonSettings.LoadByFile();
3737
}
3838

@@ -91,7 +91,7 @@ private void ThreadCheckAccount()
9191
Action start_update = delegate
9292
{
9393
//需要该exe支持,否则将无法是实现自动版本控制
94-
string update_file_name = AppDomain.CurrentDomain.BaseDirectory + @"\软件自动更新.exe";
94+
string update_file_name = AppDomain.CurrentDomain.BaseDirectory + @"软件自动更新.exe";
9595
try
9696
{
9797
System.Diagnostics.Process.Start(update_file_name);
@@ -324,9 +324,9 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
324324

325325

326326

327-
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt"))
327+
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt"))
328328
{
329-
using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt", Encoding.UTF8))
329+
using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt", Encoding.UTF8))
330330
{
331331
string temp = sr.ReadToEnd();
332332
MaterialDesignThemes.Wpf.Palette obj = JObject.Parse(temp).ToObject<MaterialDesignThemes.Wpf.Palette>();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
CornerRadius="2" MouseLeftButtonDown="Border_MouseLeftButtonDown" Cursor="Hand"
263263
Background="{DynamicResource PrimaryHueLightBrush}">
264264
<TextBlock HorizontalAlignment="Right" x:Name="TextBlock_FileCount" Margin="0,0,5,0" ScrollViewer.VerticalScrollBarVisibility="Disabled"
265-
>0</TextBlock>
265+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">0</TextBlock>
266266
</Border>
267267
<TextBlock Grid.Row="1" Grid.Column="0">在线信息:</TextBlock>
268268
<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="ListBox_Onlines" FontSize="10.5"></ListBox>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
8686

8787
//保存当前的颜色选择
8888
var p = new PaletteHelper().QueryPalette();
89-
using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt", false, Encoding.UTF8))
89+
using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt", false, Encoding.UTF8))
9090
{
9191
sw.Write(JObject.FromObject(p).ToString());
9292
}
@@ -366,6 +366,7 @@ private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
366366
{
367367
//点击了文件查看
368368
SetShowRenderControl(UIControl_Files);
369+
UIControl_Files.UpdateFiles();
369370
}
370371

371372

@@ -609,7 +610,7 @@ private void SendServerUdpData(int customer, string data)
609610

610611
private void SoftUserPortraitInitialization()
611612
{
612-
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory + @"\Portrait\" + UserClient.UserAccount.UserName,
613+
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory + @"Portrait\" + UserClient.UserAccount.UserName,
613614
m => {
614615
byte[] content = System.IO.File.ReadAllBytes(m);
615616
BitmapImage bi = new BitmapImage();

软件系统客户端Wpf/Views/UserFileRender.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</Grid>
3636

3737
<Border Grid.Row="1" BorderThickness="0,1,0,0" Margin="0,5,0,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
38-
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
38+
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
3939
<StackPanel Margin="0,5,5,0" x:Name="FileListControl" ScrollViewer.VerticalScrollBarVisibility="Auto">
4040

4141
</StackPanel>

软件系统客户端Wpf/Views/UserFileRenderItem.xaml

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,40 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:软件系统客户端Wpf.Views"
7+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
78
mc:Ignorable="d"
89
d:DesignHeight="100" d:DesignWidth="400" BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}"
910
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>
11+
<StackPanel>
12+
<Grid Margin="3">
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="auto"></RowDefinition>
15+
<RowDefinition Height="auto"></RowDefinition>
16+
</Grid.RowDefinitions>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="30"></ColumnDefinition>
19+
<ColumnDefinition></ColumnDefinition>
20+
<ColumnDefinition Width="120"></ColumnDefinition>
21+
<ColumnDefinition Width="130"></ColumnDefinition>
22+
<ColumnDefinition Width="60"></ColumnDefinition>
23+
</Grid.ColumnDefinitions>
24+
<Image x:Name="FileIcon" Grid.RowSpan="2" Width="16" Height="16" VerticalAlignment="Top" Margin="3,6,3,3"></Image>
2325

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>
26+
<TextBlock x:Name="FileName" Grid.Column="1" VerticalAlignment="Center">文件名称:</TextBlock>
27+
<TextBlock x:Name="FileSize" Grid.Column="2" VerticalAlignment="Center">大小:</TextBlock>
28+
<TextBlock x:Name="FileDate" Grid.Column="3" VerticalAlignment="Center">日期:</TextBlock>
2729

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+
<TextBlock x:Name="FileDeleteButton" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
31+
Background="{DynamicResource PrimaryHueLightBrush}" Padding="12,3,12,3" MouseLeftButtonDown="FileDeleteButton_MouseLeftButtonDown"
32+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">删除</TextBlock>
3033

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>
34+
<TextBlock x:Name="FileDescription" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">文件备注:</TextBlock>
35+
<TextBlock x:Name="FilePeople" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center">上传人:</TextBlock>
36+
<TextBlock x:Name="FileDownloadTimes" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center">下载次数:</TextBlock>
37+
<TextBlock x:Name="FileDownloadButton" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
38+
Background="{DynamicResource PrimaryHueLightBrush}" Padding="12,3,12,3" MouseLeftButtonDown="FileDownloadButton_MouseLeftButtonDown"
39+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">下载</TextBlock>
40+
</Grid>
41+
<ProgressBar x:Name="FileDownloadProgress" Grid.Row="2" Grid.ColumnSpan="4" Margin="30,-5,63,0" Height="4"></ProgressBar>
42+
</StackPanel>
3743
</UserControl>

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
using System.Windows.Media.Imaging;
1515
using System.Windows.Navigation;
1616
using System.Windows.Shapes;
17+
using HslCommunication;
18+
using System.Threading;
19+
using System.IO;
1720

1821
namespace 软件系统客户端Wpf.Views
1922
{
@@ -66,9 +69,82 @@ public void SetFile(HslSoftFile file)
6669
FileDescription.Text = "文件备注:" + file.FileNote;
6770
FilePeople.Text = "上传人:" + file.UploadName;
6871
FileDownloadTimes.Text = "下载数:" + file.FileDownloadTimes;
72+
6973

7074
FileDeleteButton.IsEnabled = file.UploadName == UserClient.UserAccount.UserName;
7175
FileDownloadButton.IsEnabled = true;
7276
}
77+
78+
private void FileDeleteButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
79+
{
80+
//删除文件
81+
if (Hufile.UploadName != UserClient.UserAccount.UserName)
82+
{
83+
MessageBox.Show("无法删除不是自己上传的文件。");
84+
return;
85+
}
86+
if (MessageBox.Show("请确认是否真的删除?", "删除确认", MessageBoxButton.YesNo) == MessageBoxResult.No)
87+
{
88+
return;
89+
}
90+
91+
//确认删除
92+
OperateResultString result = SimpleFileClient.DeleteFile(UserClient.ServerIp, CommonLibrary.CommonLibrary.Port_Share_File, Hufile.FileName);
93+
if(result.IsSuccess)
94+
{
95+
MessageBox.Show("删除成功!");
96+
}
97+
else
98+
{
99+
MessageBox.Show("删除失败!原因:" + result.Message);
100+
}
101+
}
102+
103+
private void FileDownloadButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
104+
{
105+
//下载文件
106+
FileDownloadButton.IsEnabled = false;
107+
108+
Thread thread_down_file = new Thread(new ThreadStart(ThreadDownloadFile));
109+
thread_down_file.IsBackground = true;
110+
thread_down_file.Start();
111+
}
112+
private void ThreadDownloadFile()
113+
{
114+
string save_file_name = AppDomain.CurrentDomain.BaseDirectory + "download\\files";
115+
if (!Directory.Exists(save_file_name))
116+
{
117+
Directory.CreateDirectory(save_file_name);
118+
}
119+
120+
save_file_name += "\\" + Hufile.FileName;
121+
122+
123+
OperateResultString result = SimpleFileClient.DownloadFile(UserClient.ServerIp, CommonLibrary.CommonLibrary.Port_Share_File, Hufile.FileName,
124+
(m, n) =>
125+
{
126+
Dispatcher.Invoke(new Action(() =>
127+
{
128+
FileDownloadProgress.Value = m * 100d / n;
129+
}));
130+
}, save_file_name);
131+
132+
Dispatcher.Invoke(new Action(() =>
133+
{
134+
if (result.IsSuccess)
135+
{
136+
if (MessageBox.Show("下载完成,路径为:" + save_file_name + Environment.NewLine +
137+
"是否打开文件路径?", "打开确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
138+
{
139+
System.Diagnostics.Process.Start("explorer.exe", @"/select," + save_file_name);
140+
}
141+
}
142+
else
143+
{
144+
MessageBox.Show("下载失败,错误原因:" + result.Message);
145+
}
146+
FileDownloadButton.IsEnabled = true;
147+
}));
148+
}
73149
}
74150
}

0 commit comments

Comments
 (0)