示例#1
0
        private string GetFieldToCreateTable(string name, int size, string type, DatabaseFieldAttribute fieldAttribute)
        {
            if (type == "NVARCHAR")
            {
                type = string.Format("{0}({1})", type, size);
            }

            return(string.Format("[{0}] {1} {2}", name, type, GetExtraParameters(fieldAttribute)));
        }
        public TableSchema(Type type)
        {
            if (!typeof(IDatabasable).IsAssignableFrom(type))
            {
                throw new Exception(string.Format("{0} doesn't implement IDatabasable, aborted.", type));
            }

            if (type.GetConstructor(Type.EmptyTypes) == null)
            {
                throw new Exception(string.Format("{0} should have an empty constructor", type));
            }

            itemType = type;

            fields = new List <TableField>();

            foreach (FieldInfo field in type.GetFields())
            {
                DatabaseFieldAttribute attribute = field.GetCustomAttribute <DatabaseFieldAttribute>();
                if (attribute != null)
                {
                    fields.Add(new TableField(field.FieldType, field.Name, false));
                }
            }

            bool foundID = false;

            foreach (PropertyInfo property in type.GetProperties())
            {
                DatabaseFieldAttribute attribute = property.GetCustomAttribute <DatabaseFieldAttribute>();

                if (!foundID && property.Name == "ID" && property.PropertyType == typeof(int))
                {
                    fields.Add(new TableField(property.PropertyType, property.Name, true));
                    foundID = true;
                }
                else if (attribute != null)
                {
                    fields.Add(new TableField(property.PropertyType, property.Name, true));
                }
            }

            if (!foundID)
            {
                throw new Exception(string.Format("{0} should implement <b>public int ID {get; set;}</b>", type));
            }

            isValid = true;
        }
示例#3
0
        private string GetExtraParameters(DatabaseFieldAttribute fieldAttribute)
        {
            string extraParameters = string.Empty;

            if (fieldAttribute.IsNull)
            {
                extraParameters += " NULL";
            }

            if (fieldAttribute.IsUnique)
            {
                extraParameters += " UNIQUE";
            }

            return(extraParameters);
        }
示例#4
0
        private SingleClause NuildNotNullClause(PropertyInfo pi)
        {
            SingleClause sc = new SingleClause();

            object[] pa = pi.GetCustomAttributes(typeof(DatabaseFieldAttribute), true);
            if (pa != null && pa.Length == 1)
            {
                DatabaseFieldAttribute dba = (DatabaseFieldAttribute)(pa[0]);
                if (dba != null && dba.FieldName.Length > 0)
                {
                    sc.PropertyName = dba.FieldName;
                }
            }
            sc.Operator = CriteriaOperator.IsNotNull;
            return(sc);
        }
示例#5
0
        private SingleClause BuildSingleClause(ContactsApplicationMapping c, PropertyInfo pi)
        {
            SingleClause sc = new SingleClause();

            object[] pa = pi.GetCustomAttributes(typeof(DatabaseFieldAttribute), true);
            if (pa != null && pa.Length == 1)
            {
                DatabaseFieldAttribute dba = (DatabaseFieldAttribute)(pa[0]);
                if (dba != null && dba.FieldName.Length > 0)
                {
                    sc.PropertyName = dba.FieldName;
                }
            }

            sc.Value = pi.GetValue(c, null);

            switch (sc.PropertyName)
            {
            case "APP_CODE":
            case "MAIL":
            case "FAX":
            case "TELEFONO":
            case "CODICE":
            case "BACKEND_CODE":
            case "CATEGORY":
            case "COM_CODE":
            case "SOTTOTITOLO_ACTIVE":
            case "TITOLO_ACTIVE":
                sc.Operator = CriteriaOperator.Equal;
                break;

            case "CONTACT_REF":
                sc.Operator = CriteriaOperator.StartsWith;
                break;

            case "BACKEND_DESCR":
            case "DESCR_PLUS":
                sc.Operator = CriteriaOperator.Like;
                break;
            }

            return(sc);
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldInfo"/>
 /// </summary>
 /// <param name="property">The property info</param>
 /// <param name="attribute">The database field attribute</param>
 public FieldInfo(PropertyInfo property, DatabaseFieldAttribute attribute)
 {
     Property  = property;
     Attribute = attribute;
 }