Example #1
0
        static String GetCustomAttributeValue <TAttribute>(MemberInfo member, String name)
        {
            TAttribute att = AttributeX.GetCustomAttribute <TAttribute>(member, true);

            if (att == null)
            {
                return(null);
            }

            PropertyInfoX pix = PropertyInfoX.Create(typeof(TAttribute), name);

            if (pix == null)
            {
                return(null);
            }

            return((String)pix.GetValue(att));
        }
Example #2
0
        /// <summary>设置控件的ToolTip提示信息</summary>
        /// <param name="field"></param>
        /// <param name="control"></param>
        protected virtual void SetToolTip(FieldItem field, Control control)
        {
            if (field == null || control == null)
            {
                return;
            }

            String toolTip = field.DisplayName;

            if (field.IsNullable)
            {
                toolTip = String.Format("请填写{0}!", toolTip);
            }
            else
            {
                toolTip = String.Format("必须填写{0}!", toolTip);
            }

            //if (control is Label) toolTip = null;
            if (control is Label)
            {
                return;
            }

            if (control is WebControl)
            {
                var wc = control as WebControl;

                // 设置ToolTip
                if (String.IsNullOrEmpty(wc.ToolTip) && !String.IsNullOrEmpty(toolTip))
                {
                    wc.ToolTip = toolTip;
                }
            }
            else
            {
                var pix = PropertyInfoX.Create(control.GetType(), "ToolTip");
                if (pix != null && String.IsNullOrEmpty((String)pix.GetValue(control)))
                {
                    pix.SetValue(control, toolTip);
                }
            }
        }
Example #3
0
        /// <summary>
        /// [OLD Code]返回一个新创建的实体对象,并给各个字段赋值
        /// </summary>
        /// <param name="typeName">完整实体名称, [命名空间.实体名称]</param>
        /// <param name="rval">表单集合字符串</param>
        /// <returns></returns>
        public static object GetFormEntity(this string rval, string typeName)
        {
            typeName = string.Format("{0}.{1}", ConfigHelper.GetAppSettings("EntitySpaceName"), typeName);
            TypeX  EntityType = TypeX.Create(TypeX.GetType(typeName, true));   //根据类的完整名称建立类的类型,用于动态创建类 如: Clump.Mobile.Models.NewsInfo
            Object objEntity  = EntityType.CreateInstance();                   //动态建立类的对象 实体类的对象Object objEntity = EntityType.CreateInstance(true);意思是在创建实体对象时 A a = new A(true)

            PropertyInfo[] props        = objEntity.GetType().GetProperties(); //获取此对象的,字段集合
            object         propertValue = String.Empty;

            foreach (PropertyInfo item in props)
            {
                propertValue = rval.GetFromValue(item.Name);
                if (!"".Equals(propertValue))
                {
                    //根据字段类型,转换格式
                    switch ((PropertyInfoX.Create(EntityType, item.Name)).Property.PropertyType.Name)
                    {
                    case "String": propertValue = Convert.ToString(propertValue); break;

                    case "Int64": propertValue = Convert.ToInt64(propertValue); break;

                    case "Int32": propertValue = Convert.ToInt32(propertValue); break;

                    case "Int16": propertValue = Convert.ToInt16(propertValue); break;

                    case "Byte": propertValue = Convert.ToByte(propertValue); break;

                    case "Single": propertValue = Convert.ToSingle(propertValue); break;

                    case "Double": propertValue = Convert.ToDouble(propertValue); break;

                    case "Boolean": propertValue = Convert.ToBoolean(propertValue); break;

                    case "DateTime": propertValue = Convert.ToDateTime(propertValue); break;

                    default: break;
                    }
                    PropertyInfoX.SetValue(objEntity, item.Name, propertValue);//给字段赋值
                }
            }
            PropertyInfoX.SetValue(objEntity, "CreateTime", DateTime.Now);//给CreateTime字段赋值,添加时间字段是每个数据表标配(未解决:MySql配置,暂时不能默认添加当前时间)
            return(objEntity);
        }
Example #4
0
        /// <summary>查找控件的事件</summary>
        /// <param name="control"></param>
        /// <param name="eventName"></param>
        /// <returns></returns>
        public static Delegate FindEventHandler(Control control, String eventName)
        {
            if (control == null)
            {
                return(null);
            }
            if (String.IsNullOrEmpty(eventName))
            {
                return(null);
            }

            var pix = PropertyInfoX.Create(control.GetType(), "Events");

            if (pix == null)
            {
                return(null);
            }

            EventHandlerList list = pix.GetValue(control) as EventHandlerList;

            if (list == null)
            {
                return(null);
            }

            var fix = FieldInfoX.Create(control.GetType(), eventName);

            if (fix == null && !eventName.StartsWith("Event", StringComparison.Ordinal))
            {
                fix = FieldInfoX.Create(control.GetType(), "Event" + eventName);
            }
            if (fix == null)
            {
                return(null);
            }

            return(list[fix.GetValue(control)]);
        }
