ClientApplicatie.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO.Ports;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using Newtonsoft.Json;
  13. using System.IO;
  14. using System.Net.Sockets;
  15. using System.Net;
  16. using System.Timers;
  17. using ErgometerLibrary;
  18. namespace ErgometerApplication
  19. {
  20. public partial class ClientApplicatie : Form
  21. {
  22. public PanelClientChat chat;
  23. public ErgometerTest ergotest;
  24. public ClientApplicatie()
  25. {
  26. InitializeComponent();
  27. MainClient.Init(this);
  28. }
  29. private void updateTimer_Tick(object sender, EventArgs e)
  30. {
  31. if(MainClient.Doctor.Connected)
  32. {
  33. MainClient.ComPort.Write("ST");
  34. string response = MainClient.ComPort.Read();
  35. if (response != "err")
  36. {
  37. Meting m = MainClient.SaveMeting(response);
  38. heartBeat.updateValue(m.HeartBeat);
  39. RPM.updateValue(m.RPM);
  40. speed.updateValue(m.Speed);
  41. distance.updateValue(m.Distance);
  42. power.updateValue(m.Power);
  43. energy.updateValue(m.Energy);
  44. actualpower.updateValue(m.ActualPower);
  45. time.updateValue(m.Seconds);
  46. }
  47. else
  48. {
  49. logout("De Ergometer is niet meer verbonden.", Color.Red);
  50. }
  51. }
  52. }
  53. public void validateLogin(string username, string password)
  54. {
  55. if (username.Length > 0)
  56. {
  57. if (password.Length == 0)
  58. {
  59. panelLogin.lblVerification.Text = "Vul een wachtwoord in.";
  60. panelLogin.lblVerification.ForeColor = Color.Red;
  61. panelLogin.lblVerification.Visible = true;
  62. }
  63. if (password.Length > 0)
  64. {
  65. string error = "";
  66. bool connect = MainClient.Connect(SerialPort.GetPortNames()[0], username, password, out error);
  67. if (connect)
  68. {
  69. panelGatherInfo.BringToFront();
  70. this.labelUsername.Text = panelLogin.textBoxUsername.Text;
  71. }
  72. else
  73. {
  74. panelLogin.lblVerification.Text = error;
  75. panelLogin.lblVerification.ForeColor = Color.Red;
  76. panelLogin.lblVerification.Visible = true;
  77. }
  78. }
  79. }
  80. else
  81. {
  82. panelLogin.lblVerification.Text = "Vul een gebruikersnaam in.";
  83. panelLogin.lblVerification.ForeColor = Color.Red;
  84. panelLogin.lblVerification.Visible = true;
  85. }
  86. }
  87. public void updateStepsText(string text)
  88. {
  89. steps.setText(text);
  90. }
  91. internal void CreateNewTest(char geslacht, int leeftijd, int gewicht, int lengte)
  92. {
  93. panelTopBar.Visible = true;
  94. panelClientContainer.BringToFront();
  95. chat = panelClientChat;
  96. updateTimer.Start();
  97. ergotest = new ErgometerTest()
  98. }
  99. private void buttonLogOff_Click(object sender, EventArgs e)
  100. {
  101. logout("U bent uitgelogd.", Color.Blue);
  102. }
  103. private void logout(string message, System.Drawing.Color cl)
  104. {
  105. panelLogin.BringToFront();
  106. panelTopBar.Visible = false;
  107. panelLogin.lblVerification.Text = message;
  108. panelLogin.lblVerification.ForeColor = cl;
  109. panelLogin.lblVerification.Visible = true;
  110. panelLogin.textBoxUsername.Text = "";
  111. panelLogin.textBoxPassword.Text = "";
  112. MainClient.Disconnect();
  113. updateTimer.Stop();
  114. }
  115. }
  116. }