You can access it by HttpContext.Current.Session(0)
Showing posts with label eXpressApp Framework. Show all posts
Showing posts with label eXpressApp Framework. Show all posts
Monday, March 4, 2019
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':
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:
- Override 'OnLoggingOn' Sub in 'WebApplication.vb'
- 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
- Create fake values for predefinedvalues using application model
- Create XAF view controller. i.e. PredefinedValuesController
- make it inherit from DevExpress.ExpressApp.ViewController(Of DetailView)
- override method Protected Overrides Sub OnActivated()
- Read PropertyEditor for required attribute.
i.e. Dim editor As ASPxStringPropertyEditor = TryCast(View.FindItem(AttributeName), ASPxStringPropertyEditor) - 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
- '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
- Create XAF ViewController that inherit from WebLinkUnlinkController Class
- Override Link or Unlink actions
Protected Overrides Sub Link(ByVal args As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) - Use the following code to access the current object
CType(Frame, NestedFrame).ViewItem.CurrentObject
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:
- Dim session As Session = CType(SecuritySystem.CurrentUser, User).Session
- session.ExecuteSproc("YourSqlProcedure").
- Dim paramsOperand As New List(Of OperandValue)
- Dim session As Session = CType(SecuritySystem.CurrentUser, User).Session
- Dim curUserOid As Guid = CType(SecuritySystem.CurrentUser, User).Oid
- paramsOperand.AddRange(New OperandValue() {curUserOid})
- session.ExecuteSproc("TransferThisPeriodBills", paramsOperand.ToArray)
Tuesday, July 3, 2012
XAF : Grouping of Report Data Based on Specific Field
To group report data based on specific field, you should follow the following steps
- Run XAF desktop application [note that report can't be modified from XAF web app.]
- Edit your report via XAF Report Designer
- Right mouse click then put mouse on Insert Band, after that click on GroupHeader.
Friday, May 4, 2012
XAF : Change Listview Default GroupSummary
The following steps will used to change group summary for Listview:
- Open model designer by click on application file Model.xafml under YourProject.Web
- Change GroupSummary Property as shown below:
- GroupSummary Format Structure {1}:{2},{3}:{4}
example : TotalPrivateCharge:Sum,TotalPrivateCharge:Sum={0:n2}
- Property Name
- Aggregation Function
- Property Name
- Aggregation String Format. [Sum={0:n2}]
- '0' means first argument which is TotalPrivateCharge
- 'n2' means the second argument which is aggregation function value.
- Result for this aggregation function is 'Sum=25.12'
Monday, April 30, 2012
XAF : Add Sequence (Serial) Number into a Report
In order to add sequence or serial number such that 1,2,3,4,...etc into a report in devexpress, you should follow the following steps
- Expand Label Tasks dialog
- Set Summary Function to Record Number, and Summary Running to Group
Monday, April 23, 2012
XAF : Show Reports for Individual Views
The Reports module allows you to design reports for a filtered data source. In some scenarios, you may need to preview a report for a certain object or a set of objects that are not related by a criteria. For example, the Invoice business object(s) should be able to be printed in a specific manner. In this case, a specially designed report should be available for display for a particular set of Invoice objects. For this purpose, use the Inplace Reporting feature provided by the Reports module. This topic demonstrates how to use this feature.
To show selected object(s) in a specified report, the Reports module introduces the ShowInReport Action. This Action represents the SingleChoiceAction class instance. Its items represent so-called inplace reports that are designed for the current View's object type.
Wednesday, April 11, 2012
XAF : Override ListView Default Action
In order to override list view default action, you should do the following
- Add view controller to your project [i.e. ListViewActionsController]
- make class (ListViewActionsController) inherit from DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController
- Override the function.[i.e. ProcessCurrentObject].
The following example present an example for this:
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:
11: Public Class ListViewActionsController Inherits
12: DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController
13:
14: Public Shared usrname As String
15: Public Sub New()
16: MyBase.New()
17:
18: 'This call is required by the Component Designer.
19: InitializeComponent()
20: RegisterActions(components)
21:
22: End Sub
23:
24: Protected Overrides Sub ProcessCurrentObject(ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
25: If (e.CurrentObject.GetType.Name = "PhoneHolder" And View.Id = "CustomHolderListView") Then
26: BillingSystem.Module.sharedMod.currentClickedUsername = CType(e.CurrentObject, PhoneHolder).UserName
27: End If
28:
29: MyBase.ProcessCurrentObject(e)
30: End Sub
31:
32: End Class
Thursday, April 5, 2012
XAF : Override DetailedView Action
In order to override detailed view action such as SaveAndClose, you should do the following
- Add view controller to your project [i.e. DefaultDetailViewActions]
- make class (DefaultDetailViewActions) inherit from WebDetailViewController
- Override the function.[i.e. SaveAndClose].
The following example present an example for override SaveAndClose function:
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:
11: Imports DevExpress.ExpressApp.Web.SystemModule
12: Public Class DefaultDetailViewActions
13: Inherits WebDetailViewController
14:
15: Public Sub New()
16: MyBase.New()
17:
18: 'This call is required by the Component Designer.
19: InitializeComponent()
20: RegisterActions(components)
21:
22: End Sub
23:
24: Protected Overrides Sub SaveAndClose(ByVal args As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
25: If args.CurrentObject.GetType.Name = "Calendar" Then
26: autoCalendarEntriesAddition(args)
27:
28: End If
29: MyBase.SaveAndClose(args)
30: End Sub
Monday, April 2, 2012
XAF : Replace Dropdown Listbox PropertyEditor With RadioGroup PropertyEditor
In order to change the default property editor from which is DropdownList control to RadioGroup control, first you should add the following file to your project folders [i.e. RadioGroupEnumPropertyEditor.vb]
1: Imports System
2: Imports System.Collections.Generic
3: Imports DevExpress.ExpressApp.Web.Editors
4: Imports System.Web.UI.WebControls
5: Imports DevExpress.ExpressApp.Utils
6: Imports DevExpress.ExpressApp
7: Imports DevExpress.ExpressApp.Model
8: Imports DevExpress.Web.ASPxEditors
9:
10: Imports System.ComponentModel
11:
12: Imports DevExpress.Xpo
13: Imports DevExpress.Data.Filtering
14:
15: Imports DevExpress.Persistent.Base
16: Imports DevExpress.Persistent.BaseImpl
17: Imports DevExpress.Persistent.Validation
18:
19: Imports DevExpress.ExpressApp.Editors
20:
21: <PropertyEditor(GetType(RadioButton), "CustomComboEditor", False)> _
22: Public Class CheckboxEnumPropertyEditor
23: Inherits WebPropertyEditor
24:
25: Private enumDescriptor As EnumDescriptor
26: Private controlsHash As New Dictionary(Of ASPxRadioButton, Object)()
27:
28: Public Sub New(ByVal objectType As Type, ByVal info As IModelMemberViewItem)
29: MyBase.New(objectType, info)
30: Me.enumDescriptor = New EnumDescriptor(MemberInfo.MemberType)
31:
32: End Sub
33:
34: Protected Overrides Function CreateEditModeControlCore() As WebControl
35: Dim placeHolder As New Panel()
36: controlsHash.Clear()
37: For Each enumValue As Object In enumDescriptor.Values
38: Dim radioButton As New ASPxRadioButton()
39: radioButton.ID = "radioButton_" + enumValue.ToString()
40: controlsHash.Add(radioButton, enumValue)
41: radioButton.Text = enumDescriptor.GetCaption(enumValue)
42: 'radioButton.CheckedChanged += New EventHandler(radioButton_CheckedChanged)
43: AddHandler radioButton.CheckedChanged, AddressOf radioButton_CheckedChanged
44: radioButton.GroupName = PropertyName
45: placeHolder.Controls.Add(radioButton)
46:
Sunday, April 1, 2012
XAF : Implement One-to-One Relationships
Let's consider a simple example of a One-to-One relationship, when both classes that participate in the relationship have properties with a reference to the instance of their opposite class. It's necessary to write extra code within the property's setter method for each class that participates in the relationship to ensure the relationship's integrity, i.e. when a new object is assigned to a reference property, the reference to the previous object instance should be cleared and the assigned object should reference the current one.
This technique can be implemented as shown in the following code example.
1: ' Represents the Building class which refers to the building's owner.
2: Public Class Building : Inherits XPObject
3: Dim _owner As Person = Nothing
4: Public Property Owner() As Person
5: Get
6: Return _owner
7: End Get
8: Set(ByVal Value As Person)
9: If _owner Is Value Then
10: Return
11: End If
12:
13: ' Store a reference to the former owner.
14: Dim prevOwner As Person = _owner
15: _owner = Value
16:
17: If IsLoading Then Return
18:
19: ' Remove an owner's reference to this building, if exists.
20: If Not (prevOwner Is Nothing) AndAlso prevOwner.House Is Me Then
21: prevOwner.House = Nothing
22: End If
23:
24: ' Specify that the building is a new owner's house.
25: If Not (_owner Is Nothing) Then
26: _owner.House = Me
27: End If
28:
29: OnChanged("Owner")
30:
31: End Set
32: End Property
33: End Class
34:
Saturday, March 17, 2012
XAF : Extend Built-in Property Editor's Functionality
This topic describes how to customize a built-in XAF Property Editor. The DatePropertyEditor will be customized to display date and time in the full format. The Property Editor control's dropdown will display the calendar and the clock in the Windows Vista style. The image below shows the resulting Property Editor:
Since the Property Editor inherits from the DatePropertyEditor class, which is the DXPropertyEditor class descendant, its settings can be accessed via the Repository Item. To apply the customization to the controls created both in the Detail View and List View, override the SetupRepositoryItem method. The PropertyEditor attribute is applied to the implemented Property Editor, to specify that it can be used for the String type properties:
1: Imports System
2:
3: Imports DevExpress.ExpressApp
4: Imports DevExpress.ExpressApp.Editors
5: Imports DevExpress.ExpressApp.Win.Editors
6: Imports DevExpress.ExpressApp.Model
7:
8: <PropertyEditor(GetType(DateTime), "CustomDateTimeEditor", False)> _
9: Public Class CustomDateTimeEditor
10: Inherits DatePropertyEditor
11: Public Sub New(ByVal objectType As Type, ByVal info As IModelMemberViewItem)
12: MyBase.New(objectType, info)
13: End Sub
14:
15: Protected Overrides Sub SetupRepositoryItem(ByVal item As DevExpress.XtraEditors.Repository.RepositoryItem)
16: MyBase.SetupRepositoryItem(item)
17: DirectCast(item, RepositoryItemDateTimeEdit).VistaDisplayMode = _
18: DevExpress.Utils.DefaultBoolean.[True]
19: DirectCast(item, RepositoryItemDateTimeEdit).VistaEditTime = _
20: DevExpress.Utils.DefaultBoolean.[True]
21: DirectCast(item, RepositoryItemDateTimeEdit).Mask.EditMask = _
22: "MM.dd.yyyy hh:mm:ss"
23: End Sub
24: End Class
25:
Tuesday, March 13, 2012
XAF : Set Default Property For Object Attribute
Here we will set a default value for a property of a business class, In this example we will set the default 'Priority' property in DemoTask to 'Normal' state. To do this, first we want to build DemoTask Class with 'Priority' property:
1: Public Class DemoTask
2: Inherits Task
3: ' ...
4: Private fPriority As Priority
5: Public Property Priority() As Priority
6: Get
7: Return fPriority
8: End Get
9: Set(ByVal value As Priority)
10: SetPropertyValue("Priority", fPriority, value)
11: End Set
12: End Property
13: '...
14: End Class
- 'Priority' property added to DemoTask class
Sunday, March 11, 2012
XAF : Implement One-to-Many Relationship
The following snippet of code present One-to-Many Relationship between Department and Contact business classes, in which Department object has many Contacts.
To implement the "One" part of the Department-Contacts relationship, decorate the Contact class Department property with the Association attribute.
To implement the "One" part of the Department-Contacts relationship, decorate the Contact class Department property with the Association attribute.
1: <DefaultClassOptions()> _
2: Public Class Contact
3: Inherits Person
4: '...
5: Private fDepartment As Department
6: <Association("Department-Contacts", GetType(Department))> _
7: Public Property Department() As Department
8: Get
9: Return fDepartment
10: End Get
11: Set(ByVal value As Department)
12: SetPropertyValue("Department", fDepartment, value)
13: End Set
14: End Property
15: '...
16: End Class
17:
18:
Saturday, March 10, 2012
XAF : Implement Many-to-Many Relationship
The following code snippet shows Many-to-Many Relationship between DemoTask and Contact business classes objects.
DemoTask Class:
1: Public Class DemoTask
2: Inherits Task
3: Public Sub New(ByVal session As Session)
4: MyBase.New(session)
5: End Sub
6: <Association("Contact-DemoTask", GetType(Contact))> _
7: Public ReadOnly Property Contacts() As XPCollection
8: Get
9: Return GetCollection("Contacts")
10: End Get
11: End Property
12: End Class
13:
14:
- The Association attribute is applied to the XPCollection type Contacts property, representing the collection of associated Contacts.
- The Association attribute is required when setting a relationship between objects
- The GetCollection method is used to return a collection in Contacts property getter implementation.
Friday, March 9, 2012
XAF : Building Domain Class
Business Class can be implemented in your application either from scratch by inherit your class from BaseObject or by using Business Class Library, which is contains the most common business classes such as Contact class which is include basic information about contact like FullName, SpouseName, FirstName and LastName. Note that only public members are mapped into database tables.
Create Business Class by inheriting from BaseObject:
Create Business Class by inheriting from BaseObject:
1: Imports System
2: Imports System.ComponentModel
3:
4: Imports DevExpress.Xpo
5: Imports DevExpress.Data.Filtering
6:
7: Imports DevExpress.ExpressApp
8: Imports DevExpress.Persistent.Base
9: Imports DevExpress.Persistent.BaseImpl
10: Imports DevExpress.Persistent.Validation
11:
12:
13: <DefaultClassOptions()> _
14: Public Class Department
15: Inherits BaseObject
16: <Association("DepartmentContacts", GetType(Contact))> Public ReadOnly Property
Contacts As XPCollection
17: Get
18: Return GetCollection("Contacts")
19: End Get
20: End Property
21: Private _departmentName As String
22: Public Property DepartmentName As String
23: Set(ByVal value As String)
24: SetPropertyValue("DepartmentName", Me._departmentName, value)
25: End Set
26: Get
27: Return Me._departmentName
28: End Get
29: End Property
30: Public Sub New(ByVal session As Session)
31: MyBase.New(session)
32: ' This constructor is used when an object is loaded from a persistent storage.
33: ' Do not place any code here or place it only when the IsLoading property is false:
34: ' if (!IsLoading){
35: ' It is now OK to place your initialization code here.
36: ' }
37: ' or as an alternative, move your initialization code into the AfterConstruction method.
38: End Sub
39: Public Overrides Sub AfterConstruction()
40: MyBase.AfterConstruction()
41: ' Place here your initialization code.
42: End Sub
43: End Class
Thursday, March 8, 2012
XAF : Business Classes vs Database Tables
In an application where you have to deal with information, you most likely have database tables, database systems, SQL queries, records and columns. Using relational models is a traditional way to work with databases. Today, the most common approach to database access is probably ADO.NET technology. It has the DataSet type that grants a local copy of multiple interrelated database tables. Via the DataSet object, a user can locally execute various operations, with the content of a database being physically disconnected from the DBMS.
The eXpressApp Framework (XAF) concentrates its efforts on another flow of today's development: object-oriented data handling. The need to store object-oriented data appeared when object-oriented programming became pervasive. Currently, most modern, nontrivial applications use an object-oriented paradigm to model application domains. This means that you can abstract from any persistence details, and have a clean, simple, object-oriented API to perform data storage. You do not need to handle persistence details and internal data representation in data stores be they relational, object-based, or something else. Why should you deal with low-level constructs of the data-store model, such as rows and columns, and constantly translate them back and forth? Instead, concentrate on complex applications you are required to deliver.
The ability to use object-based data handling, instead of direct interaction with databases, leads to a layer that provides mapping of objects into database tables (Object-Relational Mapping tool). In the XAF, such a layer is provided by the eXpress Persistent Objects (XPO). The XPO provides reliability and flexibility in storing the information. Its simplicity comes from the fact that you do not need to learn the details of how the data is stored.
Subscribe to:
Posts (Atom)