private void userButton1_Click(object sender, EventArgs e) { // 下载选择文件 TreeNode treeNode = treeView1.SelectedNode; if (treeNode.Name != "files_root") { // 选择文件夹 using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) { folderBrowserDialog.Description = "请选择保存路径,如果有重名文件,将会覆盖!"; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { FormFileOperate download = new FormFileOperate(UserClient.Net_File_Client, new string[] { treeNode.Text }, "Files", "Personal", UserClient.UserAccount.UserName, folderBrowserDialog.SelectedPath ); download.ShowDialog(); } } } }
public void ChangePortrait() { using (FormPortraitSelect fps = new FormPortraitSelect()) { if (fps.ShowDialog() == DialogResult.OK) { string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait; string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait; DisPic?.Invoke(); 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 void UploadFilesToServer(string[] files) { FormFileOperate upload = new FormFileOperate(UserClient.Net_File_Client, files, "Files", "Personal", UserClient.UserAccount.UserName); upload.ShowDialog(); // 更新文件列表 DownloadUserFileNames(); }
private void 远程更新ToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { using (FormFileOperate fUpload = new FormFileOperate(new System.Net.IPEndPoint( System.Net.IPAddress.Parse(UserClient.ServerIp), CommonLibrary.CommonLibrary.Port_Update_Remote), ofd.FileNames, "", "", "")) { fUpload.ShowDialog(); } } } }
private void userButton_file_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { using (FormFileOperate fUpload = new FormFileOperate( UserClient.Net_Update_Client, ofd.FileNames, "ClientFiles", "", "" )) { fUpload.ShowDialog(); } } } }
/// <summary> /// 点击更改头像后的操作,打开头像选择对话框,获取到2种分辨率的头像,然后进行上传 /// </summary> /// <param name="loadPic">加载大头像的委托</param> /// <param name="unloadPic">卸载大头像的委托</param> public void ChangePortrait(Action <string> loadPic, Action unloadPic) { using (FormPortraitSelect fps = new FormPortraitSelect()) { if (fps.ShowDialog() == DialogResult.OK) { string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait; string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait; // 先卸载图片 unloadPic?.Invoke(); Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300); Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32); try { bitmap300.Save(path300); bitmap32.Save(path32); bitmap32.Dispose(); bitmap300.Dispose(); } catch (Exception ex) { // 文件被占用的时候无法进行覆盖 UserClient.LogNet?.WriteException("头像保存失败!", ex); MessageBox.Show("头像保存失败,原因:" + ex.Message); // 加载回旧的文件 loadPic?.Invoke(path300); return; } // 传送服务器 using (FormFileOperate ffo = new FormFileOperate( UserClient.Net_File_Client, new string[] { path300, path32 }, "Files", "Portrait", UserClient.UserAccount.UserName)) { ffo.ShowDialog(); } ThreadPool.QueueUserWorkItem(new WaitCallback(obj => { // 上传文件MD5码 string SmallPortraitMD5 = ""; string LargePortraitMD5 = ""; try { SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32); LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300); } catch (Exception ex) { UserClient.LogNet.WriteException("获取文件MD5码失败:", ex); MessageBox.Show("文件信息确认失败,请重新上传!"); return; } JObject json = new JObject { { UserAccount.UserNameText, new JValue(UserClient.UserAccount.UserName) }, { UserAccount.SmallPortraitText, new JValue(SmallPortraitMD5) }, { UserAccount.LargePortraitText, new JValue(LargePortraitMD5) } }; OperateResultString result = UserClient.Net_simplify_client.ReadFromServer( CommonHeadCode.SimplifyHeadCode.头像MD5, json.ToString()); if (result.IsSuccess) { if (result.Content.Substring(0, 2) == "成功") { UserClient.UserAccount.SmallPortraitMD5 = SmallPortraitMD5; UserClient.UserAccount.LargePortraitMD5 = LargePortraitMD5; } else { MessageBox.Show("上传头像失败!原因:" + result.Content); } } else { MessageBox.Show("上传头像失败!原因:" + result.Message); } // 先显示信息 loadPic?.Invoke(path300); LoadUserSmallPortraint(); }), null); } } }
private void pictureBox_UserPortrait_Click(object sender, EventArgs e) { // UserPortrait.ChangePortrait(LoadLargeProtrait,UnloadLargeProtrait); using (FormPortraitSelect fps = new FormPortraitSelect()) { if (fps.ShowDialog() == DialogResult.OK) { string FileSavePath = Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName; string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait; string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait; Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300); Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32); try { bitmap300.Save(path300, System.Drawing.Imaging.ImageFormat.Png); bitmap32.Save(path32, System.Drawing.Imaging.ImageFormat.Png); bitmap32.Dispose(); bitmap300.Dispose(); } catch (Exception ex) { // 文件被占用的时候无法进行覆盖 UserClient.LogNet?.WriteException("头像保存失败!", ex); MessageBox.Show("头像保存失败,原因:" + ex.Message); // 加载回旧的文件 pictureBox_UserPortrait.Load(path300); return; } // 传送服务器 using (FormFileOperate ffo = new FormFileOperate( UserClient.Net_File_Client, new string[] { path300, path32 }, "Files", "Portrait", UserClient.UserAccount.UserName)) { ffo.ShowDialog(); } ThreadPool.QueueUserWorkItem(new WaitCallback(obj => { // 上传文件MD5码 string SmallPortraitMD5 = ""; string LargePortraitMD5 = ""; try { SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32); LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300); } catch (Exception ex) { UserClient.LogNet.WriteException("获取文件MD5码失败:", ex); MessageBox.Show("文件信息确认失败,请重新上传!"); return; } JObject json = new JObject { { UserAccount.UserNameText, new JValue(UserClient.UserAccount.UserName) }, { UserAccount.SmallPortraitText, new JValue(SmallPortraitMD5) }, { UserAccount.LargePortraitText, new JValue(LargePortraitMD5) } }; OperateResultString result = UserClient.Net_simplify_client.ReadFromServer( CommonHeadCode.SimplifyHeadCode.头像MD5, json.ToString()); if (result.IsSuccess) { if (result.Content.Substring(0, 2) == "成功") { UserClient.UserAccount.SmallPortraitMD5 = SmallPortraitMD5; UserClient.UserAccount.LargePortraitMD5 = LargePortraitMD5; } else { MessageBox.Show("上传头像失败!原因:" + result.Content); } } else { MessageBox.Show("上传头像失败!原因:" + result.Message); } // 先显示信息 try { pictureBox_UserPortrait.Image = new Bitmap(new System.IO.MemoryStream(File.ReadAllBytes(path300))); } catch { } }), null ); } } }