示例#1
0
 internal object GetEnum(Type type, string name,Connection conn)
 {
     return _pool.GetEnumValue(type, conn.GetInt32(TranslateFieldIndex(GetOrdinal(name))));
 }
示例#2
0
 private Dictionary<string, int> _SyncMissingValues(Dictionary<string, int> vals, Type t, Connection conn)
 {
     t = (t.IsGenericType ? t.GetGenericArguments()[0] : t);
     string[] keys = new string[vals.Count];
     vals.Keys.CopyTo(keys, 0);
     foreach (string str in Enum.GetNames(t))
     {
         if (!vals.ContainsKey(str))
         {
             conn.ExecuteNonQuery(string.Format("INSERT INTO {0}({1}) VALUES({2});",new object[]{ 
                 _enumTableMaps[t],
                 _pool.Translator.GetEnumValueFieldName(t, conn),
                 conn.CreateParameterName("value")}),
             new System.Data.IDbDataParameter[]{
                         conn.Pool.CreateParameter(conn.CreateParameterName("id"),null,Org.Reddragonit.Dbpro.Structure.Attributes.FieldType.INTEGER,4),
                         conn.CreateParameter(conn.CreateParameterName("value"),str)
                     });
             conn.ExecuteQuery("SELECT ID FROM " + _enumTableMaps[t] + " WHERE " + _pool.Translator.GetEnumValueFieldName(t, conn) + " = " + conn.CreateParameterName("value"),
                 new IDbDataParameter[]{
                     conn.CreateParameter(conn.CreateParameterName("value"),str)
                 });
             conn.Read();
             vals.Add(str, conn.GetInt32(0));
             conn.Close();
         }
     }
     return vals;
 }
示例#3
0
 internal object GetValue(int i,Connection conn){
     if (IsDBNull(i,conn))
         return null;
     if (_tableFieldCounts.ContainsKey(i))
     {
         Table t = (Table)LazyProxy.Instance(_tableFields[_fieldNames[i]].GetConstructor(System.Type.EmptyTypes).Invoke(new object[0]));
         sTableField[] flds = conn.Pool.Mapping[_tableFields[_fieldNames[i]]].Fields;
         int index = 0;
         i = TranslateFieldIndex(i);
         foreach (sTableField fld in flds)
         {
             PropertyInfo pi = t.GetType().GetProperty(fld.ClassProperty, Utility._BINDING_FLAGS_WITH_INHERITANCE);
             if (!pi.PropertyType.IsArray || !pi.PropertyType.Equals(typeof(byte[])))
             {
                 if (conn.Pool.Mapping.IsMappableType(pi.PropertyType) && !Utility.IsEnum(pi.PropertyType))
                 {
                     if (!conn.IsDBNull(i + index))
                     {
                         if (t.GetField(pi.Name) == null)
                         {
                             Table tmp = (Table)LazyProxy.Instance(pi.PropertyType.GetConstructor(Type.EmptyTypes).Invoke(new object[0]));
                             tmp.LoadStatus = LoadStatus.Partial;
                             t.SetField(fld.Name, tmp);
                         }
                         Table tbl = (Table)t.GetField(pi.Name);
                         foreach (sTableField f in conn.Pool.Mapping[tbl.GetType()].Fields)
                         {
                             if (fld.ExternalField == f.Name)
                             {
                                 t.RecurSetPropertyValue(f.Name, conn, conn.GetName(i + index), tbl);
                                 index++;
                                 break;
                             }
                         }
                     }
                     else
                         index++;
                 }
                 else
                 {
                     if (!conn.IsDBNull(i + index))
                     {
                         if (Utility.IsEnum(pi.PropertyType))
                             t.SetField(fld.ClassProperty, conn.Pool.GetEnumValue(pi.PropertyType, conn.GetInt32(i + index)));
                         else
                             t.SetField(fld.ClassProperty, conn[i + index]);
                     }
                     index++;
                 }
             }
         }
         t.LoadStatus = LoadStatus.Complete;
         return t;
     }
     else if (_enumFields.ContainsKey(i))
     {
         return _pool.GetEnumValue(_enumFields[i], conn.GetInt32(TranslateFieldIndex(i)));
     }else
         return conn.GetValue(TranslateFieldIndex(i));
 }
示例#4
0
 internal void LoadEnumsFromTable(Type t, Connection conn)
 {
     t = (t.IsGenericType ? t.GetGenericArguments()[0] : t);
     conn.ExecuteQuery("SELECT * FROM " + _enumTableMaps[t]);
     Dictionary<string, int> vals = new Dictionary<string, int>();
     while (conn.Read())
         vals.Add(conn[1].ToString(), conn.GetInt32(0));
     conn.Close();
     if (_enumValuesMap.ContainsKey(t))
         _enumValuesMap.Remove(t);
     if (_enumReverseValuesMap.ContainsKey(t))
         _enumReverseValuesMap.Remove(t);
     if (vals.Count == 0)
         InsertEnumIntoTable(t, conn);
     else
     {
         foreach (string str in Enum.GetNames(t))
         {
             if (!vals.ContainsKey(str))
             {
                 vals = _SyncMissingValues(vals, t, conn);
                 break;
             }
         }
         _enumValuesMap.Add(t, vals);
         Dictionary<int, string> revs = new Dictionary<int, string>();
         foreach (string str in vals.Keys)
             revs.Add(vals[str], str);
         _enumReverseValuesMap.Add(t, revs);
     }
 }