/// <summary> /// 查找方法 /// </summary> private void Search() { try { string search = this.tbFind.Text; //如果查找为科室 if (rbDept.Checked) { //如果查找条件为编码 if (rbCode.Checked) { search = search.PadLeft(4, '0'); foreach (TreeNode typeNode in this.ucDeptMgr.tvDeptList1.Nodes[0].Nodes) { foreach (TreeNode obj in typeNode.Nodes) { string text = obj.Text.Substring(0, 4); if (obj.Text.Substring(1, 4) == search) { this.ucDeptMgr.tvDeptList1.SelectedNode = obj; break; } } } } //如果查询条件为名称 if (rbName.Checked) { if (search != tempSearch) { searchDept = 0; searchDeptMax = this.ucDeptMgr.tvDeptList1.Nodes[0].Nodes.Count; } tempSearch = search; for (int i = searchDept; i < this.ucDeptMgr.tvDeptList1.Nodes[0].Nodes.Count; i++) { TreeNode typeNode = this.ucDeptMgr.tvDeptList1.Nodes[0].Nodes[i]; foreach (TreeNode obj in typeNode.Nodes) { if (obj.Text.IndexOf(search) >= 0) { this.ucDeptMgr.tvDeptList1.SelectedNode = obj; break; } } searchDept++; } searchDept++; if (searchDept == searchDeptMax) { searchDept = 0; } } } //如果查找为人员 if (rbEmpl.Checked) { //如果查询条件为编码 if (rbCode.Checked) { search = search.PadLeft(6, '0'); Neusoft.HISFC.Models.Base.Employee obj = perMgr.GetPersonByID(search); if (obj == null) { MessageBox.Show("没有此员工编号的人员!"); return; } SearchDept(obj.Dept.ID); for (int i = 0; i < this.ucDeptMgr.neuSpread1_Sheet1.RowCount; i++) { if (this.ucDeptMgr.neuSpread1_Sheet1.Cells[i, 0].Text == search) { //{4C8F4B67-330F-4e5e-B537-8AB753F272A7} this.ucDeptMgr.neuSpread1_Sheet1.AddSelection(i, 1, 1, 1); break; } } } //如果查询条件为名称 if (rbName.Checked) { if (search != tempSearch) { alPerson = perMgr.GetPersonByName("%" + search + "%"); /* * [2007/02/05] 这个地方应该是错误的,alPerson是全局的变的变量 * 已经在第31行初始化了,而且业务层的返回值不太可能是null. * 我觉得本意应该是 alPerson.Count==0; * * if (alPerson == null) * { * MessageBox.Show("没有名称符合" + "[" + search + "]" + "的员工!"); * return; * } * * */ if (alPerson.Count == 0) { MessageBox.Show("没有名称符合" + "[" + search + "]" + "的员工!"); return; } searchPersonMax = alPerson.Count; searchPerson = 0; } tempSearch = search; if (alPerson.Count == 0) { MessageBox.Show("没有此员工编号的人员!"); return; } Neusoft.HISFC.Models.Base.Employee obj = (Neusoft.HISFC.Models.Base.Employee)alPerson[searchPerson]; if (obj == null) { MessageBox.Show("没有此员工编号的人员!"); return; } SearchDept(obj.Dept.ID); for (int i = 0; i < this.ucDeptMgr.neuSpread1_Sheet1.RowCount; i++) { if (this.ucDeptMgr.neuSpread1_Sheet1.Cells[i, 0].Text == obj.ID) { //{4C8F4B67-330F-4e5e-B537-8AB753F272A7} this.ucDeptMgr.neuSpread1_Sheet1.AddSelection(i, 1, 1, 1); break; } } searchPerson++; if (searchPerson == searchPersonMax) { searchPerson = 0; } } } } catch (Exception ee) { MessageBox.Show(ee.Message); } }