/// <summary> /// 保存为群 /// </summary> private void SaveGroup() { String groupName = GetTextBox("txtGroupName").Text; if (groupName == null || groupName.Length == 0) { MessageBox.Show("请输入群的名称!", "提示"); return; } List <GridRow> selectedRows = m_gridHosts.SelectedRows; int selectedRowsSize = selectedRows.Count; if (selectedRowsSize > 1) { List <String> userIDs = new List <String>(); for (int i = 0; i < selectedRowsSize; i++) { userIDs.Add(selectedRows[i].GetCell("colP3").GetString()); } ChatGroup chatGroup = new ChatGroup(); chatGroup.Name = System.Guid.NewGuid().ToString(); chatGroup.DisplayName = groupName; chatGroup.UserIDs = userIDs; m_chatGroups.Add(chatGroup); ChatGroup.SaveGroups(m_chatGroups); BindGroups(); } else { MessageBox.Show("请选择至少两个人!", "提示"); } }
/// <summary> /// 点击事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值/param> private void ClickEvent(object sender, POINT mp, MouseButtonsA button, int clicks, int delta) { if (button == MouseButtonsA.Left && clicks == 1) { ControlA control = sender as ControlA; String name = control.Name; if (name == "btnSendAll") { SendAll(); } else if (name == "btnSend") { List <GridRow> selectedRows = m_gridHosts.SelectedRows; Send(selectedRows); } else if (name == "btnSendGroup") { List <GridRow> sendRows = new List <GridRow>(); foreach (GridRow row in m_gridHosts.m_rows) { if (row.Visible) { sendRows.Add(row); } } Send(sendRows); sendRows.Clear(); } else if (name == "btnLogin") { Login(); } else if (name == "btnSaveGroup") { SaveGroup(); } else if (name == "btnDelete") { String groupName = (sender as ButtonA).Tag.ToString(); int chatGroupsSize = m_chatGroups.Count; for (int i = 0; i < chatGroupsSize; i++) { ChatGroup chatGroup = m_chatGroups[i]; if (chatGroup.Name == groupName) { m_chatGroups.Remove(chatGroup); i--; chatGroupsSize--; } } if (m_currentGroupName == groupName) { m_currentGroupName = ""; } ChatGroup.SaveGroups(m_chatGroups); BindGroups(); SetHostGridRowVisible(); } } }
public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 /// <summary> /// 加载XML /// </summary> /// <param name="xmlPath">XML路径</param> public override void Load(String xmlPath) { LoadFile(xmlPath, null); DataCenter.MainUI = this; m_mainDiv = Native.GetControls()[0] as DivA; m_mainDiv.BackColor = COLOR.CONTROL; ControlPaintEvent paintLayoutEvent = new ControlPaintEvent(PaintLayoutDiv); m_mainDiv.RegisterEvent(paintLayoutEvent, EVENTID.PAINT); m_mainDiv.RegisterEvent(new ControlInvokeEvent(Invoke), EVENTID.INVOKE); DataCenter.ServerChatService.RegisterListener(DataCenter.ChatRequestID, new ListenerMessageCallBack(ChatMessageCallBack)); m_gridHosts = GetGrid("gridHosts"); m_gridHosts.GridLineColor = COLOR.CONTROLBORDER; GridRowStyle rowStyle = new GridRowStyle(); rowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; rowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; rowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; rowStyle.Font = new FONT("微软雅黑", 12, false, false, false); m_gridHosts.RowStyle = rowStyle; GridRowStyle alternateRowStyle = new GridRowStyle(); alternateRowStyle.BackColor = CDraw.PCOLORS_ALTERNATEROWCOLOR; alternateRowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; alternateRowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; alternateRowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; alternateRowStyle.Font = new FONT("微软雅黑", 12, false, false, false); m_gridHosts.AlternateRowStyle = alternateRowStyle; m_gridGroups = GetGrid("gridGroups"); m_gridGroups.RowStyle = rowStyle; m_gridGroups.AlternateRowStyle = alternateRowStyle; m_gridGroups.RegisterEvent(new GridCellMouseEvent(GridCellClick), EVENTID.GRIDCELLCLICK); RegisterEvents(m_mainDiv); //全节点服务器 if (DataCenter.IsFull) { DataCenter.UserID = DataCenter.HostInfo.m_localHost + ":" + CStr.ConvertIntToStr(DataCenter.HostInfo.m_localPort); DataCenter.UserName = DataCenter.UserID; Thread thread = new Thread(new ThreadStart(StartConnect)); thread.Start(); } else { UserCookie cookie = new UserCookie(); if (DataCenter.UserCookieService.GetCookie("USERINFO2", ref cookie) > 0) { String[] strs = cookie.m_value.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); GetTextBox("txtPhone").Text = strs[0]; GetTextBox("txtUserName").Text = strs[1]; GetTextBox("txtPort").Text = strs[2]; } } m_chatGroups = ChatGroup.ReadGroups(); BindGroups(); }
/// <summary> /// 设置主机表格可见 /// </summary> private void SetHostGridRowVisible() { ChatGroup chatGroup = null; int chatGroupsSize = m_chatGroups.Count; for (int i = 0; i < chatGroupsSize; i++) { if (m_chatGroups[i].Name == m_currentGroupName) { chatGroup = m_chatGroups[i]; break; } } List <GridRow> rows = m_gridHosts.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow row = rows[i]; if (m_currentGroupName == "") { row.Visible = true; } else { if (chatGroup != null) { if (chatGroup.UserIDs.Contains(row.GetCell("colP3").GetString())) { row.Visible = true; } else { row.Visible = false; } } else { row.Visible = true; } } } m_gridHosts.Update(); m_gridHosts.Invalidate(); }
/// <summary> /// 绑定所有的群组 /// </summary> private void BindGroups() { m_gridGroups.UseAnimation = true; List <GridRow> rows = m_gridGroups.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow row = rows[i]; if (row.EditButton != null) { m_gridGroups.RemoveControl(row.EditButton); row.EditButton = null; } m_gridGroups.RemoveRow(row); i--; rowsSize--; } m_gridGroups.Update(); GridRow firstRow = new GridRow(); m_gridGroups.AddRow(firstRow); GridStringCell cell1 = new GridStringCell(""); firstRow.AddCell("colG1", cell1); GridStringCell cell2 = new GridStringCell("全部"); firstRow.AddCell("colG2", cell2); GridStringCell cell3 = new GridStringCell(""); firstRow.AddCell("colG3", cell3); int groupsSize = m_chatGroups.Count; for (int i = 0; i < groupsSize; i++) { ChatGroup chatGroup = m_chatGroups[i]; GridRow cRow = new GridRow(); m_gridGroups.AddRow(cRow); ButtonA deleteButton = new ButtonA(); deleteButton.Height = cRow.Height; deleteButton.Name = "btnDelete"; deleteButton.Tag = chatGroup.Name; deleteButton.BackColor = COLOR.ARGB(255, 0, 0); deleteButton.Native = m_gridHosts.Native; deleteButton.Text = "删除"; cRow.EditButton = deleteButton; cRow.AllowEdit = true; GridStringCell cCell1 = new GridStringCell(chatGroup.Name); cRow.AddCell("colG1", cCell1); GridStringCell cCell2 = new GridStringCell(chatGroup.DisplayName); cRow.AddCell("colG2", cCell2); String strIDs = ""; int userIDsSize = chatGroup.UserIDs.Count; for (int j = 0; j < userIDsSize; j++) { strIDs += chatGroup.UserIDs[j]; if (j != userIDsSize - 1) { strIDs += ","; } } GridStringCell cCell3 = new GridStringCell(strIDs); cRow.AddCell("colG3", cCell3); ControlMouseEvent clickButtonEvent = new ControlMouseEvent(ClickEvent); deleteButton.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } m_gridGroups.Update(); m_gridGroups.Invalidate(); }