Exemple #1
0
        public static List <T> GetModelListTree <T>(this ISelectBuilder source)
        {
            IDataReader       dr     = source.DataReader();
            TreeMemoAttribute attr   = typeof(T).GetCustomAttributes(typeof(TreeMemoAttribute), false)[0] as TreeMemoAttribute;
            List <T>          items  = new List <T>();
            List <T>          quene  = new List <T>();
            List <string>     fields = new List <string>();

            using (dr)
            {
                while (dr.Read())
                {
                    if (fields.Count == 0)
                    {
                        for (int i = 0; i < dr.FieldCount; i++)
                        {
                            fields.Add(dr.GetName(i).ToLower());
                        }
                    }
                    if (dr[attr.PID].Equals("") || dr[attr.PID] is System.DBNull)
                    {
                        items.Add(CreateNode <T>(dr, fields));
                    }
                    else
                    {
                        var pid = items.Find(p => p.GetType().GetProperty(attr.ID).GetValue(p).Equals(dr[attr.PID].ToString()));
                        if (pid == null)
                        {
                            quene.Add(CreateNode <T>(dr, fields));
                        }
                        else
                        {
                            List <T> temp = pid.GetType().GetProperty(attr.Children).GetValue(pid) as List <T>;
                            if (temp == null)
                            {
                                temp = new List <T>();
                            }
                            temp.Add(CreateNode <T>(dr, fields));
                            pid.GetType().GetProperty(attr.Children).SetValue(pid, temp);
                        }
                    }
                    Create(items, quene, attr);
                }
            }
            return(items);
        }