From 96b15eb85a2915a34e5ed49e84dd4a3dbf841229 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Mon, 19 Oct 2015 17:29:47 +0200 Subject: [PATCH] Fixed chat --- ErgometerDoctorApplication/ChatItem.cs | 4 ++-- ErgometerDoctorApplication/ClientThread.cs | 6 +++--- ErgometerDoctorApplication/PanelClientChat.cs | 11 ++++++++--- ErgometerDoctorApplication/SessionWindow.Designer.cs | 2 +- ErgometerDoctorApplication/SessionWindow.cs | 5 ++++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ErgometerDoctorApplication/ChatItem.cs b/ErgometerDoctorApplication/ChatItem.cs index fc444b6..3772eb7 100644 --- a/ErgometerDoctorApplication/ChatItem.cs +++ b/ErgometerDoctorApplication/ChatItem.cs @@ -20,7 +20,7 @@ namespace ErgometerDoctorApplication this.setAppearance(isDoctor); this.Controls.Add(this.messageLabel); this.Controls.Add(this.timeLabel); - this.MinimumSize = new System.Drawing.Size(100, 40); + this.MinimumSize = new System.Drawing.Size(150, 60); this.Name = "messageContainer"; this.Padding = new System.Windows.Forms.Padding(6); @@ -31,7 +31,7 @@ namespace ErgometerDoctorApplication this.messageLabel.Dock = System.Windows.Forms.DockStyle.Fill; this.messageLabel.Font = new System.Drawing.Font("Segoe UI Semibold", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.messageLabel.Location = new System.Drawing.Point(6, 6); - this.messageLabel.MaximumSize = new System.Drawing.Size(190, 0); + this.messageLabel.MaximumSize = new System.Drawing.Size(250, 0); this.messageLabel.Size = new System.Drawing.Size(121, 20); this.messageLabel.Text = message; // diff --git a/ErgometerDoctorApplication/ClientThread.cs b/ErgometerDoctorApplication/ClientThread.cs index 8e6c9c9..cb5148c 100644 --- a/ErgometerDoctorApplication/ClientThread.cs +++ b/ErgometerDoctorApplication/ClientThread.cs @@ -23,7 +23,7 @@ namespace ErgometerDoctorApplication Name = name; Session = session; - window = new SessionWindow(Name, true); + window = new SessionWindow(Name, true, Session); window.FormClosed += Window_FormClosed; Metingen = new List(); @@ -37,14 +37,14 @@ namespace ErgometerDoctorApplication public void HandleCommand(NetCommand command) { - switch(command.Type) + switch (command.Type) { case NetCommand.CommandType.DATA: SaveMeting(command.Meting); break; case NetCommand.CommandType.CHAT: Chat.Add(new ChatMessage(Name, command.ChatMessage, false)); - window.panelClientChat.AddChatItem(command.ChatMessage); + window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { command.ChatMessage, Helper.MillisecondsToTime(command.Timestamp), false }); break; } } diff --git a/ErgometerDoctorApplication/PanelClientChat.cs b/ErgometerDoctorApplication/PanelClientChat.cs index d592edd..288ddc2 100644 --- a/ErgometerDoctorApplication/PanelClientChat.cs +++ b/ErgometerDoctorApplication/PanelClientChat.cs @@ -21,8 +21,9 @@ namespace ErgometerDoctorApplication private System.Windows.Forms.Label label2; private System.Windows.Forms.Panel panel3; private System.Windows.Forms.Label connectionLabel; + private int session; - public PanelClientChat() : base() + public PanelClientChat(int session) : base() { this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.panel2 = new System.Windows.Forms.Panel(); @@ -32,6 +33,7 @@ namespace ErgometerDoctorApplication this.panel1 = new System.Windows.Forms.Panel(); this.button1 = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.session = session; this.panel3 = new System.Windows.Forms.Panel(); // @@ -140,7 +142,7 @@ namespace ErgometerDoctorApplication this.Name = "container"; this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseWheel); - Form.CheckForIllegalCrossThreadCalls = false; + passChatMessage = new ChatDelegate(this.AddChatItem); } private void button1_Click(object sender, EventArgs e) @@ -148,7 +150,7 @@ namespace ErgometerDoctorApplication if (richTextBox1.TextLength > 1) { AddChatItem(richTextBox1.Text, Helper.MillisecondsToTime(Helper.Now), true); - MainClient.SendNetCommand(new NetCommand(richTextBox1.Text, MainClient.Session)); + MainClient.SendNetCommand(new NetCommand(richTextBox1.Text, session)); richTextBox1.ResetText(); } } @@ -203,5 +205,8 @@ namespace ErgometerDoctorApplication button1_Click(this, new EventArgs()); } } + + public delegate void ChatDelegate(string message, string time, bool isDoctor); + public ChatDelegate passChatMessage; } } diff --git a/ErgometerDoctorApplication/SessionWindow.Designer.cs b/ErgometerDoctorApplication/SessionWindow.Designer.cs index f562717..be7d12d 100644 --- a/ErgometerDoctorApplication/SessionWindow.Designer.cs +++ b/ErgometerDoctorApplication/SessionWindow.Designer.cs @@ -37,7 +37,7 @@ namespace ErgometerDoctorApplication this.panelClientContainer = new System.Windows.Forms.Panel(); this.panelDataViewLeft = new System.Windows.Forms.Panel(); this.panelGraphView = new ErgometerDoctorApplication.PanelGraphView(); - this.panelClientChat = new ErgometerDoctorApplication.PanelClientChat(); + this.panelClientChat = new ErgometerDoctorApplication.PanelClientChat(Session); this.panelTopBar = new System.Windows.Forms.Panel(); this.labelUsername = new System.Windows.Forms.Label(); this.labelHallo = new System.Windows.Forms.Label(); diff --git a/ErgometerDoctorApplication/SessionWindow.cs b/ErgometerDoctorApplication/SessionWindow.cs index 2f57cb4..917d23f 100644 --- a/ErgometerDoctorApplication/SessionWindow.cs +++ b/ErgometerDoctorApplication/SessionWindow.cs @@ -15,10 +15,13 @@ namespace ErgometerDoctorApplication private bool ActiveSession { get; } private string ClientName { get; set; } - public SessionWindow(string ClientName, bool ActiveSession) + public int Session { get; } + + public SessionWindow(string ClientName, bool ActiveSessionm, int session) { this.ActiveSession = ActiveSession; this.ClientName = ClientName; + Session = session; InitializeComponent(); Form.CheckForIllegalCrossThreadCalls = false;