2017-04-06 16:18:46 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Forms;
|
2017-04-06 22:00:34 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2017-04-23 18:05:12 +08:00
|
|
|
|
using HslCommunication.Enthernet;
|
|
|
|
|
|
using HslCommunication;
|
2017-05-04 11:43:50 +08:00
|
|
|
|
using CommonLibrary;
|
2017-07-12 13:13:43 +08:00
|
|
|
|
using ClientsLibrary;
|
2017-04-06 16:18:46 +08:00
|
|
|
|
|
|
|
|
|
|
namespace 软件系统客户端模版.UIControls
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class ShareFilesRender : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public ShareFilesRender()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2017-04-07 09:08:48 +08:00
|
|
|
|
|
|
|
|
|
|
DoubleBuffered = true;
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void userButton_upload_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-09-14 22:14:08 +08:00
|
|
|
|
//上传数据
|
2017-05-04 11:43:50 +08:00
|
|
|
|
if(UserClient.UserAccount.Grade<AccountGrade.Technology)
|
2017-04-06 22:00:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("权限不够!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-14 22:14:08 +08:00
|
|
|
|
// 上传文件
|
2017-04-06 22:00:34 +08:00
|
|
|
|
using (FormSimplyFileUpload upload = new FormSimplyFileUpload(
|
2017-09-19 10:37:17 +08:00
|
|
|
|
CommonLibrary.CommonProtocol.KeyToken,
|
2017-09-13 21:08:18 +08:00
|
|
|
|
UserClient.LogNet,
|
2017-04-06 22:00:34 +08:00
|
|
|
|
UserClient.ServerIp,
|
2017-09-19 10:37:17 +08:00
|
|
|
|
CommonLibrary.CommonProtocol.Port_Share_File,
|
2017-04-06 22:00:34 +08:00
|
|
|
|
UserClient.UserAccount.UserName))
|
|
|
|
|
|
{
|
|
|
|
|
|
upload.ShowDialog();
|
|
|
|
|
|
}
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void userButton_refresh_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-04-06 22:00:34 +08:00
|
|
|
|
//向服务器请求数据
|
2017-06-16 09:52:58 +08:00
|
|
|
|
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.请求文件);
|
2017-04-06 22:00:34 +08:00
|
|
|
|
if(result.IsSuccess)
|
|
|
|
|
|
{
|
2017-06-16 09:52:58 +08:00
|
|
|
|
Cache_Files = JArray.Parse(result.Content).ToObject<List<HslSoftFile>>();
|
2017-04-06 22:00:34 +08:00
|
|
|
|
SetFilesShow(Cache_Files);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(result.ToMessageShowString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-16 09:52:58 +08:00
|
|
|
|
private void SetFilesShow(List<HslSoftFile> files)
|
2017-04-06 22:00:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
panel2.SuspendLayout();
|
|
|
|
|
|
//清楚缓存
|
|
|
|
|
|
ClearControls();
|
|
|
|
|
|
if (files?.Count > 0 && panel2.Width > 20)
|
|
|
|
|
|
{
|
2017-09-14 22:14:08 +08:00
|
|
|
|
int location_y = 2 - panel2.VerticalScroll.Value;
|
2017-04-06 22:00:34 +08:00
|
|
|
|
//添加子控件
|
|
|
|
|
|
foreach(var m in files)
|
|
|
|
|
|
{
|
2017-09-13 21:08:18 +08:00
|
|
|
|
FileItemShow item = new FileItemShow(
|
2017-09-19 10:37:17 +08:00
|
|
|
|
CommonLibrary.CommonProtocol.KeyToken,
|
2017-09-13 21:08:18 +08:00
|
|
|
|
UserClient.LogNet, UserClient.ServerIp,
|
2017-09-19 10:37:17 +08:00
|
|
|
|
CommonLibrary.CommonProtocol.Port_Share_File,
|
2017-04-06 22:00:34 +08:00
|
|
|
|
() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m.UploadName != UserClient.UserAccount.UserName)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("无法删除不是自己上传的文件。");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-05-19 10:20:10 +08:00
|
|
|
|
return MessageBox.Show("请确认是否真的删除?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes;
|
2017-04-06 22:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2017-09-14 22:14:08 +08:00
|
|
|
|
panel2.Controls.Add(item); // 添加显示
|
|
|
|
|
|
item.BackColor = Color.White; // 白色的背景
|
|
|
|
|
|
item.BorderStyle = BorderStyle.FixedSingle; // 边框样式
|
|
|
|
|
|
item.SetFile(m, () => m.UploadName == UserClient.UserAccount.UserName); // 设置文件显示并提供一个删除使能的权限,此处设置是登录名和上传人不一致时,删除键不能点击
|
|
|
|
|
|
item.Location = new Point(2, location_y); // 控件的位置
|
|
|
|
|
|
int width = panel2.VerticalScroll.Visible ? panel2.Width - 4 - SystemInformation.VerticalScrollBarWidth : panel2.Width - 4; // 控件的宽度
|
|
|
|
|
|
item.Size = new Size(width, item.Size.Height); // 控件的大小
|
|
|
|
|
|
item.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;// 控件随窗口变化的样式
|
|
|
|
|
|
|
|
|
|
|
|
location_y += item.Height + 4; // 位置偏移
|
|
|
|
|
|
FilesControls.Push(item);// 控件压入堆栈
|
2017-04-06 22:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
panel2.ResumeLayout();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateFiles()
|
|
|
|
|
|
{
|
|
|
|
|
|
userButton_refresh.PerformClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearControls()
|
|
|
|
|
|
{
|
|
|
|
|
|
while (FilesControls.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
FilesControls.Pop().Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有文件信息的缓存,以支持直接的搜索
|
|
|
|
|
|
/// </summary>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
private List<HslSoftFile> Cache_Files { get; set; } = new List<HslSoftFile>();
|
2017-04-06 22:00:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 文件控件的缓存列表,方便清除垃圾
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Stack<IDisposable> FilesControls = new Stack<IDisposable>();
|
2017-04-06 16:18:46 +08:00
|
|
|
|
|
2017-04-06 22:00:34 +08:00
|
|
|
|
|
|
|
|
|
|
private void ShareFilesRender_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-09-14 22:14:08 +08:00
|
|
|
|
// 选择是否禁用上传键
|
2017-04-06 22:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-09-14 22:14:08 +08:00
|
|
|
|
// 搜索时触发的数据
|
2017-04-07 09:08:48 +08:00
|
|
|
|
if(!string.IsNullOrEmpty(textBox1.Text))
|
2017-04-06 22:00:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
string pattern = textBox1.Text;
|
2017-04-07 09:08:48 +08:00
|
|
|
|
SetFilesShow(Cache_Files.Where(f =>
|
|
|
|
|
|
f.FileName.Contains(pattern) ||
|
|
|
|
|
|
f.FileNote.Contains(pattern) ||
|
|
|
|
|
|
f.UploadName.Contains(pattern)).ToList());
|
2017-04-06 22:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SetFilesShow(Cache_Files);
|
|
|
|
|
|
}
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
2017-09-14 22:14:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|