/// <summary> /// 执行 /// </summary> /// <returns>返回执行结果</returns> public override object Do() { if (DBAccess.IsExitsTableCol("Port_Dept", "TreeNo") == false) { return("err@ Port_Dept 没有找到 TreeNo 的列."); } BP.GPM.Dept dept = new GPM.Dept(); int i = dept.Retrieve(DeptAttr.ParentNo, "0"); if (i == 0) { return("err@没有找到ParentNo=0的根节点."); } //更新跟节点的TreeNo. string sql = "UPDATE Port_Dept SET TreeNo='01' WHERE No='" + dept.No + "'"; DBAccess.RunSQL(sql); BP.Port.Depts depts = new Depts(); depts.Retrieve(BP.Port.DeptAttr.ParentNo, dept.No); int idx = 0; foreach (BP.Port.Dept item in depts) { idx++; string subNo = idx.ToString().PadLeft(2, '0'); sql = "UPDATE Port_Dept SET TreeNo='01" + subNo + "' WHERE No='" + item.No + "'"; DBAccess.RunSQL(sql); sql = "UPDATE Port_DeptEmp SET DeptTreeNo='01" + subNo + "' WHERE FK_Dept='" + item.No + "'"; DBAccess.RunSQL(sql); sql = "UPDATE Port_DeptEmpStation SET DeptTreeNo='01" + subNo + "' WHERE FK_Dept='" + item.No + "'"; DBAccess.RunSQL(sql); SetDeptTreeNo(item, "01" + subNo); } return("执行成功."); }
public void SetDeptTreeNo(Dept dept, string pTreeNo) { BP.Port.Depts depts = new Depts(); depts.Retrieve(BP.Port.DeptAttr.ParentNo, dept.No); int idx = 0; foreach (BP.Port.Dept item in depts) { idx++; string subNo = idx.ToString().PadLeft(2, '0'); string sql = "UPDATE Port_Dept SET TreeNo='" + pTreeNo + "" + subNo + "' WHERE No='" + item.No + "'"; DBAccess.RunSQL(sql); //更新其他的表字段. sql = "UPDATE Port_DeptEmp SET DeptTreeNo='" + pTreeNo + "' WHERE FK_Dept='" + item.No + "'"; DBAccess.RunSQL(sql); sql = "UPDATE Port_DeptEmpStation SET DeptTreeNo='" + pTreeNo + "' WHERE FK_Dept='" + item.No + "'"; DBAccess.RunSQL(sql); //递归调用. SetDeptTreeNo(item, pTreeNo + subNo); } }