Exemplo n.º 1
0
        public override void OnReader(DatabaseReader reader)
        {
            IList <T> list = new List <T>();

            if (reader == null)
            {
                return;
            }

            DbStructure.DbStructContainer[] containers = new DbStructure.DbStructContainer[reader.ElementCount];
            for (int i = 0; i < containers.Length; i++)
            {
                DbStructure.DbStructContainer tmpConatiner = new DbStructure.DbStructContainer();
                tmpConatiner.CopyFrom(Container);
                containers[i] = tmpConatiner;
            }

            int index = 0;

            foreach (var item in reader)
            {
                DbStructure.DbStructContainer  tmpContainer = containers[index];
                DatabaseReader.DatabaseElement oElement     = item as DatabaseReader.DatabaseElement;
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    tmpContainer.SQLFields[i].Value = oElement.GetValue(i);
                }
                index = index + 1;
            }

            for (int tmpIndex = 0; tmpIndex < containers.Length; tmpIndex++)
            {
                DbStructure.DbStructContainer tmpContainer = containers[tmpIndex];
                T           t          = new T();
                FieldInfo[] fieldInfos = t.GetType().GetFields();
                for (int i = 0; i < fieldInfos.Length; i++)
                {
                    FieldInfo   fieldInfo  = fieldInfos[i];
                    DbFieldBase oBaseField = SearchField(tmpContainer.SQLFields, fieldInfo.Name);
                    if (oBaseField != null)
                    {
                        try
                        {
                            fieldInfo.SetValue(t, Convert.ChangeType(oBaseField.Value, fieldInfo.FieldType));
                        }
                        catch (Exception e)
                        {
                            App.Logger.Error("设置参数出现异常! 表{0} 索引位置{1}, 列名{2} 异常:{3}", Container.SQLTable, i, oBaseField.FieldName, e);
                        }
                    }
                }
                list.Add(t);
                Obj = list;
            }
        }
Exemplo n.º 2
0
 public override void OnReader(DatabaseReader reader)
 {
     if (reader == null)
     {
         Obj = default(T);
     }
     if (reader.ElementCount <= 0)
     {
         Obj = default(T);
     }
     foreach (var item in reader)
     {
         DatabaseReader.DatabaseElement oElement = item as DatabaseReader.DatabaseElement;
         for (int i = 0; i < reader.FieldCount; i++)
         {
             Container.SQLFields[i].Value = oElement.GetValue(i);
         }
         break;  // Search 限定只查询一个数据,因此这里执行一次后直接返回
     }
     FieldInfo[] fieldInfos = Obj.GetType().GetFields();
     for (int i = 0; i < fieldInfos.Length; i++)
     {
         FieldInfo   fieldInfo  = fieldInfos[i];
         DbFieldBase oBaseField = SearchField(Container.SQLFields, fieldInfo.Name);
         if (oBaseField != null)
         {
             try
             {
                 fieldInfo.SetValue(Obj, Convert.ChangeType(oBaseField.Value, fieldInfo.FieldType));
             }
             catch (Exception e)
             {
                 App.Logger.Error("设置参数出现异常! 表{0} 索引位置{1}, 列名{2} 异常:{3}", Container.SQLTable, i, oBaseField.FieldName, e);
             }
         }
     }
 }