ClientApplicatie.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 ClientApplicatie()
  24. {
  25. InitializeComponent();
  26. MainClient.Init(this);
  27. }
  28. private void updateTimer_Tick(object sender, EventArgs e)
  29. {
  30. updateStepsText("Yeah: " + Helper.Now);
  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. panelClientContainer.BringToFront();
  70. chat = panelClientChat;
  71. this.labelUsername.Text = panelLogin.textBoxUsername.Text;
  72. panelTopBar.Visible = true;
  73. updateTimer.Start();
  74. }
  75. else
  76. {
  77. panelLogin.lblVerification.Text = error;
  78. panelLogin.lblVerification.ForeColor = Color.Red;
  79. panelLogin.lblVerification.Visible = true;
  80. }
  81. }
  82. }
  83. else
  84. {
  85. panelLogin.lblVerification.Text = "Vul een gebruikersnaam in.";
  86. panelLogin.lblVerification.ForeColor = Color.Red;
  87. panelLogin.lblVerification.Visible = true;
  88. }
  89. }
  90. public void updateStepsText(string text)
  91. {
  92. steps.setText(text);
  93. }
  94. private void buttonLogOff_Click(object sender, EventArgs e)
  95. {
  96. logout("U bent uitgelogd.", Color.Blue);
  97. }
  98. private void logout(string message, System.Drawing.Color cl)
  99. {
  100. panelLogin.BringToFront();
  101. panelTopBar.Visible = false;
  102. panelLogin.lblVerification.Text = message;
  103. panelLogin.lblVerification.ForeColor = cl;
  104. panelLogin.lblVerification.Visible = true;
  105. panelLogin.textBoxUsername.Text = "";
  106. panelLogin.textBoxPassword.Text = "";
  107. MainClient.Disconnect();
  108. updateTimer.Stop();
  109. }
  110. }
  111. }