示例#1
0
        private void Grid_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;

            if (btn != null)
            {
                string uid = btn.Uid;
                switch (uid)
                {
                case "Cancel":
                case "Close":
                    GroupNotice groupNotice = this.DataContext as GroupNotice;
                    if (groupNotice != null)
                    {
                        if (groupNotice.NoticeType == 0)
                        {
                            if (!AppData.ordinaryGroupNoticeDic.ContainsKey(groupNotice.GroupId))
                            {
                                AppData.ordinaryGroupNoticeDic.Add(groupNotice.GroupId, groupNotice);
                            }
                        }
                        else
                        {
                            if (!AppData.joinGroupNeedKnowDic.ContainsKey(groupNotice.GroupId))
                            {
                                AppData.joinGroupNeedKnowDic.Add(groupNotice.GroupId, groupNotice);
                            }
                        }
                    }
                    this.Close();
                    break;

                case "Sure":
                    GroupNotice gn = this.DataContext as GroupNotice;
                    if (AppData.CanInternetAction())
                    {
                        if (gn != null)
                        {
                            List <ChatViewModel> list   = AppData.MainMV.ChatListVM.Items.ToList().Where(x => x.IsGroup).Where(x => x.TargetVM != null).ToList();
                            ChatViewModel        chatVM = list.FirstOrDefault(x => ((x.TargetVM as GroupViewModel).Model as GroupModel).ID == gn.GroupId);
                            if (gn.NoticeType == 0)
                            {
                                if (!AppData.ordinaryGroupNoticeDic.ContainsKey(gn.GroupId))
                                {
                                    AppData.ordinaryGroupNoticeDic.Add(gn.GroupId, gn);
                                }
                            }
                            else
                            {
                                if (!AppData.joinGroupNeedKnowDic.ContainsKey(gn.GroupId))
                                {
                                    AppData.joinGroupNeedKnowDic.Add(gn.GroupId, gn);
                                }
                            }
                            GroupViewModel gvm = AppData.MainMV.GroupListVM.Items.ToList().FirstOrDefault(x => (x.Model as GroupModel).ID == gn.GroupId);
                            if (CheckDataLegal(gn))
                            {
                                int index = 0;
                                //bool isFirstBadWordTitle = SDKClient.SDKProperty.stringSearchEx.FindFirst(gn.NoticeTitle, out index);
                                bool isContainsBadWordTitle = SDKClient.SDKProperty.stringSearchEx.ContainsAny(gn.NoticeTitle);
                                //bool isFirstBadWordContent = SDKClient.SDKProperty.stringSearchEx.FindFirst(gn.NoticeContent, out index);
                                bool isContainsBadWordContent = SDKClient.SDKProperty.stringSearchEx.ContainsAny(gn.NoticeContent);
                                if (!isContainsBadWordTitle && !isContainsBadWordContent)
                                {
                                    MessageModel msg = new MessageModel()
                                    {
                                        Sender   = AppData.Current.LoginUser.User,
                                        SendTime = DateTime.Now,
                                        MsgType  = MessageType.addgroupnotice,
                                        IsMine   = true,
                                        Content  = gn.NoticeContent
                                    };
                                    GroupNoticeModel gnModel = new GroupNoticeModel()
                                    {
                                        NoticeTitle        = gn.NoticeTitle,
                                        NoticeId           = gn.NoticeId,
                                        GroupMId           = (gvm.Model as GroupModel).ID,
                                        GroupNoticeContent = gn.NoticeContent
                                    };
                                    msg.NoticeModel = gnModel;
                                    msg.TipMessage  = string.Format("{0}", msg.NoticeModel.NoticeTitle);
                                    if (gn.NoticeTitle.Equals("入群须知"))
                                    {
                                        SDKClient.SDKClient.Instance.AddNotice(gn.NoticeTitle, gn.NoticeContent, gn.GroupId, gn.GroupName, (result) =>
                                        {
                                            if (result.Item1)
                                            {
                                                gn.NoticeId = result.Item2;
                                                App.Current.Dispatcher.Invoke(new Action(() =>
                                                {
                                                    AppData.MainMV.TipMessage = "发布成功!";
                                                    if (AppData.joinGroupNeedKnowDic.ContainsKey(gn.GroupId))
                                                    {
                                                        AppData.joinGroupNeedKnowDic.Remove(gn.GroupId);
                                                    }
                                                    gvm.RefreshNoticeList(gn);
                                                    msg.MsgKey       = result.Item3;
                                                    gnModel.NoticeId = result.Item2;
                                                    msg.NoticeModel  = gnModel;
                                                    chatVM.AddMessage(msg);
                                                }));
                                            }
                                            else
                                            {
                                                App.Current.Dispatcher.Invoke(new Action(() =>
                                                {
                                                    AppData.MainMV.TipMessage = "发布失败!";
                                                    if (!AppData.joinGroupNeedKnowDic.ContainsKey(gn.GroupId))
                                                    {
                                                        AppData.joinGroupNeedKnowDic.Add(gn.GroupId, gn);
                                                    }
                                                }));
                                            }
                                        }, SDKClient.SDKProperty.NoticeType.JoinGroupNotice);
                                    }
                                    else
                                    {
                                        SDKClient.SDKClient.Instance.AddNotice(gn.NoticeTitle, gn.NoticeContent, gn.GroupId, gn.GroupName, (result) =>
                                        {
                                            if (result.Item1)
                                            {
                                                gn.NoticeId = result.Item2;
                                                App.Current.Dispatcher.Invoke(new Action(() =>
                                                {
                                                    AppData.MainMV.TipMessage = "发布成功!";
                                                    if (AppData.ordinaryGroupNoticeDic.ContainsKey(gn.GroupId))
                                                    {
                                                        AppData.ordinaryGroupNoticeDic.Remove(gn.GroupId);
                                                    }
                                                    gvm.RefreshNoticeList(gn);
                                                    msg.MsgKey       = result.Item3;
                                                    gnModel.NoticeId = result.Item2;
                                                    msg.NoticeModel  = gnModel;
                                                    chatVM.AddMessage(msg);
                                                }));
                                            }
                                            else
                                            {
                                                App.Current.Dispatcher.Invoke(new Action(() =>
                                                {
                                                    AppData.MainMV.TipMessage = "发布失败!";
                                                    if (!AppData.ordinaryGroupNoticeDic.ContainsKey(gn.GroupId))
                                                    {
                                                        AppData.ordinaryGroupNoticeDic.Add(gn.GroupId, gn);
                                                    }
                                                }));
                                            }
                                        }, SDKClient.SDKProperty.NoticeType.Common);
                                    }
                                    this.Close();
                                }
                                else
                                {
                                    if (isContainsBadWordTitle)
                                    {
                                        TitleContainsBadWord(gn.NoticeTitle);
                                    }
                                    else
                                    {
                                        if (isContainsBadWordContent)
                                        {
                                            ContentContainsBadWord(gn.NoticeContent);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                App.Current.Dispatcher.Invoke(new Action(() => {
                                    if (gn.NoticeType == 0)
                                    {
                                        if (AppData.ordinaryGroupNoticeDic.ContainsKey(gn.GroupId))
                                        {
                                            this.DataContext = AppData.ordinaryGroupNoticeDic[gn.GroupId];
                                        }
                                    }
                                    else
                                    {
                                        if (AppData.joinGroupNeedKnowDic.ContainsKey(gn.GroupId))
                                        {
                                            this.DataContext = AppData.joinGroupNeedKnowDic[gn.GroupId];
                                        }
                                    }
                                    //AppData.MainMV.TipMessage = "发布失败!";
                                }));
                                return;
                            }
                        }
                        //else
                        //{
                        //    App.Current.Dispatcher.Invoke(new Action(() =>
                        //    {
                        //        AppData.MainMV.TipMessage = "请检查数据合法性!";
                        //    }));
                        //}
                    }
                    else
                    {
                        App.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            if (gn.NoticeType == 0)
                            {
                                if (!AppData.ordinaryGroupNoticeDic.ContainsKey(gn.GroupId))
                                {
                                    AppData.ordinaryGroupNoticeDic.Add(gn.GroupId, gn);
                                }
                            }
                            else
                            {
                                if (!AppData.joinGroupNeedKnowDic.ContainsKey(gn.GroupId))
                                {
                                    AppData.joinGroupNeedKnowDic.Add(gn.GroupId, gn);
                                }
                            }
                            AppData.MainMV.TipMessage = "网络异常,请检查网络设置!";
                        }));
                    }
                    break;
                }
            }
        }