Пример #1
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result )
        {
            Object obj = target.get( info.Name );

            Boolean isNull = false;
            if (info.Type == typeof( String )) {
                if (obj == null) {
                    isNull = true;
                }
                else if (strUtil.IsNullOrEmpty( obj.ToString() )) {
                    isNull = true;
                }
            }
            else if (obj == null) {
                isNull = true;
            }

            if (isNull) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }
                else {
                    EntityInfo ei = Entity.GetInfo( target );
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + "can not be null" );
                }
            }
        }
Пример #2
0
 private static Boolean checkLength( EntityPropertyInfo info )
 {
     if (info.SaveAttribute == null) return false;
     if (info.SaveAttribute.LengthSetted() == false) return false;
     if (info.Type != typeof( String )) return false;
     return true;
 }
Пример #3
0
 private void addColumnSingle( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
     if (ep.Type == typeof( int )) {
         addColumn_Int( sb, ep, columnName );
     }
     else if (ep.Type == typeof( long )) {
         addColumn_Long( sb, columnName );
     }
     else if (ep.Type == typeof( DateTime )) {
         addColumn_Time( sb, columnName );
     }
     else if (ep.Type == typeof( decimal )) {
         addColumn_Decimal( entity, sb, ep, columnName );
     }
     else if (ep.Type == typeof( double )) {
         addColumn_Double( entity, sb, columnName );
     }
     else if (ep.Type == typeof( float )) {
         addColumn_Single( entity, sb, columnName );
     }
     else if (ep.Type == typeof( String )) {
         addColumn_String( entity, sb, ep, columnName );
     }
     else if (ep.IsEntity) {
         addColumn_entity( sb, columnName );
     }
 }
Пример #4
0
 protected override void addColumn_Int( StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
     sb.Append( columnName );
     if (ep.Property.IsDefined( typeof( TinyIntAttribute ), false )) {
         sb.Append( " tinyint default 0, " );
     }
     else {
         sb.Append( " int default 0, " );
     }
 }
Пример #5
0
 protected virtual void addColumn_ByColumnAttribute( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName )
 {
     if (ep.SaveAttribute.Length < 255) {
         addColumn_ShortText( sb, columnName, ep.SaveAttribute.Length );
     }
     else if ((ep.SaveAttribute.Length > 255) && (ep.SaveAttribute.Length < 4000)) {
         addColumn_MiddleText( entity, sb, ep, columnName );
     }
     else {
         addColumn_LongText( entity, sb, columnName );
     }
 }
Пример #6
0
        protected override void addColumn_Decimal( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
            if (ep.MoneyAttribute != null) {
                sb.Append( columnName );
                sb.Append( " currency default 0, " );
            }
            else {

                DecimalAttribute da = ep.DecimalAttribute;
                if (da == null) throw new Exception( "DecimalAttribute not found=" + entity.FullName + "_" + ep.Name );

                sb.Append( columnName );
                sb.Append( " decimal(" + da.Precision + "," + da.Scale + ") default 0, " );
            }
        }
Пример #7
0
 private static void setEntityPropertyValueById( IEntity obj, ObjectInfo state, EntityPropertyInfo property, int pid )
 {
     if (!property.IsAbstractEntity) {
         IEntity objValue = Entity.New( property.Type.FullName );
         objValue.Id = pid;
         // state
         //objValue.state = new ObjectInfo( property.Type ).Copy( state );
         IEntity objCache = ObjectPool.FindOne( property.Type, objValue.Id );
         if (objCache != null) {
             objValue = objCache;
         }
         obj.set( property.Name, objValue );
     }
 }
Пример #8
0
        private static Boolean isContinue( String action, EntityPropertyInfo info, EntityInfo entityInfo )
        {
            if (info.SaveToDB == false) return true;
            if (info.IsList) return true;

            if (info.Name.Equals( "Id" )) {

                if (action.Equals( "update" )) return true;
                if (action.Equals( "insert" ) && entityInfo.Parent == null) return true;

            }

            return false;
        }
