Exemple #1
0
 private void EventListener(object sender, EventArgs ee)
 {
     if (sender == this.bindButton)
     {
         string errorMessage = "";
         bool   allOk        = true;
         if (macAddressBox.Text == null || macAddressBox.Text.Length == 0)
         {
             errorMessage += "Invalid MAC Address Input!";
             allOk         = false;
         }
         if (usernameTextBox.Text == null || usernameTextBox.Text.Length == 0)
         {
             if (errorMessage.Length > 0)
             {
                 errorMessage += "\r\n";
             }
             errorMessage += "Username is empty!";
             allOk         = false;
         }
         if (passwordTextBox.Text == null || passwordTextBox.Text.Length == 0)
         {
             if (errorMessage.Length > 0)
             {
                 errorMessage += "\r\n";
             }
             errorMessage += "Password is empty!";
             allOk         = false;
         }
         if (allOk)
         {
             VisualizingTools.ShowWaitingAnimation(new Point(this.bindButton.Left, this.bindButton.Bottom + 20), new Size(this.bindButton.Width, this.bindButton.Height / 2), this);
             BackgroundWorker loaderWorker = new BackgroundWorker();
             loaderWorker.DoWork += (s, e) =>
             {
                 try
                 {
                     bool?success = ServerRequest.BindDeviceAndLogin(macAddressBox.Text, usernameTextBox.Text, passwordTextBox.Text);
                     if (success == true)
                     {
                         if (this.loginCheckbox.Checked)
                         {
                             BackendManager.SaveLoginCookie();
                         }
                         BackendManager.LoginNow(User.LoggedIn);
                         this.Invoke(new Action(() =>
                         {
                             VisualizingTools.HideWaitingAnimation();
                             this.Visible        = false;
                             this.parent.Visible = false;
                             this.parent.Dispose();
                             this.Dispose();
                         }
                                                ));
                     }
                     else if (success == false)
                     {
                         errorMessage = "Invalid username or password!";
                         this.Invoke(new Action(() =>
                         {
                             ShowErrorMessage(errorMessage);
                         }
                                                ));
                     }
                     else
                     {
                         errorMessage = "Server connection failed!";
                         this.Invoke(new Action(() =>
                         {
                             ShowErrorMessage(errorMessage);
                         }
                                                ));
                     }
                 }
                 catch { }
             };
             loaderWorker.RunWorkerAsync();
             loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); };
         }
         else
         {
             ShowErrorMessage(errorMessage);
         }
     }
     else if (sender == this.backButton)
     {
         this.parent.Visible = true;
         this.Dispose();
     }
 }