Example #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);
     }
 }
Example #2
0
 private void AfterRefreshOrganization(bool showDropDown)
 {
     try {
         MainPanel.Enabled = true;
         OrganizationComboBox.DataSource    = new BindingSource(_OrganizationDataSource, null);
         OrganizationComboBox.ValueMember   = "Key";
         OrganizationComboBox.DisplayMember = "Value";
         OrganizationComboBox.SelectedValue = RxlConfiguration.GetCurrent().OrganizationCode;
         OrganizationComboBox.Focus();
         OrganizationComboBox.DroppedDown = showDropDown;
     } catch {
         throw;
     }
 }
Example #3
0
 private void RefreshOrganization()
 {
     try {
         using (DataTable table = new DataTable("Organization")) {
             using (SqlConnection connection = new SqlConnection(RxlConfiguration.GetCurrent().GetConnectionString(null))) {
                 using (SqlCommand command = new SqlCommand(Resources.GetOrganizationCommandText, connection)) {
                     command.CommandTimeout = 0;
                     connection.Open();
                     using (SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.KeyInfo)) {
                         table.Load(dataReader);
                     }
                 }
             }
             _OrganizationDataSource.Clear();
             foreach (DataRow row in table.Rows)
             {
                 _OrganizationDataSource.Add(new KeyValuePair <string, string>(row.Field <string>("OrganizationCode"), row.Field <string>("OrganizationName")));
             }
         }
     } catch {
         throw;
     }
 }
Example #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;
            }
        }