Windchill 11 修改部件公用属性--编码,名称

编码/名称修改默认是同步的,因为通常情况下:
1)编码参与了名称合成,
2)同时两者都是大版本属性
所以我们在修改了公共属性是,其本质就是就将所有小版本的数据刷新,这是我个人的理解,如有偏颇
请多多包涵并多多指教。

	/**
		 * 修改部件编码(如果目标编码在原系统中已存在则直接抛出异常)
		 * @param beforeNumber  原始编码
		 * @param targetNumber	目标编码
		 * @return 修改状态Failed/Success
		 * @throws Exception
		 */
		public static String changePartNumber(String beforeNumber, String targetNumber) throws Exception {
			StringBuffer sb = new StringBuffer();
			boolean flag = SessionServerHelper.manager.isAccessEnforced();
			String senssionUser =SessionHelper.manager.getPrincipal().getName();
			try {
				if(flag) {
					SessionServerHelper.manager.setAccessEnforced(false);
				}
				System.out.println("更新部件的编码及名称,开始");
				if(StringUtils.isBlank(beforeNumber) || StringUtils.isBlank(targetNumber) ) {
					sb.append("Failed:更新部件的编码原始编码或目标编码为空,请输入!
"); return sb.toString(); } wt.part.WTPart partBefore = getPartByNumber(beforeNumber); if(partBefore==null){ sb.append("Failed:更新部件的编码"+beforeNumber+"在系统中不存在。
"); return sb.toString(); } wt.part.WTPart partAfter = getPartByNumber(targetNumber); if(partAfter !=null){ sb.append("Failed:更新部件的目标编码"+targetNumber+"在系统中已存在。
"); return sb.toString(); } modifyPartNumber(partBefore, targetNumber); updateName(partBefore); WTUser user = getUserByName(senssionUser); WTPrincipalReference uref =WTPrincipalReference.newWTPrincipalReference(user); partBefore = (WTPart) PersistenceHelper.manager.refresh(partBefore); ext.csc.utilities.docpart.CSCDoc.setModifier(partBefore, uref); PersistenceServerHelper.manager.update(partBefore); sb.append("Success : " +beforeNumber + "编码修改修改为 " + targetNumber + "成功。
"); } catch (WTException e) { e.printStackTrace(); sb.append("Failed :\n"+e); } finally { SessionHelper.manager.setPrincipal(senssionUser); SessionServerHelper.manager.setAccessEnforced(flag); } return sb.toString(); }
 public static void modifyPartNumber(WTPart part, String number) throws WTException, RemoteException,InvocationTargetException {
    	try {
		    if (!RemoteMethodServer.ServerFlag) {
		        RemoteMethodServer.getDefault().invoke("modifyPartNumber", NPRUtil.class.getName(), null,
		                new Class[] { WTPart.class, String.class }, new Object[] { part, number });
		    } else {
		        boolean flag = SessionServerHelper.manager.setAccessEnforced(false);
		        WTUser currentuser = (WTUser) SessionHelper.manager.getPrincipal();
		        SessionHelper.manager.setAdministrator();
		        Transaction tx = null;
		        try {
		            tx = new Transaction();
		            tx.start();
		            Identified identified = (Identified) part.getMaster();
		            String name = part.getName();
		            WTOrganization org = part.getOrganization();
		            WTPartHelper.service.changeWTPartMasterIdentity((WTPartMaster) identified, name, number, org);
		            tx.commit();
		            tx = null;
		        } catch (Exception e) {
		            e.printStackTrace();
		            if (tx != null) {
		                tx.rollback();
		                tx = null;
		            }
		        } finally {
		            SessionHelper.manager.setPrincipal(currentuser.getAuthenticationName());
		            SessionServerHelper.manager.setAccessEnforced(flag);
		        }
		    }
		} catch (WTException e1) {
		    e1.printStackTrace();
		}
	}
	/**
	 * Modify Part Name
	 * 
	 * @param part
	 * @param name
	 * @throws WTException
	 * @throws InvocationTargetException
	 * @throws RemoteException
	 */
	public static void modifyPartName(WTPart part, String name)
			throws WTException, RemoteException, InvocationTargetException {
		try {
			if (!RemoteMethodServer.ServerFlag) {
				RemoteMethodServer.getDefault().invoke("modifyPartName", NPRUtil.class.getName(), null,
						new Class[] { WTPart.class, String.class }, new Object[] { part, name });
			} else {
				boolean flag = SessionServerHelper.manager.setAccessEnforced(false);
				WTUser currentuser = (WTUser) SessionHelper.manager.getPrincipal();
				SessionHelper.manager.setAdministrator();
				Transaction tx = null;
				try {
					tx = new Transaction();
					tx.start();
					Identified identified = (Identified) part.getMaster();
					String number = part.getNumber();
					WTOrganization org = part.getOrganization();
					WTPartHelper.service.changeWTPartMasterIdentity((WTPartMaster) identified, name, number, org);
					tx.commit();
					tx = null;
				} catch (Exception e) {
					e.printStackTrace();
					if (tx != null) {
						tx.rollback();
						tx = null;
					}
				} finally {
					SessionHelper.manager.setPrincipal(currentuser.getAuthenticationName());
					SessionServerHelper.manager.setAccessEnforced(flag);
				}
			}
		} catch (WTException e1) {
			e1.printStackTrace();
		}
	}

你可能感兴趣的:(Windchill)