Login.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 connection)
  23. {
  24. this.connection = connection;
  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. }
  51. }
  52. private void menuBar_MouseDown(object sender, MouseEventArgs e)
  53. {
  54. if (e.Button == MouseButtons.Left)
  55. {
  56. ReleaseCapture();
  57. SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
  58. }
  59. }
  60. private void exit_Click(object sender, EventArgs e)
  61. {
  62. Application.Exit();
  63. }
  64. private void Login_Load(object sender, EventArgs e)
  65. {
  66. checkConnection();
  67. }
  68. private void checkConnection()
  69. {
  70. if (!connection.isConnectedFlag)
  71. {
  72. connLBL.Text = "No Connection established";
  73. }
  74. else
  75. {
  76. connLBL.Text = "";
  77. }
  78. }
  79. private void reconnectBTN_Click(object sender, EventArgs e)
  80. {
  81. if(!connection.isConnectedFlag)
  82. {
  83. connection.connect();
  84. checkConnection();
  85. this.Refresh();
  86. }
  87. }
  88. }
  89. }