I just read an article on "Unlimited Classification", address: http://www.cnblogs.com/datasky/archive/2008/05/26/1207325.html
Therefore, a previous use case is also used in the infinite tree structure, which is used in the organizational structure. However, it is basically the same as the above article.
I think it's mainly about examples used in combination with flytreeview.
Table Structure(The department may not meet the requirements ):
Create Table Department
(
Dept_id int identity (1, 1), -- department ID
Dept_name varchar (50) not null, -- department name
Dept_fullname varchar (1000) not null, -- department name
Dept_level int not null, -- department level (expanded later)
Dept_code varchar (1000) not null, -- Department track
Dept_parent int not null, -- superior department
Dept_info varchar (200) null, -- Department Information (later expanded, I think it is necessary)
Dept_status char (1) default (1), -- department status (0: Hide 1: normal 2: Special 3: delete)
)
Data(Omit dept _ in the Field _):
ID name fullname level code parent info status
1 XX Company 1 0 0 1
2 Development Department XX Company-Development Department 2 0.2 1
3 Program Group XX Company-Development Department-Program Group 3 0.2.3 2 1
4 test group XX Company-Development Department-test group 3 0.2.4 2 1
5 maintenance group XX Company-Development Department-maintenance group 3 0.2.5 2 1
6 Engineering Department XX Company-Engineering Department 2 0.6 1
7 marketing department XX Company-Marketing Department 2 0.7 1
Example:
1. Data Binding
Flytreeview can bind several pieces of data to a node as follows:
Key-> dept_id
Name-> dept_name
Parent-> dept_parent
Data-> dept_level
ToolTips-> dept_fullname
Generally, management is bound to all nodes of the entire organizational structure, as shown below:
Flytreeview1.databind ();
If you are a department administrator, you may only be able to maintain nodes under your own department, as shown below:
Flytreeview1.databind (EMP. deptid );
In this way, flytreeview automatically binds the entire tree. :)
There are several reasons for the full name of the Department:
1. displayed when you move the mouse over the tree control
2. In some cases, the full name of the employee department must be displayed.
3. avoid seeing where a department with the same name is. (Multiple branches have Development Departments)
The trajectory is for query and modification, and will be discussed later. This is also required for an infinite tree structure.
2. Add a department
On flytreeview, select a node and add a subnode to it, as shown below:
String newname = txtname. text;
String deptid = flytreeview1.selectednode. Key;
String deptcode = flytreeview1.selectednode. Data;
String deptfname = flytreeview1.selectednode. tooltips;
Insert a new node first, and then update the full name, track, and other information. Is that okay? Skip.
3. modify a department
There are two cases:
(1) Change the Department name
This involves modifying information about your own department and updating the full name of all lower-level departments.
String deptid = flytreeview1.selectednode. Key;
String deptcode = flytreeview1.selectednode. Data;
String oldname = viewstate ["dept_name"]. tostring ();
String newname = txtname. text;
Step 1: update yourself:
Update Department set dept_name = '[newname]', dept_fullname = Replace (dept_fullname, '[oldname]', '[newname]')
Where dept_id = [deptid]
Step 2: update all sub-departments:
Update Department set dept_fullname = Replace (dept_fullname, '[oldname]', '[newname]')
Where dept_code like '[deptcode] %'
(Note: the variables in the program are enclosed in brackets in the preceding SQL statement for convenience. The following example also uses this method .)
When updating a subnode, you can understand the importance of the record track. No matter how many levels of sub-nodes are available, they can be updated at one time. :)
(2) transfer a department to another department, or form a new department
For example, for the test data above, you need to set up a new department for maintenance under the Development Department.
String newparentid = ddldept. selectedvalue;
String newname = "Maintenance Department ";
String deptid = flytreeview1.selectednode. Key;
String deptcode = flytreeview1.selectednode. Data;
String deptfname = flytreeview1.selectednode. tooltips;
Step 1: Find the information of the new superior department
Select * from department where dept_id = [newparentid]
Step 2: update yourself (assuming the newparent object is obtained in the preceding result)
Update Department set dept_name = '[newname]', dept_fullname = '[newparent. dept_fullname] '+'-'+' [newname] ', dept_code =' [newparent. dept_fullname] '+ '. '+' [newname]'
Where dept_id = [deptid]
Step 3: update the sub-Portal
Use the Replace () function to replace the full name and track of the old department with the new one. (Be lazy)
4. Query
This is quite common and has a lot to use. The following are some common examples.
(1) query all sub-departments of a department as follows:
String deptcode = flytreeview1.selectednode. Data;
Select * from department where dept_code like '[deptcode] %'
(2) query departments of a certain level, which is often used to list all subsidiaries or all level-1 departments. As follows:
Select * from department where dept_level = 2
(3) query the attribution of a certain level. The full name can be seen, but sometimes all data is needed. As follows:
String deptcodes = flytreeview1.selectednode. Data. Replace (".",",");
Select * from department where dept_id in ([deptcodes]) order by dept_level;
(4) contact a superior department (this is nonsense)
String deptparent = flytreeview1.selectednode. parent;
Select * from department where dept_id = [deptparent]
5. Expand the tree
This is designed for flytreeview. Sometimes we want to expand a node on the interface.
Flytreeview1.expandnodes = dept_code.split ('.');
6. Limit the number of layers
Sometimes it is necessary to limit the maximum number of layers, which can be determined by dept_level.
If it is on the tree control, flytreeview1.selectednode. Data. Split ('.'). length can be obtained.
Okay. Let's talk about it.
In fact, the preceding example still cannot complete a task, that is, sorting.
Because the organizational structure may not involve sorting issues, it was not taken into consideration during the initial design.
I wonder if the flytreeview can be sorted? Hope you can give advice.