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
31: Private Sub autoCalendarEntriesAddition(ByRef args As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
32: Dim f As Boolean = False
33: Dim currentCalendar As Calendar = CType(args.CurrentObject, Calendar)
34:
35: If currentCalendar.CalendarEntries Is Nothing Then
36: f = True
37: Else
38: If currentCalendar.CalendarEntries.Count = 0 Then
39: f = True
40: End If
41: End If
42:
43: If f Then
44: Dim days As New List(Of WeekDay)
45: days.AddRange(New WeekDay() {WeekDay.Monday, WeekDay.Tuesday, WeekDay.Wednesday, WeekDay.Thursday, WeekDay.Friday, WeekDay.Saturday, WeekDay.Sunday})
46: For Each dayobj As WeekDay In days
47: Dim ce As CalendarEntry = ObjectSpace.CreateObject(Of CalendarEntry)()
48: ce.Day = dayobj
49: ce.StartWorkingHour = New TimeSpan(7, 30, 0)
50: ce.EndWorkingHour = New TimeSpan(14, 45, 0)
51: If dayobj = WeekDay.Saturday Or dayobj = WeekDay.Sunday Then
52: ce.IsWeekEnd = True
53: Else
54: ce.IsWeekEnd = False
55: End If
56: ce.Save()
57: currentCalendar.CalendarEntries.Add(ce)
58: currentCalendar.Save()
59: Next
60: End If
61: End Sub
62: Protected Overrides Sub Save(ByVal args As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
63: If args.CurrentObject.GetType.Name = "Calendar" Then
64: autoCalendarEntriesAddition(args)
65:
66: End If
67: MyBase.Save(args)
68: End Sub
69:
70: End Class
Calendar Class:
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: <DefaultClassOptions()> _
13: Public Class Calendar
14: Inherits BaseObject
15: Private fCalendarName As String
16: Public Property CalendarName As String
17: Get
18: Return fCalendarName
19: End Get
20: Set(ByVal value As String)
21: SetPropertyValue("CalendarName", Me.fCalendarName, value)
22: End Set
23: End Property
24: <Association("Calendar-CalendarEntries", GetType(CalendarEntry))> _
25: Public ReadOnly Property CalendarEntries As XPCollection
26: Get
27: Return GetCollection("CalendarEntries")
28: End Get
29: End Property
30: Public Sub New(ByVal session As Session)
31: MyBase.New(session)
32: End Sub
33: Public Overrides Sub AfterConstruction()
34: MyBase.AfterConstruction()
35: ' Place here your initialization code.
36: End Sub
37:
38: Public Sub addEntry(ByVal entry As CalendarEntry)
39: GetCollection("CalendarEntries").Add(entry)
40: End Sub
41: End Class
Calendar Entry Class:
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: <DefaultClassOptions()> _
13: Public Class CalendarEntry
14: Inherits BaseObject
15: Private fday As WeekDay
16: Private fisWeekEnd As Boolean
17: Private fStartWorkingHour As TimeSpan
18: Private fEndWorkingHour As TimeSpan
19: Private fCalendar As Calendar
20:
21: <Association("Calendar-CalendarEntries", GetType(Calendar))> _
22: Public Property Calendar As Calendar
23: Get
24: Return fCalendar
25: End Get
26: Set(ByVal value As Calendar)
27: SetPropertyValue("Calendar", Me.fCalendar, value)
28: End Set
29: End Property
30:
31: Public Property Day As WeekDay
32: Get
33: Return fday
34: End Get
35: Set(ByVal value As WeekDay)
36: SetPropertyValue("Day", Me.fday, value)
37: End Set
38: End Property
39:
40: Public Property IsWeekEnd As Boolean
41: Get
42: Return fisWeekEnd
43: End Get
44: Set(ByVal value As Boolean)
45: SetPropertyValue("IsWeekEnd", Me.fisWeekEnd, value)
46: End Set
47: End Property
48:
49: Public Property StartWorkingHour As TimeSpan
50: Get
51: Return fStartWorkingHour
52: End Get
53: Set(ByVal value As TimeSpan)
54: SetPropertyValue("StartWorkingHour", Me.fStartWorkingHour, value)
55: End Set
56: End Property
57:
58: Public Property EndWorkingHour As TimeSpan
59: Get
60: Return fEndWorkingHour
61: End Get
62: Set(ByVal value As TimeSpan)
63: SetPropertyValue("EndWorkingHour", Me.fEndWorkingHour, value)
64: End Set
65: End Property
66: Public Sub New(ByVal session As Session)
67: MyBase.New(session)
68: End Sub
69: Public Overrides Sub AfterConstruction()
70: MyBase.AfterConstruction()
71: ' Place here your initialization code.
72: End Sub
73: End Class
74: Public Enum WeekDay
75: Monday
76: Tuesday
77: Wednesday
78: Thursday
79: Friday
80: Saturday
81: Sunday
82: End Enum
No comments:
Post a Comment