From 37b24a07186f40f1acf34c1334170979c240d788 Mon Sep 17 00:00:00 2001 From: dathlin Date: Fri, 7 Jul 2017 10:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=B5=8B=E8=AF=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PortraitSupport/PortraitSupport.cs | 8 +-- 软件系统客户端模版/FormMainWindow.Designer.cs | 18 ++--- 软件系统客户端模版/FormMainWindow.cs | 71 ++++++++++++++----- 软件系统服务端模版/FormServerWindow.cs | 46 +++++++++++- 4 files changed, 113 insertions(+), 30 deletions(-) diff --git a/CommonLibrary/PortraitSupport/PortraitSupport.cs b/CommonLibrary/PortraitSupport/PortraitSupport.cs index 119eea9..99614a9 100644 --- a/CommonLibrary/PortraitSupport/PortraitSupport.cs +++ b/CommonLibrary/PortraitSupport/PortraitSupport.cs @@ -11,11 +11,11 @@ namespace CommonLibrary /// /// 小尺寸头像 /// - public const string SmallPortraitHead = "Size_32_"; + public const string SmallPortrait = "Size_32_.png"; /// /// 大尺寸头像 /// - public const string LargePortraitHead = "Size_300_"; + public const string LargePortrait = "Size_300_.png"; public static string GetSmallPortraitFileName(string dirPath) @@ -23,7 +23,7 @@ namespace CommonLibrary string[] files = Directory.GetFiles(dirPath); foreach(var m in files) { - if(m.Contains(SmallPortraitHead)) + if(m.Contains(SmallPortrait)) { return m; } @@ -35,7 +35,7 @@ namespace CommonLibrary string[] files = Directory.GetFiles(dirPath); foreach (var m in files) { - if (m.Contains(LargePortraitHead)) + if (m.Contains(LargePortrait)) { return m; } diff --git a/软件系统客户端模版/FormMainWindow.Designer.cs b/软件系统客户端模版/FormMainWindow.Designer.cs index 815f74d..334e204 100644 --- a/软件系统客户端模版/FormMainWindow.Designer.cs +++ b/软件系统客户端模版/FormMainWindow.Designer.cs @@ -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(); @@ -77,7 +78,6 @@ this.panel_left = new System.Windows.Forms.Panel(); this.label10 = new System.Windows.Forms.Label(); this.panel_main = new System.Windows.Forms.Panel(); - this.更换头像ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.statusStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -250,6 +250,13 @@ this.留言板ToolStripMenuItem.Text = "留言板"; 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 // 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.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 // 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.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(32, 32); this.pictureBox1.TabIndex = 6; this.pictureBox1.TabStop = false; + this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // FormMainWindow // diff --git a/软件系统客户端模版/FormMainWindow.cs b/软件系统客户端模版/FormMainWindow.cs index ef99d27..9b834cb 100644 --- a/软件系统客户端模版/FormMainWindow.cs +++ b/软件系统客户端模版/FormMainWindow.cs @@ -641,12 +641,12 @@ namespace 软件系统客户端模版 string path = GetPortraitPath(); string guid = Guid.NewGuid().ToString("N"); - string path300 = path + @"\" + PortraitSupport.LargePortraitHead + guid + ".png"; - string path32 = path + @"\" + PortraitSupport.SmallPortraitHead + guid + ".png"; + string path300 = path + @"\" + PortraitSupport.LargePortrait; + string path32 = path + @"\" + PortraitSupport.SmallPortrait; - Bitmap bitmap300 = (Bitmap)fps.GetSpecifiedSizeImage(300); + Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300); bitmap300.Save(path300); - Bitmap bitmap32 = (Bitmap)fps.GetSpecifiedSizeImage(32); + Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32); bitmap32.Save(path32); //传送服务器 bitmap300.Dispose(); @@ -679,11 +679,13 @@ namespace 软件系统客户端模版 if(result.Content[0]=='Y') { //服务器存在头像 - string fileName = PortraitSupport.GetSmallPortraitFileName(path); - string serverName = result.Content.Substring(1); - if (!string.IsNullOrEmpty(fileName)) + string fileName = path + @"\" + PortraitSupport.SmallPortrait; + string FileMd5 = result.Content.Substring(1); + if (System.IO.File.Exists(fileName)) { - if (PortraitSupport.GetSmallPortraitFileName(path).Contains(serverName)) + //文件文件 + string currentMd5 = SoftBasic.CalculateFileMD5(fileName); + if (currentMd5 == FileMd5) { //加载本地头像 pictureBox1.LoadAsync(fileName); @@ -691,20 +693,13 @@ namespace 软件系统客户端模版 else { //头像已经换了 - P1: - 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); - } + DownloadUserPortraint(path); } } else { //客户端不存在头像 - goto P1; + DownloadUserPortraint(path); } } 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 + + } } diff --git a/软件系统服务端模版/FormServerWindow.cs b/软件系统服务端模版/FormServerWindow.cs index f3a649b..80c7e8e 100644 --- a/软件系统服务端模版/FormServerWindow.cs +++ b/软件系统服务端模版/FormServerWindow.cs @@ -568,6 +568,50 @@ namespace 软件系统服务端模版 //发送到邮箱 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 { net_simplify_server.SendMessage(state, customer, data); @@ -1233,7 +1277,7 @@ namespace 软件系统服务端模版 SoftBasic.ShowExceptionMessage(ex); } } - + #endregion }