Ads 468x60px

Wednesday, April 10, 2013

XAF : Display Collection Properties in an Edit Mode Detail View for an ASP.NET Application

To display collection properties when we have 1-M relation between two classes 'ClassA' and 'ClassB':

  1. Override 'OnLoggingOn' Sub in 'WebApplication.vb'
  2. add this statement to the sub
    CType(MyBase.ShowViewStrategy, ShowViewStrategy).CollectionsEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit


Collection properties will be displayed in both the View and Edit modes. Collection properties will be editable in Edit mode and read-only in View mode:


Saturday, March 2, 2013

XAF : Set PredefinedValues from the code

  1. Create fake values for predefinedvalues using application model
  2. Create XAF view controller. i.e. PredefinedValuesController
  3. make it inherit from DevExpress.ExpressApp.ViewController(Of DetailView)
  4. override method Protected Overrides Sub OnActivated()
  5. Read PropertyEditor for required attribute.
    i.e. Dim editor As ASPxStringPropertyEditor = TryCast(View.FindItem(AttributeName), ASPxStringPropertyEditor)
  6. then, add the values to the editor
    - Dim control As ASPxComboBox = TryCast(editor, ASPxComboBox)
    -         If control IsNot Nothing Then
    -            AddHandler control.Load, Sub(s, e)
    -            control.Items.Clear()
    -            control.Items.Add("item 1")
    -            control.Items.Add("item 2")
    -       End Sub
    -       End If
Full Example:
- 'MobileDevice' is the name of buisness object
- GetPredefinedValues is an SqlServer Procedure that gets all distinct values for a business object attribute.
  in our example business object is 'MobileDevice' and the attribute is 'IMEI'
 
 

CREATE PROCEDURE [dbo].[GetPredefinedValues]
    -- Add the parameters for the stored procedure here
    @tbl nvarchar(200)
    , @col nvarchar(200)
AS
BEGIN
 
    declare @sql nvarchar(400)
    set @sql = 'SELECT DISTINCT '+@col+' FROM '+@tbl+' WHERE '+@col+' IS NOT NULL ORDER BY '+@col
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    print @sql
exec     sp_executesql @sql
    SET NOCOUNT ON;
 
    -- Insert statements for procedure here
END



   1:  Imports System
   2:  Imports System.ComponentModel
   3:  Imports System.Collections.Generic
   4:  Imports System.Diagnostics
   5:  Imports System.Text
   6:   
   7:  Imports DevExpress.ExpressApp
   8:  Imports DevExpress.ExpressApp.Actions
   9:  Imports DevExpress.Persistent.Base
  10:  Imports DevExpress.ExpressApp.Web.Editors.ASPx
  11:  Imports DevExpress.Web.ASPxEditors
  12:  Imports DevExpress.Persistent.BaseImpl
  13:  Imports DevExpress.Xpo
  14:  Imports DevExpress.Data.Filtering
  15:  Imports BillingSystem.Module.Devices
  16:   
  17:  Public Class PredefinedValuesController
  18:      Inherits DevExpress.ExpressApp.ViewController(Of DetailView)
  19:   
  20:      Public Sub New()
  21:          MyBase.New()
  22:   
  23:          'This call is required by the Component Designer.
  24:          InitializeComponent()
  25:          RegisterActions(components)
  26:   
  27:      End Sub
  28:   
  29:     
  30:   
  31:      Protected Overrides Sub OnActivated()
  32:          MyBase.OnActivated()
  33:          ' to add for more values we
  34:          If TypeOf View.CurrentObject Is MobileDevice Then
  35:              SetPreDefinedValues("MobileDevice", "IMEI")
  36:   
  37:          End If
  38:   
  39:      End Sub
  40:    
  41:      Private Sub SetPreDefinedValues(ByVal tableName As String, ByVal columnName As String)
  42:          Dim editor As ASPxStringPropertyEditor = TryCast(View.FindItem(columnName), ASPxStringPropertyEditor)
  43:          If editor IsNot Nothing AndAlso View.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit Then
  44:              If editor.Control IsNot Nothing Then
  45:                  Customize(editor.Editor, tableName, columnName)
  46:              Else
  47:                  AddHandler editor.ControlCreated, Sub(s, e) Customize(editor.Editor, tableName, columnName)
  48:              End If
  49:          End If
  50:      End Sub
  51:   
  52:      Private Sub Customize(ByVal p As Object, ByVal tableName As String, ByVal columnName As String)
  53:          Dim control As ASPxComboBox = TryCast(p, ASPxComboBox)
  54:          If control IsNot Nothing Then
  55:              AddHandler control.Load, Sub(s, e)
  56:                                           control.Items.Clear()
  57:                                           For Each item As String In GetPredefinedValuesFromTableColumn(tableName, columnName)
  58:                                               control.Items.Add(item)
  59:                                           Next
  60:                                       End Sub
  61:          End If
  62:      End Sub
  63:      Private Function GetPredefinedValuesFromTableColumn(ByVal tableName As String, ByVal columnName As String) As List(Of String)
  64:          Dim paramsOperand As New List(Of OperandValue)
  65:          paramsOperand.AddRange(New OperandValue() {tableName, columnName})
  66:          Dim session As Session = CType(SecuritySystem.CurrentUser, User).Session
  67:          Dim res As DB.SelectedData = session.ExecuteSproc("GetPredefinedValues", paramsOperand.ToArray)
  68:          Dim result As New List(Of String)
  69:          For Each row As DB.SelectStatementResultRow In res.ResultSet(0).Rows
  70:              result.Add(row.Values(0).ToString())
  71:          Next
  72:          Return result
  73:   
  74:      End Function
  75:   
  76:   
  77:  End Class

