Intersoft ClientUI Documentation
CanUserDeleteItemCommand Property
See Also  Send Feedback
Intersoft.Client.UI.ScheduleView Namespace > UXScheduleView Class : CanUserDeleteItemCommand Property






Gets or sets a command that invoked when user is deleting an event.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Action")>
<TypeConverterAttribute("Intersoft.Client.Framework.Input.CommandConverter, Intersoft.Client.Framework, Version=3.0.5000.1, Culture=neutral, PublicKeyToken=c3d9b11444163e76")>
Public Property CanUserDeleteItemCommand As ICommand
Visual Basic (Usage)Copy Code
Dim instance As UXScheduleView
Dim value As ICommand
 
instance.CanUserDeleteItemCommand = value
 
value = instance.CanUserDeleteItemCommand
C# 
[CategoryAttribute("Action")]
[TypeConverterAttribute("Intersoft.Client.Framework.Input.CommandConverter, Intersoft.Client.Framework, Version=3.0.5000.1, Culture=neutral, PublicKeyToken=c3d9b11444163e76")]
public ICommand CanUserDeleteItemCommand {get; set;}
Delphi 
public read-write property CanUserDeleteItemCommand: ICommand; 
JScript 
CategoryAttribute("Action")
TypeConverterAttribute("Intersoft.Client.Framework.Input.CommandConverter, Intersoft.Client.Framework, Version=3.0.5000.1, Culture=neutral, PublicKeyToken=c3d9b11444163e76")
public function get,set CanUserDeleteItemCommand : ICommand
Managed Extensions for C++ 
[CategoryAttribute("Action")]
[TypeConverterAttribute("Intersoft.Client.Framework.Input.CommandConverter, Intersoft.Client.Framework, Version=3.0.5000.1, Culture=neutral, PublicKeyToken=c3d9b11444163e76")]
public: __property ICommand* get_CanUserDeleteItemCommand();
public: __property void set_CanUserDeleteItemCommand( 
   ICommand* value
);
C++/CLI 
[CategoryAttribute("Action")]
[TypeConverterAttribute("Intersoft.Client.Framework.Input.CommandConverter, Intersoft.Client.Framework, Version=3.0.5000.1, Culture=neutral, PublicKeyToken=c3d9b11444163e76")]
public:
property ICommand^ CanUserDeleteItemCommand {
   ICommand^ get();
   void set (    ICommand^ value);
}

Example

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
    }
}

Remarks

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:

  • CanUserAddItemCommand
    Called when the user is about to insert a new item using inline editing.
  • CanUserDeleteItemCommand
    Called when the user is about to delete a single item or collection of item.
  • CanUserEditItemCommand
    Called when the user is about to edit an item using inline editing.
  • CanUserMoveItemCommand
    Called when the user is about to move an item to certain area.
  • CanUserResizeItemCommand
    Called when the user is about to resize the item to certain area.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.