Exemple #1
0
 public virtual void Setup(DbMgr mgr, T obj, DbStructure.DbStructContainer container, Action <object> onFinished = null)
 {
     Mgr        = mgr;
     Obj        = obj as T;
     Container  = container;
     OnFinished = onFinished;
 }
Exemple #2
0
 public void SearchAll <T>(Action <object> action = null) where T : class, new()
 {
     DbStructure.DbStructContainer container = SQLStructure.SearchAll <T>();
     if (container != null)
     {
         SearchAllData <T> operate = new SearchAllData <T>();
         operate.Setup(this, null, container, action);
         Enqueue(operate);
     }
 }
Exemple #3
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.Error("设置参数出现异常! 表{0} 索引位置{1}, 列名{2} 异常:{3}", Container.SQLTable, i, oBaseField.FieldName, e);
                        }
                    }
                }
                list.Add(t);
                Obj = list;
            }
        }
Exemple #4
0
 public void Search <T>(T obj, Action <object> onFinished = null) where T : class, new()
 {
     lock (_lock)
     {
         DbStructure.DbStructContainer container = SQLStructure.Modify(obj);
         if (container != null)
         {
             SearchData <T> operate = new SearchData <T>();
             operate.Setup(this, obj, container, onFinished);
             Enqueue(operate);
         }
     }
 }