/// <summary>
        /// Assigns the properties of aSource to this instance.
        /// </summary>
        /// <param name="aSource">A source object.</param>
        public override void AssignFromSource(object aSource)
        {
            if (!(aSource is UserFunctionAccessCollection))
            {
                throw new ArgumentException("Invalid Source Argument to UserFunctionAccessCollection Assign");
            }

            base.AssignFromSource(aSource);
            _functionAccessList.Clear();
            (aSource as UserFunctionAccessCollection)._functionAccessList.ForEach(vFunctionAccessSource =>
            {
                var vFunctionAccessTarget = new FunctionAccess();
                vFunctionAccessTarget.AssignFromSource(vFunctionAccessSource);
                _functionAccessList.Add(vFunctionAccessTarget);
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the access to all functions for a specific user.
        /// </summary>
        /// <param name="aUserFunctionAccessCollection">A user function access collection.</param>
        public static void Load(UserFunctionAccessCollection aUserFunctionAccessCollection)
        {
            if (aUserFunctionAccessCollection == null)
            {
                throw new ArgumentNullException("aUserFunctionAccessCollection");
            }

            // Clear the list
            aUserFunctionAccessCollection.FunctionAccessList.Clear();

            using (var vSqlCommand = new SqlCommand()
            {
                CommandType = CommandType.Text,
                Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
            })
            {
                var vStringBuilder = new StringBuilder();
                vStringBuilder.AppendLine("select FNC_Code, RFC_AccessMap");
                vStringBuilder.AppendLine("from URL_UserRole t1, RFC_RoleFunction t2, FNC_Function t3");
                vStringBuilder.AppendLine("where t1.ROL_Key = t2.ROL_Key");
                vStringBuilder.AppendLine("and   t2.FNC_Key = t3.FNC_Key");
                vStringBuilder.AppendLine("and   t1.USR_Key = @USRKey");
                vSqlCommand.Parameters.AddWithValue("@USRKey", aUserFunctionAccessCollection.UsrKey);
                vSqlCommand.CommandText = vStringBuilder.ToString();
                vSqlCommand.Connection.Open();
                using (var vSqlDataReader = vSqlCommand.ExecuteReader())
                {
                    bool _haveRows = Read(vSqlDataReader);
                    while (_haveRows)
                    {
                        // Create an initialized FunctionAccess
                        FunctionAccess vFunctionAccess = new FunctionAccess();
                        vFunctionAccess.Function = Convert.ToString(vSqlDataReader["FNC_Code"]);
                        vFunctionAccess.Access.AccessMap = 0;
                        while (_haveRows && vFunctionAccess.Function == Convert.ToString(vSqlDataReader["FNC_Code"]))
                        {
                            vFunctionAccess.Access.Merge(new Access() { AccessMap = Convert.ToInt32(vSqlDataReader["RFC_AccessMap"]) });
                            _haveRows = Read(vSqlDataReader);
                        }
                        aUserFunctionAccessCollection.FunctionAccessList.Add(vFunctionAccess);
                    }
                    vSqlDataReader.Close();
                }
                vSqlCommand.Connection.Close();
            }
        }