ClientApplicatie.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 updateBeep(object sender, EventArgs e)
  30. {
  31. MainClient.RPMBeatAudio();
  32. }
  33. private void updateTimer_Tick(object sender, EventArgs e)
  34. {
  35. if (MainClient.Doctor.Connected)
  36. {
  37. MainClient.ComPort.Write("ST");
  38. string response = MainClient.ComPort.Read();
  39. if (response != "err")
  40. {
  41. Meting m = MainClient.SaveMeting(response);
  42. heartBeat.updateValue(m.HeartBeat);
  43. RPM.updateValue(m.RPM);
  44. speed.updateValue(m.Speed);
  45. distance.updateValue(m.Distance);
  46. power.updateValue(m.Power);
  47. energy.updateValue(m.Energy);
  48. actualpower.updateValue(m.ActualPower);
  49. time.updateValue(m.Seconds);
  50. ergotest.timerTick();
  51. }
  52. else
  53. {
  54. logout("De Ergometer is niet meer verbonden.", Color.Red);
  55. }
  56. }
  57. }
  58. public void validateLogin(string username, string password)
  59. {
  60. if (username.Length > 0)
  61. {
  62. if (password.Length == 0)
  63. {
  64. panelLogin.lblVerification.Text = "Vul een wachtwoord in.";
  65. panelLogin.lblVerification.ForeColor = Color.Red;
  66. panelLogin.lblVerification.Visible = true;
  67. }
  68. if (password.Length > 0)
  69. {
  70. string error = "";
  71. bool connect = MainClient.Connect(SerialPort.GetPortNames()[0], username, password, out error);
  72. if (connect)
  73. {
  74. panelGatherInfo.BringToFront();
  75. this.labelUsername.Text = panelLogin.textBoxUsername.Text;
  76. }
  77. else
  78. {
  79. panelLogin.lblVerification.Text = error;
  80. panelLogin.lblVerification.ForeColor = Color.Red;
  81. panelLogin.lblVerification.Visible = true;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. panelLogin.lblVerification.Text = "Vul een gebruikersnaam in.";
  88. panelLogin.lblVerification.ForeColor = Color.Red;
  89. panelLogin.lblVerification.Visible = true;
  90. }
  91. }
  92. public void updateStepsText(string text)
  93. {
  94. steps.setText(text);
  95. }
  96. public void CreateNewTest(char geslacht, int leeftijd, int gewicht, int lengte)
  97. {
  98. panelTopBar.Visible = true;
  99. panelClientContainer.BringToFront();
  100. chat = panelClientChat;
  101. MainClient.ComPort.Write("RS");
  102. MainClient.ComPort.Read();
  103. Thread.Sleep(200);
  104. MainClient.ComPort.Write("CM");
  105. MainClient.ComPort.Read();
  106. ergotest = new ErgometerTest(gewicht, lengte, leeftijd, geslacht, this);
  107. updateTimer.Start();
  108. beeptimer.Start();
  109. }
  110. private void buttonLogOff_Click(object sender, EventArgs e)
  111. {
  112. logout("U bent uitgelogd.", Color.Blue);
  113. }
  114. private void logout(string message, System.Drawing.Color cl)
  115. {
  116. panelLogin.BringToFront();
  117. panelTopBar.Visible = false;
  118. panelLogin.lblVerification.Text = message;
  119. panelLogin.lblVerification.ForeColor = cl;
  120. panelLogin.lblVerification.Visible = true;
  121. panelLogin.textBoxUsername.Text = "";
  122. panelLogin.textBoxPassword.Text = "";
  123. MainClient.Disconnect();
  124. updateTimer.Stop();
  125. }
  126. }
  127. }