Exemplo n.º 1
0
 public static bool TryLogin(string applicationName, string organizationCode, string userName, string password)
 {
     try {
         using (DataTable employeeTable = new DataTable("Employee")) {
             using (SqlConnection connection = new SqlConnection(RxlConfiguration.GetCurrent().GetConnectionString(applicationName))) {
                 using (SqlCommand command = new SqlCommand(Resources.GetEmployeeByLoginCommandText, connection)) {
                     command.CommandTimeout = 0;
                     command.Parameters.AddWithValue("@OrganizationCode", organizationCode);
                     command.Parameters.AddWithValue("@UserName", userName);
                     command.Parameters.AddWithValue("@Password", Convert.ToBase64String(Encoding.ASCII.GetBytes(password)));
                     connection.Open();
                     using (SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.CloseConnection)) {
                         employeeTable.Load(dataReader);
                     }
                 }
             }
             DataRow row = employeeTable.Rows[0];
             _LoginInfo = new LoginInfoArgs(
                 row.Field <int>("LevelNumber"), row.Field <string>("OrganizationCode"),
                 row.Field <string>("OrganizationName"), row.Field <string>("EmployeeCode"),
                 row.Field <string>("EmployeeName"), row.Field <string>("LoginName")
                 );
             return(true);
         }
     } catch {
         return(false);
     }
 }
Exemplo n.º 2
0
 private static void _LoginForm_LoginSucceeded(object sender, LoginInfoArgs e)
 {
     try {
         _LoginInfo = e;
     } catch {
         throw;
     }
 }
Exemplo n.º 3
0
 protected void OnLoginSucceeded(LoginInfoArgs e)
 {
     try {
         if (LoginSucceeded != null)
         {
             LoginSucceeded(this, e);
         }
     } catch {
         throw;
     }
 }
Exemplo n.º 4
0
        private void Login()
        {
            try {
                if (!IsValidated())
                {
                    return;
                }
                int result = 0;
                using (SqlConnection connection = new SqlConnection(RxlConfiguration.GetCurrent().GetConnectionString(_ApplicationName))) {
                    string commandText = string.Empty;
                    switch (_LoginType)
                    {
                    case LoginType.SelectableLogin:
                    case LoginType.LockedLogin:
                        commandText = Resources.GetEmployeeByLoginCommandText;
                        break;

                    case LoginType.AdminLogin:
                        commandText = Resources.AdminLoginCommandText;
                        break;

                    default:
                        break;
                    }
                    using (SqlCommand command = new SqlCommand(commandText, connection)) {
                        command.CommandTimeout = 0;
                        if ((_LoginType == LoginType.SelectableLogin) || (_LoginType == LoginType.LockedLogin))
                        {
                            command.Parameters.AddWithValue("@OrganizationCode", Convert.ToString(OrganizationComboBox.SelectedValue));
                        }
                        command.Parameters.AddRange(
                            new SqlParameter[] {
                            new SqlParameter("@UserName", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, UserNameTextBox.Text),
                            new SqlParameter("@Password", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, Convert.ToBase64String(Encoding.ASCII.GetBytes(PasswordTextBox.Text))),
                        }
                            );
                        connection.Open();
                        try {
                            if (_LoginType == LoginType.AdminLogin)
                            {
                                result = (int)command.ExecuteScalar();
                            }
                            else
                            {
                                using (DataTable table = new DataTable("Employee")) {
                                    using (SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.KeyInfo | CommandBehavior.SingleRow)) {
                                        table.Load(dataReader);
                                    }
                                    result = table.Rows.Count;
                                    foreach (DataRow row in table.Rows)
                                    {
                                        _LoginInfoArgs = new LoginInfoArgs(row.Field <int>("LevelNumber"), row.Field <string>("OrganizationCode"), row.Field <string>("OrganizationName"), row.Field <string>("EmployeeCode"), row.Field <string>("EmployeeName"), row.Field <string>("LoginName"));
                                    }
                                }
                            }
                        } catch { }
                    }
                }
                if (result <= 0)
                {
                    string errorMessage = string.Empty;
                    if (_LoginType == LoginType.AdminLogin)
                    {
                        errorMessage = "You are not authorized to use this tool, only Administrator allowed to use this tool.";
                    }
                    else
                    {
                        errorMessage = "Wrong User Name or Password.";
                    }
                    MessageBox.Show(this, errorMessage, _ApplicationName.Length > 0 ? _ApplicationName : DefaultApplicationInfo.FullApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    LoginButton.Focus();
                    return;
                }
                if (_LoginType == LoginType.AdminLogin)
                {
                    OnLoginSucceeded(LoginInfoArgs.Empty);
                }
                else
                {
                    OnLoginSucceeded(_LoginInfoArgs);
                }
                Close(true);
            } catch {
                throw;
            }
        }