Private _conn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString) |
|
Private ReadOnly Property CurrentDockStates() As List(Of DockState) |
Get |
'Get saved state string from the database - set it to dockState variable for example |
Dim dockStatesFromDB As String = "" |
|
_conn.Open() |
Dim command As New SqlCommand("select State from States where id='" + Me.DropDownList1.SelectedValue.ToString + "'", _conn) |
dockStatesFromDB = command.ExecuteScalar().ToString() |
_conn.Close() |
|
Dim _currentDockStates As New List(Of DockState)() |
Dim stringStates As String() = dockStatesFromDB.Split("|"c) |
For Each stringState As String In stringStates |
If stringState.Trim() <> String.Empty Then |
_currentDockStates.Add(DockState.Deserialize(stringState)) |
End If |
Next |
Return _currentDockStates |
End Get |
End Property |
|
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init |
|
'Recreate the docks in order to ensure their proper operation |
Dim i As Integer = 0 |
While i < CurrentDockStates.Count |
If CurrentDockStates(i).Closed = False Then |
Dim dock As RadDock = CreateRadDockFromState(CurrentDockStates(i)) |
'We will just add the RadDock control to the RadDockLayout. |
' You could use any other control for that purpose, just ensure |
' that it is inside the RadDockLayout control. |
' The RadDockLayout control will automatically move the RadDock |
' controls to their corresponding zone in the LoadDockLayout |
' event (see below). |
|
'We want to save the dock state every time a dock is moved. |
CreateSaveStateTrigger(dock) |
'Load the selected widget |
LoadWidget(dock) |
|
RadDockLayout1.Controls.Add(dock) |
End If |
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) |
End While |
End Sub |
|
Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) |
'Populate the event args with the state information. The RadDockLayout control |
' will automatically move the docks according that information. |
For Each state As DockState In CurrentDockStates |
e.Positions(state.UniqueName) = state.DockZoneID |
e.Indices(state.UniqueName) = state.Index |
Next |
End Sub |
|
Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) |
Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState() |
Dim serializedList As New StringBuilder() |
Dim i As Integer = 0 |
|
While i < stateList.Count |
serializedList.Append(stateList(i).ToString()) |
serializedList.Append("|") |
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) |
End While |
|
Dim dockState As String = serializedList.ToString() |
If dockState.Trim() <> [String].Empty Then |
_conn.Open() |
Dim command As New SqlCommand([String].Format("update States set State='{0}' where id='" + Me.DropDownList1.SelectedValue.ToString + "'", dockState), _conn) |
command.ExecuteNonQuery() |
_conn.Close() |
End If |
End Sub |
|
Private Function CreateRadDockFromState(ByVal state As DockState) As RadDock |
Dim dock As New RadDock() |
dock.DockMode = DockMode.Docked |
dock.ID = String.Format("RadDock{0}", state.UniqueName) |
dock.ApplyState(state) |
dock.EnableAnimation = True |
|
dock.Commands.Add(New DockCloseCommand) |
dock.Commands.Add(New DockExpandCollapseCommand()) |
|
Return dock |
End Function |
|
Private Function CreateRadDock() As RadDock |
Dim docksCount As Integer = CurrentDockStates.Count |
|
Dim dock As New RadDock() |
dock.DockMode = DockMode.Docked |
dock.UniqueName = Guid.NewGuid().ToString() |
dock.ID = String.Format("RadDock{0}", dock.UniqueName) |
dock.Title = Replace(Replace(DroptDownWidget.SelectedItem.Text, ".ascx", ""), "_", " ") |
dock.EnableAnimation = True |
|
dock.Text = String.Format("Added at {0}", DateTime.Now) |
dock.Width = Unit.Pixel(386) |
|
dock.Commands.Add(New DockCloseCommand()) |
dock.Commands.Add(New DockExpandCollapseCommand()) |
dock.CommandsAutoPostBack = True |
|
Return dock |
End Function |
|
Private Sub CreateSaveStateTrigger(ByVal dock As RadDock) |
'Ensure that the RadDock control will initiate postback |
' when its position changes on the client or any of the commands is clicked. |
'Using the trigger we will "ajaxify" that postback. |
dock.AutoPostBack = True |
dock.CommandsAutoPostBack = True |
|
Dim updatedControl As New AjaxUpdatedControl() |
updatedControl.ControlID = "Panel1" |
|
Dim setting1 As New AjaxSetting(dock.ID) |
setting1.EventName = "DockPositionChanged" |
setting1.UpdatedControls.Add(updatedControl) |
|
Dim setting2 As New AjaxSetting(dock.ID) |
setting2.EventName = "Command" |
setting2.UpdatedControls.Add(updatedControl) |
|
RadAjaxManager1.AjaxSettings.Add(setting1) |
RadAjaxManager1.AjaxSettings.Add(setting2) |
|
|
End Sub |
|
Private Sub LoadWidget(ByVal dock As RadDock) |
If String.IsNullOrEmpty(dock.Tag) Then |
Return |
End If |
Dim widget As Control = LoadControl(dock.Tag) |
dock.ContentContainer.Controls.Add(widget) |
End Sub |
|
Protected Sub ButtonAddDock_Click(ByVal sender As Object, ByVal e As EventArgs) |
Dim dock As RadDock = CreateRadDock() |
'find the target zone and add the new dock there |
Dim dz As RadDockZone = DirectCast(XMLUtilities.FindControlRecursive(Master, "RadDockZone1"), RadDockZone) |
|
dz.Controls.Add(dock) |
|
CreateSaveStateTrigger(dock) |
|
'Load the selected widget in the RadDock control |
dock.Tag = DroptDownWidget.SelectedValue |
|
LoadWidget(dock) |
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "MoveDock", String.Format("function _moveDock() {{" & vbCr & vbLf & vbTab & vbTab & vbTab & " " & vbTab & "Sys.Application.remove_load(_moveDock);" & vbCr & vbLf & vbTab & vbTab & vbTab & vbTab & " $find('{1}').dock($find('{0}'),{2});" & vbCr & vbLf & vbTab & vbTab & vbTab & " }};" & vbCr & vbLf & vbTab & vbTab & vbTab & " Sys.Application.add_load(_moveDock);", "$find('<%= RadDock1.ClientID %>');", "RadDockZone1", dz.Docks.Count), True) |
|
End Sub |