using System;
using System.Collections;
using BP.DA;
using System.Reflection;
namespace BP.En
{
///
/// 显示位置
///
public enum RMShowWhere
{
///
/// 实例左侧
///
EnLeft,
///
/// 实例工具栏
///
EnToolbar,
///
/// 查询工具栏
///
SearchToolbar
}
///
/// 相关功能类型
///
public enum RefMethodType
{
///
/// 左侧功能
///
Func,
///
/// 模态窗口打开
///
LinkModel,
///
/// 新窗口打开
///
LinkeWinOpen,
///
/// 右侧窗口打开
///
RightFrameOpen,
///
/// Tab页签打开
///
TabOpen
}
///
/// RefMethod 的摘要说明。
///
public class RefMethod
{
#region 与窗口有关的方法.
///
/// 高度
///
public int Height = 600;
///
/// 宽度
///
public int Width = 800;
///
/// 目标
///
public string Target = "_B123";
#endregion
///
/// 功能
///
public RefMethodType RefMethodType = RefMethodType.Func;
///
/// 功能显示位置
///
public RMShowWhere RMShowWhere = RMShowWhere.EnLeft;
///
/// 相关字段
///
public string RefAttrKey = null;
///
/// 连接标签
///
public string RefAttrLinkLabel = null;
///
/// 分组名称
///
public string GroupName = null;
///
/// 是否显示在Ens中?
///
public bool IsForEns = false;
///
/// 显示位置
///
public string IsShowForEnsCondtion = null;
///
/// 相关功能
///
public RefMethod()
{
}
///
/// 参数
///
private Attrs _HisAttrs = null;
///
/// 参数
///
public Attrs HisAttrs
{
get
{
if (_HisAttrs == null)
_HisAttrs = new Attrs();
return _HisAttrs;
}
set
{
_HisAttrs = value;
}
}
///
/// 索引位置,用它区分实体.
///
public int Index = 0;
///
/// 是否显示
///
public bool Visable = true;
///
/// 是否可以批处理
///
public bool IsCanBatch = false;
///
/// 标题
///
public string Title = null;
///
/// 操作前提示信息
///
public string Warning = "您确定要执行吗?";
///
/// 连接
///
public string ClassMethodName = null;
///
/// 图标
///
public string Icon = null;
///
/// 提示信息
///
public string ToolTip = null;
///
/// PKVal
///
public object PKVal = "PKVal";
///
///
///
public Entity HisEn = null;
///
/// 执行
///
///
///
public object Do(object[] paras)
{
string str = this.ClassMethodName.Trim(' ', ';', '.');
int pos = str.LastIndexOf(".");
string clas = this.HisEn.ToString();
string meth = str;
if (pos > 0)
{
clas = str.Substring(0, pos);
meth = str.Substring(pos, str.Length - pos).Trim('.', ' ', '(', ')');
}
if (this.HisEn == null)
{
this.HisEn = ClassFactory.GetEn(clas);
Attrs attrs = this.HisEn.EnMap.Attrs;
}
//如果当前的en与方法的en不同.
if (this.HisEn.ToString().Equals(clas) == false)
{
this.HisEn = ClassFactory.GetEn(clas);
this.HisEn.PKVal = this.PKVal;
this.HisEn.Retrieve();
}
Type tp = this.HisEn.GetType();
MethodInfo mp = tp.GetMethod(meth);
if (mp == null)
throw new Exception("@对象实例[" + tp.FullName + "]中没有找到方法[" + meth + "]!");
try
{
return mp.Invoke(this.HisEn, paras); //调用由此 MethodInfo 实例反射的方法或构造函数。
}
catch (System.Reflection.TargetException ex)
{
string strs = "";
if (paras == null)
{
throw new Exception(ex.Message);
}
else
{
foreach (object obj in paras)
{
strs += "para= " + obj.ToString() + " type=" + obj.GetType().ToString() + "\n
";
}
}
throw new Exception(ex.Message + " more info:" + strs);
}
}
}
///
/// 方法集合
///
[Serializable]
public class RefMethods : CollectionBase
{
///
/// 加入
///
/// attr
public void Add(RefMethod en)
{
if (this.IsExits(en))
return;
en.Index = this.InnerList.Count;
this.InnerList.Add(en);
}
///
/// 是不是存在集合里面
///
/// 要检查的RefMethod
/// true/false
public bool IsExits(RefMethod en)
{
foreach (RefMethod dtl in this)
{
if (dtl.ClassMethodName == en.ClassMethodName)
return true;
}
return false;
}
///
/// 根据索引访问集合内的元素Attr。
///
public RefMethod this[int index]
{
get
{
return (RefMethod)this.InnerList[index];
}
}
}
}