public void OpenMessageRoom(ChatRoom room) { Form openForm = BlindChatUtil.GetFormWithName(room.ID.ToString()); if (openForm != null) { ExecuteWithInvoke(openForm, delegate { if (openForm.WindowState == FormWindowState.Minimized) { openForm.WindowState = FormWindowState.Normal; openForm.Location = new Point(openForm.Location.X + openForm.Width, openForm.Location.Y); } openForm.Activate(); }); } else { Task tMessageRoom = new Task(() => { MessageRoom messageRoom = new MessageRoom(_UserID, room, GetMessageList(room.ID)); messageRoom.SendChatMessage = ChatMessageSend; messageRoom.Location = new Point(form.Location.X + form.Width, form.Location.Y); Application.Run(messageRoom); }); tMessageRoom.Start(); } }
public void AddMessage(ChatMessage message) { string sql = $"insert into ChatMessage (message, userID, roomID, time) values (\'{message.Message}\', {message.UserID}, {message.RoomID}, \'{message.Time}\');"; DB.ExecuteNonQuery(sql); sql = $"update ChatRoom set LastMessageTime = \'{message.Time}\' where ID={message.RoomID}"; DB.ExecuteNonQuery(sql); foreach (ChatRoom a in BlindChat.roomList) { if (a.ID == message.RoomID) { ChatRoom tmpRoom = a; tmpRoom.LastMessageTime = message.Time; BlindChat.roomList[roomList.IndexOf(a)] = tmpRoom; break; } } ExecuteWithInvoke(this.form, delegate { //UI._RoomControl.LoadRooms(); foreach (Room_Item item in UI._RoomControl.RoomItem_LayoutPanel.Controls) { if (item.ID == message.RoomID) { DateTime time = DateTime.Parse(message.Time); item.Time = time.ToString("tt hh:mm"); UI._RoomControl.RoomItem_LayoutPanel.Controls.SetChildIndex((Control)item, 0); UI._RoomControl.RoomItem_LayoutPanel.Invalidate(); } } }); MessageRoom form = BlindChatUtil.GetFormWithName(message.RoomID.ToString()) as MessageRoom; if (form != null) { ExecuteWithInvoke(form, delegate { form.AddMessage(message); }); } }
public static void ExitRoom(uint userID, int roomID) { ChatRoomJoined roomJoined = new ChatRoomJoined(); roomJoined.UserID = userID; roomJoined.RoomID = roomID; roomJoined.Time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ChatPacketSend(BlindChatUtil.StructToChatPacket(roomJoined, ChatType.Exit)); Form form = BlindChatUtil.GetFormWithName(roomJoined.RoomID.ToString()); if (form != null) { form.Close(); } }