在开发应用程序过程中编写Script是件很烦人的事情其实我们可以把常用的Script装成相应的NET组件在服务端调用这样可以大大简化Script的编写还提高的Script的重用
以下是常用的打开模式窗体并获取返回值的类调用实际上可以给设置多个参数传入和不同控件获取不同返回值的结果.
定义打开窗体并设置返回值脚本类
HFSoftWebScriptsShowModalDialog dialog=new HFSoftWebScriptsShowModalDialog(
XXXUnitsConfigWebBoot+Appunit/WindowOpenDialogaspx
FrmFailureLogSearchPageURI());
dialogHeight=;
dialogWidth=;
dialogReturnElementsAdd(new HFSoftWebScriptsReturnElement(thistxtReturnClientIDReturnString));
HFSoftWebScriptsReGISterScriptRegiOnClick(cmdSearchdialog);
打开窗体设置返回值的代码
HFSoftWebScriptsReturnValues returnValue=new HFSoftWebScriptsReturnValues();
returnValueAdd(ReturnStringfilter);
HFSoftWebScriptsRegisterScriptRegiPageClient(thisreturnreturnValue);
打开窗体类的代码(其实很多Script都可以通过这样的方式来封装).
namespace HFSoft Web Scripts
{
/// <summary>
/// 创建打开窗体脚本类
/// 注意:返回值参数据接收的数据格式必须
/// key=value|key=value|
/// </summary>
public class ShowModalDialog : IExecuteScript
{
private const string _Dialog =windowshowModalDialog({} dialogHeight : { } px ;
dialogWidth : { } px ; edge : Raised ; center : Yes ; help : No ; resizable : No ; status : No ; scroll :
Yes ;); ;
#region IExecuteScript 成员
private bool mParent = false ;
/// <summary>
/// 是否需要加载父指向
/// </summary>
public bool Parent
{
get
{
// TODO: 添加 SetElementsValueParent getter 实现
return mParent ;
}
set
{
// TODO: 添加 SetElementsValueParent setter 实现
mParent = value ;
}
}
private string GetParent ()
{
if ( Parent )
return parent ;
return ;
}
/// <summary>
/// 构造对象
/// </summary>
/// <param name=pageContainer>容器页</param>
/// <param name=openPage>具本打开的页面</param>
public ShowModalDialog ( string pageContainer string openPage )
{
PageContainer = pageContainer ;
OpenPage = openPage ;
}
public const string PageUrlTag =pageurl ;
/// <summary>
/// 生成脚本
/// </summary>
/// <returns>string</returns>
public string Execute ()
{
// TODO: 添加 ShowModalDialogExecute 实现
string url = + PageContainer + ? pageurl =+ + GetPage ();
url = string Format ( _Dialog url Height Width );
url = GetParent () + url ;
if ( ReturnElements Count >)
{
url = var getvalue= + url +;if(getvalue != null){ ;
foreach ( ReturnElement item in ReturnElements )
{
url += item GetScript ( GetParent ());
}
url +=} ;
return url +; ;
}
return url +; ;
}
#endregion
private string mPageContainer ;
/// <summary>
/// 获取或设置容器页(包含路径)
/// </summary>
public string PageContainer
{
get
{
return mPageContainer ;
}
set
{
mPageContainer = value ;
}
}
private string mOpenPage ;
/// <summary>
/// 打开的页(包含路径)
/// </summary>
public string OpenPage
{
get
{
return mOpenPage ;
}
set
{
mOpenPage = value ;
}
}
private int mHeight =;
/// <summary>
/// 获取或设置打开窗体的高度
/// </summary>
public int Height
{
get
{
return mHeight ;
}
set
{
mHeight = value ;
}
}
private int mWidth =;
/// <summary>
/// 获取或设置打开窗体的宽度
/// </summary>
public int Width
{
get
{
return mWidth ;
}
set
{
mWidth = value ;
}
}
private ReturnElementCollections mReturnElements = new ReturnElementCollections ();
/// <summary>
/// 获取返回值元素集
/// </summary>
public ReturnElementCollections ReturnElements
{
get
{
return mReturnElements ;
}
}
private ParameterCollection mParameters = new ParameterCollection ();
/// <summary>
/// 获取打开页面的参数集
/// </summary>
public ParameterCollection Parameters
{
get
{
return mParameters ;
}
}
private string GetPage ()
{
if ( Parameters Count ==)
return +OpenPage+ ;
System Text StringBuilder sb = new System Text StringBuilder ();
sb Append ( +OpenPage+ );
string param = ;
string parent = GetParent ();
for ( int i =; i < Parameters Count ; i ++)
{
if ( Parameters [ i ] Element == ElementType Element )
{
param = + Parameters[i]Name + = + + parent +documentall(
+Parameters[i]Value + )value ;
}
else if ( Parameters [ i ] Element == ElementType Select )
{
param = + Parameters[i]Name + = + + parent +__getSeletedButton( + parent +
documentall( +Parameters[i]Value + )) ;
}
if ( i ==)
{
sb Append (+ +SystemWebHttpUtilityUrlEncode( ?) + + + param );
}
else
{
sb Append (+ +SystemWebHttpUtilityUrlEncode( &) + + + param );
}
}
return sb ToString ();
}
}
#region subClass
public enum ElementType
{
None
Element
Select
}
/// <summary>
/// 参数描述类
/// </summary>
public class Parameter
{
/// <summary>
/// 构造参数对象
/// </summary>
public Parameter ()
{
}
/// <summary>
/// 构造指定名称和值的参数对象
/// </summary>
/// <param name=name>参数名称</param>
/// <param name=value>参数值</param>
public Parameter ( string name string value )
{
Name = name ;
Value = value ;
}
/// <summary>
/// 构造指定名称和值的参数对象
/// </summary>
/// <param name=name>参数名称</param>
/// <param name=value>参数值</param>
/// <param name=iselement>值是否元素名称</param>
public Parameter ( string name string value ElementType element )
{
Name = name ;
Value = value ;
Element = element ;
}
private string mName ;
/// <summary>
/// 获取或设置参数名称
/// </summary>
public string Name
{
get
{
return mName ;
}
set
{
mName = value ;
}
}
private string mValue ;
/// <summary>
/// 获取或设置参数值
/// </summary>
public string Value
{
get
{
return mValue ;
}
set
{
mValue = value ;
}
}
private ElementType mElement = ElementType None ;
/// <summary>
/// 获取或设置参数值是否参数名称
/// </summary>
public ElementType Element
{
get
{
return mElement ;
}
set
{
mElement = value ;
}
}
}
public class ParameterCollection : System Collections CollectionBase
{
public Parameter this [ int index ]
{
get
{
return ( ( Parameter ) List [ index ] );
}
set
{
List [ index ] = value ;
}
}
public int Add ( Parameter value )
{
return ( List Add ( value ) );
}
public int IndexOf ( Parameter value )
{
return ( List IndexOf ( value ) );
}
public void Insert ( int index Parameter value )
{
List Insert ( index value );
}
public void Remove ( Parameter value )
{
List Remove ( value );
}
public bool Contains ( Parameter value )
{
// If value is not of type Int this will return false
return ( List Contains ( value ) );
}
}
/// <summary>
/// 返回值接收元素描述类
/// </summary>
public class ReturnElement
{
/// <summary>
/// 构造对象
/// </summary>
/// <param name=id>接收值的元素ID</param>
/// <param name=key>对应值的键值</param>
public ReturnElement ( string id string key )
{
ID = id ;
Key = key ;
}
private string mID ;
/// <summary>
/// 获取或设置元素ID
/// </summary>
public string ID
{
get
{
return mID ;
}
set
{
mID = value ;
}
}
private string mKey ;
/// <summary>
/// 获取或设置对应值的键值
/// </summary>
public string Key
{
get
{
return mKey ;
}
set
{
mKey = value ;
}
}
/// <summary>
/// 获取操作脚本
/// </summary>
/// <returns>string</returns>
public string GetScript ( string parent )
{
return parent +documentall( +ID + )value= + parent +__AnalyseString( +Key +
getvalue); ;
}
}
public class ReturnElementCollections : System Collections CollectionBase
{
public ReturnElement this [ int index ]
{
get
{
return ( ( ReturnElement ) List [ index ] );
}
set
{
List [ index ] = value ;
}
}
public int Add ( ReturnElement value )
{
return ( List Add ( value ) );
}
public int IndexOf ( ReturnElement value )
{
return ( List IndexOf ( value ) );
}
public void Insert ( int index ReturnElement value )
{
List Insert ( index value );
}
public void Remove ( ReturnElement value )
{
List Remove ( value );
}
public bool Contains ( ReturnElement value )
{
// If value is not of type Int this will return false
return ( List Contains ( value ) );
}
}
#endregion
}