Intersoft.Client.UI.ScheduleView Namespace > UXScheduleView Class : CanUserDeleteItemCommand Property |
Besides the standard validation when committing changes during editing, UXScheduleView also provides interactive validation procedures that you can implement to limit certain interactive actions. Similar to handling the CUD operation, UXScheduleView also provides command-related properties that you can bind to your ViewModel. These command-related properties are listed as follows:
The following example shows how to utilize interactive commands in a real-world scenario:
For these interactive validation commands, you need to handle the logic in CanExecuteCommand method instead of the ExecuteCommand method. |
Interactive Validation |
Copy Code
|
---|---|
using System; using Intersoft.Client.Framework.Input; using Intersoft.Client.UI.ScheduleView; using UXScheduleView.Samples.Web; namespace UXScheduleView.Samples.ViewModels { public class InteractiveValidationViewModel : HospitalViewModel { #region Constructors public InteractiveValidationViewModel() { this.CanUserAddItemCommand = new DelegateCommand(ExecuteCanUserAddItem, CanUserAddItem); this.CanUserDeleteItemCommand = new DelegateCommand(ExecuteCanUserDeleteItem, CanUserDeleteItem); this.CanUserEditItemCommand = new DelegateCommand(ExecuteCanUserEditItem, CanUserEditItem); this.CanUserMoveItemCommand = new DelegateCommand(ExecuteCanUserMoveItem, CanUserMoveItem); this.CanUserResizeItemCommand = new DelegateCommand(ExecuteCanUserResizeItem, CanUserResizeItem); } #endregion #region Commands public DelegateCommand CanUserAddItemCommand { get; set; } public DelegateCommand CanUserDeleteItemCommand { get; set; } public DelegateCommand CanUserEditItemCommand { get; set; } public DelegateCommand CanUserMoveItemCommand { get; set; } public DelegateCommand CanUserResizeItemCommand { get; set; } #endregion #region Methods private bool IsWeekend(DateTime date) { return date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday; } // User can only add item to week days. private bool CanUserAddItem(object parameter) { object[] parameters = (object[])parameter; bool allDayEvent = (bool)parameters[0]; DateTime startDate = (DateTime)parameters[1]; DateTime endDate = (DateTime)parameters[2]; return !this.IsWeekend(startDate) && !this.IsWeekend(endDate); } // User can not delete item with resource id == 1 private bool CanUserDeleteItem(object parameter) { HospitalEvent evt = parameter as HospitalEvent; if (evt != null) { if (evt.ResourceID == 1) return false; } return true; } // User can not edit item with resource id == 1 private bool CanUserEditItem(object parameter) { HospitalEvent evt = parameter as HospitalEvent; if (evt != null) { if (evt.ResourceID == 1) return false; } return true; } // User can not move item to weekend private bool CanUserMoveItem(object parameter) { UXScheduleViewInteractiveData data = parameter as UXScheduleViewInteractiveData; if (data != null && data.TargetDate.HasValue) { HospitalEvent evt = data.EventModel.OriginalObject as HospitalEvent; if (evt != null) { if (evt.ResourceID == 1) return false; DateTime startDate = data.TargetDate.Value; TimeSpan diff = startDate - evt.StartDate; DateTime endDate = evt.EndDate.Add(diff); return !this.IsWeekend(startDate) && !this.IsWeekend(endDate); } } return true; } // User can not resize item to weekend private bool CanUserResizeItem(object parameter) { UXScheduleViewInteractiveData data = parameter as UXScheduleViewInteractiveData; if (data != null && data.TargetDate.HasValue) { HospitalEvent evt = data.EventModel.OriginalObject as HospitalEvent; if (evt != null) { if (evt.ResourceID == 1) return false; return !this.IsWeekend(data.TargetDate.Value); } } return true; } private void ExecuteCanUserAddItem(object parameter) { throw new NotImplementedException(); } private void ExecuteCanUserDeleteItem(object parameter) { throw new NotImplementedException(); } private void ExecuteCanUserEditItem(object parameter) { throw new NotImplementedException(); } private void ExecuteCanUserMoveItem(object parameter) { throw new NotImplementedException(); } private void ExecuteCanUserResizeItem(object parameter) { throw new NotImplementedException(); } #endregion } } |
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2