Пример #1
0
        private int flag_init = 0;//初始化,0未初始化,1已初始化

        public void InitUserControlUI()
        {
            if (flag_init == 1)
            {
                return;
            }
            flag_init = 1;

            DataTable table = dbOperation.GetDepartment();

            if (table != null)
            {
                department = new Department();
                //DataRow[] rows = table.Select("FK_CODE_DEPT='0'");
                //if (rows.Length == 0)
                //{
                //    return;
                //}
                DataRow[] rows = table.Select();
                department.Name = rows[0]["INFO_NAME"].ToString();
                department.Row  = rows[0];
                rows            = table.Select("FK_CODE_DEPT='" + rows[0]["INFO_CODE"].ToString() + "'");
                foreach (DataRow row1 in rows)
                {
                    Department department1 = new Department();
                    department1.Parent = department;
                    department1.Row    = row1;
                    department1.Name   = row1["INFO_NAME"].ToString();
                    //rows = table.Select("FK_CODE_DEPT='" + row1["INFO_CODE"].ToString() + "'");
                    //foreach (DataRow row2 in rows)
                    //{
                    //    Department department2 = new Department();
                    //    department2.Parent = department1;
                    //    department2.Row = row2;
                    //    department2.Name = row2["INFO_NAME"].ToString();
                    //    rows = table.Select("FK_CODE_DEPT='" + row2["INFO_CODE"].ToString() + "'");
                    //    foreach (DataRow row3 in rows)
                    //    {
                    //        Department department3 = new Department();
                    //        department3.Parent = department2;
                    //        department3.Row = row3;
                    //        department3.Name = row3["INFO_NAME"].ToString();
                    //        rows = table.Select("FK_CODE_DEPT='" + row3["INFO_CODE"].ToString() + "'");
                    //        foreach (DataRow row4 in rows)
                    //        {
                    //            Department department4 = new Department();
                    //            department4.Parent = department3;
                    //            department4.Row = row4;
                    //            department4.Name = row4["INFO_NAME"].ToString();
                    //            department3.Children.Add(department4);
                    //        }
                    //        department2.Children.Add(department3);
                    //    }
                    //    department1.Children.Add(department2);
                    //}
                    department.Children.Add(department1);
                }

                departmentViewModel   = new FamilyTreeViewModel(department);
                _treeView.DataContext = departmentViewModel;
            }
        }
Пример #2
0
        public void Load_DeptManager(object sender, RoutedEventArgs e)
        {
            //if (flag_init == 1)
            //{
            //    return;
            //}
            //flag_init = 1;

            DataTable table = dbOperation.GetDepartment();

            if (table != null)
            {
                department = new Department();
                //DataRow[] rows = table.Select("FK_CODE_DEPT='0'");
                //if (rows.Length == 0)
                //{
                //    return;
                //}
                DataRow[] rows = table.Select();
                department.Name = rows[0]["INFO_NAME"].ToString();
                department.Row  = rows[0];
                //对应湖北省级有3个部门(101 湖北畜安处,102 湖北动监处,103 湖北屠宰办),数据库中存在下级部门的是102
                string deptId = "";
                deptId = rows[0]["INFO_CODE"].ToString();
                rows   = table.Select("FK_CODE_DEPT='" + deptId + "'", " orderid asc");
                foreach (DataRow row1 in rows)
                {
                    Department department1 = new Department();
                    department1.Parent = department;
                    department1.Row    = row1;
                    department1.Name   = row1["INFO_NAME"].ToString();
                    //对应湖北省级有3个部门(101 湖北畜安处,102 湖北动监处,103 湖北屠宰办),数据库中存在下级部门的是102
                    string deptId2 = "";
                    deptId2 = row1["INFO_CODE"].ToString();
                    rows    = table.Select("FK_CODE_DEPT='" + deptId2 + "'", " orderid asc");
                    foreach (DataRow row2 in rows)
                    {
                        Department department2 = new Department();
                        department2.Parent = department1;
                        department2.Row    = row2;
                        department2.Name   = row2["INFO_NAME"].ToString();
                        rows = table.Select("FK_CODE_DEPT='" + row2["INFO_CODE"].ToString() + "'", " orderid asc");
                        foreach (DataRow row3 in rows)
                        {
                            Department department3 = new Department();
                            department3.Parent = department2;
                            department3.Row    = row3;
                            department3.Name   = row3["INFO_NAME"].ToString();
                            rows = table.Select("FK_CODE_DEPT='" + row3["INFO_CODE"].ToString() + "'", " orderid asc");
                            foreach (DataRow row4 in rows)
                            {
                                Department department4 = new Department();
                                department4.Parent = department3;
                                department4.Row    = row4;
                                department4.Name   = row4["INFO_NAME"].ToString();
                                department3.Children.Add(department4);
                            }
                            department2.Children.Add(department3);
                        }
                        department1.Children.Add(department2);
                    }
                    department.Children.Add(department1);
                }
                departmentViewModel   = new FamilyTreeViewModel(department);
                _treeView.DataContext = departmentViewModel;
            }
        }