头像上传下载测试完成
This commit is contained in:
@@ -11,11 +11,11 @@ namespace CommonLibrary
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 小尺寸头像
|
/// 小尺寸头像
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string SmallPortraitHead = "Size_32_";
|
public const string SmallPortrait = "Size_32_.png";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 大尺寸头像
|
/// 大尺寸头像
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string LargePortraitHead = "Size_300_";
|
public const string LargePortrait = "Size_300_.png";
|
||||||
|
|
||||||
|
|
||||||
public static string GetSmallPortraitFileName(string dirPath)
|
public static string GetSmallPortraitFileName(string dirPath)
|
||||||
@@ -23,7 +23,7 @@ namespace CommonLibrary
|
|||||||
string[] files = Directory.GetFiles(dirPath);
|
string[] files = Directory.GetFiles(dirPath);
|
||||||
foreach(var m in files)
|
foreach(var m in files)
|
||||||
{
|
{
|
||||||
if(m.Contains(SmallPortraitHead))
|
if(m.Contains(SmallPortrait))
|
||||||
{
|
{
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ namespace CommonLibrary
|
|||||||
string[] files = Directory.GetFiles(dirPath);
|
string[] files = Directory.GetFiles(dirPath);
|
||||||
foreach (var m in files)
|
foreach (var m in files)
|
||||||
{
|
{
|
||||||
if (m.Contains(LargePortraitHead))
|
if (m.Contains(LargePortrait))
|
||||||
{
|
{
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|||||||
18
软件系统客户端模版/FormMainWindow.Designer.cs
generated
18
软件系统客户端模版/FormMainWindow.Designer.cs
generated
@@ -48,6 +48,7 @@
|
|||||||
this.设置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.设置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.修改密码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.修改密码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.留言板ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.留言板ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.更换头像ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.关于ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.关于ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.关于本软件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.关于本软件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.更新日志ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.更新日志ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
@@ -77,7 +78,6 @@
|
|||||||
this.panel_left = new System.Windows.Forms.Panel();
|
this.panel_left = new System.Windows.Forms.Panel();
|
||||||
this.label10 = new System.Windows.Forms.Label();
|
this.label10 = new System.Windows.Forms.Label();
|
||||||
this.panel_main = new System.Windows.Forms.Panel();
|
this.panel_main = new System.Windows.Forms.Panel();
|
||||||
this.更换头像ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
@@ -250,6 +250,13 @@
|
|||||||
this.留言板ToolStripMenuItem.Text = "留言板";
|
this.留言板ToolStripMenuItem.Text = "留言板";
|
||||||
this.留言板ToolStripMenuItem.Click += new System.EventHandler(this.留言板ToolStripMenuItem_Click);
|
this.留言板ToolStripMenuItem.Click += new System.EventHandler(this.留言板ToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
|
// 更换头像ToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.更换头像ToolStripMenuItem.Name = "更换头像ToolStripMenuItem";
|
||||||
|
this.更换头像ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
|
||||||
|
this.更换头像ToolStripMenuItem.Text = "更换头像";
|
||||||
|
this.更换头像ToolStripMenuItem.Click += new System.EventHandler(this.更换头像ToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// 关于ToolStripMenuItem
|
// 关于ToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.关于ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.关于ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
@@ -539,21 +546,16 @@
|
|||||||
this.panel_main.Size = new System.Drawing.Size(557, 419);
|
this.panel_main.Size = new System.Drawing.Size(557, 419);
|
||||||
this.panel_main.TabIndex = 5;
|
this.panel_main.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// 更换头像ToolStripMenuItem
|
|
||||||
//
|
|
||||||
this.更换头像ToolStripMenuItem.Name = "更换头像ToolStripMenuItem";
|
|
||||||
this.更换头像ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
|
|
||||||
this.更换头像ToolStripMenuItem.Text = "更换头像";
|
|
||||||
this.更换头像ToolStripMenuItem.Click += new System.EventHandler(this.更换头像ToolStripMenuItem_Click);
|
|
||||||
//
|
|
||||||
// pictureBox1
|
// pictureBox1
|
||||||
//
|
//
|
||||||
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||||
this.pictureBox1.Location = new System.Drawing.Point(887, 1);
|
this.pictureBox1.Location = new System.Drawing.Point(887, 1);
|
||||||
this.pictureBox1.Name = "pictureBox1";
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
|
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
|
||||||
this.pictureBox1.TabIndex = 6;
|
this.pictureBox1.TabIndex = 6;
|
||||||
this.pictureBox1.TabStop = false;
|
this.pictureBox1.TabStop = false;
|
||||||
|
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
|
||||||
//
|
//
|
||||||
// FormMainWindow
|
// FormMainWindow
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -641,12 +641,12 @@ namespace 软件系统客户端模版
|
|||||||
string path = GetPortraitPath();
|
string path = GetPortraitPath();
|
||||||
|
|
||||||
string guid = Guid.NewGuid().ToString("N");
|
string guid = Guid.NewGuid().ToString("N");
|
||||||
string path300 = path + @"\" + PortraitSupport.LargePortraitHead + guid + ".png";
|
string path300 = path + @"\" + PortraitSupport.LargePortrait;
|
||||||
string path32 = path + @"\" + PortraitSupport.SmallPortraitHead + guid + ".png";
|
string path32 = path + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
|
||||||
Bitmap bitmap300 = (Bitmap)fps.GetSpecifiedSizeImage(300);
|
Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300);
|
||||||
bitmap300.Save(path300);
|
bitmap300.Save(path300);
|
||||||
Bitmap bitmap32 = (Bitmap)fps.GetSpecifiedSizeImage(32);
|
Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32);
|
||||||
bitmap32.Save(path32);
|
bitmap32.Save(path32);
|
||||||
//传送服务器
|
//传送服务器
|
||||||
bitmap300.Dispose();
|
bitmap300.Dispose();
|
||||||
@@ -679,11 +679,13 @@ namespace 软件系统客户端模版
|
|||||||
if(result.Content[0]=='Y')
|
if(result.Content[0]=='Y')
|
||||||
{
|
{
|
||||||
//服务器存在头像
|
//服务器存在头像
|
||||||
string fileName = PortraitSupport.GetSmallPortraitFileName(path);
|
string fileName = path + @"\" + PortraitSupport.SmallPortrait;
|
||||||
string serverName = result.Content.Substring(1);
|
string FileMd5 = result.Content.Substring(1);
|
||||||
if (!string.IsNullOrEmpty(fileName))
|
if (System.IO.File.Exists(fileName))
|
||||||
{
|
{
|
||||||
if (PortraitSupport.GetSmallPortraitFileName(path).Contains(serverName))
|
//文件文件
|
||||||
|
string currentMd5 = SoftBasic.CalculateFileMD5(fileName);
|
||||||
|
if (currentMd5 == FileMd5)
|
||||||
{
|
{
|
||||||
//加载本地头像
|
//加载本地头像
|
||||||
pictureBox1.LoadAsync(fileName);
|
pictureBox1.LoadAsync(fileName);
|
||||||
@@ -691,20 +693,13 @@ namespace 软件系统客户端模版
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//头像已经换了
|
//头像已经换了
|
||||||
P1:
|
DownloadUserPortraint(path);
|
||||||
result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.下载小头, UserClient.UserAccount.UserName);
|
|
||||||
if(result.IsSuccess)
|
|
||||||
{
|
|
||||||
byte[] data = Convert.FromBase64String(result.Content);
|
|
||||||
System.IO.File.WriteAllBytes(path + @"\" + serverName, data);
|
|
||||||
pictureBox1.LoadAsync(path + @"\" + serverName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//客户端不存在头像
|
//客户端不存在头像
|
||||||
goto P1;
|
DownloadUserPortraint(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -714,7 +709,49 @@ namespace 软件系统客户端模版
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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.SmallPortrait;
|
||||||
|
System.IO.File.WriteAllBytes(path32, data);
|
||||||
|
System.Diagnostics.Process.Start(path32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,6 +568,50 @@ namespace 软件系统服务端模版
|
|||||||
//发送到邮箱
|
//发送到邮箱
|
||||||
SendUserMail("异常记录", "时间:" + DateTime.Now.ToString("O") + Environment.NewLine + data);
|
SendUserMail("异常记录", "时间:" + DateTime.Now.ToString("O") + Environment.NewLine + data);
|
||||||
}
|
}
|
||||||
|
else if (customer == CommonHeadCode.SimplifyHeadCode.请求小头)
|
||||||
|
{
|
||||||
|
string fileName = Application.StartupPath + @"\Files\Portrait\" + data + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
if(string.IsNullOrEmpty(fileName))
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "Y" + SoftBasic.CalculateFileMD5(fileName));
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "N");
|
||||||
|
RuntimeLogHelper.SaveError(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (customer == CommonHeadCode.SimplifyHeadCode.下载小头)
|
||||||
|
{
|
||||||
|
string fileName = Application.StartupPath + @"\Files\Portrait\" + data + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
if (string.IsNullOrEmpty(fileName))
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "Y" + Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (customer == CommonHeadCode.SimplifyHeadCode.下载大头)
|
||||||
|
{
|
||||||
|
string fileName = Application.StartupPath + @"\Files\Portrait\" + data + @"\" + PortraitSupport.LargePortrait;
|
||||||
|
if (string.IsNullOrEmpty(fileName))
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
net_simplify_server.SendMessage(state, customer, "Y" + Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
net_simplify_server.SendMessage(state, customer, data);
|
net_simplify_server.SendMessage(state, customer, data);
|
||||||
@@ -1233,7 +1277,7 @@ namespace 软件系统服务端模版
|
|||||||
SoftBasic.ShowExceptionMessage(ex);
|
SoftBasic.ShowExceptionMessage(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user