wpf客户端实现文件上传下载。
This commit is contained in:
Binary file not shown.
@@ -1962,6 +1962,31 @@
|
||||
刷新客户端的文件信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:HslCommunication.Enthernet.SimpleFileClient">
|
||||
<summary>
|
||||
文件传送中的客户端类
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:HslCommunication.Enthernet.SimpleFileClient.DeleteFile(System.String,System.Int32,System.String)">
|
||||
<summary>
|
||||
删除服务器上的文件
|
||||
</summary>
|
||||
<param name="serverIp"></param>
|
||||
<param name="serverPort"></param>
|
||||
<param name="fileName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:HslCommunication.Enthernet.SimpleFileClient.DownloadFile(System.String,System.Int32,System.String,System.Action{System.Int32,System.Int32},System.String)">
|
||||
<summary>
|
||||
下载文件信息
|
||||
</summary>
|
||||
<param name="serverIp"></param>
|
||||
<param name="serverPort"></param>
|
||||
<param name="fileName"></param>
|
||||
<param name="processReport"></param>
|
||||
<param name="fileSave"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:HslCommunication.Enthernet.Net_File_Server">
|
||||
<summary>
|
||||
文件传送类服务器,仅仅负责数据传送部分,不负责数据库的存储
|
||||
@@ -2990,6 +3015,14 @@
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:HslCommunication.NetSupport.GetBytesFromString(System.Int32,System.String)">
|
||||
<summary>
|
||||
根据字符串及指令头返回数据信息
|
||||
</summary>
|
||||
<param name="code"></param>
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:HslCommunication.NetBase">
|
||||
<summary>
|
||||
一个网络通信类的基础类
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace 软件系统客户端Wpf
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
UserClient.JsonSettings.FileSavePath = AppDomain.CurrentDomain.BaseDirectory + @"\JsonSettings.txt";
|
||||
UserClient.JsonSettings.FileSavePath = AppDomain.CurrentDomain.BaseDirectory + @"JsonSettings.txt";
|
||||
UserClient.JsonSettings.LoadByFile();
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace 软件系统客户端Wpf
|
||||
Action start_update = delegate
|
||||
{
|
||||
//需要该exe支持,否则将无法是实现自动版本控制
|
||||
string update_file_name = AppDomain.CurrentDomain.BaseDirectory + @"\软件自动更新.exe";
|
||||
string update_file_name = AppDomain.CurrentDomain.BaseDirectory + @"软件自动更新.exe";
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start(update_file_name);
|
||||
@@ -324,9 +324,9 @@ namespace 软件系统客户端Wpf
|
||||
|
||||
|
||||
|
||||
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt"))
|
||||
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt"))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt", Encoding.UTF8))
|
||||
using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt", Encoding.UTF8))
|
||||
{
|
||||
string temp = sr.ReadToEnd();
|
||||
MaterialDesignThemes.Wpf.Palette obj = JObject.Parse(temp).ToObject<MaterialDesignThemes.Wpf.Palette>();
|
||||
|
||||
@@ -262,7 +262,7 @@
|
||||
CornerRadius="2" MouseLeftButtonDown="Border_MouseLeftButtonDown" Cursor="Hand"
|
||||
Background="{DynamicResource PrimaryHueLightBrush}">
|
||||
<TextBlock HorizontalAlignment="Right" x:Name="TextBlock_FileCount" Margin="0,0,5,0" ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
>0</TextBlock>
|
||||
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">0</TextBlock>
|
||||
</Border>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0">在线信息:</TextBlock>
|
||||
<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="ListBox_Onlines" FontSize="10.5"></ListBox>
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace 软件系统客户端Wpf
|
||||
|
||||
//保存当前的颜色选择
|
||||
var p = new PaletteHelper().QueryPalette();
|
||||
using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\Palette.txt", false, Encoding.UTF8))
|
||||
using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"Palette.txt", false, Encoding.UTF8))
|
||||
{
|
||||
sw.Write(JObject.FromObject(p).ToString());
|
||||
}
|
||||
@@ -366,6 +366,7 @@ namespace 软件系统客户端Wpf
|
||||
{
|
||||
//点击了文件查看
|
||||
SetShowRenderControl(UIControl_Files);
|
||||
UIControl_Files.UpdateFiles();
|
||||
}
|
||||
|
||||
|
||||
@@ -609,7 +610,7 @@ namespace 软件系统客户端Wpf
|
||||
|
||||
private void SoftUserPortraitInitialization()
|
||||
{
|
||||
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory + @"\Portrait\" + UserClient.UserAccount.UserName,
|
||||
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory + @"Portrait\" + UserClient.UserAccount.UserName,
|
||||
m => {
|
||||
byte[] content = System.IO.File.ReadAllBytes(m);
|
||||
BitmapImage bi = new BitmapImage();
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1" BorderThickness="0,1,0,0" Margin="0,5,0,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
|
||||
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="0,5,5,0" x:Name="FileListControl" ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
|
||||
</StackPanel>
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:软件系统客户端Wpf.Views"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="100" d:DesignWidth="400" BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}"
|
||||
Margin="0,0,0,3" MinWidth="400">
|
||||
<StackPanel>
|
||||
<Grid Margin="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
@@ -19,19 +21,23 @@
|
||||
<ColumnDefinition Width="130"></ColumnDefinition>
|
||||
<ColumnDefinition Width="60"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="FileIcon" Grid.RowSpan="2" Width="18" Height="18" VerticalAlignment="Top" Margin="3,6,3,3"></Image>
|
||||
<Image x:Name="FileIcon" Grid.RowSpan="2" Width="16" Height="16" VerticalAlignment="Top" Margin="3,6,3,3"></Image>
|
||||
|
||||
<TextBlock x:Name="FileName" Grid.Column="1" VerticalAlignment="Center">文件名称:</TextBlock>
|
||||
<TextBlock x:Name="FileSize" Grid.Column="2" VerticalAlignment="Center">大小:</TextBlock>
|
||||
<TextBlock x:Name="FileDate" Grid.Column="3" VerticalAlignment="Center">日期:</TextBlock>
|
||||
|
||||
<TextBlock x:Name="FileDeleteButton" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
|
||||
Background="{DynamicResource PrimaryHueLightBrush}" Padding="6,3,6,3">删除</TextBlock>
|
||||
Background="{DynamicResource PrimaryHueLightBrush}" Padding="12,3,12,3" MouseLeftButtonDown="FileDeleteButton_MouseLeftButtonDown"
|
||||
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">删除</TextBlock>
|
||||
|
||||
<TextBlock x:Name="FileDescription" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">文件备注:</TextBlock>
|
||||
<TextBlock x:Name="FilePeople" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center">上传人:</TextBlock>
|
||||
<TextBlock x:Name="FileDownloadTimes" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center">下载次数:</TextBlock>
|
||||
<TextBlock x:Name="FileDownloadButton" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand"
|
||||
Background="{DynamicResource PrimaryHueLightBrush}" Padding="6,3,6,3">下载</TextBlock>
|
||||
Background="{DynamicResource PrimaryHueLightBrush}" Padding="12,3,12,3" MouseLeftButtonDown="FileDownloadButton_MouseLeftButtonDown"
|
||||
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">下载</TextBlock>
|
||||
</Grid>
|
||||
<ProgressBar x:Name="FileDownloadProgress" Grid.Row="2" Grid.ColumnSpan="4" Margin="30,-5,63,0" Height="4"></ProgressBar>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -14,6 +14,9 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using HslCommunication;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
|
||||
namespace 软件系统客户端Wpf.Views
|
||||
{
|
||||
@@ -67,8 +70,81 @@ namespace 软件系统客户端Wpf.Views
|
||||
FilePeople.Text = "上传人:" + file.UploadName;
|
||||
FileDownloadTimes.Text = "下载数:" + file.FileDownloadTimes;
|
||||
|
||||
|
||||
FileDeleteButton.IsEnabled = file.UploadName == UserClient.UserAccount.UserName;
|
||||
FileDownloadButton.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void FileDeleteButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//删除文件
|
||||
if (Hufile.UploadName != UserClient.UserAccount.UserName)
|
||||
{
|
||||
MessageBox.Show("无法删除不是自己上传的文件。");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("请确认是否真的删除?", "删除确认", MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//确认删除
|
||||
OperateResultString result = SimpleFileClient.DeleteFile(UserClient.ServerIp, CommonLibrary.CommonLibrary.Port_Share_File, Hufile.FileName);
|
||||
if(result.IsSuccess)
|
||||
{
|
||||
MessageBox.Show("删除成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("删除失败!原因:" + result.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void FileDownloadButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//下载文件
|
||||
FileDownloadButton.IsEnabled = false;
|
||||
|
||||
Thread thread_down_file = new Thread(new ThreadStart(ThreadDownloadFile));
|
||||
thread_down_file.IsBackground = true;
|
||||
thread_down_file.Start();
|
||||
}
|
||||
private void ThreadDownloadFile()
|
||||
{
|
||||
string save_file_name = AppDomain.CurrentDomain.BaseDirectory + "download\\files";
|
||||
if (!Directory.Exists(save_file_name))
|
||||
{
|
||||
Directory.CreateDirectory(save_file_name);
|
||||
}
|
||||
|
||||
save_file_name += "\\" + Hufile.FileName;
|
||||
|
||||
|
||||
OperateResultString result = SimpleFileClient.DownloadFile(UserClient.ServerIp, CommonLibrary.CommonLibrary.Port_Share_File, Hufile.FileName,
|
||||
(m, n) =>
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
FileDownloadProgress.Value = m * 100d / n;
|
||||
}));
|
||||
}, save_file_name);
|
||||
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
if (MessageBox.Show("下载完成,路径为:" + save_file_name + Environment.NewLine +
|
||||
"是否打开文件路径?", "打开确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
System.Diagnostics.Process.Start("explorer.exe", @"/select," + save_file_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("下载失败,错误原因:" + result.Message);
|
||||
}
|
||||
FileDownloadButton.IsEnabled = true;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user