反射:InvokeMethod 活动调用多种方法的方法配置要点

MethodName: 方法名称

TargetObject: 当调用方法不为静态的时候,需要新建调用方法类实例

TargetType: 当调用方法为静态的时候,需要指定调用方法类的类型

GenericTypeArguments: 若调用方法为静态方法,则在此泛型集合中指定。

Parameters: 在此集合中指定方法参数的值

Result: 在此指定方法返回值

 

---------------------------------------------------

private string Action="Add";

private string BaseMethodName = "Accident{0}";

 

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string methodName = string.Format(BaseMethodName, Action);
                Type thisType = this.GetType();
                MethodInfo excuteMethod = thisType.GetMethod(methodName);
                excuteMethod.Invoke(this, null);
            }
            catch (Exception ex)
            {
                MyLog.log.Warn(ex.Message);
                QueryScript.ErrorMessageShow(this.Page, "showerr", ex.Message);
            }
        }

        /// <summary>
        /// 添加一个事故
        /// </summary>
        /// <returns></returns>
        public void AccidentAdd()
        {
            MySession mySession = new MySession(this.Page);
            BzAccidentEntity model = new BzAccidentEntity();
            model.DATE_HAPPENED = DateTime.Parse(txtDate.Text.ToString());
            model.TITLE = txtTitle.Text;
            model.TYPE_ID = Int32.Parse(txtType.SelectedValue.ToString());
            model.REASON = txtReason.Text;
            model.SUMMARY = txtSummary.Text;

            model.CREATE_MAN = mySession.getUserId();
            model.DATE_CREATED = DateTime.Now;
            model.ORGAN_ID = mySession.getOrganId();
            int i=accBLL.AddBzAccident(model);
            MyControlOption.ClearValue(this);
            txtDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            QueryScript.MessageShow(this.Page, "showSuc", MyPrompt.AccidentDicOptionInfo["success"].ToString());
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值