Exemple #1
0
        /// <summary>
        /// Excute user login  validation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginButton_Click(object sender, EventArgs e)
        {
            User user = new User()
            {
                UserName = UserNameTextBox.Text.Trim(),
                Password = PasswordTextBox.Text.Trim()
            };
            Response response = new Response();

            if (string.IsNullOrEmpty(UserNameTextBox.Text.Trim()))
            {
                UserNameTextBox.Focus();
                UserNameErrorProvider.SetError(UserNameTextBox, "UserName can't be vacant!");
            }
            else
            {
                UserNameErrorProvider.SetError(UserNameTextBox, "");
                if (string.IsNullOrEmpty(PasswordTextBox.Text.Trim()))
                {
                    PasswordTextBox.Focus();
                    PasswordErrorProvider.SetError(PasswordTextBox, "Password can't be vacant!");
                }
                else
                {
                    PasswordErrorProvider.SetError(PasswordTextBox, "");
                    if (string.IsNullOrEmpty(IdentifyingCodeTextBox.Text.Trim()))
                    {
                        IdentifyingCodeTextBox.Focus();
                        IdentifyingCodeErrorProvider.SetError(IdentifyingCodeTextBox, "IdentifyingCode can't be vacant!");
                    }
                    else
                    {
                        try
                        {
                            response = new UserService().Authentication(user);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        if (string.IsNullOrEmpty(response.Message))
                        {
                            if (IdentifyingCodeTextBox.Text.Trim() == identifyingCode || IdentifyingCodeTextBox.Text.Trim().ToLowerInvariant() == identifyingCode.ToLowerInvariant() || IdentifyingCodeTextBox.Text.Trim().ToUpperInvariant() == identifyingCode.ToUpperInvariant())
                            {
                                Form f = Application.OpenForms["StaffList"];
                                if (f == null)
                                {
                                    f = new StaffList();
                                    f.Show();
                                    this.Hide();
                                }
                                else
                                {
                                    f.Show();
                                    this.Hide();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Identifying code do not match!", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show(response.Message, "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearInformation();
                            Bind();
                        }
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Clear all the textbox content
 /// </summary>
 public void ClearInformation()
 {
     UserNameTextBox.Clear();
     PasswordTextBox.Clear();
     IdentifyingCodeTextBox.Clear();
 }