6.0以上的版本中,平台内置构件提供了编辑的数据加锁控制,可以通过参数配置开启改加锁功能。
例如卡片界面:在集成开发环境中打开需要加锁的单据界面,点击“动作管理”打开动作管理界面,在“构件管理”Tab页中选择单据的编辑方法对应的构件控制器,设置扩展属性“IsUseDataLock”为true。如下图:
由于平台内置构件中的编辑方法处理了加锁机制,所以直接设置该属性即可。如果是完全自己实现的方法,则需要自行调用加锁接口。
注意:操作前加锁,操作完成解锁。(例如对于编辑操作就是编辑前加锁,取消编辑、保存后解锁。)
下面以演示构件控制器中的编辑加锁方法:
public override void BeforeEdit()
{
base.BeforeEdit();
//不是新增的编辑且使用锁,则处理之
this.AddLockInEdit(this.DataIDOfCard);
}
///
/// 加锁
///
/// 数据Id
///
protected virtual void AddLockInEdit(string psDataId)
{
//不是新增的编辑且使用锁,则处理之
if (this.CompContext.IsBeginAdding == false
&& this.Ext_IsUseDataLock == true)
{
Boolean vbRtn = this.AddLock(psDataId);
if (!vbRtn)
{
string msg = this.CompContext.Session.FuncID;
DialogResult dialogResult
= UMessageBox.Information("此数据已被其他人锁定,不能被编辑!", "提示!");
this.CompContext.IsActionCanceled = true;
}
}
}
保存后解锁:
public virtual void AfterSave()
{
this.FormHandler.AfterSave();
//解锁
this.RemoveLockAfterSave();
}
///
/// 解锁
///
protected virtual void RemoveLockAfterSave()
{
if (this.Ext_IsUseDataLock == true)
{
string lockId = string.Empty;
if (this.CompContext.DataLockIds.Count > 0)
{
lockId = this.CompContext.DataLockIds[0];
this.CompContext.DataLockIds.RemoveAt(0);
this.RemoveLockByLockId(lockId);
}
}
}