void SaveMessage(SignalCore.publicMessage notice, string userName) { bool isExistence = false; foreach (var node in NoticeStackPanel.Children) { if ((node as PLeftMessageBoxUControl).Id == notice.Id) { var item = node as PLeftMessageBoxUControl; item.UpdateListBox(notice.Comments); isExistence = true; break; } } if (!isExistence) { if (notice.KeyWord == Expander_Range.Header.ToString() || Expander_Range.Header.ToString() == "所有内容") { PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl(); pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime, notice.From, notice.Id, notice.Message); pLeftMessage.Comment = (id) => { this.CommentId = id; this.input.ToolTip = "评论"; this.InputNoticeTBox.Text = userName + ":"; }; NoticeStackPanel.Children.Add(pLeftMessage); } } _noticeList.Add(notice); }
public void Init(String userName, String group, SignalRProxy signalrProxy) { if (signalrProxy != null) { this.SignalRProxy = signalrProxy; } this.Group = group; this.UserName = userName; if (SignalRProxy.ReceviceNotice == null) { SignalRProxy.ReceviceNotice = (username, notice) => { this.Dispatcher.Invoke(() => { bool isExistence = false; foreach (var node in NoticeStackPanel.Children) { if ((node as PLeftMessageBoxUControl).Id == notice.Id) { var item = node as PLeftMessageBoxUControl; item.UpdateListBox(notice.Comments); isExistence = true; break; } } if (!isExistence) { PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl(); pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime, notice.From, notice.Id, notice.Message); pLeftMessage.Comment = (id) => { this.CommentId = id; this.input.ToolTip = "评论"; this.InputNoticeTBox.Text = userName + ":"; }; NoticeStackPanel.Children.Add(pLeftMessage); } }); }; } SignalRProxy.ConnectAsync(); }
void Show(String keyword, String userName) { if (NoticeStackPanel.Children.Count >= 0) { NoticeStackPanel.Children.Clear(); } foreach (var notice in _noticeList) { bool isExistence = false; foreach (var node in NoticeStackPanel.Children) { if ((node as PLeftMessageBoxUControl).Id == notice.Id) { var item = node as PLeftMessageBoxUControl; item.UpdateListBox(notice.Comments); isExistence = true; break; } } if (!isExistence) { if (notice.KeyWord == keyword || keyword == "所有内容") { PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl(); pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime, notice.From, notice.Id, notice.Message); pLeftMessage.Comment = (id) => { this.CommentId = id; this.input.ToolTip = "评论"; this.InputNoticeTBox.Text = userName + ":"; }; NoticeStackPanel.Children.Add(pLeftMessage); } } } }