Пример #9
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result )
        {
            if (!Regex.IsMatch( cvt.ToNotNull( target.get( info.Name ) ), this.Regexp, RegexOptions.Singleline )) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }

                else {
                    EntityInfo ei = Entity.GetInfo( target );
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + " is not match the format pattern : " + this.Regexp );
                }

            }
        }
Пример #10
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result )
        {
            Object obj = target.get( info.Name );

            EntityInfo ei = Entity.GetInfo( target );
            int count = getCount( action, target, ei, info, obj );

            if (count > 0) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }

                else {
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + " should be unique, but it has been in database" );
                }
            }
        }
Пример #11
0
        private static int getCount( String action, IEntity target, EntityInfo entityInfo, EntityPropertyInfo info, Object obj )
        {
            if (obj == null) return 1;

            String usql;
            IDatabaseDialect dialect = entityInfo.Dialect;
            if (action.Equals( "update" )) {
                usql = String.Format( "select count(Id) from {0} where Id<>{3} and {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ), target.Id );
            }
            else {
                usql = String.Format( "select count(Id) from {0} where {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ) );
            }

            logger.Info( LoggerUtil.SqlPrefix + " validate unique sql : " + usql );
            IDbCommand cmd = DataFactory.GetCommand( usql, DbContext.getConnection( entityInfo ) );
            DataFactory.SetParameter( cmd, info.ColumnName, obj );
            return cvt.ToInt( cmd.ExecuteScalar() );
        }
Пример #12
0
        private static Boolean isContinue( String action, EntityPropertyInfo info, EntityInfo entityInfo )
        {
            if (info.SaveToDB == false) return true;
            if (info.IsList) return true;

            if (info.Name.Equals( "Id" )) {

                if (action.Equals( "update" )) return true;

                // ����ʵ�������ʶ��
                if (/**/DbConfig.Instance.IsAutoId && action.Equals("insert")
                    && entityInfo.Parent == null
                    )
                    return true;
            }

            return false;
        }
Пример #13
0
 internal void AddPropertyToHashtable( EntityPropertyInfo p )
 {
     _propertyHashTable[p.Name] = p;
     if (strUtil.HasText( p.ColumnName )) {
         _propertyHashTableByColumn[p.ColumnName.ToLower()] = p;
     }
 }
        private string getEntityPropertyName( EntityPropertyInfo ep, object propertyValue ) {

            IEntity pValue = propertyValue as IEntity;
            if (pValue == null) return "";

            string val = null;

            EntityInfo ei = Entity.GetInfo( pValue );

            if ((ei.GetProperty( "Name" ) != null) && (pValue.get( "Name" ) != null)) {
                val = pValue.get( "Name" ).ToString();
            }
            else if ((ei.GetProperty( "Title" ) != null) && (pValue.get( "Title" ) != null)) {
                val = pValue.get( "Title" ).ToString();
            }

            if (strUtil.HasText( val )) {
                String lnk = to( Model ) + "?typeName=" + ep.ParentEntityInfo.FullName + "&p=" + ep.Name + "&id=" + pValue.Id;
                return "<a title=\"" + ep.Type.FullName + ", Id=" + pValue.Id + "\" href=\"" + lnk + "\">" + val + "</a>";
            }
            else {
                return ep.Type.Name + "_" + pValue.Id;
            }
        }
 private string getPropertyValue( IEntity obj, EntityPropertyInfo ep ) {
     object val = obj.get( ep.Name );
     if (val == null) {
         return "";
     }
     return val.ToString();
 }
Пример #16
0
 protected virtual void addColumn_String( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName )
 {
     if (ep.LongTextAttribute != null) {
         addColumn_LongText( entity, sb, columnName );
     }
     else if (ep.SaveAttribute != null) {
         addColumn_ByColumnAttribute( entity, sb, ep, columnName );
     }
     else {
         addColumn_ShortText( sb, columnName, 250 );
     }
 }
Пример #17
0
 protected virtual void addColumn_MiddleText( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName )
 {
     addColumn_ShortText( sb, columnName, ep.SaveAttribute.Length );
 }
Пример #18
0
        // 是否在sql中选择当前属性的column
        private Boolean isAddColumn(String selectedProperty, EntityPropertyInfo ep)
        {
            //选择字符串和属性完全同名
            if (selectedProperty.Equals(ep.Name)) return true;

            //属性Member,selectProperty为Member.Name,只要前缀相同,即可选取属性的columnName
            if (ep.IsEntity && selectedProperty.StartsWith(ep.Name + ".")) return true;

            return false;
        }
Пример #19
0
 private static void setEntityId( IDbCommand cmd, EntityPropertyInfo info, Object paramVal )
 {
     int id = ((IEntity)paramVal).Id;
     DataFactory.SetParameter( cmd, info.ColumnName, id );
 }
Пример #20
0
 protected override void addColumn_MiddleText( EntityInfo entity, StringBuilder sb, EntityPropertyInfo temP, string columnName )
 {
     addColumn_LongText( entity, sb, columnName );
 }
        private static string getDropText( EntityPropertyInfo ep ) {

            if (ep.EntityInfo.GetProperty( "Name" ) != null) return "Name";
            if (ep.EntityInfo.GetProperty( "Title" ) != null) return "Title";
            return "";
        }
Пример #22
0
 //1029
 private static Boolean isSavedProperty( EntityPropertyInfo ep )
 {
     if (ep.SaveToDB) return true;
     return false;
 }
 private object getPropertyValue( EntityPropertyInfo ep, string postValue ) {
     if (ep.Type == typeof( int )) {
         return cvt.ToInt( postValue );
     }
     if (ep.Type == typeof( decimal )) {
         return Convert.ToDecimal( postValue );
     }
     if (ep.Type == typeof( DateTime )) {
         return cvt.ToTime( postValue );
     }
     return postValue;
 }
Пример #24
0
 private static void setDefaultValue( IDbCommand cmd, EntityPropertyInfo info, EntityInfo entityInfo )
 {
     if (MappingClass.Instance.ClassList.Contains( info.Type.FullName )) {
         DataFactory.SetParameter( cmd, info.ColumnName, -1 );
     }
     else if (info.Type == typeof( DateTime )) {
         if (entityInfo.DbType == DatabaseType.Access) {
             DataFactory.SetParameter( cmd, info.ColumnName, DateTime.Now.ToString() );
         }
         else {
             DataFactory.SetParameter( cmd, info.ColumnName, DateTime.Now );
         }
     }
     else {
         DataFactory.SetParameter( cmd, info.ColumnName, "" );
     }
 }
Пример #25
0
 internal EntityPropertyInfo FindRelationProperty( Type t )
 {
     if (_relationProperty == null) {
         for (int i = 0; i < EntityPropertyList.Count; i++) {
             EntityPropertyInfo info = EntityPropertyList[i];
             if (info.Type != t) {
                 _relationProperty = info;
             }
         }
     }
     return _relationProperty;
 }
Пример #26
0
 private static bool shouldPass( EntityPropertyInfo info )
 {
     if (info.Type == typeof( int )) return false;
     if (info.Type == typeof( long )) return false;
     if (info.Type == typeof( string )) return false;
     if (info.Type == typeof( decimal )) return false;
     if (info.Type == typeof( DateTime )) return false;
     if (info.Type == typeof( bool )) return false;
     if (info.Type == typeof( double )) return false;
     if (info.IsEntity) return false;
     return true;
 }
Пример #27
0
        //-------------------------------------------------------------------------------------------


        private string getEntityName( EntityPropertyInfo ep ) {

            String pn = getEntityNameSimple( ep );
            return pn == null ? ep.Name : ep.Name + "." + pn;
        }
Пример #28
0
        internal static EntityPropertyInfo Get( PropertyInfo property )
        {
            EntityPropertyInfo ep = new EntityPropertyInfo();

            object[] arrAttr = property.GetCustomAttributes( typeof( ValidationAttribute ), true );
            foreach (Object at in arrAttr) {
                ep.ValidationAttributes.Add( at as ValidationAttribute );
            }

            ep.SaveAttribute = ReflectionUtil.GetAttribute( property, typeof( ColumnAttribute ) ) as ColumnAttribute;
            ep.LongTextAttribute = ReflectionUtil.GetAttribute( property, typeof( LongTextAttribute ) ) as LongTextAttribute;
            ep.MoneyAttribute = ReflectionUtil.GetAttribute( property, typeof( MoneyAttribute ) ) as MoneyAttribute;
            ep.DecimalAttribute = ReflectionUtil.GetAttribute( property, typeof( DecimalAttribute ) ) as DecimalAttribute;
            ep.DefaultAttribute = ReflectionUtil.GetAttribute( property, typeof( DefaultAttribute ) ) as DefaultAttribute;

            ep.Property = property;
            ep.Name = property.Name;
            ep.Type = property.PropertyType;
            ep.SaveToDB = !property.IsDefined( typeof( NotSaveAttribute ), false );

            if (property.PropertyType is IList) {
                ep.IsList = true;
                ep.SaveToDB = false;
            }

            return ep;
        }
Пример #29
0
        private object getInputBox( EntityPropertyInfo ep, bool isEdit, ref string valid, ref string rule, ref string msg, ref string tip ) {
            string controlName = "x." + ep.Name;
            string valueStr = string.Empty;
            if (isEdit) valueStr = "#{" + controlName + "}";
            if (rft.GetAttribute( ep.Property, typeof( NotNullAttribute ) ) != null) {
                valid = "class=\"valid\"";
                msg = string.Format( "msg=\"{0}\"", rft.GetPropertyValue( rft.GetAttribute( ep.Property, typeof( NotNullAttribute ) ), "Message" ) );
            }
            if (rft.GetAttribute( ep.Property, typeof( EmailAttribute ) ) != null) {
                rule = "rule=\"email\"";
                msg = string.Format( "msg=\"输入Email格式有误\"", ep.Label == null ? ep.Name : ep.Label );
            }
            if (rft.GetAttribute( ep.Property, typeof( TinyIntAttribute ) ) != null) {
                rule = "rule=\"int\"";
            }
            if (rft.GetAttribute( ep.Property, typeof( MoneyAttribute ) ) != null) {
                rule = "rule=\"money\"";
            }
            tip = string.Format( " class=\"tipInput\" tip=\"请输入{0}\"", ep.Label == null ? ep.Name : ep.Label );
            if (ep.IsLongText) {
                if (rft.GetAttribute( ep.Property, typeof( HtmlTextAttribute ) ) != null) {
                    return "#{Editor}";
                }
                else {
                    return Html.TextArea( controlName, valueStr, "width:95%;height:50px;" );
                }
            }

            if (ep.IsEntity) {
                return "#{" + controlName + "}";
            }

            if (ep.Type == typeof( DateTime ) && !isEdit) {
                return Html.TextInput( controlName, DateTime.Now.ToString( "g" ), "width:150px;" );
            }

            if (ep.Type == typeof( int ) || ep.Type == typeof( decimal )) {
                return Html.TextInput( controlName, valueStr, "width:60px;" );
            }

            if (ep.Type == typeof( string ) && ep.SaveAttribute != null && ep.SaveAttribute.Length > 50) {
                return Html.TextInput( controlName, valueStr, "width:450px;" );
            }

            return Html.TextInput( controlName, valueStr, "width:250px;" );
        }
Пример #30
0
        private string getEntityNameSimple( EntityPropertyInfo ep ) {

            if (ep.EntityInfo.GetProperty( "Name" ) != null) return "Name";
            if (ep.EntityInfo.GetProperty( "Title" ) != null) return "Title";

            return null;
        }