ConClientData.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using ErgometerLibrary;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Security.AccessControl;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace ErgometerDoctorApplication
  12. {
  13. public class ConClientData : Panel
  14. {
  15. public System.Windows.Forms.TextBox textBoxPassword;
  16. public System.Windows.Forms.TextBox textBoxUsername;
  17. public System.Windows.Forms.Button buttonCreate;
  18. public System.Windows.Forms.ListBox listUsers;
  19. public System.Windows.Forms.Label newUsername;
  20. public System.Windows.Forms.Label newPassword;
  21. public ConClientData() : base()
  22. {
  23. this.buttonCreate = new System.Windows.Forms.Button();
  24. this.textBoxPassword = new System.Windows.Forms.TextBox();
  25. this.textBoxUsername = new System.Windows.Forms.TextBox();
  26. this.listUsers = new System.Windows.Forms.ListBox();
  27. this.newUsername = new System.Windows.Forms.Label();
  28. this.newPassword = new System.Windows.Forms.Label();
  29. //
  30. // buttonLogin
  31. //
  32. this.buttonCreate.Anchor = System.Windows.Forms.AnchorStyles.Left;
  33. this.buttonCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  34. this.buttonCreate.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  35. this.buttonCreate.Location = new System.Drawing.Point(20, 215);
  36. this.buttonCreate.Name = "buttonCreate";
  37. this.buttonCreate.Size = new System.Drawing.Size(168, 31);
  38. this.buttonCreate.TabIndex = 3;
  39. this.buttonCreate.Text = "Aanmaken";
  40. this.buttonCreate.BackColor = Color.LightGray;
  41. this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
  42. //
  43. // textBoxPassword
  44. //
  45. this.textBoxPassword.Anchor = System.Windows.Forms.AnchorStyles.Left;
  46. this.textBoxPassword.Location = new System.Drawing.Point(170, 180);
  47. this.textBoxPassword.MaxLength = 16;
  48. this.textBoxPassword.Name = "textBoxPassword";
  49. this.textBoxPassword.Size = new System.Drawing.Size(167, 60);
  50. this.textBoxPassword.TabIndex = 2;
  51. this.textBoxPassword.KeyDown += TextBoxEnterPress;
  52. //
  53. // textBoxUsername
  54. //
  55. this.textBoxUsername.Anchor = System.Windows.Forms.AnchorStyles.Left;
  56. this.textBoxUsername.Location = new System.Drawing.Point(170, 150);
  57. this.textBoxUsername.MaxLength = 16;
  58. this.textBoxUsername.Name = "textBoxUsername";
  59. this.textBoxUsername.Size = new System.Drawing.Size(167, 20);
  60. this.textBoxUsername.TabIndex = 2;
  61. this.textBoxUsername.KeyDown += TextBoxEnterPress;
  62. //
  63. // listUsers
  64. //
  65. this.listUsers.Anchor = System.Windows.Forms.AnchorStyles.Left;
  66. this.listUsers.Location = new System.Drawing.Point(20, -150);
  67. this.listUsers.Name = "listUsers";
  68. this.listUsers.Size = new System.Drawing.Size(200, 280);
  69. this.listUsers.Items.Add("Geen gebruikers");
  70. //
  71. // newPassword
  72. //
  73. this.newPassword.Anchor = System.Windows.Forms.AnchorStyles.Left;
  74. this.newPassword.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  75. this.newPassword.ForeColor = Color.Black;
  76. this.newPassword.Location = new System.Drawing.Point(20, 182);
  77. this.newPassword.Name = "newPassword";
  78. this.newPassword.Size = new System.Drawing.Size(167, 20);
  79. this.newPassword.TabIndex = 3;
  80. this.newPassword.Text = "Nieuw wachtwoord";
  81. //
  82. // newUsername
  83. //
  84. this.newUsername.Anchor = System.Windows.Forms.AnchorStyles.Left;
  85. this.newUsername.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  86. this.newUsername.Location = new System.Drawing.Point(20, 152);
  87. this.newUsername.Name = "newUsername";
  88. this.newUsername.Size = new System.Drawing.Size(167, 20);
  89. this.newUsername.TabIndex = 3;
  90. this.newUsername.Text = "Nieuwe gebruikersnaam";
  91. this.Controls.Add(this.listUsers);
  92. this.Controls.Add(this.buttonCreate);
  93. this.Controls.Add(this.textBoxUsername);
  94. this.Controls.Add(this.textBoxPassword);
  95. this.Controls.Add(this.newUsername);
  96. this.Controls.Add(this.newPassword);
  97. //
  98. // ConClientData
  99. //
  100. this.Dock = System.Windows.Forms.DockStyle.Fill;
  101. this.Location = new System.Drawing.Point(20, 0);
  102. this.Name = "ConClientData";
  103. this.Size = new System.Drawing.Size(584, 459);
  104. this.TabIndex = 0;
  105. this.BackColor = System.Drawing.Color.White;
  106. }
  107. private void TextBoxEnterPress(object sender, KeyEventArgs e)
  108. {
  109. if (e.KeyCode == Keys.Enter)
  110. {
  111. buttonCreate_Click(this, new EventArgs());
  112. }
  113. }
  114. internal void updateUsers(Dictionary<string, string> users)
  115. {
  116. this.listUsers.Items.Clear();
  117. foreach(KeyValuePair<string, string> user in users)
  118. {
  119. this.listUsers.Items.Add(user.Key + ": " + user.Value);
  120. }
  121. }
  122. private void buttonCreate_Click(object sender, EventArgs e)
  123. {
  124. if (!MainClient.users.ContainsKey(textBoxUsername.Text))
  125. {
  126. MainClient.SendNetCommand(new NetCommand(textBoxUsername.Text, textBoxPassword.Text, MainClient.Session));
  127. MainClient.SendNetCommand(new NetCommand(NetCommand.RequestType.USERS, MainClient.Session));
  128. textBoxUsername.Text = "";
  129. Thread.Sleep(250);
  130. updateUsers(MainClient.users);
  131. }
  132. textBoxPassword.Text = "";
  133. }
  134. }
  135. }