diff --git a/ErgometerDoctorApplication/ChatItem.cs b/ErgometerDoctorApplication/ChatItem.cs deleted file mode 100644 index 3772eb7..0000000 --- a/ErgometerDoctorApplication/ChatItem.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ErgometerDoctorApplication -{ - public class ChatItem : Panel - { - private Label messageLabel, timeLabel; - - public ChatItem(string message, string time, bool isDoctor) : base() - { - this.messageLabel = new Label(); - this.timeLabel = new Label(); - - this.AutoSize = true; - this.setAppearance(isDoctor); - this.Controls.Add(this.messageLabel); - this.Controls.Add(this.timeLabel); - this.MinimumSize = new System.Drawing.Size(150, 60); - this.Name = "messageContainer"; - this.Padding = new System.Windows.Forms.Padding(6); - - // - // Message Label - // - this.messageLabel.AutoSize = true; - 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(250, 0); - this.messageLabel.Size = new System.Drawing.Size(121, 20); - this.messageLabel.Text = message; - // - // Time Label - // - this.timeLabel.AutoSize = true; - this.timeLabel.Dock = System.Windows.Forms.DockStyle.Bottom; - this.timeLabel.Font = new System.Drawing.Font("Segoe UI Semilight", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.timeLabel.Location = new System.Drawing.Point(6, 26); - this.timeLabel.Margin = new System.Windows.Forms.Padding(6); - this.timeLabel.Size = new System.Drawing.Size(32, 13); - this.timeLabel.Text = "Time:" + time; - } - - private void setAppearance(bool isDoctor) - { - if (isDoctor) - { - this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); - this.Dock = DockStyle.Right; - } - else - { - this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); - this.Dock = DockStyle.Left; - } - } - } -} diff --git a/ErgometerDoctorApplication/ClientThread.cs b/ErgometerDoctorApplication/ClientThread.cs index cb5148c..7cac651 100644 --- a/ErgometerDoctorApplication/ClientThread.cs +++ b/ErgometerDoctorApplication/ClientThread.cs @@ -43,8 +43,9 @@ namespace ErgometerDoctorApplication SaveMeting(command.Meting); break; case NetCommand.CommandType.CHAT: - Chat.Add(new ChatMessage(Name, command.ChatMessage, false)); - window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { command.ChatMessage, Helper.MillisecondsToTime(command.Timestamp), false }); + ChatMessage chat = new ChatMessage(command.DisplayName, command.ChatMessage, false); + Chat.Add(chat); + window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { chat }); break; } } diff --git a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj index a5ca7c6..ca7f403 100644 --- a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj +++ b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj @@ -55,9 +55,6 @@ Component - - Component - Component diff --git a/ErgometerDoctorApplication/MainClient.cs b/ErgometerDoctorApplication/MainClient.cs index c6b3da7..1b34877 100644 --- a/ErgometerDoctorApplication/MainClient.cs +++ b/ErgometerDoctorApplication/MainClient.cs @@ -51,11 +51,21 @@ namespace ErgometerDoctorApplication activesessions = new Dictionary(); } - public static bool Connect(string password) + public static bool Connect(string password, out string error) { + error = "Succes"; + if (!Server.Connected) { - Server.Connect(HOST, PORT); + try + { + Server.Connect(HOST, PORT); + } + catch(Exception e) + { + error = "Server is niet online."; + return false; + } NetCommand net = NetHelper.ReadNetCommand(Server); if (net.Type == NetCommand.CommandType.SESSION) @@ -64,6 +74,7 @@ namespace ErgometerDoctorApplication throw new Exception("Session not assigned"); running = true; + t.IsBackground = true; t.Start(); } @@ -76,6 +87,7 @@ namespace ErgometerDoctorApplication if (response.Type == NetCommand.CommandType.RESPONSE && response.Response == NetCommand.ResponseType.LOGINWRONG) { loggedin = false; + error = "Het wachtwoord is onjuist."; return false; } @@ -196,6 +208,7 @@ namespace ErgometerDoctorApplication //Run client on new thread Thread thread = new Thread(new ThreadStart(cl.run)); + thread.IsBackground = true; thread.Start(); } } diff --git a/ErgometerDoctorApplication/MainWindow.Designer.cs b/ErgometerDoctorApplication/MainWindow.Designer.cs index aaf30f8..3dfe380 100644 --- a/ErgometerDoctorApplication/MainWindow.Designer.cs +++ b/ErgometerDoctorApplication/MainWindow.Designer.cs @@ -273,7 +273,8 @@ namespace ErgometerDoctorApplication // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(784, 561); + this.ClientSize = new System.Drawing.Size(700, 500); + this.MinimumSize = new System.Drawing.Size(550, 450); this.Controls.Add(this.MainContainer); this.Controls.Add(this.panel1); this.Controls.Add(this.MenuPanel); diff --git a/ErgometerDoctorApplication/MainWindow.cs b/ErgometerDoctorApplication/MainWindow.cs index 129bb8a..c037572 100644 --- a/ErgometerDoctorApplication/MainWindow.cs +++ b/ErgometerDoctorApplication/MainWindow.cs @@ -54,7 +54,10 @@ namespace ErgometerDoctorApplication } public void validateLogin() { - if (MainClient.Connect(conPanelLogin.textBoxPassword.Text)) + string error = ""; + bool connect = MainClient.Connect(conPanelLogin.textBoxPassword.Text, out error); + + if (connect) { conPanelLogin.textBoxPassword.Text = ""; conPanelLogin.labelLoginInfo.Text = ""; @@ -62,7 +65,7 @@ namespace ErgometerDoctorApplication } else { - conPanelLogin.labelLoginInfo.Text = "Password incorrect"; + conPanelLogin.labelLoginInfo.Text = error; showLoginScreen(); } } diff --git a/ErgometerDoctorApplication/PanelClientChat.cs b/ErgometerDoctorApplication/PanelClientChat.cs index 288ddc2..ec0f685 100644 --- a/ErgometerDoctorApplication/PanelClientChat.cs +++ b/ErgometerDoctorApplication/PanelClientChat.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ErgometerLibrary; +using ErgometerLibrary.Chat; namespace ErgometerDoctorApplication { @@ -21,9 +22,10 @@ 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(int session) : base() + private int Session { get; } + + public PanelClientChat(int session, string name) : base() { this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.panel2 = new System.Windows.Forms.Panel(); @@ -33,7 +35,8 @@ 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; + + Session = session; this.panel3 = new System.Windows.Forms.Panel(); // @@ -68,7 +71,7 @@ namespace ErgometerDoctorApplication this.connectionLabel.Name = "connectionLabel"; this.connectionLabel.Size = new System.Drawing.Size(112, 13); this.connectionLabel.TabIndex = 0; - this.connectionLabel.Text = "Now connected with:"; + this.connectionLabel.Text = "Now connected with: " + name; // // label2 // @@ -102,7 +105,7 @@ namespace ErgometerDoctorApplication this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(85, 90); this.button1.TabIndex = 1; - this.button1.Text = "Verstuur"; + this.button1.Text = "Send"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // @@ -149,25 +152,15 @@ namespace ErgometerDoctorApplication { if (richTextBox1.TextLength > 1) { - AddChatItem(richTextBox1.Text, Helper.MillisecondsToTime(Helper.Now), true); - MainClient.SendNetCommand(new NetCommand(richTextBox1.Text, session)); + AddChatItem(new ChatMessage("Doctor", richTextBox1.Text, true)); + MainClient.SendNetCommand(new NetCommand(richTextBox1.Text, Session)); richTextBox1.ResetText(); } } - public void AddChatItem(string text) + public void AddChatItem(ChatMessage chat) { - flowLayoutPanel1.Controls.Add(new ChatItem(text, Helper.MillisecondsToTime(Helper.Now), false)); - } - - public void AddChatItem(string text, bool isDoctor) - { - flowLayoutPanel1.Controls.Add(new ChatItem(text, Helper.MillisecondsToTime(Helper.Now), isDoctor)); - } - - public void AddChatItem(string text, string time, bool isDoctor) - { - flowLayoutPanel1.Controls.Add(new ChatItem(text, time, isDoctor)); + flowLayoutPanel1.Controls.Add(new ChatItem(chat)); } private void panel3_MouseWheel(object sender, MouseEventArgs e) @@ -203,10 +196,11 @@ namespace ErgometerDoctorApplication if (e.KeyCode == Keys.Enter) { button1_Click(this, new EventArgs()); + e.Handled = true; } } - public delegate void ChatDelegate(string message, string time, bool isDoctor); + public delegate void ChatDelegate(ChatMessage chat); public ChatDelegate passChatMessage; } } diff --git a/ErgometerDoctorApplication/SessionWindow.Designer.cs b/ErgometerDoctorApplication/SessionWindow.Designer.cs index be7d12d..24557cf 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(Session); + this.panelClientChat = new ErgometerDoctorApplication.PanelClientChat(Session, ClientName); this.panelTopBar = new System.Windows.Forms.Panel(); this.labelUsername = new System.Windows.Forms.Label(); this.labelHallo = new System.Windows.Forms.Label(); @@ -133,6 +133,7 @@ namespace ErgometerDoctorApplication this.Controls.Add(this.panelTopBar); this.Controls.Add(this.panelClientContainer); this.Name = "SessionWindow"; + this.Text = "Sessie: " + ClientName; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Resize += new System.EventHandler(this.ClientApplicatie_Resize); this.panelClientContainer.ResumeLayout(false);