示例#1
0
        public void _Init(string GroupTableName, string GroupWhere, string GroupIDField, string GroupDisplayField, string GroupParentIDField,
            string TableName, string Where, string IDField, string DisplayField, string LinkField, string[] VisibleFields, string[] Captions,
            TreeListColumnType[] ColumnTypes, string RootImage, string GroupImage, string image)
        {
            if (VisibleFields == null)
                VisibleFields = new string[0];
            if (Captions == null)
                Captions = new string[0];
            if (ColumnTypes == null)
                ColumnTypes = new TreeListColumnType[0];
            if (VisibleFields.Length != Captions.Length ||
               VisibleFields.Length != ColumnTypes.Length || Captions.Length != ColumnTypes.Length)
                throw new Exception("Vui lòng tryền 3 tham số mảng 'VisibleFields', 'Captions', 'ColumTypes' có cùng số phần tử!");

            IsGroup_Child = true;
            this.IDField = IDField;
            this.ParentIDField = GroupParentIDField;
            this.DisplayField = DisplayField;
            treeList.KeyFieldName = IDField;
            treeList.ParentFieldName = ParentIDField;
            string sqlGroup = "";
            string sqlChild = "";
            string tempField = "";
            treeList.Columns.Add().FieldName = IDField;

            for (int i = 0; i < VisibleFields.Length; i++)
            {
                tempField = VisibleFields[i];
                if (tempField != GroupDisplayField)
                    sqlGroup += "NULL " + tempField + ",";
                if (tempField != DisplayField)
                    sqlChild += tempField + ",";
                TreeListColumn col = treeList.Columns.Add();
                col.OptionsColumn.AllowFocus = false;
                col.Visible = true;
                col.Caption = Captions[i];
                col.FieldName = tempField;
                TreeListSupport.SetColumnType(col, ColumnTypes[i]);
            }
            sqlGroup = sqlGroup.TrimEnd(',');
            sqlChild = sqlChild.TrimEnd(',');
            string sql = string.Format(@"select * from (select {0} {1}, {2} {3},{4}, 'Y' {5} {6}
                                       from {7}
                                       Where 1=1 {8}
                                       union
                                       select {1}, {3},{9} {4}, 'N' {5} {10}
                                       from {11}
                                       where {9} IS NOT NULL {12}) order by {5} desc, {3} asc", GroupIDField, IDField, GroupDisplayField, DisplayField, GroupParentIDField,
                                                                                     IsGroupField, (sqlGroup == "" ? "" : "," + sqlGroup), GroupTableName, (GroupWhere == "" ? "" : " AND " + GroupWhere),
                                                      LinkField, (sqlChild == "" ? "" : "," + sqlChild), TableName, (Where == "" ? "" : " AND " + Where));

            DataSet ds = HelpDB.getDBService().LoadDataSet(sql, TableName);
            Image rimg = ResourceMan.getImage(RootImage);
            Image gimg = ResourceMan.getImage(GroupImage);
            Image img = ResourceMan.getImage(image);
            if (gimg != null || image != null || rimg != null)
            {
                IndexRootImage = imageCollection1.Images.Add(rimg, RootImage);
                IndexGroupImage = imageCollection1.Images.Add(gimg, GroupImage);
                IndexImage = imageCollection1.Images.Add(img, image);
            }
            else treeList.StateImageList = null;
            if (ds != null && ds.Tables.Count > 0)
            {
                treeList.DataSource = ds.Tables[0];
                treeList.ExpandAll();
            }
        }
示例#2
0
        public void _Init(DataTable DataSource, string IDField, string ParentIDField,
            string DisplayField, string[] VisibleFields, string[] Captions, TreeListColumnType[] ColumTypes, string RootImage,string GroupImage,string image)
        {
            if (VisibleFields == null)
                VisibleFields = new string[0];
            if (Captions == null)
                Captions = new string[0];
            if (ColumTypes == null)
                ColumTypes = new TreeListColumnType[0];
            if (VisibleFields.Length != Captions.Length &&
                VisibleFields.Length != ColumTypes.Length)
                throw new Exception("Vui lòng tryền 3 tham số mảng 'VisibleFields', 'Captions', 'ColumTypes' có cùng số phần tử!");

            Image rimg = ResourceMan.getImage(RootImage);
            Image gimg = ResourceMan.getImage(GroupImage);
            Image img = ResourceMan.getImage(image);
            if (gimg != null || img != null || rimg != null)
            {
                IndexRootImage = imageCollection1.Images.Add(rimg, RootImage);
                IndexGroupImage = imageCollection1.Images.Add(gimg, GroupImage);
                IndexImage = imageCollection1.Images.Add(img, image);
            }
            else treeList.StateImageList = null;
            this.IsGroup_Child = false;
            this.IDField = IDField;
            this.ParentIDField = ParentIDField;
            this.DisplayField = DisplayField;
            treeList.KeyFieldName = IDField;
            treeList.ParentFieldName = ParentIDField;
            treeList.Columns.Add().FieldName = IDField;
            for (int i = 0; i < VisibleFields.Length; i++)
            {
                TreeListColumn col = treeList.Columns.Add();
                col.OptionsColumn.AllowFocus = false;
                col.Visible = true;
                col.Caption = Captions[i];
                if (VisibleFields != null)
                    col.FieldName = VisibleFields[i];
                if (ColumTypes != null)
                    TreeListSupport.SetColumnType(col, ColumTypes[i]);
            }
            treeList.DataSource = DataSource;
            treeList.ExpandAll();
        }