用反射根据单据号获取单号ID值

 

int   propertyValue = Model.Commons.Property.DynaAccessUtils.GetProperty(info, "ID");

 #region GetBillIDForBillNo[根据单据号获取单据ID值]
        public virtual int GetBillIDForBillNo(string billNo, EnumHuRmBillTypeCode billTypeCode)
        {
            int billID = 0;
            string bllMainName = BLL.HuRmCommon.GetBillBLLMainName(billTypeCode);
            string bllClassName = "BLL." + bllMainName;
            string bllMethonName = string.Format( "{0}_SelectByBillNo",bllMainName.Substring(1));

            if (billNo == null) return 0;

            //使用反射来得到一个单据对象。
            object bll = System.Activator.CreateInstance("BLL", bllClassName).Unwrap();
//BLL的对象类名,bll.GetType()获取对象所有属性(方法名及属性)
            Type typeBll = bll.GetType();
//paras根据数组的长度传参
            object[] paras = new object[1];
            paras[0] = billNo;
//根据放射获取的对象(bllMethonName【方法名】)(bll【放射获取的对应,类】)(paras【参数】)
            Model.ModelList listBillMain =
            (Model.ModelList)typeBll.GetMethod(bllMethonName).Invoke(bll, paras);

            //根据条件返回ID或BillNo
            if (listBillMain != null && listBillMain.Count > 0)
            {
                Tmain info = listBillMain[0];
                object propertyValue = null;
//获取对象对应属性的值(ID)
                propertyValue = Model.Commons.Property.DynaAccessUtils.GetProperty(info, "ID");
                billID = int.Parse(propertyValue.ToString());
            }
            return billID;
        }
        #endregion







 

你可能感兴趣的:(笔录)