Example #5
0
        void CompressContent(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            if (!(app.Context.CurrentHandler is System.Web.UI.Page) || app.Request["HTTP_X_MICROSOFTAJAX"] != null)
            {
                return;
            }

            // 如果已经写入头部,这里就不能压缩了
            var pix = PropertyInfoX.Create(app.Response.GetType(), "HeadersWritten");

            if (pix != null && (Boolean)pix.GetValue(app.Response))
            {
                return;
            }
            // .net 2.0没有HeadersWritten
            //if (PropertyInfoX.GetValue<Boolean>(app.Response, "HeadersWritten")) return;

            //压缩
            String url   = app.Request.Url.OriginalString.ToLower();
            String files = Config.GetConfig <String>("NewLife.CommonEntity.CompressFiles", ".aspx,.axd,.js,.css");

            if (files.ToLower().Split(",", ";", " ").Any(t => url.Contains(t)))
            {
                //是否支持压缩协议
                if (IsEncodingAccepted(GZIP))
                {
                    app.Response.Filter = new GZipStream(app.Response.Filter, CompressionMode.Compress);
                    SetEncoding(GZIP);
                }
                else if (IsEncodingAccepted(DEFLATE))
                {
                    app.Response.Filter = new DeflateStream(app.Response.Filter, CompressionMode.Compress);
                    SetEncoding(DEFLATE);
                }
            }
        }
Example #6
0
        Type GetItemType(String name)
        {
            if (String.IsNullOrEmpty(name) || EntityType == null)
            {
                return(null);
            }

            PropertyInfoX pi = PropertyInfoX.Create(EntityType, name);

            if (pi != null)
            {
                return(pi.Type);
            }

            FieldInfoX fi = FieldInfoX.Create(EntityType, name);

            if (fi != null)
            {
                return(fi.Type);
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// 把实体成员的值设置到控件上
        /// </summary>
        /// <param name="field"></param>
        /// <param name="control"></param>
        /// <param name="canSave"></param>
        protected virtual void SetFormItem(FieldItem field, System.Web.UI.Control control, Boolean canSave)
        {
            if (field == null || control == null)
            {
                return;
            }

            String toolTip = String.IsNullOrEmpty(field.Description) ? field.Name : field.Description;

            if (field.IsNullable)
            {
                toolTip = String.Format("请填写{0}!", toolTip);
            }
            else
            {
                toolTip = String.Format("必须填写{0}!", toolTip);
            }

            if (control is Label)
            {
                toolTip = null;
            }

            if (control is ExtAspNet.ControlBase)
            {
                ExtAspNet.ControlBase wc = control as ExtAspNet.ControlBase;

                // 设置ToolTip
                //if (String.IsNullOrEmpty(wc.ToolTip) && !String.IsNullOrEmpty(toolTip)) wc.ToolTip = toolTip;

                //// 必填项
                //if (!field.IsNullable) SetNotAllowNull(field, control, canSave);

                // 设置只读,只有不能保存时才设置,因为一般都不是只读,而前端可能自己设置了控件为只读,这种情况下这里再设置就会修改前端的意思
                if (!canSave)
                {
                    if (wc is ExtAspNet.TextBox)
                    {
                        (wc as TextBox).Enabled = !canSave;
                    }
                    else
                    {
                        wc.Enabled = canSave;
                    }
                }

                // 分控件处理
                if (wc is TextBox || wc is DatePicker)
                {
                    SetFormItemTextBox(field, wc as RealTextField, canSave);
                }
                else if (wc is Label)
                {
                    SetFormItemLabel(field, wc as Label, canSave);
                }
                else if (wc is RadioButton)
                {
                    SetFormItemRadioButton(field, wc as RadioButton, canSave);
                }
                else if (wc is CheckBox)
                {
                    SetFormItemCheckBox(field, wc as CheckBox, canSave);
                }
                else if (wc is DropDownList)
                {
                    SetFormItemListControl(field, wc as DropDownList, canSave);
                }
                else
                {
                    SetControlValue(control as ControlBase, Entity[field.Name]);
                }
            }
            else
            {
                SetControlValue(control as ControlBase, Entity[field.Name]);

                PropertyInfoX pix = PropertyInfoX.Create(control.GetType(), "ToolTip");
                if (pix != null && String.IsNullOrEmpty((String)pix.GetValue(control)))
                {
                    pix.SetValue(control, toolTip);
                }
            }
        }
Example #8
0
 static PropertyInfoX[] GetProperties(Type type)
 {
     return(cache2.GetItem(type, item => item.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => !p.Name.EqualIgnoreCase("Item")).Select(p => PropertyInfoX.Create(p)).ToArray()));
 }