ClientApplicatie.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. Console.Beep(1000,5);
  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. power.updateValue(m.Power);
  45. actualpower.updateValue(m.ActualPower);
  46. time.updateValue(m.Seconds);
  47. if(ergotest != null)
  48. ergotest.timerTick();
  49. }
  50. else
  51. {
  52. logout("De Ergometer is niet meer verbonden.", Color.Red);
  53. }
  54. }
  55. }
  56. public void validateLogin(string username, string password)
  57. {
  58. if (username.Length > 0)
  59. {
  60. if (password.Length == 0)
  61. {
  62. panelLogin.lblVerification.Text = "Vul een wachtwoord in.";
  63. panelLogin.lblVerification.ForeColor = Color.Red;
  64. panelLogin.lblVerification.Visible = true;
  65. }
  66. if (password.Length > 0)
  67. {
  68. if (SerialPort.GetPortNames().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. panelTopBar.Visible = true;
  76. this.labelUsername.Text = panelLogin.textBoxUsername.Text;
  77. }
  78. else
  79. {
  80. panelLogin.lblVerification.Text = error;
  81. panelLogin.lblVerification.ForeColor = Color.Red;
  82. panelLogin.lblVerification.Visible = true;
  83. }
  84. }
  85. else
  86. {
  87. panelLogin.lblVerification.Text = "De Ergometer is niet verbonden.";
  88. panelLogin.lblVerification.ForeColor = Color.Red;
  89. panelLogin.lblVerification.Visible = true;
  90. }
  91. }
  92. }
  93. else
  94. {
  95. panelLogin.lblVerification.Text = "Vul een gebruikersnaam in.";
  96. panelLogin.lblVerification.ForeColor = Color.Red;
  97. panelLogin.lblVerification.Visible = true;
  98. }
  99. }
  100. public void updateStepsText(string text)
  101. {
  102. steps.setText(text);
  103. MainClient.SendNetCommand(new NetCommand(MainClient.Session, text));
  104. }
  105. public void CreateNewTest(char geslacht, int leeftijd, int gewicht, int lengte)
  106. {
  107. panelTopBar.Visible = true;
  108. panelClientContainer.BringToFront();
  109. chat = panelClientChat;
  110. MainClient.SendNetCommand(new NetCommand(gewicht, lengte, leeftijd, geslacht, MainClient.Session));
  111. MainClient.ComPort.Write("RS");
  112. MainClient.ComPort.Read();
  113. Thread.Sleep(200);
  114. MainClient.ComPort.Write("CM");
  115. MainClient.ComPort.Read();
  116. ergotest = new ErgometerTest(gewicht, lengte, leeftijd, geslacht, this);
  117. updateTimer.Start();
  118. beeptimer.Start();
  119. }
  120. private void buttonLogOff_Click(object sender, EventArgs e)
  121. {
  122. logout("U bent uitgelogd.", Color.Blue);
  123. }
  124. private void logout(string message, System.Drawing.Color cl)
  125. {
  126. MainClient.Disconnect();
  127. updateTimer.Stop();
  128. beeptimer.Stop();
  129. ergotest = null;
  130. panelTopBar.Visible = false;
  131. panelLogin.lblVerification.Text = message;
  132. panelLogin.lblVerification.ForeColor = cl;
  133. panelLogin.lblVerification.Visible = true;
  134. panelLogin.textBoxUsername.Text = "";
  135. panelLogin.textBoxPassword.Text = "";
  136. panelLogin.BringToFront();
  137. }
  138. }
  139. }