| |
|
|
| |
|
Отображать: |
Admin
|
 |
 |
| Присоединился: 18 Mar 2003 |
| Число сообщений: 36 |
| |
|
IBuySpy Portal Two-Level tabs's Source code
Отправлено: 18 Mar 2003 07:07 PM |
*********************************************************************************
* Below are the contents of the affected files for nested Tabs. I chose to *
* create a seperate control for the subnavigation. You may very choose to *
* implement this differently but the details below should keep you from pulling *
* your hair out like I've heard all too many people about to do releated to *
* this topic. *
* *
* This code is as-is, without warranty implied or expressed. Use at your own *
* risk! *
* *
* IF you use this. I would appreciate just a comment in your code that you *
* got it from us, City of Arlington, Texas. Also, send me a postcard, our *
* project team would get a kick out of knowing who is using it. Thanks and have *
* a joyful day. *
* *
* Webmaster *
* 201 E. Abram St. *
* Arlington, TX 76010 *
* Attn: Technology Services *
*********************************************************************************
Configuration.vb ****************************************************************
Imports System
Imports System.Configuration
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Namespace ASPNetPortal
'*********************************************************************
'
' TabStripDetails Class
'
' Class that encapsulates the just the tabstrip details -- TabName, TabId and TabOrder
' -- for a specific Tab in the Portal
'
'*********************************************************************
Public Class TabStripDetails
Public TabId As Integer
Public TabName As String
Public TabOrder As Integer
Public AuthorizedRoles As String
'Added 8/16/02 THL Child Tabs
Public ParentTabID As Integer
End Class
'*********************************************************************
'
' TabSettings Class
'
' Class that encapsulates the detailed settings for a specific Tab
' in the Portal
'
'*********************************************************************
Public Class TabSettings
Public TabIndex As Integer
Public TabId As Integer
Public TabName As String
Public TabOrder As Integer
Public MobileTabName As String
Public AuthorizedRoles As String
Public ShowMobile As Boolean
Public Modules As New ArrayList()
'Added 8/16/02 THL Child Tabs
Public ParentTabID As Integer
End Class
'*********************************************************************
'
' ModuleSettings Class
'
' Class that encapsulates the detailed settings for a specific Tab
' in the Portal
'
'*********************************************************************
Public Class ModuleSettings
Public ModuleId As Integer
Public ModuleDefId As Integer
Public TabId As Integer
Public CacheTime As Integer
Public ModuleOrder As Integer
Public PaneName As String
Public ModuleTitle As String
Public AuthorizedEditRoles As String
Public ShowMobile As Boolean
Public DesktopSrc As String
Public MobileSrc As String
'Added THL for per module view roles 7/11/02
Public AuthorizedViewRoles As String
End Class
'*********************************************************************
'
' PortalSettings Class
'
' This class encapsulates all of the settings for the Portal, as well
' as the configuration settings required to execute the current tab
' view within the portal.
'
'*********************************************************************
Public Class PortalSettings
Public PortalId As Integer
Public PortalName As String
Public AlwaysShowEditButton As Boolean
Public DesktopTabs As New ArrayList()
Public MobileTabs As New ArrayList()
Public ActiveTab As New TabSettings()
'*********************************************************************
'
' 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 Sub New(ByVal tabIndex As Integer, ByVal tabId As Integer)
' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("GetPortalSettings", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterPortalAlias As New SqlParameter("@PortalAlias", SqlDbType.NVarChar, 50)
parameterPortalAlias.Value = "p_default"
myCommand.Parameters.Add(parameterPortalAlias)
Dim parameterTabId As New SqlParameter("@TabId", SqlDbType.Int, 4)
parameterTabId.Value = tabId
myCommand.Parameters.Add(parameterTabId)
' Add out parameters to Sproc
Dim parameterPortalID As New SqlParameter("@PortalID", SqlDbType.Int, 4)
parameterPortalID.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterPortalID)
Dim parameterPortalName As New SqlParameter("@PortalName", SqlDbType.NVarChar, 128)
parameterPortalName.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterPortalName)
Dim parameterEditButton As New SqlParameter("@AlwaysShowEditButton", SqlDbType.Bit, 1)
parameterEditButton.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterEditButton)
Dim parameterTabName As New SqlParameter("@TabName", SqlDbType.NVarChar, 50)
parameterTabName.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterTabName)
Dim parameterTabOrder As New SqlParameter("@TabOrder", SqlDbType.Int, 4)
parameterTabOrder.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterTabOrder)
'Added 7/16/02 THL Child Tabs
Dim parameterParentTabID As New SqlParameter("@ParentTabID", SqlDbType.Int, 4)
parameterParentTabID.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterParentTabID)
Dim parameterMobileTabName As New SqlParameter("@MobileTabName", SqlDbType.NVarChar, 50)
parameterMobileTabName.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterMobileTabName)
Dim parameterAuthRoles As New SqlParameter("@AuthRoles", SqlDbType.NVarChar, 256)
parameterAuthRoles.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterAuthRoles)
Dim parameterShowMobile As New SqlParameter("@ShowMobile", SqlDbType.Bit, 1)
parameterShowMobile.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterShowMobile)
' Open the database connection and execute the command
myConnection.Open()
Dim result As SqlDataReader = myCommand.ExecuteReader()
' Read the first resultset -- Desktop Tab Information
While result.Read()
Dim tabDetails As New TabStripDetails()
tabDetails.TabId = CInt(result("TabId"))
tabDetails.TabName = CStr(result("TabName"))
tabDetails.TabOrder = CInt(result("TabOrder"))
tabDetails.AuthorizedRoles = CStr(result("AuthorizedRoles"))
'Added 8/16/02 THL Child Tabs
tabdetails.ParentTabID = CInt(result("ParentTabID"))
Me.DesktopTabs.Add(tabDetails)
End While
If Me.ActiveTab.TabId = 0 Then
Me.ActiveTab.TabId = CType(Me.DesktopTabs(0), TabStripDetails).TabId
End If
' Read the second result -- Mobile Tab Information
result.NextResult()
While result.Read()
Dim tabDetails As New TabStripDetails()
tabDetails.TabId = CInt(result("TabId"))
tabDetails.TabName = CStr(result("MobileTabName"))
tabDetails.AuthorizedRoles = CStr(result("AuthorizedRoles"))
'Added 8/16/02 THL Child Tabs
tabdetails.ParentTabID = CInt(result("ParentTabID"))
Me.MobileTabs.Add(tabDetails)
End While
' Read the third result -- Module Tab Information
result.NextResult()
While result.Read()
Dim m As New ModuleSettings()
m.ModuleId = CInt(result("ModuleID"))
m.ModuleDefId = CInt(result("ModuleDefID"))
m.TabId = CInt(result("TabID"))
m.PaneName = CStr(result("PaneName"))
m.ModuleTitle = CStr(result("ModuleTitle"))
m.AuthorizedEditRoles = CStr(result("AuthorizedEditRoles"))
m.CacheTime = CInt(result("CacheTime"))
m.ModuleOrder = CInt(result("ModuleOrder"))
m.ShowMobile = CBool(result("ShowMobile"))
m.DesktopSrc = CStr(result("DesktopSrc"))
m.MobileSrc = CStr(result("MobileSrc"))
'Added THL per module view roles 7/11/02
m.AuthorizedViewRoles = CStr(result("AuthorizedViewRoles"))
Me.ActiveTab.Modules.Add(m)
End While
' Now read Portal out params
result.NextResult()
Me.PortalId = CInt(parameterPortalID.Value)
Me.PortalName = CStr(parameterPortalName.Value)
Me.AlwaysShowEditButton = CBool(parameterEditButton.Value)
Me.ActiveTab.TabIndex = tabIndex
Me.ActiveTab.TabId = tabId
Me.ActiveTab.TabOrder = CInt(parameterTabOrder.Value)
Me.ActiveTab.MobileTabName = CStr(parameterMobileTabName.Value)
Me.ActiveTab.AuthorizedRoles = CStr(parameterAuthRoles.Value)
Me.ActiveTab.TabName = CStr(parameterTabName.Value)
Me.ActiveTab.ShowMobile = CBool(parameterShowMobile.Value)
'Added 8/19/02 Child Tabs
Me.ActiveTab.ParentTabID = CInt(parameterParentTabID.Value)
myConnection.Close()
End Sub
'*********************************************************************
'
' GetModuleSettings Static Method
'
' The PortalSettings.GetModuleSettings Method returns a hashtable of
' custom module specific settings from the database. This method is
' used by some user control modules (Xml, Image, etc) to access misc
' settings.
'
'*********************************************************************
Public Shared Function GetModuleSettings(ByVal moduleId As Integer) As Hashtable
' Get Settings for this module from the database
Dim _settings As New Hashtable()
' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("GetModuleSettings", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterModuleId As New SqlParameter("@ModuleID", SqlDbType.Int, 4)
parameterModuleId.Value = moduleId
myCommand.Parameters.Add(parameterModuleId)
' Execute the command
myConnection.Open()
Dim dr As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read()
_settings(dr.GetString(0)) = dr.GetString(1)
End While
dr.Close()
Return _settings
End Function
End Class
End Namespace
DesktopChildNav.ascx ************************************************************
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="DesktopChildNav.ascx.vb" Inherits="ASPNetPortal.DesktopChildNav" TargetSchema="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" %>
<%@ Import Namespace="ASPNetPortal" %>
<TABLE class="SiteLink" id="ChildNavTable" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD width="100%" class="SubHead">
Navigation: <asp:HyperLink id="UpLevel" runat="server"></asp:HyperLink>
<DIV class="SiteLink">
<asp:datalist id="ChildTabs" width="100%" cssclass="OtherChildTabsBg" runat="server" EnableViewState="false" SelectedItemStyle-CssClass="TabBg" ItemStyle-Height="15" repeatdirection="Vertical" RepeatLayout="Flow">
<SelectedItemStyle CssClass="ChildTabBg"></SelectedItemStyle>
<SelectedItemTemplate>
<A class=SelectedChildTab href="<%= Request.ApplicationPath %>/DesktopDefault.aspx?tabindex=<%# TabIndex %>&tabid=<%# Ctype(Container.DataItem, TabStripDetails).TabId %>"><%# Ctype(Container.DataItem, TabStripDetails).TabName %></A> <!-- Added 8/16/02 THL to support nested tabs -->
</SelectedItemTemplate>
<ItemStyle Height="15px" CssClass="OtherChildTabsBG:"></ItemStyle>
<ItemTemplate>
<A class=OtherChildTabs href="<%= Request.ApplicationPath %>/DesktopDefault.aspx?tabindex=<%# tabIndex %>&tabid=<%# Ctype(Container.DataItem, TabStripDetails).TabId %>"><%# Ctype(Container.DataItem, TabStripDetails).TabName %></A>
</ItemTemplate>
</asp:datalist></DIV>
</TD>
</TR>
</TABLE>
<br/>
DesktopChildNav.ascx.vb *********************************************************
Namespace ASPNetPortal
Public MustInherit Class DesktopChildNav
Inherits System.Web.UI.UserControl
Protected WithEvents ChildTabs As System.Web.UI.WebControls.DataList
Public tabIndex As Integer
Protected WithEvents UpLevel As System.Web.UI.WebControls.HyperLink
Public ShowTabs As Boolean = True
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
GetChildTabs()
End Sub
Public Function GetChildTabs()
' Obtain PortalSettings from Current Context
Dim tabid As Integer
Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
If ShowTabs = True Then
tabid = _portalSettings.ActiveTab.TabId
tabIndex = _portalSettings.ActiveTab.TabIndex
' Build list of tabs to be shown to user
' Added 8/16/02 THL to support child tabs
Dim authorizedChildTabs As New ArrayList()
Dim addedTabs As Integer = 0
Dim i As Integer
For i = 0 To _portalSettings.DesktopTabs.Count - 1
Dim tab As TabStripDetails = CType(_portalSettings.DesktopTabs(i), TabStripDetails)
'Use this out logic to show all top level tabs if we are at
'the top level of the navigation hierarchy.
If PortalSecurity.IsInRoles(tab.AuthorizedRoles) And tab.ParentTabID = tabid Then
If tab.ParentTabID <> 0 Then
tab.TabName = " " & tab.TabName
End If
authorizedChildTabs.Add(tab)
If tab.TabId = tabid Then
ChildTabs.SelectedIndex = addedTabs
End If
addedTabs += 1
ElseIf PortalSecurity.IsInRoles(tab.AuthorizedRoles) And tab.TabId = tabid Then
authorizedChildTabs.Add(tab)
' Create the Parent Link
If tab.ParentTabID <> 0 Or tab.ParentTabID <> Nothing Then
UpLevel.CssClass = "Normal"
UpLevel.ImageUrl = "~/images/lt.gif"
UpLevel.NavigateUrl() = Request.ApplicationPath & "/DesktopDefault.aspx?tabindex=" & tabIndex & "&tabid=" & tab.ParentTabID
UpLevel.Text = "Back..."
End If
If tab.TabId = tabid Then
ChildTabs.SelectedIndex = addedTabs
End If
addedTabs += 1
End If
Next i
' Populate Tab List at Top of the Page with authorized tabs
ChildTabs.DataSource = authorizedChildTabs
ChildTabs.DataBind()
End If
End Function
End Class
End Namespace
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Modules_Tabs]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Modules] DROP CONSTRAINT FK_Modules_Tabs
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tabs_Parent]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tabs] DROP CONSTRAINT FK_Tabs_Parent
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tabs]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tabs]
GO
CREATE TABLE [dbo].[Tabs] (
[TabID] [int] IDENTITY (0, 1) NOT NULL ,
[TabOrder] [int] NOT NULL ,
[PortalID] [int] NOT NULL ,
[TabName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[MobileTabName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[AuthorizedRoles] [nvarchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ShowMobile] [bit] NOT NULL ,
[ParentTabID] [int] NULL
) ON [PRIMARY]
GO
/******************************************************************************/
CREATE PROCEDURE UpdateTab
(
@PortalID int,
@TabID int,
@TabOrder int,
@ParentTabID int,
@TabName nvarchar(50),
@AuthorizedRoles nvarchar(256),
@MobileTabName nvarchar(50),
@ShowMobile bit
)
AS
IF NOT EXISTS (
SELECT
*
FROM
Tabs
WHERE
TabID = @TabID
)
INSERT INTO Tabs (
PortalID,
TabOrder,
ParentTabID,
TabName,
AuthorizedRoles,
MobileTabName,
ShowMobile
)
VALUES (
@PortalID,
@TabOrder,
@PArentTabID,
@TabName,
@AuthorizedRoles,
@MobileTabName,
@ShowMobile
)
ELSE
UPDATE
Tabs
SET
TabOrder = @TabOrder,
ParentTabID = @PArentTabID,
TabName = @TabName,
AuthorizedRoles = @AuthorizedRoles,
MobileTabName = @MobileTabName,
ShowMobile = @ShowMobile
WHERE
TabID = @TabID
GO
/******************************************************************************/
CREATE PROCEDURE GetPortalSettings
(
@PortalAlias nvarchar(50),
@TabID int,
@PortalID int OUTPUT,
@PortalName nvarchar(128) OUTPUT,
@AlwaysShowEditButton bit OUTPUT,
@TabName nvarchar (50) OUTPUT,
@TabOrder int OUTPUT,
@ParentTabID int OUTPUT,
@MobileTabName nvarchar (50) OUTPUT,
@AuthRoles nvarchar (256) OUTPUT,
@ShowMobile bit OUTPUT
)
AS
/* First, get Out Params */
IF @TabID = 0
SELECT TOP 1
@PortalID = Portals.PortalID,
@PortalName = Portals.PortalName,
@AlwaysShowEditButton = Portals.AlwaysShowEditButton,
@TabID = Tabs.TabID,
@TabOrder = Tabs.TabOrder,
@PArentTabID = Tabs.PArentTabID,
@TabName = Tabs.TabName,
@MobileTabName = Tabs.MobileTabName,
@AuthRoles = Tabs.AuthorizedRoles,
@ShowMobile = Tabs.ShowMobile
FROM
Tabs
INNER JOIN
Portals ON Tabs.PortalID = Portals.PortalID
WHERE
PortalAlias=@PortalAlias
ORDER BY
TabOrder
ELSE
SELECT
@PortalID = Portals.PortalID,
@PortalName = Portals.PortalName,
@AlwaysShowEditButton = Portals.AlwaysShowEditButton,
@TabName = Tabs.TabName,
@TabOrder = Tabs.TabOrder,
/* Added 8/16/02 THL to support child tabs */
@ParentTabID = Tabs.ParentTabID,
@MobileTabName = Tabs.MobileTabName,
@AuthRoles = Tabs.AuthorizedRoles,
@ShowMobile = Tabs.ShowMobile
FROM
Tabs
INNER JOIN
Portals ON Tabs.PortalID = Portals.PortalID
WHERE
TabID=@TabID
/* Get Tabs list */
SELECT
TabName,
AuthorizedRoles,
TabID,
TabOrder,
ParentTabID
FROM
Tabs
WHERE
PortalID = @PortalID
ORDER BY
ParentTabID, TabOrder
/* Get Mobile Tabs list */
SELECT
MobileTabName,
AuthorizedRoles,
TabID,
ShowMobile,
ParentTabID
FROM
Tabs
WHERE
PortalID = @PortalID
AND
ShowMobile = 1
ORDER BY
ParentTabID, TabOrder
/* Then, get the DataTable of module info */
SELECT
*
FROM
Modules
INNER JOIN
ModuleDefinitions ON Modules.ModuleDefID = ModuleDefinitions.ModuleDefID
WHERE
TabID = @TabID
ORDER BY
ModuleOrder
GO
|
//Igor
|
|
|
|
Admin
|
 |
 |
| Присоединился: 18 Mar 2003 |
| Число сообщений: 36 |
| |
|
Re: IBuySpy Portal Two-Level tabs's Source code
Отправлено: 18 Mar 2003 07:08 PM |
Configuration.cs
****************************************************************************
using System;
using System.Configuration;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace ASPNetPortal {
//*********************************************************************
//
// TabStripDetails Class
//
// Class that encapsulates the just the tabstrip details -- TabName, TabId and TabOrder
// -- for a specific Tab in the Portal
//
//*********************************************************************
public class TabStripDetails {
public int TabId;
public String TabName;
public int TabOrder;
public String AuthorizedRoles;
// Added 20/08/2002 Child Tabs
public int ParentTabId;
}
//*********************************************************************
//
// TabSettings Class
//
// Class that encapsulates the detailed settings for a specific Tab
// in the Portal
//
//*********************************************************************
public class TabSettings {
public int TabIndex;
public int TabId;
public String TabName;
public int TabOrder;
public String MobileTabName;
public String AuthorizedRoles;
public bool ShowMobile;
public ArrayList Modules = new ArrayList();
// Added 20/08/2002 Child Tabs
public int ParentTabId;
}
//*********************************************************************
//
// ModuleSettings Class
//
// Class that encapsulates the detailed settings for a specific Tab
// in the Portal
//
//*********************************************************************
public class ModuleSettings {
public int ModuleId;
public int ModuleDefId;
public int TabId;
public int CacheTime;
public int ModuleOrder;
public String PaneName;
public String ModuleTitle;
public String AuthorizedEditRoles;
public bool ShowMobile;
public String DesktopSrc;
public String MobileSrc;
// Added 20/08/2002 Authorised View Roles
public String AuthorizedViewRoles;
}
//*********************************************************************
//
// PortalSettings Class
//
// This class encapsulates all of the settings for the Portal, as well
// as the configuration settings required to execute the current tab
// view within the portal.
//
//*********************************************************************
public class PortalSettings {
public int PortalId;
public String PortalName;
public bool AlwaysShowEditButton;
public ArrayList DesktopTabs = new ArrayList();
public ArrayList MobileTabs = new ArrayList();
public TabSettings ActiveTab = new TabSettings();
//*********************************************************************
//
// 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) {
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("GetPortalSettings", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterPortalAlias = new SqlParameter("@PortalAlias", SqlDbType.NVarChar, 50);
parameterPortalAlias.Value = "p_default";
myCommand.Parameters.Add(parameterPortalAlias);
SqlParameter parameterTabId = new SqlParameter("@TabId", SqlDbType.Int, 4);
parameterTabId.Value = tabId;
myCommand.Parameters.Add(parameterTabId);
// Add out parameters to Sproc
SqlParameter parameterPortalID = new SqlParameter("@PortalID", SqlDbType.Int, 4);
parameterPortalID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterPortalID);
SqlParameter parameterPortalName = new SqlParameter("@PortalName", SqlDbType.NVarChar, 128);
parameterPortalName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterPortalName);
SqlParameter parameterEditButton = new SqlParameter("@AlwaysShowEditButton", SqlDbType.Bit, 1);
parameterEditButton.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterEditButton);
SqlParameter parameterTabName = new SqlParameter("@TabName", SqlDbType.NVarChar, 50);
parameterTabName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterTabName);
SqlParameter parameterTabOrder = new SqlParameter("@TabOrder", SqlDbType.Int, 4);
parameterTabOrder.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterTabOrder);
// Added 7/16/02 Child Tabs
SqlParameter parameterParentTabID = new SqlParameter("@ParentTabID", SqlDbType.Int, 4);
parameterParentTabID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterParentTabID);
SqlParameter parameterMobileTabName = new SqlParameter("@MobileTabName", SqlDbType.NVarChar, 50);
parameterMobileTabName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterMobileTabName);
SqlParameter parameterAuthRoles = new SqlParameter("@AuthRoles", SqlDbType.NVarChar, 256);
parameterAuthRoles.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterAuthRoles);
SqlParameter parameterShowMobile = new SqlParameter("@ShowMobile", SqlDbType.Bit, 1);
parameterShowMobile.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterShowMobile);
// Open the database connection and execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader();
// Read the first resultset -- 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"];
// Added 8/16/02 THL Child Tabs
tabDetails.ParentTabId = (int) result["ParentTabID"];
this.DesktopTabs.Add(tabDetails);
}
if (this.ActiveTab.TabId == 0) {
this.ActiveTab.TabId = ((TabStripDetails) this.DesktopTabs[0]).TabId;
}
// Read the second result -- 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"];
// Added 8/16/02 THL Child Tabs
tabDetails.ParentTabId = (int) result["ParentTabID"];
this.MobileTabs.Add(tabDetails);
}
// Read the third result -- Module Tab Information
result.NextResult();
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"];
//Added THL per module view roles 7/11/02
//m.AuthorizedViewRoles = (String) result["AuthorizedViewRoles"];
this.ActiveTab.Modules.Add(m);
}
// Now read Portal out params
result.NextResult();
this.PortalId = (int) parameterPortalID.Value;
this.PortalName = (String) parameterPortalName.Value;
this.AlwaysShowEditButton = (bool) parameterEditButton.Value;
this.ActiveTab.TabIndex = tabIndex;
this.ActiveTab.TabId = tabId;
this.ActiveTab.TabOrder = (int) parameterTabOrder.Value;
this.ActiveTab.MobileTabName = (String) parameterMobileTabName.Value;
this.ActiveTab.AuthorizedRoles = (String) parameterAuthRoles.Value;
this.ActiveTab.TabName = (String) parameterTabName.Value;
this.ActiveTab.ShowMobile = (bool) parameterShowMobile.Value;
// Added 8/19/02 Child Tabs
this.ActiveTab.ParentTabId = (int) parameterParentTabID.Value;
myConnection.Close();
}
//*********************************************************************
//
// GetModuleSettings Static Method
//
// The PortalSettings.GetModuleSettings Method returns a hashtable of
// custom module specific settings from the database. This method is
// used by some user control modules (Xml, Image, etc) to access misc
// settings.
//
//*********************************************************************
public static Hashtable GetModuleSettings(int moduleId) {
// Get Settings for this module from the database
Hashtable _settings = new Hashtable();
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("GetModuleSettings", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterModuleId = new SqlParameter("@ModuleID", SqlDbType.Int, 4);
parameterModuleId.Value = moduleId;
myCommand.Parameters.Add(parameterModuleId);
// Execute the command
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read()) {
_settings[dr.GetString(0)] = dr.GetString(1);
}
dr.Close();
return _settings;
}
}
}
*****************************************************************************
DesktopChildNav.ascx ************************************************************
<%@ Import Namespace="ASPNetPortal" %>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="DesktopChildNav.ascx.cs" Inherits="ASPNetPortal.DesktopChildNav" TargetSchema="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" %>
<TABLE class="SiteLink" id="ChildNavTable" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD width="100%" class="SubHead">
Navigation:
<asp:HyperLink id="UpLevel" runat="server"></asp:HyperLink>
<DIV class="SiteLink">
<asp:datalist id="ChildTabs" width="100%" cssclass="OtherChildTabsBg" runat="server" EnableViewState="false" SelectedItemStyle-CssClass="TabBg" ItemStyle-Height="15" repeatdirection="Vertical" RepeatLayout="Flow">
<SelectedItemStyle CssClass="ChildTabBg"></SelectedItemStyle>
<SelectedItemTemplate>
<A class=SelectedChildTab href="<%= Request.ApplicationPath %>/DesktopDefault.aspx?tabindex=<%# TabIndex %>&tabid=<%# ((TabStripDetails)(Container.DataItem)).TabId %>"><%# ((TabStripDetails)(Container.DataItem)).TabName %></A> <!-- Added 8/16/02 THL to support nested tabs -->
</SelectedItemTemplate>
<ItemStyle Height="15px" CssClass="OtherChildTabsBG:"></ItemStyle>
<ItemTemplate>
<A class=OtherChildTabs href="<%= Request.ApplicationPath %>/DesktopDefault.aspx?tabindex=<%# tabIndex %>&tabid=<%# ((TabStripDetails)(Container.DataItem)).TabId %>"><%# ((TabStripDetails)(Container.DataItem)).TabName %></A>
</ItemTemplate>
</asp:datalist></DIV>
</TD>
</TR>
</TABLE>
<br>
DesktopChildNav.ascx.vb *********************************************************
namespace ASPNetPortal
{
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for DesktopChildNav.
/// </summary>
public abstract class DesktopChildNav : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.HyperLink UpLevel;
protected System.Web.UI.WebControls.DataList ChildTabs;
public int tabIndex;
public bool ShowTabs = true;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
GetChildTabs();
}
public void GetChildTabs()
{
int tabid;
PortalSettings portalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"];
if( ShowTabs )
{
tabid = portalSettings.ActiveTab.TabId;
tabIndex = portalSettings.ActiveTab.TabIndex;
// Build list of tabs to be shown to user
ArrayList authorizedTabs = new ArrayList();
int addedTabs = 0;
for (int i=0; i < portalSettings.DesktopTabs.Count; i++)
{
TabStripDetails tab = (TabStripDetails)portalSettings.DesktopTabs[i];
if (PortalSecurity.IsInRoles(tab.AuthorizedRoles) && tab.ParentTabId == tabid )
{
if ( tab.ParentTabId != 0 )
{
tab.TabName = " " + tab.TabName;
}
authorizedTabs.Add(tab);
if ( tab.TabId == tabid )
{
ChildTabs.SelectedIndex = addedTabs;
}
addedTabs++;
}
else
{
if (PortalSecurity.IsInRoles(tab.AuthorizedRoles) && tab.TabId == tabid )
{
authorizedTabs.Add(tab);
if( tab.ParentTabId != 0 )
{
UpLevel.CssClass = "Normal";
UpLevel.ImageUrl = "~/images/lt.gif";
UpLevel.NavigateUrl = Request.ApplicationPath + "/DesktopDefault.aspx?tabindex=" + tabIndex + "&tabid=" + tab.ParentTabId;
UpLevel.Text = "Back...";
}
}
if (addedTabs == tabIndex)
{
ChildTabs.SelectedIndex = addedTabs;
}
addedTabs++;
}
}
// Populate Tab List at Top of the Page with authorized tabs
ChildTabs.DataSource = authorizedTabs;
ChildTabs.DataBind();
}
}
public int TabIndex
{
get
{
return tabIndex;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
|
//Igor
|
|
|
|
Admin
|
 |
 |
| Присоединился: 18 Mar 2003 |
| Число сообщений: 36 |
| |
|
Re: IBuySpy Portal Two-Level tabs's Source code
Отправлено: 18 Mar 2003 07:09 PM |
public void UpdateTab (int portalId, int tabId, int parentTabId, String tabName, int tabOrder, String authorizedRoles, String mobileTabName, bool showMobile) {
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("UpdateTab", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterPortalId = new SqlParameter("@PortalId", SqlDbType.Int, 4);
parameterPortalId.Value = portalId;
myCommand.Parameters.Add(parameterPortalId);
SqlParameter parameterTabId = new SqlParameter("@TabId", SqlDbType.Int, 4);
parameterTabId.Value = tabId;
myCommand.Parameters.Add(parameterTabId);
SqlParameter parameterParentTabId = new SqlParameter("@ParentTabId", SqlDbType.Int, 4);
parameterParentTabId.Value = parentTabId;
myCommand.Parameters.Add(parameterParentTabId);
SqlParameter parameterTabName = new SqlParameter("@TabName", SqlDbType.NVarChar, 50);
parameterTabName.Value = tabName;
myCommand.Parameters.Add(parameterTabName);
SqlParameter parameterTabOrder = new SqlParameter("@TabOrder", SqlDbType.Int, 4);
parameterTabOrder.Value = tabOrder;
myCommand.Parameters.Add(parameterTabOrder);
SqlParameter parameterAuthRoles = new SqlParameter("@AuthorizedRoles", SqlDbType.NVarChar, 256);
parameterAuthRoles.Value = authorizedRoles;
myCommand.Parameters.Add(parameterAuthRoles);
SqlParameter parameterMobileTabName = new SqlParameter("@MobileTabName", SqlDbType.NVarChar, 50);
parameterMobileTabName.Value = mobileTabName;
myCommand.Parameters.Add(parameterMobileTabName);
SqlParameter parameterShowMobile = new SqlParameter("@ShowMobile", SqlDbType.Bit, 1);
parameterShowMobile.Value = showMobile;
myCommand.Parameters.Add(parameterShowMobile);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
-----------
Now the steps to add the code to portal would be something like:-
-----------
1.) Replace ConfigurationDB with the relevant ConfigurationDB (C# or VB)
2.) Add DesktopChildNav to your solution, ( I added it at root, but you can add it anywhere )
(This is both aspx, and cs/vb file)
3.) Modify the Tab Table, I did this through enterprise manager, so I didn't have to drop the table, etc. (the main step is to add this field [ParentTabID] [int] NULL )
4.) Drop UpdateTab stored procedure, replace it with the new one.
5.) Drop GetPortalSettings, replace it with new one.
Now,
Modify your administration section to allow the population of the the parenttab, you could use a hierarchial tab view, or just dropdowns, however you like. You need to modify AddTab, UpdateTab in AdminDB to handle the ParentTabId parameter.
To Test, I just manipulated the database directly, its just the administration that is not complete. If I get some time this week, I'll post my administration. Its not complete yet.
|
//Igor
|
|
|
|
Admin
|
 |
 |
