Login.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. <<<<<<< HEAD
  33. public void setError(string message)
  34. =======
  35. public void setError(String message)
  36. >>>>>>> origin/feature/prepare
  37. {
  38. errorLBL.Text = message;
  39. }
  40. private void SubmitButton_Click(object sender, EventArgs e)
  41. {
  42. if(string.IsNullOrWhiteSpace(UsernameBox.Text))
  43. {
  44. errorLBL.Text = "Username is incorrect";
  45. }
  46. else if (string.IsNullOrWhiteSpace(PasswordBox.Text))
  47. {
  48. errorLBL.Text = "Password is incorrect";
  49. }
  50. else
  51. {
  52. connection.SendLogin(UsernameBox.Text, PasswordBox.Text);
  53. PasswordBox.Text = "";
  54. }
  55. }
  56. private void menuBar_MouseDown(object sender, MouseEventArgs e)
  57. {
  58. if (e.Button == MouseButtons.Left)
  59. {
  60. ReleaseCapture();
  61. SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
  62. }
  63. }
  64. private void exit_Click(object sender, EventArgs e)
  65. {
  66. Application.Exit();
  67. }
  68. private void Login_Load(object sender, EventArgs e)
  69. {
  70. checkConnection();
  71. }
  72. private void checkConnection()
  73. {
  74. if (!connection.isConnectedFlag)
  75. {
  76. connLBL.Text = "No Connection established";
  77. }
  78. else
  79. {
  80. connLBL.Text = "";
  81. }
  82. }
  83. private void reconnectBTN_Click(object sender, EventArgs e)
  84. {
  85. if(!connection.isConnectedFlag)
  86. {
  87. connection.connect();
  88. checkConnection();
  89. this.Refresh();
  90. }
  91. }
  92. }
  93. }