//*********************************************************************
        //
        // PortalSettings Constructor
        //
        // The PortalSettings Constructor encapsulates all of the logic
        // necessary to obtain configuration settings necessary to render
        // a Portal Tab view for a given request.
        //
        // These Portal Settings are stored within a SQL database, and are
        // fetched below by calling the "GetPortalSettings" stored procedure.
        // This stored procedure returns values as SPROC output parameters,
        // and using three result sets.
        //
        //*********************************************************************

        public PortalSettings(int tabIndex, int tabId)
        {
            // GetPortalSettings within SQL Server returns 3 Resultsets, as well as a set of output
            // Parameters.  For the Npgsql implementation, we will need 4 resultsets to duplicate
            // this functionality.  Also, the tabid used internal to the GetPortalSettings stored
            // procedure changes, but is not returned.  In this implementation, we will store that
            // temporary TabID value in the tmpTabId variable.
            int tmpTabId = tabId;

            // Create Instance of Connection and Command Object
            NpgsqlConnection myConnection = new NpgsqlConnection(ConfigurationSettings.AppSettings["NpgsqlConnectionString"]);
            NpgsqlCommand    myCommand    = new NpgsqlCommand("GetPortalSettings(:PortalAlias, :TabId)", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            NpgsqlParameter parameterPortalAlias = new NpgsqlParameter("PortalAlias", DbType.String);

            parameterPortalAlias.Value = "p_default";
            myCommand.Parameters.Add(parameterPortalAlias);

            NpgsqlParameter parameterTabId = new NpgsqlParameter("TabId", DbType.Int32);

            parameterTabId.Value = tabId;
            myCommand.Parameters.Add(parameterTabId);

            // Open the database connection and execute the command
            myConnection.Open();
            NpgsqlDataReader result = myCommand.ExecuteReader();

            // Read Portal Settings (Output params from SQL implementation
            if (result.Read())
            {
                this.PortalId             = (int)result["portalid"];
                this.PortalName           = (String)result["portalname"];
                this.AlwaysShowEditButton = (bool)result["alwaysshoweditbutton"];
                tmpTabId = (int)result["tabid"];
                this.ActiveTab.TabOrder        = (int)result["taborder"];
                this.ActiveTab.MobileTabName   = (String)result["mobiletabname"];
                this.ActiveTab.AuthorizedRoles = (String)result["authorizedroles"];
                this.ActiveTab.TabName         = (String)result["tabname"];
                this.ActiveTab.ShowMobile      = (bool)result["showmobile"];
            }

            // Close the datareader
            result.Close();


            myCommand = new NpgsqlCommand("GetTabs(:PortalID)", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            NpgsqlParameter parameterPortalId = new NpgsqlParameter("PortalID", DbType.Int32);

            parameterPortalId.Value = this.PortalId;
            myCommand.Parameters.Add(parameterPortalId);

            // Open the database connection and execute the command
            result = myCommand.ExecuteReader();


            // Read Desktop Tab Information
            while (result.Read())
            {
                TabStripDetails tabDetails = new TabStripDetails();
                tabDetails.TabId           = (int)result["tabid"];
                tabDetails.TabName         = (String)result["tabname"];
                tabDetails.TabOrder        = (int)result["taborder"];
                tabDetails.AuthorizedRoles = (String)result["authorizedroles"];

                this.DesktopTabs.Add(tabDetails);
            }

            // Close the datareader
            result.Close();

            if (this.ActiveTab.TabId == 0)
            {
                this.ActiveTab.TabId = ((TabStripDetails)this.DesktopTabs[0]).TabId;
            }

            // // Read Mobile Tab Information
            // result.NextResult();



            // while(result.Read()) {

            //     TabStripDetails tabDetails = new TabStripDetails();
            //     tabDetails.TabId = (int) result["TabId"];
            //     tabDetails.TabName = (String) result["MobileTabName"];
            //     tabDetails.AuthorizedRoles = (String) result["AuthorizedRoles"];

            //     this.MobileTabs.Add(tabDetails);
            // }

            // Module Tab Information

            myCommand = new NpgsqlCommand("GetModuleModuleDefinitions(:TabId)", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            parameterTabId       = new NpgsqlParameter("TabId", DbType.Int32);
            parameterTabId.Value = tmpTabId;
            myCommand.Parameters.Add(parameterTabId);

            // Open the database connection and execute the command
            result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);


            while (result.Read())
            {
                ModuleSettings m = new ModuleSettings();
                m.ModuleId            = (int)result["moduleid"];
                m.ModuleDefId         = (int)result["moduledefid"];
                m.TabId               = (int)result["tabid"];
                m.PaneName            = (String)result["panename"];
                m.ModuleTitle         = (String)result["moduletitle"];
                m.AuthorizedEditRoles = (String)result["authorizededitroles"];
                m.CacheTime           = (int)result["cachetime"];
                m.ModuleOrder         = (int)result["moduleorder"];
                m.ShowMobile          = (bool)result["showmobile"];
                m.DesktopSrc          = (String)result["desktopsrc"];
                m.MobileSrc           = (String)result["mobilesrc"];

                this.ActiveTab.Modules.Add(m);
            }

            // Close the datareader
            result.Close();

            this.ActiveTab.TabIndex = tabIndex;
            this.ActiveTab.TabId    = tabId;


            myConnection.Close();
        }
Exemple #2
0
        //*******************************************************
        //
        // The ApplyChanges_Click server event handler on this page is used
        // to save the module settings into the portal configuration system
        //
        //*******************************************************

        private void ApplyChanges_Click(Object Sender, EventArgs e)
        {
            // Obtain PortalSettings from Current Context
            PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];

            object value = GetModule();

            if (value != null)
            {
                ModuleSettings m = (ModuleSettings)value;

                // Construct Authorized User Roles String
                String editRoles = "";

                foreach (ListItem item in authEditRoles.Items)
                {
                    if (item.Selected == true)
                    {
                        editRoles = editRoles + item.Text + ";";
                    }
                }

                // update module
                AdminDB admin = new AdminDB();
                admin.UpdateModule(moduleId, m.ModuleOrder, m.PaneName, moduleTitle.Text, Int32.Parse(cacheTime.Text), editRoles, showMobile.Checked);

                // Update Textbox Settings
                moduleTitle.Text = m.ModuleTitle;
                cacheTime.Text   = m.CacheTime.ToString();

                // Populate checkbox list with all security roles for this portal
                // and "check" the ones already configured for this module
                IDataReader roles = admin.GetPortalRoles(portalSettings.PortalId);

                // Clear existing items in checkboxlist
                authEditRoles.Items.Clear();

                ListItem allItem = new ListItem();
                allItem.Text = "All Users";

                if (m.AuthorizedEditRoles.LastIndexOf("All Users") > -1)
                {
                    allItem.Selected = true;
                }

                authEditRoles.Items.Add(allItem);

                while (roles.Read())
                {
                    ListItem item = new ListItem();
                    item.Text  = (String)roles["rolename"];
                    item.Value = roles["roleid"].ToString();

                    if ((m.AuthorizedEditRoles.LastIndexOf(item.Text)) > -1)
                    {
                        item.Selected = true;
                    }

                    authEditRoles.Items.Add(item);
                }
            }

            // Navigate back to admin page
            Response.Redirect("TabLayout.aspx?tabid=" + tabId);
        }