Beispiel #1
0
        private void Login()
        {
            if (txtUsername.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Username is required", "Message");
            }
            else if (txtPassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Password is required", "Message");
            }
            else
            {
                CheckLoginDto checkedLogin = new CheckLoginDto();
                DALCheckedLogin checkedLoginAPI = new DALCheckedLogin();
                checkedLogin = checkedLoginAPI.CheckedLogin(txtUsername.Text.Trim(), txtPassword.Text.Trim());
                if (!checkedLogin.IsSuccess)
                {
                    MessageBox.Show(checkedLogin.Message, "Message");
                    return;
                }
                this.Hide();
                CRMain frm = new CRMain();
                frm.Show();
                //frm.ShowDialog();

            }
        }
 public CheckLoginDto CheckedLogin(string username, string password)
 {
     CheckLoginDto checkedLogin = new CheckLoginDto();
     try
     {
         var objAdmin = contextDB.Users.First(attr => attr.UserName == username && attr.Password == password);
         checkedLogin.IsSuccess = true;
         checkedLogin.Permission = 1;
         checkedLogin.UserId = objAdmin.UserId;
         checkedLogin.Username = objAdmin.UserName;
         checkedLogin.Message = "Login is successful";
         return checkedLogin;
     }
     catch (Exception exx)
     {
         checkedLogin.IsSuccess = false;
         checkedLogin.Message = "Username or Password is incorrect";
         return checkedLogin;
     }
 }