예제 #1
0
        /// <summary>
        /// 设置预览模式。
        /// </summary>
        private void SetViewMode()
        {
            var removeList = new List <Control>();
            var addList    = new Dictionary <Control, string>();

            foreach (var kvp in form.EntityPropertyExtend.GetProperties())
            {
                var map = ControlEntityMapConfig.Get(kvp.Key.GetType());
                if (map != null)
                {
                    var newControl = map.SetViewControl(kvp.Key);
                    if (newControl != null)
                    {
                        removeList.Add(kvp.Key);
                        addList.Add(newControl, kvp.Value);
                    }
                }
            }

            foreach (var control in removeList)
            {
                form.EntityPropertyExtend.SetPropertyName(control, string.Empty);
            }

            foreach (var kvp in addList)
            {
                form.EntityPropertyExtend.SetPropertyName(kvp.Key, kvp.Value);
            }
        }
예제 #2
0
        /// <summary>
        /// 根据属性名称获取对应控件的文本值。
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        protected object GetControlValue(string propertyName)
        {
            var map = form.EntityPropertyExtend.GetProperties().FirstOrDefault(s => s.Value == propertyName);

            if (map.Key != null)
            {
                var converter = ControlEntityMapConfig.Get(map.Key.GetType());
                if (converter != null)
                {
                    return(converter.GetValue(map.Key));
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// 清空控件里的值。
        /// </summary>
        public void ClearForm()
        {
            if (errorProvider1 != null)
            {
                errorProvider1.Clear();
            }

            foreach (var kvp in form.EntityPropertyExtend.GetProperties())
            {
                var converter = ControlEntityMapConfig.Get(kvp.Key.GetType());

                if (converter != null && form.EntityPropertyExtend.GetCanClear(kvp.Key))
                {
                    converter.Clear(kvp.Key);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 将实体的属性值填充到窗体上。
        /// </summary>
        /// <param name="entity"></param>
        protected virtual void FillEntityValues(IEntity entity)
        {
            foreach (var kvp in form.EntityPropertyExtend.GetProperties())
            {
                var value = GetEntityValue(entity, kvp.Value);
                if (value == null || value.IsEmpty)
                {
                    continue;
                }

                var converter = ControlEntityMapConfig.Get(kvp.Key.GetType());

                if (converter != null)
                {
                    var ovalue = GetFormatValue(kvp.Key, value.GetStorageValue());
                    converter.SetValue(kvp.Key, ovalue);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 读取窗口上的控件值,写给实体属性。
        /// </summary>
        /// <param name="entity"></param>
        protected virtual void ReadEntityValues(IEntity entity)
        {
            foreach (var kvp in form.EntityPropertyExtend.GetProperties())
            {
                var box = kvp.Key as TextBoxBase;
                if (box != null && box.ReadOnly)
                {
                    continue;
                }

                var converter = ControlEntityMapConfig.Get(kvp.Key.GetType());

                if (converter != null)
                {
                    var value = converter.GetValue(kvp.Key);
                    if (value != null)
                    {
                        var property = PropertyUnity.GetProperty(form.EntityType, kvp.Value);
                        entity.SetValue(kvp.Value, PropertyValue.New(value, property.Type));
                    }
                }
            }
        }