大面积更新,主要文件功能块更改,账号新增BUG修复,新增框架版本验证,v1.5.0
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:软件系统客户端Wpf.Views"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="400" d:DesignWidth="800">
|
||||
d:DesignHeight="400" d:DesignWidth="800" Loaded="UserControl_Loaded">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
@@ -31,7 +31,7 @@
|
||||
</Button>
|
||||
|
||||
<TextBlock Grid.Column="3" VerticalAlignment="Center" FontSize="15">搜索:</TextBlock>
|
||||
<TextBox Grid.Column="4" Width="200" x:Name="FileSearchFilter" TextChanged="FileSearchFilter_TextChanged"></TextBox>
|
||||
<TextBox Grid.Column="4" Width="200" x:Name="FileSearchFilter" TextChanged="FileSearchFilter_TextChanged" PreviewKeyDown="FileSearchFilter_PreviewKeyDown"></TextBox>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1" BorderThickness="0,1,0,0" Margin="0,5,0,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ClientsLibrary;
|
||||
using ClientsLibrary.FileSupport;
|
||||
using CommonLibrary;
|
||||
using HslCommunication;
|
||||
using HslCommunication.Enthernet;
|
||||
@@ -25,55 +26,28 @@ namespace 软件系统客户端Wpf.Views
|
||||
/// </summary>
|
||||
public partial class UserFileRender : UserControl
|
||||
{
|
||||
public UserFileRender()
|
||||
#region Constructor
|
||||
|
||||
|
||||
public UserFileRender(string factory, string group, string id)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
m_Factory = factory;
|
||||
m_Group = group;
|
||||
m_Id = id;
|
||||
}
|
||||
|
||||
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(
|
||||
CommonLibrary.CommonProtocol.KeyToken,
|
||||
UserClient.LogNet,
|
||||
UserClient.ServerIp,
|
||||
CommonLibrary.CommonProtocol.Port_Share_File,
|
||||
UserClient.UserAccount.UserName))
|
||||
{
|
||||
upload.ShowDialog();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Render File List
|
||||
|
||||
private void Button_FileRefresh_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//向服务器请求数据
|
||||
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.请求文件);
|
||||
OperateResult result = UserClient.Net_File_Client.DownloadPathFileNames(out GroupFileItem[] files, "ShareFiles", "", "");
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
Cache_Files = JArray.Parse(result.Content).ToObject<List<HslSoftFile>>();
|
||||
Cache_Files = new List<GroupFileItem>(files);
|
||||
SetFilesShow(Cache_Files);
|
||||
}
|
||||
else
|
||||
@@ -97,7 +71,7 @@ namespace 软件系统客户端Wpf.Views
|
||||
//}
|
||||
}
|
||||
|
||||
private void SetFilesShow(List<HslSoftFile> files)
|
||||
private void SetFilesShow(List<GroupFileItem> files)
|
||||
{
|
||||
//清楚缓存
|
||||
ClearControls();
|
||||
@@ -106,21 +80,118 @@ namespace 软件系统客户端Wpf.Views
|
||||
//添加子控件
|
||||
foreach (var m in files)
|
||||
{
|
||||
UserFileRenderItem item = new UserFileRenderItem();
|
||||
UserFileRenderItem item = new UserFileRenderItem(
|
||||
UserClient.Net_File_Client,
|
||||
m_Factory,
|
||||
m_Group,
|
||||
m_Id,
|
||||
DeleteCheck);
|
||||
FileListControl.Children.Add(item);
|
||||
item.SetFile(m);
|
||||
item.SetFile(m, () => m.Owner == UserClient.UserAccount.UserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete Check
|
||||
|
||||
private bool DeleteCheck(GroupFileItem item)
|
||||
{
|
||||
if (item.Owner != UserClient.UserAccount.UserName)
|
||||
{
|
||||
MessageBox.Show("无法删除不是自己上传的文件。");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MessageBox.Show("请确认是否真的删除?", "删除确认",MessageBoxButton.YesNo) == MessageBoxResult.Yes;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filter Support
|
||||
|
||||
|
||||
private void FileSearchFilter_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void FileSearchFilter_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if(e.Key == Key.Enter)
|
||||
{
|
||||
//搜索时触发的数据
|
||||
if (!string.IsNullOrEmpty(FileSearchFilter.Text))
|
||||
{
|
||||
string pattern = FileSearchFilter.Text;
|
||||
SetFilesShow(Cache_Files.Where(f =>
|
||||
f.FileName.Contains(pattern) ||
|
||||
f.Description.Contains(pattern) ||
|
||||
f.Owner.Contains(pattern)).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFilesShow(Cache_Files);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Upload
|
||||
|
||||
|
||||
private void Button_FileUpload_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//上传数据,先对权限进行验证
|
||||
if (UserClient.UserAccount.Grade < AccountGrade.Technology)
|
||||
{
|
||||
MessageBox.Show("权限不够!");
|
||||
return;
|
||||
}
|
||||
|
||||
using (FormSimplyFileUpload upload = new FormSimplyFileUpload(
|
||||
m_Factory,
|
||||
m_Group,
|
||||
m_Id
|
||||
))
|
||||
{
|
||||
upload.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
/// <summary>
|
||||
/// 所有文件信息的缓存,以支持直接的搜索
|
||||
/// </summary>
|
||||
private List<HslSoftFile> Cache_Files { get; set; } = new List<HslSoftFile>();
|
||||
private List<GroupFileItem> Cache_Files { get; set; } = new List<GroupFileItem>();
|
||||
/// <summary>
|
||||
/// 文件控件的缓存列表,方便清除垃圾
|
||||
/// </summary>
|
||||
private Stack<IDisposable> FilesControls = new Stack<IDisposable>();
|
||||
|
||||
private string m_Factory; // 文件的第一大类
|
||||
private string m_Group; // 文件的第二大类
|
||||
private string m_Id; // 文件的第三大类
|
||||
|
||||
#endregion
|
||||
|
||||
#region Control Load
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateFiles();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ using HslCommunication;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using ClientsLibrary.FileSupport;
|
||||
|
||||
namespace 软件系统客户端Wpf.Views
|
||||
{
|
||||
@@ -26,23 +27,31 @@ namespace 软件系统客户端Wpf.Views
|
||||
/// </summary>
|
||||
public partial class UserFileRenderItem : UserControl
|
||||
{
|
||||
public UserFileRenderItem()
|
||||
#region Constructor
|
||||
|
||||
|
||||
public UserFileRenderItem(IntegrationFileClient client, string factory, string group, string id, Func<GroupFileItem, bool> deleteCheck)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
fileClient = new SimpleFileClient()
|
||||
{
|
||||
KeyToken = CommonLibrary.CommonProtocol.KeyToken,
|
||||
LogNet = UserClient.LogNet,
|
||||
ServerIpEndPoint =new IPEndPoint(IPAddress.Parse(UserClient.ServerIp),CommonLibrary.CommonProtocol.Port_Share_File)
|
||||
};
|
||||
DeleteCheck = deleteCheck;
|
||||
m_Factory = factory;
|
||||
m_Group = group;
|
||||
m_Id = id;
|
||||
fileClient = client;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method
|
||||
|
||||
|
||||
private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
|
||||
{
|
||||
BitmapImage bitmapImage = new BitmapImage();
|
||||
|
||||
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bitmap.Save(ms, bitmap.RawFormat);
|
||||
bitmapImage.BeginInit();
|
||||
@@ -55,50 +64,67 @@ namespace 软件系统客户端Wpf.Views
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
private HslSoftFile Hufile { get; set; } = null;
|
||||
#endregion
|
||||
|
||||
#region Render File Information
|
||||
|
||||
/// <summary>
|
||||
/// 设置文件数据
|
||||
/// </summary>
|
||||
/// <param name="file">文件的信息对象</param>
|
||||
/// <param name="deleteEnable">删除控件的使能委托</param>
|
||||
public void SetFile(HslSoftFile file)
|
||||
/// <exception cref="ArgumentNullException">file参数不能为空</exception>
|
||||
public void SetFile(GroupFileItem file, Func<bool> deleteEnable)
|
||||
{
|
||||
Hufile = file;
|
||||
//获取后缀名
|
||||
int dotIndex = Hufile.FileName.LastIndexOf('.');
|
||||
if (dotIndex >= 0)
|
||||
{
|
||||
FileIcon.Source = BitmapToBitmapImage(Hufile.GetFileIcon());
|
||||
}
|
||||
fileItem = file;
|
||||
|
||||
|
||||
// 设置文件图标
|
||||
FileIcon.Source = BitmapToBitmapImage(FileSupport.GetFileIcon(file.FileName));
|
||||
|
||||
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;
|
||||
|
||||
FileDate.Text = "日期:" + file.UploadTime.ToString("yyyy-MM-dd");
|
||||
FileDescription.Text = "文件备注:" + file.Description;
|
||||
FilePeople.Text = "上传人:" + file.Owner;
|
||||
FileDownloadTimes.Text = "下载数:" + file.DownloadTimes;
|
||||
|
||||
FileDeleteButton.IsEnabled = file.UploadName == UserClient.UserAccount.UserName;
|
||||
FileDownloadButton.IsEnabled = true;
|
||||
|
||||
FileDeleteButton.IsEnabled = deleteEnable.Invoke();
|
||||
FileDownloadButton.IsEnabled = true; // 一般都是允许下载,如果不允许下载,在此处设置
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete Support
|
||||
|
||||
private void FileDeleteButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//删除文件
|
||||
if (Hufile.UploadName != UserClient.UserAccount.UserName)
|
||||
// 删除文件
|
||||
if (DeleteCheck != null)
|
||||
{
|
||||
MessageBox.Show("无法删除不是自己上传的文件。");
|
||||
return;
|
||||
// 删除的权限检查
|
||||
if (!DeleteCheck.Invoke(fileItem))
|
||||
{
|
||||
// 没有通过
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (MessageBox.Show("请确认是否真的删除?", "删除确认", MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//确认删除
|
||||
OperateResult result = fileClient.DeleteFile(Hufile.FileName);
|
||||
if(result.IsSuccess)
|
||||
OperateResult result = fileClient.DeleteFile(
|
||||
fileItem.FileName, // 文件的名称
|
||||
m_Factory, // 第一大类
|
||||
m_Group, // 第二大类
|
||||
m_Id // 第三大类
|
||||
);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
MessageBox.Show("删除成功!");
|
||||
}
|
||||
@@ -108,6 +134,11 @@ namespace 软件系统客户端Wpf.Views
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Download Support
|
||||
|
||||
|
||||
private void FileDownloadButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//下载文件
|
||||
@@ -125,11 +156,14 @@ namespace 软件系统客户端Wpf.Views
|
||||
Directory.CreateDirectory(save_file_name);
|
||||
}
|
||||
|
||||
save_file_name += "\\" + Hufile.FileName;
|
||||
save_file_name += "\\" + fileItem.FileName;
|
||||
|
||||
|
||||
OperateResult result = fileClient.DownloadFile(
|
||||
Hufile.FileName,
|
||||
fileItem.FileName,
|
||||
m_Factory,
|
||||
m_Group,
|
||||
m_Id,
|
||||
(m, n) =>
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
@@ -159,7 +193,17 @@ namespace 软件系统客户端Wpf.Views
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
SimpleFileClient fileClient;
|
||||
private IntegrationFileClient fileClient; // 进行文件操作的客户端
|
||||
private Func<GroupFileItem, bool> DeleteCheck; // 删除操作时的检查方法
|
||||
private GroupFileItem fileItem; // 本控件关联显示的文件
|
||||
private string m_Factory; // 文件的第一大类
|
||||
private string m_Group; // 文件的第二大类
|
||||
private string m_Id; // 文件的第三大类
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user