ClientApplicatie.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. 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. MainClient.SendNetCommand(new NetCommand(MainClient.Session, text));
  96. Console.Beep(1200, 500);
  97. }
  98. public void CreateNewTest(char geslacht, int leeftijd, int gewicht, int lengte)
  99. {
  100. panelTopBar.Visible = true;
  101. panelClientContainer.BringToFront();
  102. chat = panelClientChat;
  103. MainClient.ComPort.Write("RS");
  104. MainClient.ComPort.Read();
  105. Thread.Sleep(200);
  106. MainClient.ComPort.Write("CM");
  107. MainClient.ComPort.Read();
  108. ergotest = new ErgometerTest(gewicht, lengte, leeftijd, geslacht, this);
  109. updateTimer.Start();
  110. }
  111. private void buttonLogOff_Click(object sender, EventArgs e)
  112. {
  113. logout("U bent uitgelogd.", Color.Blue);
  114. }
  115. private void logout(string message, System.Drawing.Color cl)
  116. {
  117. panelLogin.BringToFront();
  118. panelTopBar.Visible = false;
  119. panelLogin.lblVerification.Text = message;
  120. panelLogin.lblVerification.ForeColor = cl;
  121. panelLogin.lblVerification.Visible = true;
  122. panelLogin.textBoxUsername.Text = "";
  123. panelLogin.textBoxPassword.Text = "";
  124. MainClient.Disconnect();
  125. updateTimer.Stop();
  126. }
  127. }
  128. }