private void GetChildSelectedCompany(TreeViewItem item, List <ExtOrgObj> selObj) { foreach (TreeViewItem childItem in item.Items) { TreeViewItem myItem = (TreeViewItem)(item.ItemContainerGenerator.ContainerFromItem(childItem)); CheckBox cbx = SMT.SaaS.FrameworkUI.Helper.UIHelper.FindChildControl <CheckBox>(myItem); if (cbx != null && cbx.IsChecked.GetValueOrDefault(false)) { OrgTreeItemTypes type = (OrgTreeItemTypes)(childItem.Tag); if (SelectedObjType == OrgTreeItemTypes.All || type == SelectedObjType) { if (type == OrgTreeItemTypes.Post) { ExtOrgObj obj = childItem.DataContext as ExtOrgObj; ExtOrgObj pobj = item.DataContext as ExtOrgObj; if (obj != null && pobj != null) { //附父节点的值 ((T_HR_POST)obj.ObjectInstance).T_HR_DEPARTMENT = pobj.ObjectInstance as T_HR_DEPARTMENT; } } selObj.Add(childItem.DataContext as ExtOrgObj); } } GetChildSelectedCompany(childItem, selObj); } }
private void AddChildOrgItems(TreeViewItem item, string companyID) { List <T_HR_COMPANY> childs = GetChildORG(companyID); if (childs == null || childs.Count <= 0) { return; } foreach (T_HR_COMPANY childOrg in childs) { TreeViewItem childItem = new TreeViewItem(); childItem.Header = childOrg.CNAME; childItem.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childOrg; childItem.DataContext = obj; //设置父级对像 obj.ParentObject = item.DataContext; // childItem.Style = this.Resources["CheckBoxTreeItemStyle"] as Style; childItem.HeaderTemplate = treeViewItemTemplate; //标记为公司 childItem.Tag = OrgTreeItemTypes.Company; item.Items.Add(childItem); AddChildOrgItems(childItem, childOrg.COMPANYID); } }
private void BindPosition() { allPositions = Application.Current.Resources["SYS_PostInfo"] as List <T_HR_POST>; if (allPositions == null) { return; } if (allPositions.Count() == 0) { return; } foreach (T_HR_POST tmpPosition in allPositions) { if (tmpPosition.T_HR_DEPARTMENT == null || string.IsNullOrEmpty(tmpPosition.T_HR_DEPARTMENT.DEPARTMENTID)) { continue; } TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Department, tmpPosition.T_HR_DEPARTMENT.DEPARTMENTID); if (parentItem != null) { TreeViewItem item = new TreeViewItem(); item.Header = tmpPosition.T_HR_POSTDICTIONARY.POSTNAME; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpPosition; item.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; // item.Style = this.Resources["CheckBoxTreeItemStyle"] as Style; item.HeaderTemplate = treeViewItemTemplate; //标记为岗位 item.Tag = OrgTreeItemTypes.Post; parentItem.Items.Add(item); } } //树全部展开 // treeOrganization.ExpandAll(); if (treeOrganization.Items.Count > 0) { TreeViewItem selectedItem = treeOrganization.Items[0] as TreeViewItem; selectedItem.IsSelected = true; } }
//private string parentName = ""; //private void UnCheckChildCheckbox(TreeViewItem item, CheckBox selfCheckbox) //{ // foreach (TreeViewItem childItem in item.Items) // { // TreeViewItem myItem = // (TreeViewItem)(item.ItemContainerGenerator.ContainerFromItem(childItem)); // CheckBox cbx = Helper.UIHelper.FindChildControl<CheckBox>(myItem); // if (cbx == selfCheckbox) // { // UnCheckChildCheckbox(myItem, selfCheckbox); // } // else // { // //if (MultiSelected && parentName == GetParentName(myItem) && cbx.IsChecked==true) // if (MultiSelected && !HaveChildItemChecked(myItem, selfCheckbox)) // { // return; // } // if (cbx != null && cbx.IsChecked.GetValueOrDefault(false)) // { // cbx.IsChecked = false; // } // UnCheckChildCheckbox(childItem, selfCheckbox); // } // } //} private bool IsSameParent(TreeViewItem item, CheckBox selfCheckbox) { if (item == null || item.Parent == null) { return(false); } ExtOrgObj obj = new ExtOrgObj(); TreeViewItem parentItem = new TreeViewItem(); parentItem = item.Parent as TreeViewItem; obj = parentItem.DataContext as ExtOrgObj; //ExtOrgObj obj1 = new ExtOrgObj(); //obj1= selfCheckbox.DataContext as ExtOrgObj; return(obj.ObjectName == selfCheckbox.DataContext.ToString()); }
private TreeViewItem GetParentItemFromChild(TreeViewItem item, OrgTreeItemTypes parentType, string parentID) { TreeViewItem tmpItem = null; ExtOrgObj obj = item.DataContext as ExtOrgObj; if (obj != null && item.Tag != null && item.Tag.ToString() == parentType.ToString()) { switch (parentType) { case OrgTreeItemTypes.Company: T_HR_COMPANY tmpOrg = obj.ObjectInstance as T_HR_COMPANY; if (tmpOrg != null) { if (tmpOrg.COMPANYID == parentID) { return(item); } } break; case OrgTreeItemTypes.Department: T_HR_DEPARTMENT tmpDep = obj.ObjectInstance as T_HR_DEPARTMENT; if (tmpDep != null) { if (tmpDep.DEPARTMENTID == parentID) { return(item); } } break; } } if (item.Items != null && item.Items.Count > 0) { foreach (TreeViewItem childitem in item.Items) { tmpItem = GetParentItemFromChild(childitem, parentType, parentID); if (tmpItem != null) { break; } } } return(tmpItem); }
private void BindEmployeeByTreeViewItem(TreeViewItem item) { if (item == null) { return; } ExtOrgObj tmp = new ExtOrgObj(); tmp = item.DataContext as ExtOrgObj; if (tmp.ObjectType == OrgTreeItemTypes.Personnel) { foreach (var h in ((PersonnelWS.T_HR_EMPLOYEE)tmp.ObjectInstance).T_HR_EMPLOYEEPOST) { PersonnelWS.T_HR_POST tmpPost_P = new PersonnelWS.T_HR_POST(); OrganizationWS.T_HR_POST tmpPost_O = new OrganizationWS.T_HR_POST(); tmpPost_O = BindEmployeePost(item); } } }
protected void lookUpTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { //return; if (treeOrganization.SelectedItem == null) { return; } if (treeOrganization.SelectedItem.GetType() != typeof(TreeViewItem)) { return; } TreeViewItem item = (TreeViewItem)treeOrganization.SelectedItem; //TODO: 这个方法在单选时选择有bug,可能是Selected事件与Checked事件有冲突 //CheckBox cbx = Helper.UIHelper.FindChildControl<CheckBox>(item); //if (cbx != null) // cbx.IsChecked = true; if (item == null || item.DataContext == null) { return; } OrgTreeItemTypes type = (OrgTreeItemTypes)(item.Tag); if ((SelectedObjType == OrgTreeItemTypes.All || SelectedObjType == OrgTreeItemTypes.Personnel) && type == OrgTreeItemTypes.Post) { //TODO:多选 ExtOrgObj obj = new ExtOrgObj(); obj = item.DataContext as ExtOrgObj; if (type == OrgTreeItemTypes.Post && obj != null) { //加载员工 BindEmployee(item, obj.ObjectID); } } }
private void BindDepartment() { allDepartments = Application.Current.Resources["SYS_DepartmentInfo"] as List <T_HR_DEPARTMENT>; if (allDepartments == null) { return; } if (allDepartments.Count() == 0) { return; } foreach (T_HR_DEPARTMENT tmpDep in allDepartments) { if (tmpDep.T_HR_COMPANY == null) { continue; } TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Company, tmpDep.T_HR_COMPANY.COMPANYID); if (parentItem != null) { TreeViewItem item = new TreeViewItem(); item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; item.Header = tmpDep.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTNAME; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpDep; item.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; item.HeaderTemplate = treeViewItemTemplate; //标记为部门 item.Tag = OrgTreeItemTypes.Department; parentItem.Items.Add(item); } } }
void perclient_GetEmployeePostByPostIDCompleted(object sender, PersonnelWS.GetEmployeePostByPostIDCompletedEventArgs e) { List <PersonnelWS.T_HR_EMPLOYEEPOST> eplist = new List <PersonnelWS.T_HR_EMPLOYEEPOST>(); if (e.Result != null) { eplist = e.Result.ToList(); } TreeViewItem parentItem = e.UserState as TreeViewItem; if (eplist == null || eplist.Count == 0 || parentItem == null) { return; } parentItem.Items.Clear(); foreach (PersonnelWS.T_HR_EMPLOYEEPOST ep in eplist) { TreeViewItem subItem = new TreeViewItem(); subItem.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; subItem.Header = ep.T_HR_EMPLOYEE.EMPLOYEECNAME; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = ep.T_HR_EMPLOYEE; subItem.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; //标记为岗位 subItem.Tag = OrgTreeItemTypes.Personnel; subItem.HeaderTemplate = treeViewItemTemplate; parentItem.Items.Add(subItem); } }
void perclient_GetEmployeePostByPostIDCompleted(object sender, PersonnelWS.GetEmployeePostByPostIDCompletedEventArgs e) { List<PersonnelWS.T_HR_EMPLOYEEPOST> eplist = new List<PersonnelWS.T_HR_EMPLOYEEPOST>(); if (e.Result != null) { eplist = e.Result.ToList(); } TreeViewItem parentItem = e.UserState as TreeViewItem; if (eplist == null || eplist.Count == 0 || parentItem == null) return; parentItem.Items.Clear(); foreach (PersonnelWS.T_HR_EMPLOYEEPOST ep in eplist) { TreeViewItem subItem = new TreeViewItem(); subItem.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; subItem.Header = ep.T_HR_EMPLOYEE.EMPLOYEECNAME; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = ep.T_HR_EMPLOYEE; subItem.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; //标记为岗位 subItem.Tag = OrgTreeItemTypes.Personnel; subItem.HeaderTemplate = treeViewItemTemplate; parentItem.Items.Add(subItem); } }
protected void lookUpTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { //return; if (treeOrganization.SelectedItem == null) { return; } if (treeOrganization.SelectedItem.GetType() != typeof(TreeViewItem)) return; TreeViewItem item = (TreeViewItem)treeOrganization.SelectedItem; //TODO: 这个方法在单选时选择有bug,可能是Selected事件与Checked事件有冲突 //CheckBox cbx = Helper.UIHelper.FindChildControl<CheckBox>(item); //if (cbx != null) // cbx.IsChecked = true; if (item == null || item.DataContext == null) return; OrgTreeItemTypes type = (OrgTreeItemTypes)(item.Tag); if ((SelectedObjType == OrgTreeItemTypes.All || SelectedObjType == OrgTreeItemTypes.Personnel) && type == OrgTreeItemTypes.Post) { //TODO:多选 ExtOrgObj obj = new ExtOrgObj(); obj = item.DataContext as ExtOrgObj; if (type == OrgTreeItemTypes.Post && obj != null) { //加载员工 BindEmployee(item, obj.ObjectID); } } }
private void BindPosition() { allPositions = Application.Current.Resources["SYS_PostInfo"] as List<T_HR_POST>; if (allPositions == null) { return; } if (allPositions.Count() == 0) { return; } foreach (T_HR_POST tmpPosition in allPositions) { if (tmpPosition.T_HR_DEPARTMENT == null || string.IsNullOrEmpty(tmpPosition.T_HR_DEPARTMENT.DEPARTMENTID)) continue; TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Department, tmpPosition.T_HR_DEPARTMENT.DEPARTMENTID); if (parentItem != null) { TreeViewItem item = new TreeViewItem(); item.Header = tmpPosition.T_HR_POSTDICTIONARY.POSTNAME; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpPosition; item.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; // item.Style = this.Resources["CheckBoxTreeItemStyle"] as Style; item.HeaderTemplate = treeViewItemTemplate; //标记为岗位 item.Tag = OrgTreeItemTypes.Post; parentItem.Items.Add(item); } } //树全部展开 // treeOrganization.ExpandAll(); if (treeOrganization.Items.Count > 0) { TreeViewItem selectedItem = treeOrganization.Items[0] as TreeViewItem; selectedItem.IsSelected = true; } }
private void BindDepartment() { allDepartments = Application.Current.Resources["SYS_DepartmentInfo"] as List<T_HR_DEPARTMENT>; if (allDepartments == null) { return; } if (allDepartments.Count() == 0) { return; } foreach (T_HR_DEPARTMENT tmpDep in allDepartments) { if (tmpDep.T_HR_COMPANY == null) continue; TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Company, tmpDep.T_HR_COMPANY.COMPANYID); if (parentItem != null) { TreeViewItem item = new TreeViewItem(); item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; item.Header = tmpDep.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTNAME; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpDep; item.DataContext = obj; //设置父级对像 obj.ParentObject = parentItem.DataContext; item.HeaderTemplate = treeViewItemTemplate; //标记为部门 item.Tag = OrgTreeItemTypes.Department; parentItem.Items.Add(item); } } }
private void AddChildOrgItems(TreeViewItem item, string companyID) { List<T_HR_COMPANY> childs = GetChildORG(companyID); if (childs == null || childs.Count <= 0) return; foreach (T_HR_COMPANY childOrg in childs) { TreeViewItem childItem = new TreeViewItem(); childItem.Header = childOrg.CNAME; childItem.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childOrg; childItem.DataContext = obj; //设置父级对像 obj.ParentObject = item.DataContext; // childItem.Style = this.Resources["CheckBoxTreeItemStyle"] as Style; childItem.HeaderTemplate = treeViewItemTemplate; //标记为公司 childItem.Tag = OrgTreeItemTypes.Company; item.Items.Add(childItem); AddChildOrgItems(childItem, childOrg.COMPANYID); } }
/// <summary> /// 添加子节点 /// </summary> /// <param name="lsCompany"></param> /// <param name="lsDepartment"></param> /// <param name="FatherNode"></param> private void AddOrgNode(List<T_HR_COMPANY> lsCompany, List<T_HR_DEPARTMENT> lsDepartment, TreeViewItem FatherNode) { //绑定公司的子公司 foreach (var childCompany in lsCompany) { TreeViewItem item = new TreeViewItem(); item.Header = childCompany.CNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childCompany; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; FatherNode.Items.Add(item); if (lsCompany.Count() > 0) { List<T_HR_COMPANY> lsTempCom = (from ent in allCompanys where ent.FATHERID == childCompany.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); List<T_HR_DEPARTMENT> lsTempDep = (from ent in allDepartments where ent.FATHERID == childCompany.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); AddOrgNode(lsTempCom, lsTempDep, item); } } //绑定公司下的部门 foreach (var childDepartment in lsDepartment) { TreeViewItem item = new TreeViewItem(); item.Header = childDepartment.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childDepartment; item.DataContext = obj; //标记为部门 item.Tag = OrgTreeItemTypes.Department; FatherNode.Items.Add(item); if (lsDepartment.Count() > 0) { List<T_HR_COMPANY> lsTempCom = (from ent in allCompanys where ent.FATHERID == childDepartment.DEPARTMENTID && ent.FATHERTYPE == "1" select ent).ToList(); List<T_HR_DEPARTMENT> lsTempDep = (from ent in allDepartments where ent.FATHERID == childDepartment.DEPARTMENTID && ent.FATHERTYPE == "1" select ent).ToList(); AddOrgNode(lsTempCom, lsTempDep, item); } } }
/// <summary> /// 绑定组织架构节点 /// </summary> private void BindCompany() { treeOrganization.Items.Clear(); allCompanys = Application.Current.Resources["SYS_DepartmentInfo"] as List<T_HR_COMPANY>; allDepartments = Application.Current.Resources["SYS_DepartmentInfo"] as List<T_HR_DEPARTMENT>; if (allCompanys == null) { return; } List<T_HR_COMPANY> TopCompany = new List<T_HR_COMPANY>(); foreach (T_HR_COMPANY tmpOrg in allCompanys) { //如果当前公司没有父机构的ID,则为顶级公司 if (string.IsNullOrWhiteSpace(tmpOrg.FATHERID)) { TreeViewItem item = new TreeViewItem(); item.Header = tmpOrg.CNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpOrg; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; treeOrganization.Items.Add(item); TopCompany.Add(tmpOrg); } else { //查询当前公司是否在公司集合内有父公司存在 var ent = from c in allCompanys where c.COMPANYID == tmpOrg.FATHERID && tmpOrg.FATHERTYPE == "0" select c; var ent2 = from c in allDepartments where tmpOrg.FATHERTYPE == "1" && tmpOrg.FATHERID == c.DEPARTMENTID select c; //如果不存在,则为顶级公司 if (ent.Count() == 0 && ent2.Count() == 0) { TreeViewItem item = new TreeViewItem(); item.Header = tmpOrg.CNAME; item.HeaderTemplate = treeViewItemTemplate; ; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpOrg; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; treeOrganization.Items.Add(item); TopCompany.Add(tmpOrg); } } } //开始递归 foreach (var topComp in TopCompany) { TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Company, topComp.COMPANYID); List<T_HR_COMPANY> lsCompany = (from ent in allCompanys where ent.FATHERTYPE == "0" && ent.FATHERID == topComp.COMPANYID select ent).ToList(); List<T_HR_DEPARTMENT> lsDepartment = (from ent in allDepartments where ent.FATHERID == topComp.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); AddOrgNode(lsCompany, lsDepartment, parentItem); } }
/// <summary> /// 添加子节点 /// </summary> /// <param name="lsCompany"></param> /// <param name="lsDepartment"></param> /// <param name="FatherNode"></param> private void AddOrgNode(List <T_HR_COMPANY> lsCompany, List <T_HR_DEPARTMENT> lsDepartment, TreeViewItem FatherNode) { //绑定公司的子公司 foreach (var childCompany in lsCompany) { TreeViewItem item = new TreeViewItem(); item.Header = childCompany.CNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childCompany; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; FatherNode.Items.Add(item); if (lsCompany.Count() > 0) { List <T_HR_COMPANY> lsTempCom = (from ent in allCompanys where ent.FATHERID == childCompany.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); List <T_HR_DEPARTMENT> lsTempDep = (from ent in allDepartments where ent.FATHERID == childCompany.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); AddOrgNode(lsTempCom, lsTempDep, item); } } //绑定公司下的部门 foreach (var childDepartment in lsDepartment) { TreeViewItem item = new TreeViewItem(); item.Header = childDepartment.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = childDepartment; item.DataContext = obj; //标记为部门 item.Tag = OrgTreeItemTypes.Department; FatherNode.Items.Add(item); if (lsDepartment.Count() > 0) { List <T_HR_COMPANY> lsTempCom = (from ent in allCompanys where ent.FATHERID == childDepartment.DEPARTMENTID && ent.FATHERTYPE == "1" select ent).ToList(); List <T_HR_DEPARTMENT> lsTempDep = (from ent in allDepartments where ent.FATHERID == childDepartment.DEPARTMENTID && ent.FATHERTYPE == "1" select ent).ToList(); AddOrgNode(lsTempCom, lsTempDep, item); } } }
private void BindEmployeeByTreeViewItem(TreeViewItem item) { if (item == null) return; ExtOrgObj tmp = new ExtOrgObj(); tmp = item.DataContext as ExtOrgObj; if (tmp.ObjectType == OrgTreeItemTypes.Personnel) { foreach (var h in ((PersonnelWS.T_HR_EMPLOYEE)tmp.ObjectInstance).T_HR_EMPLOYEEPOST) { PersonnelWS.T_HR_POST tmpPost_P = new PersonnelWS.T_HR_POST(); OrganizationWS.T_HR_POST tmpPost_O = new OrganizationWS.T_HR_POST(); tmpPost_O = BindEmployeePost(item); } } }
//private string parentName = ""; //private void UnCheckChildCheckbox(TreeViewItem item, CheckBox selfCheckbox) //{ // foreach (TreeViewItem childItem in item.Items) // { // TreeViewItem myItem = // (TreeViewItem)(item.ItemContainerGenerator.ContainerFromItem(childItem)); // CheckBox cbx = Helper.UIHelper.FindChildControl<CheckBox>(myItem); // if (cbx == selfCheckbox) // { // UnCheckChildCheckbox(myItem, selfCheckbox); // } // else // { // //if (MultiSelected && parentName == GetParentName(myItem) && cbx.IsChecked==true) // if (MultiSelected && !HaveChildItemChecked(myItem, selfCheckbox)) // { // return; // } // if (cbx != null && cbx.IsChecked.GetValueOrDefault(false)) // { // cbx.IsChecked = false; // } // UnCheckChildCheckbox(childItem, selfCheckbox); // } // } //} private bool IsSameParent(TreeViewItem item, CheckBox selfCheckbox) { if (item == null || item.Parent == null) return false; ExtOrgObj obj = new ExtOrgObj(); TreeViewItem parentItem = new TreeViewItem(); parentItem = item.Parent as TreeViewItem; obj = parentItem.DataContext as ExtOrgObj; //ExtOrgObj obj1 = new ExtOrgObj(); //obj1= selfCheckbox.DataContext as ExtOrgObj; return obj.ObjectName == selfCheckbox.DataContext.ToString(); }
/// <summary> /// 绑定组织架构节点 /// </summary> private void BindCompany() { treeOrganization.Items.Clear(); allCompanys = Application.Current.Resources["SYS_DepartmentInfo"] as List <T_HR_COMPANY>; allDepartments = Application.Current.Resources["SYS_DepartmentInfo"] as List <T_HR_DEPARTMENT>; if (allCompanys == null) { return; } List <T_HR_COMPANY> TopCompany = new List <T_HR_COMPANY>(); foreach (T_HR_COMPANY tmpOrg in allCompanys) { //如果当前公司没有父机构的ID,则为顶级公司 if (string.IsNullOrWhiteSpace(tmpOrg.FATHERID)) { TreeViewItem item = new TreeViewItem(); item.Header = tmpOrg.CNAME; item.HeaderTemplate = treeViewItemTemplate; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpOrg; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; treeOrganization.Items.Add(item); TopCompany.Add(tmpOrg); } else { //查询当前公司是否在公司集合内有父公司存在 var ent = from c in allCompanys where c.COMPANYID == tmpOrg.FATHERID && tmpOrg.FATHERTYPE == "0" select c; var ent2 = from c in allDepartments where tmpOrg.FATHERTYPE == "1" && tmpOrg.FATHERID == c.DEPARTMENTID select c; //如果不存在,则为顶级公司 if (ent.Count() == 0 && ent2.Count() == 0) { TreeViewItem item = new TreeViewItem(); item.Header = tmpOrg.CNAME; item.HeaderTemplate = treeViewItemTemplate;; item.Style = Application.Current.Resources["TreeViewItemStyle"] as Style; ExtOrgObj obj = new ExtOrgObj(); obj.ObjectInstance = tmpOrg; item.DataContext = obj; //标记为公司 item.Tag = OrgTreeItemTypes.Company; treeOrganization.Items.Add(item); TopCompany.Add(tmpOrg); } } } //开始递归 foreach (var topComp in TopCompany) { TreeViewItem parentItem = GetParentItem(OrgTreeItemTypes.Company, topComp.COMPANYID); List <T_HR_COMPANY> lsCompany = (from ent in allCompanys where ent.FATHERTYPE == "0" && ent.FATHERID == topComp.COMPANYID select ent).ToList(); List <T_HR_DEPARTMENT> lsDepartment = (from ent in allDepartments where ent.FATHERID == topComp.COMPANYID && ent.FATHERTYPE == "0" select ent).ToList(); AddOrgNode(lsCompany, lsDepartment, parentItem); } }