CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Prevent Operation for Individual Records via Editable Grid.

This example shows how to prevent an operation (Insert, Update, Delete) for individual records via Editable Grid. In this case, we have an Editable Grid called 'Tasks' which is based on the 'tasks' database table.

When the Editable Grid is submitted, corresponding events are called for each record. Insert will not be performed if the user assigns the task to himself or herself. If the current user is not the one who the task is assigned to, the Update operation for this record is not performed. If the user is not the one who assigned the task, the Delete operation is not performed.

In this example, we have a Tasks Editable Grid.

  1. Add the Before Execute Insert event to the Editable Grid
  2. Add the Before Execute Update event to the Editable Grid
  3. Add the Before Execute Delete event to the Editable Grid
  4. Within the events, add the code below:

ASP

Function Tasks_DataSource_BeforeExecuteInsert(Sender) 
  If CCGetUserID() = Tasks.user_id_assign_to.Value Then  
     Tasks.DataSource.CmdExecution = false
  End if
End Function

Function Tasks_DataSource_BeforeExecuteUpdate(Sender) 
  If CCGetUserID() <> Tasks.user_id_assign_to.Value Then 
     Tasks.DataSource.CmdExecution = false
  End if
End Function

Function Tasks_DataSource_BeforeExecuteDelete(Sender) 
  If CCGetUserID() <> Tasks.user_id_assign_by.Value Then 
     Tasks.DataSource.CmdExecution = false
  End if
End Function

PHP

function Tasks_DataSource_BeforeExecuteInsert(& $sender)  {
  global $Tasks;
   if (CCGetUserID() == $Tasks->user_id_assign_to->GetValue()) { 
   $Tasks->DataSource->CmdExecution = false;
  }
}

function Tasks_DataSource_BeforeExecuteUpdate(& $sender)  {
global $Tasks;
   if (CCGetUserID() != $Tasks->user_id_assign_to->GetValue()) { 
   $Tasks->DataSource->CmdExecution = false;
  }
}

function Tasks_DataSource_BeforeExecuteDelete(& $sender)  {
global $Tasks;
   if (CCGetUserID() != $Tasks->user_id_assign_by->GetValue()) { 
   $Tasks->DataSource->CmdExecution = false;
  }
}

Perl

sub Tasks_DataSource_BeforeExecuteInsert()  {
   if (CCGetUserID() == $Tasks->{user_id_assign_to}->GetValue()) { 
   $Tasks->{DataSource}->{CmdExecution} = 0;
  }
}

sub Tasks_DataSource_BeforeExecuteUpdate()  {
   if (CCGetUserID() <> $Tasks->{user_id_assign_to}->GetValue()) { 
   $Tasks->{DataSource}->{CmdExecution} = 0;
  }
}

sub Tasks_DataSource_BeforeExecuteDelete()  {
   if (CCGetUserID() != $Tasks->{user_id_assign_by}->GetValue()) { 
   $Tasks->{DataSource}->{CmdExecution} = 0;
  }
}

ColdFusion

<!--- Tasks_BeforeExecuteInsert --->
<CFIF Session.UserID EQ flduser_id_assign_to> 
  <CFSET endOperationTasks=True>
</CFIF>

<!--- Tasks_BeforeExecuteUpdate --->
<CFIF Session.UserID NEQ flduser_id_assign_to> 
  <CFSET endOperationTasks=True>
</CFIF>

<!--- Tasks_BeforeExecuteDelete --->
<CFIF Session.UserID NEQ flduser_id_assign_to> 
  <CFSET endOperationTasks=True>
</CFIF>

 

Java

//Tasks_BeforeExecuteUpdate
Object ctrlValue = e.getEditableGrid().getControl("user_id_assign_to").getFormattedValue();
String user_id = Utils.getUserId(e.getPage());
if (user_id == null || !user_id.equals(ctrlValue)) {
  e.getCommand().setCmdExecution(false);
}

//Tasks_BeforeExecuteDelete
Object ctrlValue = e.getEditableGrid().getControl("user_id_assign_to").getFormattedValue();
String user_id = Utils.getUserId(e.getPage());
if (user_id == null || !user_id.equals(ctrlValue)) {
  e.getCommand().setCmdExecution(false);
} 

VB.Net

'Tasks_BeforeExecuteUpdate
If DBUtility.UserID = item.user_id_assign_to.Value Then
  CmdExecution = False
End If

'Tasks_BeforeExecuteDelete
If DBUtility.UserID = item.user_id_assign_to.Value Then
  CmdExecution = False
End If

'Tasks_BeforeExecuteInsert
If DBUtility.UserID = item.user_id_assign_to.Value Then
  CmdExecution = False
End If

C#

//Tasks_BeforeExecuteUpdate
if(DBUtility.UserId == item.user_id_assign_to.Value)
  CmdExecution = false;

//Tasks_BeforeExecuteDelete
if(DBUtility.UserId == item.user_id_assign_to.Value)
  CmdExecution = false;

//Tasks_BeforeExecuteInsert
if(DBUtility.UserId == item.user_id_assign_to.Value)
  CmdExecution = false;

See Also:

Before Execute Insert event,
Before Execute Update event,
Before Execute Delete event


On-line, printable versions and updates