提交 a32b337e 编写于 作者: Richard__Hu's avatar Richard__Hu

根据最新提炼的头像类更改完成。

上级 f5b50de0
......@@ -81,6 +81,8 @@ namespace 软件系统客户端模版
net_socket_client.AcceptString += Net_socket_client_AcceptString;
//启动网络服务
Net_Socket_Client_Initialization();
//启动头像
SoftUserPortraitInitialization();
label_Announcement.Text = UserClient.Announcement;
......@@ -118,7 +120,7 @@ namespace 软件系统客户端模版
//启动定时器
TimeTickInitilization();
//显示头像
DownloadUserPortraint();
SoftUserPortrait.DownloadUserPortraint();
}
private void FormMainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
......@@ -300,7 +302,7 @@ namespace 软件系统客户端模版
private void 更换头像ToolStripMenuItem_Click(object sender, EventArgs e)
{
ChangePortrait();
SoftUserPortrait.ChangePortrait();
}
#endregion
......@@ -623,133 +625,26 @@ namespace 软件系统客户端模版
#region 头像图片上传下载块
private string GetPortraitPath()
{
string path = Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName;
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
return path;
}
private void ChangePortrait()
{
using (FormPortraitSelect fps = new FormPortraitSelect())
{
if (fps.ShowDialog() == DialogResult.OK)
{
string path = GetPortraitPath();
string guid = Guid.NewGuid().ToString("N");
string path300 = path + @"\" + PortraitSupport.LargePortrait;
string path32 = path + @"\" + PortraitSupport.SmallPortrait;
Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300);
bitmap300.Save(path300);
Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32);
bitmap32.Save(path32);
//传送服务器
bitmap300.Dispose();
bitmap32.Dispose();
using (FormFileOperate ffo = new FormFileOperate(CommonHeadCode.KeyToken, new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp), CommonLibrary.CommonLibrary.Port_Portrait_Server),
new string[]
{
path300,
path32
}, "Files", "Portrait", UserClient.UserAccount.UserName))
{
ffo.ShowDialog();
}
DownloadUserPortraint();
}
}
}
private UserPortrait SoftUserPortrait { get; set; }
private void DownloadUserPortraint()
private void SoftUserPortraitInitialization()
{
string path = GetPortraitPath();
//获取服务器文件名称
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.请求小头, UserClient.UserAccount.UserName);
if(result.IsSuccess)
{
if(result.Content[0]=='Y')
{
//服务器存在头像
string fileName = path + @"\" + PortraitSupport.SmallPortrait;
string FileMd5 = result.Content.Substring(1);
if (System.IO.File.Exists(fileName))
{
//文件文件
string currentMd5 = SoftBasic.CalculateFileMD5(fileName);
if (currentMd5 == FileMd5)
{
//加载本地头像
pictureBox1.LoadAsync(fileName);
}
else
{
//头像已经换了
DownloadUserPortraint(path);
}
}
else
{
//客户端不存在头像
DownloadUserPortraint(path);
}
}
else
{
//服务器不存在头像,本次加载结束
}
}
SoftUserPortrait = new UserPortrait(Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName, m => pictureBox1.LoadAsync(m));
}
private void DownloadUserPortraint(string path)
{
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.下载小头, UserClient.UserAccount.UserName);
if (result.IsSuccess)
{
if (result.Content[0] == 'Y')
{
byte[] data = Convert.FromBase64String(result.Content.Substring(1));
string path32 = path + @"\" + PortraitSupport.SmallPortrait;
System.IO.File.WriteAllBytes(path32, data);
pictureBox1.LoadAsync(path32);
}
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
//点击了头像,请求下载高清版本头像
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", ThreadPoolDownloadSizeLarge))
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", SoftUserPortrait.ThreadPoolDownloadSizeLarge))
{
fmr.ShowDialog();
}
}
private void ThreadPoolDownloadSizeLarge()
{
string path = GetPortraitPath();
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.下载大头, UserClient.UserAccount.UserName);
if (result.IsSuccess)
{
if (result.Content[0] == 'Y')
{
byte[] data = Convert.FromBase64String(result.Content.Substring(1));
string path32 = path + @"\" + PortraitSupport.LargePortrait;
System.IO.File.WriteAllBytes(path32, data);
System.Diagnostics.Process.Start(path32);
}
}
Thread.Sleep(1000);
}
#endregion
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册