VB.NET酒店预订系统:获取ResourceTree单元格值并跳转至子调度器
酒店预订管理系统ResourceTree点击事件解决方案
一、正确获取ResourceTree选中的Room资源
RowCellClick事件中,e.CellValue通常是单元格的显示文本,而非绑定的Rooms实体对象。需通过TreeList的内置方法获取当前行绑定的数据:
场景1:ResourceTree绑定DataTable数据源
Private Sub ResourcesTree1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles ResourcesTree1.RowCellClick Try ' 获取当前点击行的DataRow Dim roomRow As DataRow = ResourcesTree1.GetDataRow(e.RowHandle) If roomRow IsNot Nothing Then ' 转换为Rooms实体(根据实际字段调整) Dim selectedRoom As Rooms = New Rooms() With { .RoomId = CInt(roomRow("RoomId")), .RoomName = roomRow("RoomName").ToString() } ' 获取对应预订数据并打开详情UC Dim roomBookings As List(Of Bookings) = GetRoomBookings(selectedRoom.RoomId) Me.ShowRoomDetails(selectedRoom, roomBookings, "Overview") End If Catch ex As Exception ' 添加异常日志便于排查 Debug.WriteLine($"点击事件出错:{ex.Message}") End Try End Sub
场景2:ResourceTree直接绑定List(Of Rooms)集合
Private Sub ResourcesTree1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles ResourcesTree1.RowCellClick Try ' 直接获取当前行绑定的Rooms实体 Dim selectedRoom As Rooms = TryCast(ResourcesTree1.GetRow(e.RowHandle), Rooms) If selectedRoom IsNot Nothing Then Dim roomBookings As List(Of Bookings) = GetRoomBookings(selectedRoom.RoomId) Me.ShowRoomDetails(selectedRoom, roomBookings, "Overview") End If Catch ex As Exception Debug.WriteLine($"点击事件出错:{ex.Message}") End Try End Sub
二、获取对应房间的预订数据
实现GetRoomBookings方法,根据房间ID筛选预订数据。若数据存储在Scheduler控件的Appointments集合中,可通过自定义字段过滤:
Private Function GetRoomBookings(roomId As Integer) As List(Of Bookings) Dim bookings As New List(Of Bookings)() ' 遍历Scheduler的所有预约,筛选当前房间的记录 For Each apt As Appointment In SchedulerControl1.Storage.Appointments.Items If apt.CustomFields("RoomId") IsNot Nothing AndAlso CInt(apt.CustomFields("RoomId")) = roomId Then bookings.Add(New Bookings() With { .BookingId = apt.Id, .StartDate = apt.Start, .EndDate = apt.End, .GuestName = apt.Subject, .RoomId = roomId ' 补充其他预订属性 }) End If Next Return bookings End Function
三、子UC调度器的专属资源展示
在子UC中添加初始化方法,仅加载选中房间的资源和预订:
' 子UC的初始化方法 Public Sub LoadRoomSchedule(selectedRoom As Rooms, bookings As List(Of Bookings)) ' 清空原有数据 SchedulerUC.Storage.Resources.Items.Clear() SchedulerUC.Storage.Appointments.Items.Clear() ' 添加选中房间为唯一资源 Dim roomResource As Resource = SchedulerUC.Storage.Resources.CreateResource(selectedRoom.RoomId) roomResource.Caption = selectedRoom.RoomName roomResource.CustomFields("RoomId") = selectedRoom.RoomId SchedulerUC.Storage.Resources.Items.Add(roomResource) ' 加载该房间的预订 For Each booking In bookings Dim apt As Appointment = SchedulerUC.Storage.Appointments.CreateAppointment(AppointmentType.Normal) apt.Start = booking.StartDate apt.End = booking.EndDate apt.Subject = booking.GuestName apt.ResourceId = selectedRoom.RoomId SchedulerUC.Storage.Appointments.Items.Add(apt) Next ' 强制筛选,仅显示当前房间的预约 SchedulerUC.ActiveView.FilterString = $"[ResourceId] = {selectedRoom.RoomId}" End Sub
内容的提问来源于stack exchange,提问作者Blaiso Talla
相关产品推荐
相关产品推荐

