Пример #1
0
        /// <summary>
        /// 实体信息填充到表单
        /// </summary>
        /// <param name="container">容器</param>
        /// <param name="model">实体</param>
        /// <param name="type">命名类型</param>
        public static void FillForm(Control container, object model, PrefixType type)
        {
            Control.ControlCollection ctrs = container.Controls;
            if (ctrs == null || ctrs.Count <= 0)
            {
                return;
            }
            ClassInfoHandle classHandle = ClassInfoManager.GetClassHandle(model.GetType());

            foreach (Control ctr in ctrs)
            {
                string proName = UpdateModelInfo.GetKey(ctr.Name, type);
                if (string.IsNullOrEmpty(proName))
                {
                    continue;
                }
                PropertyInfoHandle handle = classHandle.PropertyInfo[proName];
                if (handle == null || !handle.HasGetHandle)//搜索里层
                {
                    FillForm(ctr, model, type);
                }
                else
                {
                    try
                    {
                        object value = handle.GetValue(model);
                        if (value != null)
                        {
                            ControlDefaultValue.SetControlDefaultPropertyValue(ctr, value);
                        }
                    }
                    catch { }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 给模型赋值
        /// </summary>
        /// <param name="ctr">控件</param>
        /// <param name="model">模型</param>
        /// <param name="handle">属性信息</param>
        private static void SetModelValue(Control ctr, object model, PropertyInfoHandle handle)
        {
            object value = ControlDefaultValue.GetControlDefaultPropertyValue(ctr);

            if (value == null)
            {
                return;
            }
            object readValue = CommonMethods.EntityProChangeType(value, handle.PropertyType);

            handle.SetValue(model, readValue);
        }