| Присоединился: 18 Mar 2003 |
| Число сообщений: 36 |
| |
|
Re: IBuySpy Portal Two-Level tabs's Source code
Отправлено: 18 Mar 2003 07:10 PM |
Sorry folks, that's what I get for trying to toss together an answer for someone without getting all my documentation together. I'm not at work but these should be the relevent portions of the admin.vb below.
DesktopChildNav.aspx does NOT exist in the standard IBuySpy Portal installation. This was a new page that I chose to use to house the child navigation. It's rough right now but should get the idea across. You may choose to implement child navigation in a single control, it's up to you.
Just remember that if you choose to try nested datalists, for each item in the parent datalist, it will create another instance of the child. You cannot directly access the nested datalist by name. You will probably want to do a findControl associated with the ItemCreated or ItemBound events of the parent control. (This is jsut an FYI so you don't spend days trying to figure it out like my sloooow little mind did ;o) )
In regard to the SPROCS, assumption on my part that one would see that the Procedures were meant to be recreated. So much for that. I'll try and keep that in mind next time.
Again, I want to make these modification as easy as I can for ya'll without rewriting the application for you. Either way, atleast I hope the concepts shared will assist you in modifiying the portal to you specifications.
HTH
'
' TABS
'
'*********************************************************************
'
' AddTab Method
'
' The AddTab method adds a new tab to the portal.
'
' Other relevant sources:
' + AddTab Stored Procedure
'
'*********************************************************************
Public Function AddTab(ByVal portalId As Integer, ByVal tabName As String, ByVal tabOrder As Integer) As Integer
' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("AddTab", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterPortalId As New SqlParameter("@PortalId", SqlDbType.Int, 4)
parameterPortalId.Value = portalId
myCommand.Parameters.Add(parameterPortalId)
Dim parameterTabName As New SqlParameter("@TabName", SqlDbType.NVarChar, 50)
parameterTabName.Value = tabName
myCommand.Parameters.Add(parameterTabName)
Dim parameterTabOrder As New SqlParameter("@TabOrder", SqlDbType.Int, 4)
parameterTabOrder.Value = tabOrder
myCommand.Parameters.Add(parameterTabOrder)
Dim parameterAuthRoles As New SqlParameter("@AuthorizedRoles", SqlDbType.NVarChar, 256)
parameterAuthRoles.Value = "All Users"
myCommand.Parameters.Add(parameterAuthRoles)
Dim parameterMobileTabName As New SqlParameter("@MobileTabName", SqlDbType.NVarChar, 50)
parameterMobileTabName.Value = ""
myCommand.Parameters.Add(parameterMobileTabName)
Dim parameterTabId As New SqlParameter("@TabId", SqlDbType.Int, 4)
parameterTabId.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterTabId)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Return CInt(parameterTabId.Value)
End Function
'*********************************************************************
'
' UpdateTab Method
'
' The UpdateTab method updates the settings for the specified tab.
'
' Other relevant sources:
' + UpdateTab Stored Procedure
'
'*********************************************************************
Public Sub UpdateTab(ByVal portalId As Integer, ByVal tabId As Integer, ByVal tabName As String, ByVal tabOrder As Integer, ByVal authorizedRoles As String, ByVal mobileTabName As String, ByVal showMobile As Boolean, ByVal ParentTabID As Integer)
' Create Instance of Connection and Command Object
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("UpdateTab", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterPortalId As New SqlParameter("@PortalId", SqlDbType.Int, 4)
parameterPortalId.Value = portalId
myCommand.Parameters.Add(parameterPortalId)
Dim parameterTabId As New SqlParameter("@TabId", SqlDbType.Int, 4)
parameterTabId.Value = tabId
myCommand.Parameters.Add(parameterTabId)
Dim parameterTabName As New SqlParameter("@TabName", SqlDbType.NVarChar, 50)
parameterTabName.Value = tabName
myCommand.Parameters.Add(parameterTabName)
Dim parameterTabOrder As New SqlParameter("@TabOrder", SqlDbType.Int, 4)
parameterTabOrder.Value = tabOrder
myCommand.Parameters.Add(parameterTabOrder)
'Added 8/19/02 THL - ParentTabID for child tabs
Dim parameterParentTabID As New SqlParameter("@ParentTabID", SqlDbType.Int, 4)
parameterParentTabID.Value = ParentTabID
myCommand.Parameters.Add(parameterParentTabID)
Dim parameterAuthRoles As New SqlParameter("@AuthorizedRoles", SqlDbType.NVarChar, 256)
parameterAuthRoles.Value = authorizedRoles
myCommand.Parameters.Add(parameterAuthRoles)
Dim parameterMobileTabName As New SqlParameter("@MobileTabName", SqlDbType.NVarChar, 50)
parameterMobileTabName.Value = mobileTabName
myCommand.Parameters.Add(parameterMobileTabName)
Dim parameterShowMobile As New SqlParameter("@ShowMobile", SqlDbType.Bit, 1)
parameterShowMobile.Value = showMobile
myCommand.Parameters.Add(parameterShowMobile)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
|
//Igor
|
|
|
|
|
| |
| Перейти к: |
|
|
|
|
|
|