void OnDelMsg(object sender, Mi e) { var l = (Letter)e.DataContext; AtState.Exec($"delete from Letter where ID={l.ID}"); _lv.Data.Remove(l); }
/// <summary> /// 更新好友列表,默认超过10小时需要刷新 /// </summary> /// <returns></returns> public static async Task Refresh() { if (!NeedRefresh()) { return; } // 暂时取所有,后续增加好友功能 var tbl = await new UnaryRpc( "cm", "Da.Query", "select id,name,phone,sex,(case photo when '' then 'photo/profilephoto.jpg' else photo end) as photo, mtime from cm_user" ).Call <Table <ChatMember> >(); // 将新列表缓存到本地库 AtState.Exec("delete from ChatMember"); if (tbl != null && tbl.Count > 0) { foreach (var r in tbl) { r.IsAdded = true; } await AtState.BatchSave(tbl, false); } // 记录刷新时间 AtState.SaveCookie(_refreshKey, Kit.Now.ToString()); }
/// <summary> /// 获取用户可访问的菜单 /// </summary> /// <returns></returns> static async Task <List <long> > GetAllUserMenus() { int cnt = AtState.GetScalar <int>("select count(*) from DataVersion where id='menu'"); if (cnt == 0) { // 查询服务端 Dict dt = await AtCm.GetMenus(Kit.UserID); // 记录版本号 var ver = new DataVersion(ID: "menu", Ver: dt.Str("ver")); await AtState.Save(ver, false); // 清空旧数据 AtState.Exec("delete from UserMenu"); // 插入新数据 var ls = (List <long>)dt["result"]; if (ls != null && ls.Count > 0) { List <Dict> dts = new List <Dict>(); foreach (var id in ls) { dts.Add(new Dict { { "id", id } }); } AtState.BatchExec("insert into UserMenu (id) values (:id)", dts); } return(ls); } return(AtState.FirstCol <long>("select id from UserMenu")); }
void OnClearHis(object sender, RoutedEventArgs e) { using (Items.Defer()) { RemoveAllHis(); } AtState.Exec($"delete from SearchFvHis where BaseUri='{_baseUri}'"); }
/// <summary> /// 恢复默认布局 /// 1. 删除状态库的历史布局 /// 2. 加载最初布局 /// </summary> public void LoadDefaultLayout() { if (AllowSaveLayout()) { AtState.Exec($"delete from DockLayout where BaseUri=\"{_owner.BaseUri.AbsolutePath}\""); } ApplyLayout(_default); _owner.AllowResetLayout = false; }
/// <summary> /// 接收服务器推送的聊天信息 /// </summary> /// <param name="p_letter"></param> internal static async void ReceiveLetter(LetterInfo p_letter) { if (p_letter == null || string.IsNullOrEmpty(p_letter.ID)) { return; } // 撤回消息 if (p_letter.LetterType == LetterType.Undo) { var letter = AtState.First <Letter>("select * from Letter where MsgID=@msgid and LoginID=@loginid and IsReceived=1", new Dict { { "msgid", p_letter.ID }, { "loginid", Kit.UserID } }); if (letter != null) { // 删除 AtState.Exec($"delete from Letter where ID={letter.ID}"); UndoLetter?.Invoke(letter); } return; } // 新消息 Letter l = new Letter( LoginID: Kit.UserID, MsgID: p_letter.ID, OtherID: p_letter.SenderID, OtherName: p_letter.SenderName, LetterType: p_letter.LetterType, Content: p_letter.Content, STime: p_letter.SendTime, IsReceived: true, Unread: true); // 自增主键插入后自动赋值 await AtState.Save(l, false); // 外部可修改 Unread 状态 NewLetter?.Invoke(l); if (l.Unread) { // 外部未读提示 StateChanged?.Invoke(l.OtherID); ShowUnreadNotify(l); } else { // Unread状态被修改 await AtState.Save(l, false); } }
async void SaveCookie(string p_text) { _lastText = p_text; // 删除重复 AtState.Exec($"delete from SearchFvHis where BaseUri='{_baseUri}' and Content='{p_text}'"); SearchFvHis his = new SearchFvHis(BaseUri: _baseUri, Content: p_text); await AtState.Save(his, false); using (Items.Defer()) { RemoveAllHis(); LoadHisItems(); } }
void OnDelHis(object sender, RoutedEventArgs e) { SearchFvHis his = (SearchFvHis)((Button)sender).DataContext; if (AtState.Exec($"delete from SearchFvHis where BaseUri='{_baseUri}' and Content='{his.Content}'") == 1) { for (int i = _hisStart; i < Items.Count; i++) { if (((Button)sender).DataContext == Items[i].DataContext) { Items.RemoveAt(i); break; } } } }
async void OnReset(object sender, Mi e) { int cntFixed = Kit.Stub.FixedMenus == null ? 0 : Kit.Stub.FixedMenus.Count; if (MenuKit.FavMenus.Count > cntFixed) { var cnt = AtState.Exec($"delete from menufav where userid={Kit.UserID}"); if (cnt > 0) { await MenuKit.LoadMenus(); _lv.Data = MenuKit.RootPageMenus; e.Visibility = Visibility.Collapsed; Kit.Msg("重置常用菜单成功!"); } } }
/// <summary> /// 清除和某人的未读消息状态 /// </summary> /// <param name="p_otherid">对方标识</param> public static void ClearUnreadFlag(long p_otherid) { Kit.RunAsync(() => { int cnt = AtState.Exec("update Letter set unread=0 where otherid=@otherid and loginid=@loginid and unread=1", new Dict { { "otherid", p_otherid }, { "loginid", Kit.UserID } }); if (cnt > 0) { StateChanged?.Invoke(p_otherid); } }); }
/// <summary> /// 打开菜单项窗口,可以由点击菜单项或直接代码构造Menu的方式调用 /// </summary> /// <param name="p_menu">OmMenu实例</param> /// <returns>返回打开的窗口或视图,null表示打开失败</returns> public static object OpenMenu(OmMenu p_menu) { if (p_menu == null) { Kit.Msg("打开菜单项不可为空!"); return(null); } Type tp = Kit.GetViewType(p_menu.ViewName); if (tp == null) { Kit.Msg(string.Format("打开菜单时未找到视图【{0}】!", p_menu.ViewName)); return(null); } Icons icon; Enum.TryParse(p_menu.Icon, out icon); object win = Kit.OpenWin(tp, p_menu.Name, icon, string.IsNullOrEmpty(p_menu.Params) ? null : p_menu.Params); // 保存点击次数,用于确定哪些是收藏菜单 if (win != null) { Task.Run(() => { if (AtModel.GetScalar <int>($"select count(id) from ommenu where id=\"{p_menu.ID}\"") > 0) { // 点击次数保存在客户端 Dict dt = new Dict(); dt["userid"] = Kit.UserID; dt["menuid"] = p_menu.ID; int cnt = AtState.Exec("update menufav set clicks=clicks+1 where userid=:userid and menuid=:menuid", dt); if (cnt == 0) { AtState.Exec("insert into menufav (userid, menuid, clicks) values (:userid, :menuid, 1)", dt); } } // 收集使用频率 //await AtAuth.ClickMenu(p_menu.ID); }); } return(win); }
/// <summary> /// 撤回发出的消息 /// </summary> /// <param name="p_letter">待撤消息</param> /// <returns></returns> public static async Task <bool> SendUndoLetter(Letter p_letter) { if (p_letter == null) { return(false); } LetterInfo li = new LetterInfo { ID = p_letter.MsgID, SenderID = Kit.UserID, SenderName = Kit.UserName, LetterType = LetterType.Undo, SendTime = Kit.Now }; await AtMsg.SendLetter(p_letter.OtherID, li); AtState.Exec($"delete from Letter where ID={p_letter.ID}"); return(true); }
/// <summary> /// 附加值改变时的处理方法,提供外部自定义显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnDataPropertyChanged(object sender, PropertyChangedEventArgs e) { ICell cell = (ICell)sender; if (e.PropertyName == "Val") { OnValChanged(); if (!AutoCookie || string.IsNullOrEmpty(Owner.Name)) { return; } // 记录单元格最近一次编辑值 Kit.RunAsync(() => { string id = string.Format("{0}+{1}+{2}", BaseUri.AbsolutePath, Owner.Name, ID); object val = cell.Val; if (val == null || string.IsNullOrEmpty(val.ToString())) { // 为空时删除记录,避免造成不一致情况 AtState.Exec($"delete from CellLastVal where id=\"{id}\""); } else { CellLastVal cookie = new CellLastVal(id, val.ToString()); _ = AtState.Save(cookie, false); } }); } else if (e.PropertyName == "IsChanged") { if (_panel != null) { _panel.ToggleIsChanged(cell.IsChanged); } } }
/// <summary> /// 将xml布局描述应用到当前布局,若应用过程中若异常从状态库中删除xml,已调优 /// </summary> /// <param name="p_content"></param> /// <returns>应用布局是否成功</returns> bool ApplyLayout(string p_content) { if (string.IsNullOrEmpty(p_content)) { return(false); } bool succ = true; _owner.IsReseting = true; ClearAllItems(); try { using (StringReader reader = new StringReader(p_content)) { XDocument doc = XDocument.Load(reader); if (p_content != _default) { // 校验标签 int count = 0; foreach (XElement item in doc.Root.Descendants("Tab")) { count++; XAttribute attr = item.Attribute("Title"); if (attr == null || string.IsNullOrEmpty(attr.Value) || !_tabs.ContainsKey(attr.Value)) { succ = false; break; } } if (!succ || count != _tabs.Count) { throw new Exception("加载时确保标签个数和标题都能对上,否则删除历史布局!"); } } // 停靠项 XElement elem = doc.Root.Element("Win"); foreach (XElement item in elem.Elements()) { Pane winItem = CreateWinItem(item); _owner.Items.Add(winItem); _owner.RootPanel.Children.Add(winItem); } // 中部项 elem = doc.Root.Element("Center"); if (elem != null) { foreach (XElement item in elem.Elements()) { if (item.Name == "Tabs") { _owner.CenterItem.Items.Add(CreateTabs(item)); } else if (item.Name == "Pane") { _owner.CenterItem.Items.Add(CreateWinItem(item)); } } } // 左侧隐藏项 elem = doc.Root.Element("Left"); if (elem != null) { if (_owner.LeftAutoHide == null) { _owner.CreateLeftAutoHideTab(); } foreach (XElement item in elem.Elements()) { _owner.LeftAutoHide.Unpin(CreateTab(item)); } } // 右侧隐藏项 elem = doc.Root.Element("Right"); if (elem != null) { if (_owner.RightAutoHide == null) { _owner.CreateRightAutoHideTab(); } foreach (XElement item in elem.Elements()) { _owner.RightAutoHide.Unpin(CreateTab(item)); } } // 上侧隐藏项 elem = doc.Root.Element("Top"); if (elem != null) { if (_owner.TopAutoHide == null) { _owner.CreateTopAutoHideTab(); } foreach (XElement item in elem.Elements()) { _owner.TopAutoHide.Unpin(CreateTab(item)); } } // 下侧隐藏项 elem = doc.Root.Element("Bottom"); if (elem != null) { if (_owner.BottomAutoHide == null) { _owner.CreateBottomAutoHideTab(); } foreach (XElement item in elem.Elements()) { _owner.BottomAutoHide.Unpin(CreateTab(item)); } } // 浮动项 elem = doc.Root.Element("Float"); if (elem != null) { foreach (XElement item in elem.Elements()) { OpenInWindow(CreateWinItem(item)); } } } } catch { succ = false; if (AllowSaveLayout()) { AtState.Exec($"delete from DockLayout where BaseUri=\"{_owner.BaseUri.AbsolutePath}\""); } } finally { _owner.IsReseting = false; } return(succ); }