FormMail.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using CommonRPG.Data;
  2. using CommonRPG.Protocol;
  3. using CommonRPG.Protocol.Client;
  4. using DDogProtocol.Data;
  5. using DDogProtocol.Protocol.Client;
  6. using DDogServer.Common.Data;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Windows.Forms;
  11. namespace CommonRPG.Client.Win32.Forms
  12. {
  13. public partial class FormMail : Form
  14. {
  15. private readonly RPGClient client;
  16. public FormMail(RPGClient client)
  17. {
  18. InitializeComponent();
  19. this.client = client;
  20. AddListener();
  21. }
  22. protected override void OnClosing(CancelEventArgs e)
  23. {
  24. base.OnClosing(e);
  25. e.Cancel = true;
  26. this.Hide();
  27. }
  28. protected override void OnShown(EventArgs e)
  29. {
  30. base.OnShown(e);
  31. UpdateMailListInfo();
  32. }
  33. private void AddListener()
  34. {
  35. this.client.GameClient.Listen<DDogClientIncomingMailNotify>(OnReceiveClientIncomingMailNotify);
  36. }
  37. private void OnReceiveClientIncomingMailNotify(DDogClientIncomingMailNotify notify)
  38. {
  39. MessageBox.Show("收到新邮件!");
  40. UpdateMailListInfo();
  41. }
  42. private void FormMail_Load(object sender, EventArgs e)
  43. {
  44. }
  45. /// <summary>
  46. /// 更新邮箱界面.
  47. /// </summary>
  48. private void UpdateMailListInfo()
  49. {
  50. this.client.GameClient.Request<DDogClientGetMailBoxInfoResponse>(new DDogClientGetMailBoxInfoRequest(), (err, rsp) =>
  51. {
  52. if (Response.CheckSuccess(rsp))
  53. {
  54. UpdateMailListInfo(rsp.s2c_mailsnap_list);
  55. }
  56. else
  57. {
  58. MessageBox.Show("更新邮件列表失败 : " + rsp.s2c_code);
  59. }
  60. });
  61. }
  62. /// <summary>
  63. /// 更新邮箱界面.
  64. /// </summary>
  65. /// <param name="list"></param>
  66. private void UpdateMailListInfo(List<DDogMailSnapInfoData> list)
  67. {
  68. listView1.Items.Clear();
  69. if (list != null)
  70. {
  71. DDogMailSnapInfoData snap = null;
  72. for (int i = 0; i < list.Count; i++)
  73. {
  74. snap = list[i];
  75. var item = new ListViewItem(snap.uuid);
  76. switch (snap.mail_status)
  77. {
  78. case DDogMailData.MailStatus.Status_Read:
  79. item.Text = "已读";
  80. break;
  81. case DDogMailData.MailStatus.Status_UnRead:
  82. item.Text = "未读";
  83. break;
  84. default:
  85. item.Text = "Error";
  86. break;
  87. }
  88. item.SubItems.Add(snap.uuid);
  89. item.SubItems.Add(snap.title);
  90. item.SubItems.Add(snap.attachment.ToString());
  91. item.SubItems.Add(snap.sender_name);
  92. item.SubItems.Add(snap.sender_uuid);
  93. item.SubItems.Add(snap.create_time.ToString());
  94. item.Tag = snap;
  95. listView1.Items.Add(item);
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// 删邮件.
  101. /// </summary>
  102. /// <param name="sender"></param>
  103. /// <param name="e"></param>
  104. private void btn_DeleteMail_Click(object sender, EventArgs e)
  105. {
  106. DDogMailSnapInfoData snap = null;
  107. List<string> removelist = new List<string>(); ;
  108. foreach (ListViewItem item in listView1.SelectedItems)
  109. {
  110. snap = item.Tag as DDogMailSnapInfoData;
  111. removelist.Add(snap.uuid);
  112. }
  113. DDogClientDeleteMailRequest req = new DDogClientDeleteMailRequest();
  114. req.c2s_delete_all = false;
  115. req.c2s_remove_uuid_list = removelist;
  116. this.client.GameClient.Request<DDogClientDeleteMailResponse>(req, (err, rsp) =>
  117. {
  118. if (DDogClientDeleteMailResponse.CheckSuccess(rsp))
  119. {
  120. UpdateMailListInfo();
  121. MessageBox.Show("邮件删除成功 : " + rsp);
  122. }
  123. else
  124. {
  125. MessageBox.Show("邮件删除失败 : " + rsp);
  126. }
  127. }
  128. );
  129. }
  130. /// <summary>
  131. /// 写邮件.
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void btn_WriteMail_Click(object sender, EventArgs e)
  136. {
  137. DDogClientSendMailRequest req = new DDogClientSendMailRequest();
  138. //临时用,发给自己.
  139. req.c2s_receiver_uuid = this.client.LastRoleData.uuid;
  140. req.c2s_title = "邮件测试";
  141. req.c2s_content = new DDogMailContentData { txt_content = "暗地里发了快递费骄傲了看对方进度发", attachment_list = null };
  142. this.client.GameClient.Request<DDogClientSendMailResponse>(req, (err, rsp) =>
  143. {
  144. if (Response.CheckSuccess(rsp))
  145. {
  146. MessageBox.Show("邮件发送成功 : " + rsp);
  147. }
  148. else if (err != null)
  149. {
  150. MessageBox.Show("邮件发送失败 : " + err.Message);
  151. }
  152. });
  153. }
  154. /// <summary>
  155. /// 清空邮件.
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void btn_ClearMail_Click(object sender, EventArgs e)
  160. {
  161. DDogClientDeleteMailRequest req = new DDogClientDeleteMailRequest();
  162. req.c2s_delete_all = true;
  163. this.client.GameClient.Request<DDogClientDeleteMailResponse>(req, (err, rsp) =>
  164. {
  165. if (rsp.IsSuccess)
  166. {
  167. UpdateMailListInfo(rsp.s2c_mailsnap_list);
  168. MessageBox.Show("清空邮件成功 : " + rsp);
  169. }
  170. else
  171. {
  172. MessageBox.Show("清空邮件失败 : " + rsp);
  173. }
  174. }
  175. );
  176. }
  177. /// <summary>
  178. /// 获取附件.
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void btn_GetAttachment_Click(object sender, EventArgs e)
  183. {
  184. DDogClientGetMailAttachmentRequest req = new DDogClientGetMailAttachmentRequest();
  185. DDogMailSnapInfoData ms = null;
  186. foreach (ListViewItem item in listView1.SelectedItems)
  187. {
  188. ms = item.Tag as DDogMailSnapInfoData;
  189. }
  190. if (ms != null)
  191. {
  192. req.c2s_mailuuid = ms.uuid;
  193. this.client.GameClient.Request<DDogClientGetMailAttachmentResponse>(req, (err, rsp) =>
  194. {
  195. if (rsp.IsSuccess)
  196. {
  197. UpdateMailListInfo();
  198. MessageBox.Show("获取附件成功: " + rsp);
  199. }
  200. else
  201. {
  202. MessageBox.Show("获取详情失败 : " + rsp);
  203. }
  204. });
  205. }
  206. }
  207. /// <summary>
  208. /// 获取邮件附件通知.
  209. /// </summary>
  210. /// <param name="sender"></param>
  211. /// <param name="e"></param>
  212. private void btn_GetMailDetail_Click(object sender, EventArgs e)
  213. {
  214. DDogClientGetMailDetailRequest req = new DDogClientGetMailDetailRequest();
  215. DDogMailSnapInfoData ms = null;
  216. foreach (ListViewItem item in listView1.SelectedItems)
  217. {
  218. ms = item.Tag as DDogMailSnapInfoData;
  219. }
  220. if (ms != null)
  221. {
  222. req.c2s_mailuuid = ms.uuid;
  223. this.client.GameClient.Request<DDogClientGetMailDetailResponse>(req, (err, rsp) =>
  224. {
  225. if (rsp.IsSuccess)
  226. {
  227. UpdateMailListInfo();
  228. MessageBox.Show("邮件内容: " + rsp.s2c_mail_detail.content.txt_content);
  229. }
  230. else
  231. {
  232. MessageBox.Show("获取详情失败 : " + rsp);
  233. }
  234. }
  235. );
  236. }
  237. }
  238. }
  239. }