Wednesday, February 27, 2013

XAF : Remove HyperLinks between objects

  • Create custom property by descend from the ASPxLookupPropertyEditor class
  • decide class object in which this custom property will use for.
  • override ShowLink property and make it return value of '0' as below example

Imports DevExpress.ExpressApp.Web.Editors.ASPx
Imports DevExpress.ExpressApp.Model

<DevExpress.ExpressApp.Editors.PropertyEditor(GetType(YourBusinessClass), False)> _
Public Class CustomASPxLookupPropertyEditor
    Inherits ASPxLookupPropertyEditor

    Public Sub New(ByVal objectType As Type, ByVal info As IModelMemberViewItem)
        MyBase.New(objectType, info)

    End Sub
    Protected Overrides Function CanShowLink() As Boolean
        Return False ' MyBase.CanShowLink()
    End Function

End Class

Tuesday, February 19, 2013

XAF : Access current object when override Link or UnLink actions

To do this, follow the following steps
  1. Create XAF ViewController that inherit from WebLinkUnlinkController Class
  2. Override Link or Unlink actions
    Protected Overrides Sub Link(ByVal args As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs)
  3. Use the following code to access the current object
    CType(Frame, NestedFrame).ViewItem.CurrentObject
Code:

   1:  Imports System
   2:  Imports System.ComponentModel
   3:  Imports System.Collections.Generic
   4:  Imports System.Diagnostics
   5:  Imports System.Text
   6:   
   7:  Imports DevExpress.ExpressApp
   8:  Imports DevExpress.ExpressApp.Actions
   9:  Imports DevExpress.Persistent.Base
  10:  Imports DevExpress.ExpressApp.SystemModule
  11:  Imports DevExpress.Persistent.BaseImpl
  12:  Imports DevExpress.Data.Filtering
  13:  Imports DevExpress.ExpressApp.Web.SystemModule
  14:   
  15:  Public Class CustomLinkUnlinkViewController
  16:      Inherits WebLinkUnlinkController
  17:   
  18:      Public Sub New()
  19:          MyBase.New()
  20:   
  21:          'This call is required by the Component Designer.
  22:          InitializeComponent()
  23:          RegisterActions(components)
  24:   
  25:      End Sub
  26:   
  27:      Protected Overrides Sub OnActivated()
  28:          'Dim target As LinkUnlinkController = Frame.GetController(Of LinkUnlinkController)()
  29:          ' target.LinkAction.Active.SetItemValue("LinkAction", False)
  30:          ' target.UnlinkAction.Active.SetItemValue("UnlinkAction", False)
  31:          'InputBox("", "", View.Id)
  32:          MyBase.OnActivated()
  33:      End Sub
  34:   
  35:      Protected Overrides Sub Link(ByVal args As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs)
  36:          MyBase.Link(args)
  37:   
  38:      End Sub
  39:   
  40:   
  41:   
  42:  End Class

Monday, January 28, 2013

XAF : Execute SQL Procedure within Controller

Simply you can access session object via current user object, then you'll have full access to all functions in this object. To do this:
  1. Dim session As Session = CType(SecuritySystem.CurrentUser, User).Session
  2. session.ExecuteSproc("YourSqlProcedure").
another example:
  1. Dim paramsOperand As New List(Of OperandValue)
  2. Dim session As Session = CType(SecuritySystem.CurrentUser, User).Session
  3. Dim curUserOid As Guid = CType(SecuritySystem.CurrentUser, User).Oid
  4. paramsOperand.AddRange(New OperandValue() {curUserOid})
  5. session.ExecuteSproc("TransferThisPeriodBills", paramsOperand.ToArray)