Login.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace FietsClient
  12. {
  13. public partial class Login : Form
  14. {
  15. private TcpConnection connection;
  16. public const int WM_NCLBUTTONDOWN = 0xA1;
  17. public const int HTCAPTION = 0x2;
  18. [DllImport("User32.dll")]
  19. public static extern bool ReleaseCapture();
  20. [DllImport("User32.dll")]
  21. public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
  22. public Login(TcpConnection conn)
  23. {
  24. connection = conn;
  25. InitializeComponent();
  26. }
  27. public Login(String message)
  28. {
  29. InitializeComponent();
  30. errorLBL.Text = message;
  31. }
  32. public void setError(String message)
  33. {
  34. errorLBL.Text = message;
  35. }
  36. private void SubmitButton_Click(object sender, EventArgs e)
  37. {
  38. if(string.IsNullOrWhiteSpace(UsernameBox.Text))
  39. {
  40. errorLBL.Text = "Username is incorrect";
  41. }
  42. else if (string.IsNullOrWhiteSpace(PasswordBox.Text))
  43. {
  44. errorLBL.Text = "Password is incorrect";
  45. }
  46. else
  47. {
  48. connection.sendLogin(UsernameBox.Text, PasswordBox.Text);
  49. PasswordBox.Text = "";
  50. this.Dispose();
  51. }
  52. }
  53. private void menuBar_MouseDown(object sender, MouseEventArgs e)
  54. {
  55. if (e.Button == MouseButtons.Left)
  56. {
  57. ReleaseCapture();
  58. SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
  59. }
  60. }
  61. private void exit_Click(object sender, EventArgs e)
  62. {
  63. Application.Exit();
  64. }
  65. private void Login_Load(object sender, EventArgs e)
  66. {
  67. checkConnection();
  68. }
  69. private void checkConnection()
  70. {
  71. if (!connection.isConnected())
  72. {
  73. connLBL.Text = "No Connection established";
  74. }
  75. else
  76. {
  77. connLBL.Text = "";
  78. }
  79. }
  80. private void reconnectBTN_Click(object sender, EventArgs e)
  81. {
  82. if(!connection.isConnected())
  83. {
  84. connection.connect();
  85. checkConnection();
  86. this.Refresh();
  87. }
  88. }
  89. }
  90. }