Form打开时自动定位到上次关闭时的记录
做项目时客户提出这样一个需求:由于单据数量太多,希望打开Form时定位到上次关闭时查看的那条记录。于是乎查资料,看原代码,问同事。终于找到了解决方法。在此和大家一起来分享。(初次遇到这个问题,可能解决方案不是很好,请各位大虾提出宝贵的意见和建议
)
AX中提供了一个系统类xSysLastValue,分析其原代码我们发现他主要提供了两组保存和提取最后信息的方法:
1: getValue和putValue 2 :saveLast 和getLast 。
其实这两组代码实现的功能基本上是一样的,
putValue (saveLast)负责把记录保存起来,putValue(getLast )负责把保存的记录提取出来。
对比putValue (saveLast)
static public void putValue(
container _value,
CompanyId _company,
userId _userId,
UtilElementType _type,
identifiername _elementName,
identifiername _designName = ''
)
{
;
if (_elementName == '')
return;
classfactory.lastValuePut( _value,
_company,
_userId,
_type,
_elementName,
_designName);
}
static public void saveLast(Object caller)
{
;
if (caller.lastValueElementName() == '')
return;
classfactory.lastValuePut(caller.pack(),
caller.lastValueDataAreaId(),
caller.lastValueUserId(),
caller.lastValueType(),
caller.lastValueElementName(),
caller.lastValueDesignName());
}
我们发现他们唯一的区别就是传参方式不一样,putValue传入的是一组变量,而saveLast传入的是一个对象实例。而在功能实现中,putValue是直接将变量传给 classfactory.lastValuePut,而saveLast则是通过调用对象实例的特定方法实现的
(这就要求我们在使用saveLast时,对象中一定要先定义相关的方法)。
同样查看getValue(getLast)的代码
/*MAN
The method checks if a last choice exists.
*/
static public boolean existLast(Object caller)
{
container value;
if (caller.lastValueElementName() == '')
return false;
value = classfactory.lastValueGet(caller.lastValueDataAreaId(),
caller.lastValueUserId(),
caller.lastValueType(),
caller.lastValueElementName(),
caller.lastValueDesignName());
return conlen(value) > 0;
}
/*MAN
The method gets last choice.
Returns true if a last choice was found and unpacked
*/
static public boolean getLast(Object caller)
{
boolean initParm = true;
container value;
if (caller.lastValueElementName() == '')
return false;
value = classfactory.lastValueGet(caller.lastValueDataAreaId(),
caller.lastValueUserId(),
caller.lastValueType(),
caller.lastValueElementName(),
caller.lastValueDesignName());
if (value)
initParm = ! caller.unpack(value);
if (initParm)
caller.initParmDefault();
return !initParm;
} 发现他们的实现方式和putValue (saveLast)基本上是一样的。
没有找到classfactory.lastValuePut和classfactory.lastValueGet的定义,但是根据以往系统的实现方式,我们在系统表中找到了SysLastValue这张表,看表定义后我们就可以大胆的猜测classfactory.lastValuePut就是实现将参数插入表SysLastValue中。classfactory.lastValuePut中传入的第一个container 类型的参数就是我们要保留的当前信息。而classfactory.lastValueGet 就是将上次保存的container 取出来。由于是container 类型的,所有对我们开发就相当灵活,我们可以保存我们要的一切相关信息。
同样getValue(getLast)就是把我们保存的信息提出出来。
好了,到这里,客户提出的需求我们就可以迎刃而解了。。
1: 在Form关闭的时候记录当前信息(recid,salesid.....想记什么记什么)封装在一个container 中。然后调用类xSysLastValue中的静态方法保存在表SysLastValue中。
2:Form打开初始化时调用类xSysLastValue中的静态方法取出container 。剩下的时候就是解析,定位。。。。。
好了,大概就是这个样子了,其实在AX标准FORM里面经常会用到这个功能,比如Salestable,ProjTable.有兴趣的朋友可以一起研究![]()


浙公网安备 33010602011771号