Exemple #1
0
 private void buttonLogin_Click_1(object sender, EventArgs e)
 {
     if (ValidateUsername() && ValidatePassword())
     {
         string username = textBoxUsername.Text.Trim();
         string password = DataHelper.EncryptString(textBoxPassword.Text);
         Task <HttpResponseMessage> taskResponse = HttpClientHelper.WebApiClient
                                                   .PostAsync(ApiUrlConstants.LoginBaseUrl + $"?Username={username}&password={password}", null);
         HttpResponseMessage response = taskResponse.GetAwaiter().GetResult();
         if (response.IsSuccessStatusCode)
         {
             GlobalInfo.CurrentUser = new UserInfo("", textBoxUsername.Text);
             HomeMdiContainer home = new HomeMdiContainer();
             home.Show();
             _mdiParent.Hide();
             MessageBox.Show("You have successfully Logged in.", "Login Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
             ClearForm();
             ClearFormError();
         }
         else
         {
             MessageBox.Show("Login Failed, Please try again." + "\n" + "Error Code" + response.StatusCode
                             , "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Form Is Invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }