Example #1
0
 public object 瀏覽查詢(string[] 資料表名稱, string 查詢條件)
 {
     string dataevent = 資料表名稱[0];
     瀏覽Bll 瀏覽bll = new 瀏覽Bll();
     DataSet ds = 瀏覽bll.瀏覽查詢(dataevent, 查詢條件);
     return ds;
 }
Example #2
0
 public void 瀏覽查詢(string[] 資料表名稱, string 查詢條件, CollectionViewSource[] collectionViewSources)
 {
     string dataevent = 資料表名稱[0];
     瀏覽Bll 瀏覽bll = new 瀏覽Bll();
     DataSet ds = 瀏覽bll.瀏覽查詢(dataevent, 查詢條件);
     for (int i = 0; i < ds.Tables.Count; i++)
     {
         string model = "Model." + 資料表名稱[i].Substring(0, 1).ToUpper() + 資料表名稱[i].Substring(1).ToLower() + "Model";
         Assembly[] AssembliesLoaded = AppDomain.CurrentDomain.GetAssemblies();
         Type trgType = AssembliesLoaded.Select(assembly => assembly.GetType(model))
             .Where(type => type != null)
             .FirstOrDefault();
         //List<T> list = (List<T>)DataTableToList<T>.ConvertToModel(dt);
         if (trgType == null)
         {
             break;
         }
         Type generic = typeof(List<>);
         Type constructor = generic.MakeGenericType(trgType);
         dynamic listq = Activator.CreateInstance(constructor);
         Type datatabletolistType = typeof(DataTableToList<>).MakeGenericType(trgType);
         MethodInfo minfo = datatabletolistType.GetMethod("ConvertToModel");
         listq = minfo.Invoke(null, new object[] { ds.Tables[i] });
         Type obser = typeof(ObservableCollection<>);
         Type obserconstructor = obser.MakeGenericType(trgType);
         var observableCollection = Activator.CreateInstance(constructor, listq);
         collectionViewSources[i].Source = observableCollection;
     }
 }