private void AddContextMenu(TreeNodeStaff node, object s) { (node.ContextMenu.Items[0] as MenuItem).Items.Clear(); TreeNodeStaff treeNodeStaff = s as TreeNodeStaff; if (treeNodeStaff == null || treeNodeStaff.Staff.Uid != this.sessionService.Uid) { foreach (CustomGroup item in DataModel.Instance.CustomeGroupName.Values) { MenuItem menuitem = new MenuItem(); menuitem.Header = item.GroupName; menuitem.Tag = item; if (treeNodeStaff != null && item.Members != null && item.Members.Count > 0) { foreach (Staff sta in item.Members) { if (sta.Uid == treeNodeStaff.Staff.Uid) { menuitem.IsCheckable = false; menuitem.IsEnabled = false; menuitem.IsChecked = true; break; } } } (node.ContextMenu.Items[0] as MenuItem).Items.Add(menuitem); menuitem.Click += new RoutedEventHandler(this.menuitem_Click); } } }
public void AddStaff(Staff staff) { try { if (staff != null) { System.Threading.Monitor.Enter(this.staffNode); if (!this.staffNode.ContainsKey(staff.Uid) && this.departmentNode.ContainsKey(staff.DepartmentId)) { TreeNodeStaff node = new TreeNodeStaff(staff); node.SessionService = this.sessionService; node.DataService = this.dataService; if (!this.staffNode.ContainsKey(staff.Uid)) { this.staffNode.Add(staff.Uid, node); this.departmentNode[staff.DepartmentId].Items.Add(node); node.ContextMenu = this.GetContextMenu(node); node.ContextMenuOpening += delegate(object s, ContextMenuEventArgs e) { if (DataModel.Instance.CustomeGroupName.Count > 0) { this.AddContextMenu(node, s); } }; } } System.Threading.Monitor.Exit(this.staffNode); } } catch (System.Exception ex) { System.Console.WriteLine(ex.ToString()); } }
private ContextMenu GetContextMenu(TreeNodeStaff node) { return(new ContextMenu { Items = { new MenuItem { Header = "将联系人添加至" } } }); }
private int CountStaffTotal(TreeViewItem tvi) { int count = 0; for (int i = 0; i < tvi.Items.Count; i++) { TreeNodeStaff tree = tvi.Items[i] as TreeNodeStaff; if (tree != null) { count++; } } return(count); }
public void ChangeAllUserOffline() { foreach (TreeViewItem node in this.departmentNode.Values) { int count = node.Items.Count; for (int i = 0; i < count; i++) { TreeNodeStaff tns = node.Items[i] as TreeNodeStaff; if (tns != null) { tns.Staff.Status = UserStatus.Offline; tns.imgFaceForeground.Source = null; tns.Status = UserStatus.Offline; } } } }
private void menuitem_Click(object sender, RoutedEventArgs e) { if (this.tree.SelectedItem != null) { TreeNodeStaff staff = this.tree.SelectedItem as TreeNodeStaff; if (staff != null) { CustomGroup group = (sender as MenuItem).Tag as CustomGroup; CustomGroupManagerWindowViewModel viewModel = CustomGroupManagerWindowViewModel.GetInstance(); viewModel.AddMemberToCustomGroup((int)this.SessionService.Uid, group.GroupID, this.GetMembers(group) + staff.Staff.Uid + ":", staff.Staff.Uid.ToString()); if (DataModel.Instance.CustomeGroupName[group.GroupID].Members == null) { DataModel.Instance.CustomeGroupName[group.GroupID].Members = new System.Collections.Generic.List <Staff>(); } DataModel.Instance.CustomeGroupName[group.GroupID].Members.Add(staff.Staff); } } }
private ContextMenu GetContextMenu(TreeNodeStaff node) { return new ContextMenu { Items = { new MenuItem { Header = "将联系人添加至" } } }; }
private void AddContextMenu(TreeNodeStaff node, object s) { (node.ContextMenu.Items[0] as MenuItem).Items.Clear(); TreeNodeStaff treeNodeStaff = s as TreeNodeStaff; if (treeNodeStaff == null || treeNodeStaff.Staff.Uid != this.sessionService.Uid) { foreach (CustomGroup item in DataModel.Instance.CustomeGroupName.Values) { MenuItem menuitem = new MenuItem(); menuitem.Header = item.GroupName; menuitem.Tag = item; if (treeNodeStaff != null && item.Members != null && item.Members.Count > 0) { foreach (Staff sta in item.Members) { if (sta.Uid == treeNodeStaff.Staff.Uid) { menuitem.IsCheckable = false; menuitem.IsEnabled = false; menuitem.IsChecked = true; break; } } } (node.ContextMenu.Items[0] as MenuItem).Items.Add(menuitem); menuitem.Click += new RoutedEventHandler(this.menuitem_Click); } } }
public void AddStaff(Staff staff) { try { if (staff != null) { System.Threading.Monitor.Enter(this.staffNode); if (!this.staffNode.ContainsKey(staff.Uid) && this.departmentNode.ContainsKey(staff.DepartmentId)) { TreeNodeStaff node = new TreeNodeStaff(staff); node.SessionService = this.sessionService; node.DataService = this.dataService; if (!this.staffNode.ContainsKey(staff.Uid)) { this.staffNode.Add(staff.Uid, node); this.departmentNode[staff.DepartmentId].Items.Add(node); node.ContextMenu = this.GetContextMenu(node); node.ContextMenuOpening += delegate(object s, ContextMenuEventArgs e) { if (DataModel.Instance.CustomeGroupName.Count > 0) { this.AddContextMenu(node, s); } }; } } System.Threading.Monitor.Exit(this.staffNode); } } catch (System.Exception ex) { System.Console.WriteLine(ex.ToString()); } }
private void SortStatus(TreeViewItem parentNode) { System.Collections.Generic.IList <System.Collections.Generic.IList <TreeNodeStaff> > list = new System.Collections.Generic.List <System.Collections.Generic.IList <TreeNodeStaff> >(); System.Collections.Generic.IList <TreeNodeStaff> nodes = null; int count = parentNode.Items.Count; int[] onLineAndTotalCount = new int[2]; parentNode.Tag = onLineAndTotalCount; for (int i = 0; i < count; i++) { TreeNodeStaff node = parentNode.Items[i] as TreeNodeStaff; if (node != null) { if (nodes == null) { nodes = new System.Collections.Generic.List <TreeNodeStaff>(); } nodes.Add(node); } } if (nodes != null && nodes.Count > 0) { System.Collections.Generic.IList <TreeNodeStaff> offline = null; System.Collections.Generic.IList <TreeNodeStaff> online = null; System.Collections.Generic.IList <TreeNodeStaff> away = null; System.Collections.Generic.IList <TreeNodeStaff> busy = null; System.Collections.Generic.IList <TreeNodeStaff> hide = null; System.Collections.Generic.IList <TreeNodeStaff> inme = null; System.Collections.Generic.IList <TreeNodeStaff> outting = null; System.Collections.Generic.IList <TreeNodeStaff> meeting = null; System.Collections.Generic.IList <TreeNodeStaff> doNotDisturb = null; foreach (TreeNodeStaff node in nodes) { switch (node.Status) { case UserStatus.Offline: if (offline == null) { offline = new System.Collections.Generic.List <TreeNodeStaff>(); } offline.Add(node); break; case UserStatus.Online: if (online == null) { online = new System.Collections.Generic.List <TreeNodeStaff>(); } online.Add(node); break; case UserStatus.Away: if (away == null) { away = new System.Collections.Generic.List <TreeNodeStaff>(); } away.Add(node); break; case UserStatus.Busy: if (busy == null) { busy = new System.Collections.Generic.List <TreeNodeStaff>(); } busy.Add(node); break; case UserStatus.Hide: if (hide == null) { hide = new System.Collections.Generic.List <TreeNodeStaff>(); } hide.Add(node); break; case UserStatus.In: if (inme == null) { inme = new System.Collections.Generic.List <TreeNodeStaff>(); } inme.Add(node); break; case UserStatus.Out: if (outting == null) { outting = new System.Collections.Generic.List <TreeNodeStaff>(); } outting.Add(node); break; case UserStatus.Meeting: if (meeting == null) { meeting = new System.Collections.Generic.List <TreeNodeStaff>(); } meeting.Add(node); break; case UserStatus.DoNotDisturb: if (doNotDisturb == null) { doNotDisturb = new System.Collections.Generic.List <TreeNodeStaff>(); } doNotDisturb.Add(node); break; } } int onlineCount = 0; if (online != null) { list.Add(online); onlineCount += online.Count; } if (inme != null) { list.Add(inme); onlineCount += inme.Count; } if (away != null) { list.Add(away); onlineCount += away.Count; } if (meeting != null) { list.Add(meeting); onlineCount += meeting.Count; } if (busy != null) { list.Add(busy); onlineCount += busy.Count; } if (doNotDisturb != null) { list.Add(doNotDisturb); onlineCount += doNotDisturb.Count; } if (outting != null) { list.Add(outting); onlineCount += outting.Count; } if (hide != null) { list.Add(hide); } if (offline != null) { list.Add(offline); } foreach (TreeNodeStaff tn in nodes) { parentNode.Items.Remove(tn); } foreach (System.Collections.Generic.IList <TreeNodeStaff> tlist in list) { foreach (TreeNodeStaff tn in tlist) { parentNode.Items.Add(tn); } } Department department = parentNode.DataContext as Department; if (department != null) { onLineAndTotalCount[0] = onlineCount; onLineAndTotalCount[1] = nodes.Count; parentNode.Tag = onLineAndTotalCount; this.UpdateDepartmentName(parentNode, string.Concat(new object[] { department.Name, "[", onlineCount, "/", nodes.Count, "]" })); } online = null; inme = null; away = null; meeting = null; busy = null; doNotDisturb = null; outting = null; hide = null; offline = null; nodes = null; list = null; } }