protected override void ProcessProtocol(object arg) { string content = string.Empty; string protocol = arg as string; if (protocol.StartsWith(MailServerCommand.MailUsersResponse.ToString())) { content = protocol.Substring(MailServerCommand.MailUsersResponse.ToString().Length).Trim(); try { List <MailUser> mailUserList = JsonConvert.DeserializeObject <List <MailUser> >(content); if (MailUsersResponse != null) { MailUsersResponse(mailUserList); } string sendMsg = CommonUtils.GetCommand(MailServerCommunicate.MailServerCommand.MailRecordsRequest.ToString(), localIP, "send", "1", "10"); SendMsgToServer(sendMsg); sendMsg = CommonUtils.GetCommand(MailServerCommunicate.MailServerCommand.MailRecordsRequest.ToString(), localIP, "receive", "1", "10"); SendMsgToServer(sendMsg); } catch { } } else if (protocol.StartsWith(MailServerCommand.MailRecordsResponse.ToString())) { content = protocol.Substring(MailServerCommand.MailRecordsResponse.ToString().Length).Trim(); try { var JResult = JObject.Parse(content); bool result = (bool)JResult["Result"]; string message = JResult["Message"].ToString(); MsgHint(message); if (result == false) { return; } MailTableAssemble mailTableAssemble = JResult["MailTableAssemble"].ToObject <MailTableAssemble>(); if (MailRecordsResponse != null) { MailRecordsResponse(mailTableAssemble); } } catch { } } else if (protocol.StartsWith(MailServerCommand.MailSendResponse.ToString())) { content = protocol.Substring(MailServerCommand.MailSendResponse.ToString().Length).Trim(); try { var JResult = JObject.Parse(content); string message = JResult["Message"].ToString(); MsgHint(message); string sendMsg = CommonUtils.GetCommand(MailServerCommunicate.MailServerCommand.MailRecordsRequest.ToString(), localIP, "send", "1", "10"); SendMsgToServer(sendMsg); } catch { } } else if (protocol.StartsWith(MailServerCommand.DownloadMailFileResponse.ToString())) { content = protocol.Substring(MailServerCommand.DownloadMailFileResponse.ToString().Length).Trim(); try { var JResult = JObject.Parse(content); bool result = (bool)JResult["Result"]; if (result == false) { listener.Stop(); string message = JResult["Message"].ToString(); DownloadHint(message); return; } } catch { } } else if (protocol.StartsWith(MailServerCommand.NewMail.ToString())) { //获取接收文电记录 string sendMsg = CommonUtils.GetCommand(MailServerCommunicate.MailServerCommand.MailRecordsRequest.ToString(), localIP, "receive", "1", "10"); SendMsgToServer(sendMsg); } else if (protocol.StartsWith(MailServerCommand.UpdateMailUsers.ToString())) { content = protocol.Substring(MailServerCommand.UpdateMailUsers.ToString().Length).Trim(); try { MailUser mailUser = JsonConvert.DeserializeObject <MailUser>(content); if (UpdateMailUsers != null) { UpdateMailUsers(mailUser); } } catch { } } }
private void MailRecordsResponse(MailTableAssemble mailTableAssemble) { if (this.dataGridView_Received.InvokeRequired) { MailRecordsResponseDel del = new MailRecordsResponseDel(MailRecordsResponse); this.Invoke(del, mailTableAssemble); } else { if (mailTableAssemble.MailType == "receive") { mailRecordsReceived.Clear(); DataTable dt = (DataTable)dataGridView_Received.DataSource; if (dt.Rows.Count > 0) { dt.Rows.Clear(); } myPageControl_Received.PageIndex = mailTableAssemble.PageNumber; myPageControl_Received.PageRecordNumber = mailTableAssemble.rowsPerPage; myPageControl_Received.PageRecordCount = mailTableAssemble.MailCount; foreach (var item in mailTableAssemble.MailTableList) { DataRow row = dt.NewRow(); row[0] = false; row[1] = item.MailID; row[2] = item.IsRead ? "已读" : "未读"; row[3] = item.Receiver; row[4] = item.MailTitle; row[5] = item.SendTime; dt.Rows.Add(row); Thread.Sleep(10); } dataGridView_Received.DataSource = dt; mailRecordsReceived.AddRange(mailTableAssemble.MailTableList); } else { mailRecordsSent.Clear(); DataTable dt = (DataTable)dataGridView_Sent.DataSource; dt.Rows.Clear(); myPageControl_Sent.PageIndex = mailTableAssemble.PageNumber; myPageControl_Sent.PageRecordNumber = mailTableAssemble.rowsPerPage; myPageControl_Sent.PageRecordCount = mailTableAssemble.MailCount; foreach (var item in mailTableAssemble.MailTableList) { DataRow row = dt.NewRow(); row[0] = false; row[1] = item.MailID; row[2] = item.IsRead ? "已读" : "未读"; row[3] = item.Receiver; row[4] = item.MailTitle; row[5] = item.SendTime; dt.Rows.Add(row); } dataGridView_Sent.DataSource = dt; mailRecordsSent.AddRange(mailTableAssemble.MailTableList); } } }