diff --git a/.classpath b/.classpath index 82d2abb..bca886b 100644 --- a/.classpath +++ b/.classpath @@ -5,5 +5,7 @@ + + diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 8ed1435..b66bf3c 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -54,4 +54,6 @@ Export-Package: cn.net.connor.std.processedit, cn.net.connor.std.processedit.word Bundle-ClassPath: lib/jsqlparser-4.3.jar, ., - lib/jacob.jar + lib/jacob.jar, + lib/mssql-jdbc-7.0.0.jre8.jar, + lib/ojdbc8.jar diff --git a/build.properties b/build.properties index eed0977..55eabe3 100644 --- a/build.properties +++ b/build.properties @@ -5,4 +5,6 @@ bin.includes = plugin.xml,\ .,\ icons/,\ lib/jsqlparser-4.3.jar,\ - lib/jacob.jar + lib/jacob.jar,\ + lib/mssql-jdbc-7.0.0.jre8.jar,\ + lib/ojdbc8.jar diff --git a/lib/mssql-jdbc-7.0.0.jre8.jar b/lib/mssql-jdbc-7.0.0.jre8.jar new file mode 100644 index 0000000..9f68c4d Binary files /dev/null and b/lib/mssql-jdbc-7.0.0.jre8.jar differ diff --git a/lib/ojdbc8.jar b/lib/ojdbc8.jar new file mode 100644 index 0000000..8517287 Binary files /dev/null and b/lib/ojdbc8.jar differ diff --git a/plugin.xml b/plugin.xml index 8197bf7..d9c5270 100644 --- a/plugin.xml +++ b/plugin.xml @@ -55,6 +55,7 @@ + @@ -82,10 +83,11 @@ - - - - + + + + + @@ -164,10 +166,13 @@ - + - + + + + diff --git a/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQHandler.java b/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQHandler.java new file mode 100644 index 0000000..01ef763 --- /dev/null +++ b/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQHandler.java @@ -0,0 +1,87 @@ +package cn.net.connor.std.processedit.gygxsqbm; + +import java.util.ArrayList; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class GYBMSQHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + //System.out.println("CodeApplyHandler"); + TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + InterfaceAIFComponent[] targets = AIFUtility.getCurrentApplication().getTargetComponents(); + ArrayList target = new ArrayList<>(); + ArrayList boms = new ArrayList<>(); + StringBuilder msg = new StringBuilder(""); + for(InterfaceAIFComponent t : targets) { + TCComponentItemRevision rev; + TCComponentBOMLine bom = null; + if(t instanceof TCComponentItemRevision) { + rev = (TCComponentItemRevision) t; + }else if(t instanceof TCComponentBOMLine) { + bom = (TCComponentBOMLine) t; + rev = bom.getItemRevision(); + }else { + msg.append("ѡж ").append(t).append(" BOM汾\n"); + continue; +// MessageBox.post(desktop, "ѡж "+t+" BOM汾ѡ", "ERROR", MessageBox.ERROR); +// return null; + } + if(rev.getTCProperty("j6_wlbm")==null) { + msg.append("ѡж ").append(t).append(" ûйչ\n"); + continue; +// MessageBox.post(desktop, "ѡж "+rev+" ûйչԣȷѡ϶", "ERROR", MessageBox.ERROR); +// return null; + } + if(!rev.getProperty("j6_wlbm").isEmpty()) { + msg.append("ѡж ").append(t).append(" йչ룬޷ٴ\n"); + continue; +// MessageBox.post(desktop, "ѡж"+t+"йչ룬޷ٴ룡", "ERROR", MessageBox.ERROR); +// return null; + } + if(bom != null) + boms.add(bom); + else + target.add(rev); + } + ArrayList list = new ArrayList<>(); + String[] ops = new String[] { "Jd_Code_Apply_ME", "Jd_TC_Info_Connect", "Jd_TICODE_Info_Connect", "Jd_Code_Product_Class" }; + if(boms.size()>0) + ops[0] = "Jd_BOM_Code_Apply_ME"; + for(String name : ops) { + String[] options = session.getPreferenceService().getStringValues(name); + if(options == null || options.length == 0) { + MessageBox.post(desktop, "ѡ"+name+"òȷ", "ERROR", MessageBox.ERROR); + return null; + } + list.add(options); + } + if(boms.size()==0 && target.size()==0) { + MessageBox.post(desktop, "¶빤չ⣺\n"+msg, "ʾ", MessageBox.ERROR); + return null; + }else if(boms.size()>0) + new GYBMSQOperation(session, boms, list, msg).executeOperation(); + else + new GYBMSQOperation(session, target, list, msg).executeOperation(); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQOperation.java b/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQOperation.java new file mode 100644 index 0000000..3a05740 --- /dev/null +++ b/src/cn/net/connor/std/processedit/gygxsqbm/GYBMSQOperation.java @@ -0,0 +1,231 @@ +package cn.net.connor.std.processedit.gygxsqbm; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class GYBMSQOperation extends AbstractAIFOperation { + +// private TCSession session; + private ArrayList revs; + private ArrayList options; + private StringBuilder msg; + private HashMap classmap; + + public GYBMSQOperation(TCSession session, ArrayList revs, ArrayList options, StringBuilder msg) { +// this.session = session; + this.revs = revs; + this.options = options; + this.msg = msg; + this.classmap = new HashMap<>(); + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + HashMap opmap = new HashMap<>(); + for(String s : options.get(0)) { + String[] ss = s.split("@@"); + opmap.put(ss[0].split("@"), ss[1].split("\\+")); + } + for(String s : options.get(3)) { + String[] ss = s.split("="); + classmap.put(ss[0], ss[1]); + } + String[] sqlOptions = options.get(1); + Connection conn1 = SqlUtil.getSqlserverConnection("oracle.jdbc.driver.OracleDriver", + "jdbc:oracle:thin:@" + sqlOptions[0] + ":1521:" + sqlOptions[3], sqlOptions[1], sqlOptions[2]); + sqlOptions = options.get(2); +// Connection conn2 = SqlUtil.getSqlserverConnection("oracle.jdbc.driver.OracleDriver", +// "jdbc:oracle:thin:@" + sqlOptions[0] + ":1521:" + sqlOptions[3], sqlOptions[1], sqlOptions[2]); +// Class.forName("oracle.jdbc.driver.OracleDriver"); + Connection conn2 = DriverManager.getConnection("jdbc:oracle:thin:@" + sqlOptions[0] + ":1521:" + sqlOptions[3], sqlOptions[1], sqlOptions[2]); + conn2.setAutoCommit(false); +// StringBuilder msg = new StringBuilder(""); + for(TCComponent comp : revs) { + try { + TCComponentItemRevision rev = null; + TCComponentBOMLine bom = null; + if(comp instanceof TCComponentItemRevision) { + rev = (TCComponentItemRevision) comp; + }else { + bom = (TCComponentBOMLine) comp; + rev = bom.getItemRevision(); + } + String[] ops = null; + OPTS:for(String[] ss : opmap.keySet()) { + for(String s : ss) { + String[] ps = s.split("="); + String[] pss = ps[1].split(";"); + if(!TCUtil.contains(pss, getProp(rev, ps[0]))) { + continue OPTS; + } + } + ops = opmap.get(ss); + } + if(ops==null) { + continue; + } + StringBuilder sb = new StringBuilder(""); + int lshc = 0; + for(String op : ops) { + if(op.equals(".")) { + sb.append(op); + }else if(op.contains(".")) { + sb.append(getProp(rev, bom, op)); + }else if(op.startsWith("LSH")) { + sb.append("LSH"); + lshc = Integer.parseInt(op.substring(3)); + }else if(op.startsWith("#")) { + throw new Exception(op.substring(1)); + }else { + sb.append(op); + } + } + String code = sb.toString(); + if(lshc>0) { + String lsh = "%" + String.format("%02d", lshc) + "d"; + ArrayList> results = SqlUtil.getDBInfo(conn1, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+sb+"'"); + if(results.size()>0) { + int no = (Integer) results.get(0).get("SERIALNUMBER") + 1; + if((no+"").length() > lshc) + throw new Exception(rev+" Ĺչˮصֵٴν룡\n"); + SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" + code + "'"); + code = code.replace("LSH", String.format(lsh, no)); + }else { + String id = sb.substring(0, sb.indexOf("LSH")).replaceAll("\\.", ""); + String sql = "select max(ECMS_CODE) as ECMS_NEXTCODE from ECMS_SERIAL where ECMS_PRE='" +id+ "' group by ECMS_PRE"; + System.out.println("ECMS_SERIAL:"+sql); + results = SqlUtil.getDBInfo(conn2, sql); + if(results.size()>0) { + int no = Integer.parseInt(results.get(0).get("ECMS_NEXTCODE").toString()) + 1; + if((no+"").length() > lshc) + throw new Exception(rev+" Ĺչˮصֵٴν룡\n"); + SqlUtil.update("insert into JD_CODE_RULE values('" +code+ "',"+no+")"); + code = code.replace("LSH", String.format(lsh, no)); + }else { + int no = 1; + SqlUtil.update("insert into JD_CODE_RULE values('" +code+ "',1)"); + code = code.replace("LSH", String.format(lsh, no)); + } + } + }else { + List> results = SqlUtil.getDBInfo(conn1, + "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+code+"'"); + if (results.size() == 0) { + SqlUtil.update("insert into JD_CODE_RULE values('" +code+ "',0)"); + }else { + throw new Exception(rev+" Ĺչ "+code+" Ѵڣֵ\n"); + } + } + rev.setProperty("j6_wlbm", code); + } catch (Exception e) { + e.printStackTrace(); + msg.append(comp).append(" ").append(e.getMessage()).append("\n"); + } + } + if(msg.length()==0) + MessageBox.post(desktop, "չɣ", "ʾ", MessageBox.INFORMATION); + else + MessageBox.post(desktop, "¶빤չ⣺\n"+msg, "ʾ", MessageBox.WARNING); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + + private String getProp(TCComponentItemRevision rev, TCComponentBOMLine bom, String op) throws Exception { + String value = ""; + String[] split = op.split(";"); + String[] ss = split[0].split("\\."); + if(ss[0].equals("rev")) { + if(ss[1].contains("@Jd_Code_Product_Class")) { + String v = ss[1].substring(0, ss[1].indexOf("@")); + value = classmap.get(getProp(rev, v)); + }else + value = getProp(rev, ss[1]); + }else if(ss[0].equals("part")) { + AIFComponentContext[] zjtz = TCUtil.getPseudoFolder(rev, "TC_Is_Represented_By").getChildren(); + if(zjtz.length>0) { + AIFComponentContext[] ljtz = ((TCComponent)zjtz[0].getComponent()).whereReferencedByTypeRelation(null, new String[] { "J6_ASSOCIATED_REL" }); + if(ljtz.length>0) { + AIFComponentContext[] ljwl = TCUtil.getPseudoFolder((TCComponent)ljtz[0].getComponent(), "representation_for").getChildren(); + if(ljwl.length>0) { + value = getProp((TCComponent)ljwl[0].getComponent(), ss[1]); + } + } + } + }else if(ss[0].equals("parent")) { + if(bom==null) + throw new Exception("ѡBOMУ֧parent"); + TCComponentBOMLine parent = bom.parent(); + if(parent==null) + throw new Exception("δҵBOM"); + value = getProp(parent.getItemRevision(), ss[1]); + } + if(value.isEmpty()) { + if(ss[0].equals("part")) + throw new Exception("ȡչʧ"); + else + throw new Exception(ss[1]+" Ϊ"); + } + if(split.length==1) + return value; + if(split[1].startsWith("LEN")) { + value = "" + Integer.parseInt(value) / Integer.parseInt(split[1].substring(3)); + if(value.length() > 4) + throw new Exception("³ȡϢд±д"); + while(value.length() < 4) { + value = "0" + value; + } + //lidy20240711жϳȣȳȡ0 + //20240715ͻҪԭȥ +// int length = value.length(); +// if(length > 5) +// throw new Exception("³ȡϢд±д"); +// String divisor = split[1].substring(3); +// int len = 5 - divisor.length() + 1; +// System.out.println("LEN" + split[1] + "=" + value + "=" + length + "=" + divisor + "=" + len); +// if(length > len) +// value = "" + Integer.parseInt(value) / Integer.parseInt(divisor); +// System.out.println("value1" + value); +// while(value.length() < len) { +// value = "0" + value; +// } + System.out.println("value2" + value); + value = value.substring(0, 2) + "." + value.substring(2); + }else if(split[1].contains(">")) { + String[] sp = split[1].split(">"); + int n = Integer.parseInt(sp[0])-1; + value = value.substring(n, n+Integer.parseInt(sp[1])); + }else { + int len = Integer.parseInt(split[1]); + while(value.length() 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < args.length; i++) { + insertSql.append(args[i]); + insertSql.append(", "); + if (args[i].toUpperCase().equals("LAST_UPDATE_DATE") || args[i].toUpperCase().equals("CREATED_DATE")) { + values.append("to_date(?,'yyyy-MM-dd HH24:mi:ss'), "); + } else { + values.append("?, "); + } + + } + } else { + return null; + } + insertSql.delete(insertSql.length() - 2, insertSql.length()); + values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * õݿ + * + * @param tableName + * @param args + * + * @param args2 + * + * @return ƴӺĴݿ + */ + public final static String GetCreateTableSQL(String tableName, String[] args, String[] args2) { + + if (args == null || args2 == null || args.length != args2.length) { + System.out.println("THE INPUT PRAGREMS IS ERROR"); + return null; + } + StringBuffer createSQL = new StringBuffer("create table "); + createSQL.append(tableName); + createSQL.append("("); + for (int i = 0; i < args.length; i++) { + createSQL.append(args[i] + " "); + createSQL.append(args2[i] + ", "); + } + createSQL.delete(createSQL.length() - 2, createSQL.length()); + createSQL.append(")"); + return createSQL.toString(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql) throws Exception { + return getPs(sql, null); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws Exception { + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws Exception { + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * + */ + public final static int write(String sql) { + return write(sql, null); + } + + /** + * + */ + public final static int write(Object[] argments, String sql) { + return write(sql, argments); + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql) { + return delete(sql, null); + } + + /** + * ɾ + */ + public final static int delete(Object[] argments, String sql) { + return delete(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql, Object[] argments) { + return update(sql, argments); + } + + /** + * ޸ + */ + public final static int update(String sql) { + return update(sql, null); + } + + /** + * ޸ + */ + public final static int update(String[] argments, String sql) { + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + i = SqlUtil.getPs(argments, sql).executeUpdate(); + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + return i; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws Exception { + return read(sql, null); + } + + /** + * ѯ + */ + public final static ResultSet read(Object[] argments, String sql) throws Exception { + return read(sql, argments); + } + + /** + * ѯ(вѯնҪô˷治쳣׳ɵߴfinallyͷԴ) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws Exception { + System.out.println("argments=" + argments.length); + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + + /** + * + */ + public final static boolean createTable(String sql) { + return go(sql, null); + } + + /** + * ɾ + */ + public final static boolean dropTable(String sql) { + return go(sql, null); + } + + /** + * ޸ı + */ + public final static boolean alterTable(String sql) { + return go(sql, null); + } + + /** + * ˷ִDDL(,޸ı,ɾ) + */ + private final static boolean go(String sql, Object[] argments) { + boolean flag = false; + try { + flag = SqlUtil.getPs(sql, argments).execute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + if (flag) { + try { + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return flag; + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(SqlUtil.rs, SqlUtil.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + public static List> getDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List> vecData = new ArrayList>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + System.out.println("meta"+meta.getColumnCount()); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + System.out.println("columnTypes"+i+"=="+columnNames[i]); + } + + while (rs.next()) { + HashMap dataTable = new HashMap(); + + for (int i = 1; i <= columnNames.length; i++) { + Object value = null; + switch (columnTypes[i-1]) { + case Types.NVARCHAR: + case Types.VARCHAR: + value = rs.getString(i);//columnNames[i] + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(i); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(i); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(i); + break; + case Types.CLOB: + Clob clob = rs.getClob(i); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } + dataTable.put(columnNames[i-1], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + } + vecData.add(dataTable); + } + rs.close(); + statement.close(); + return vecData; + } + public static List getArrayDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List vecData = new LinkedList(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + } + + while (rs.next()) { + Object[] result = new Object[columnNames.length]; + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } +// dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + result[i] = value; + } + vecData.add(result); + } + rs.close(); + statement.close(); + return vecData; + } +} diff --git a/src/cn/net/connor/std/processedit/gygxsqbm/SqlUtil.java b/src/cn/net/connor/std/processedit/gygxsqbm/SqlUtil.java new file mode 100644 index 0000000..6de0b02 --- /dev/null +++ b/src/cn/net/connor/std/processedit/gygxsqbm/SqlUtil.java @@ -0,0 +1,688 @@ +package cn.net.connor.std.processedit.gygxsqbm; + +import java.io.Reader; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.sql.Timestamp; +import java.sql.Types; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class SqlUtil { + + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; +// public static Registry reg = Registry.getRegistry(SqlUtil.class); + public static int ORACLE = 1; + public static int SQLSERVER = 2; + +// public static Connection getConnection(int dbType) { +// if (dbType == ORACLE) { +// return getOracleConnection(); +// } else if (dbType == SQLSERVER) { +// return getSqlserverConnection(); +// } +// return null; +// } + + public static Date getDate(java.sql.Date date) { + if (date == null) { + return null; + } + return new Date(date.getTime()); + } + + /** + * ݿ + + public static Connection getSqlserverConnection() { + String driver = reg.getString("SQL.SQLSERVER.DRIVER"); + String url = reg.getString("SQL.SQLSERVER.URL"); + String user = reg.getString("SQL.SQLSERVER.USER"); + String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + }*/ + + public static Connection getSqlserverConnection(String driver, String url, String user, String password) { +// String driver = reg.getString("SQL.SQLSERVER.DRIVER"); +// String url = reg.getString("SQL.SQLSERVER.URL"); +// String user = reg.getString("SQL.SQLSERVER.USER"); +// String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); +// System.out.println("DRIVER: " + driver); +// System.out.println("URL: " + url); +// System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + + public static Connection getOracleConnection(String url, String user, String password) { + String driver = "oracle.jdbc.driver.OracleDriver"; + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + // 1.getConnection()MySQLݿ⣡ + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + + /* + public static Connection getOracleConnection() { + // String driver = reg.getString("SQL.ORACLE.DRIVER"); + String url = reg.getString("SQL.ORACLE.URL"); + String user = reg.getString("SQL.ORACLE.USER"); + String password = reg.getString("SQL.ORACLE.PASSWORD"); +// if(prefs!=null&&prefs.length==5) { +// url = "jdbc:oracle:thin:@"+prefs[0]+":"+prefs[1]+":"+prefs[2]; +// user = prefs[3]; +// password = prefs[4]; +// } + return getOracleConnection(url, user, password); + }*/ + + /** + * ˽йnew󣬷ֹö + */ + private SqlUtil() { + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql(String tableName, String[] selectElement, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT "); + if (selectElement != null) { + for (String element : selectElement) { + valuesSB.append(element).append(","); + } + valuesSB.delete(valuesSB.length() - 1, valuesSB.length()); + } + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param args + * @return + */ + public static String getSelectSql(String tableName, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT * FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴӸ + * + * @param tableName + * @param args + * @param args2 + * @return + */ + public static String getUpdataSQL(String tableName, String[] args, String[] args2) { + StringBuffer updateSB = new StringBuffer("UPDATE "); + updateSB.append(tableName); + updateSB.append(" SET "); + // ƴӸ + for (int i = 0; i < args.length; i++) { + if (args[i].toUpperCase().equals("CREATED_DATE") || args[i].toUpperCase().equals("LAST_UPDATE_DATE")) { + updateSB.append(args[i]).append("=to_date(?,'yyyy-MM-dd HH24:mi:ss') ,"); + } else { + updateSB.append(args[i]).append("=? ,"); + } + } + updateSB.delete(updateSB.length() - 2, updateSB.length()); + ; + updateSB.append(" WHERE "); + for (int i = 0; i < args2.length; i++) { + updateSB.append(args2[i]).append("=? AND "); + } + updateSB.delete(updateSB.length() - 4, updateSB.length()); + return updateSB.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql(String tableName, String... args) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && args != null && args.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < args.length; i++) { + insertSql.append(args[i]); + insertSql.append(", "); + if (args[i].toUpperCase().equals("LAST_UPDATE_DATE") || args[i].toUpperCase().equals("CREATED_DATE")) { + values.append("to_date(?,'yyyy-MM-dd HH24:mi:ss'), "); + } else { + values.append("?, "); + } + + } + } else { + return null; + } + insertSql.delete(insertSql.length() - 2, insertSql.length()); + values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * õݿ + * + * @param tableName + * @param args + * + * @param args2 + * + * @return ƴӺĴݿ + */ + public final static String GetCreateTableSQL(String tableName, String[] args, String[] args2) { + + if (args == null || args2 == null || args.length != args2.length) { + System.out.println("THE INPUT PRAGREMS IS ERROR"); + return null; + } + StringBuffer createSQL = new StringBuffer("create table "); + createSQL.append(tableName); + createSQL.append("("); + for (int i = 0; i < args.length; i++) { + createSQL.append(args[i] + " "); + createSQL.append(args2[i] + ", "); + } + createSQL.delete(createSQL.length() - 2, createSQL.length()); + createSQL.append(")"); + return createSQL.toString(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql) throws Exception { + return getPs(sql, null); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws Exception { + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws Exception { + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * + */ + public final static int write(String sql) { + return write(sql, null); + } + + /** + * + */ + public final static int write(Object[] argments, String sql) { + return write(sql, argments); + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql) { + return delete(sql, null); + } + + /** + * ɾ + */ + public final static int delete(Object[] argments, String sql) { + return delete(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql, Object[] argments) { + return update(sql, argments); + } + + /** + * ޸ + */ + public final static int update(String sql) { + return update(sql, null); + } + + /** + * ޸ + */ + public final static int update(String[] argments, String sql) { + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + i = SqlUtil.getPs(argments, sql).executeUpdate(); + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + return i; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws Exception { + return read(sql, null); + } + + /** + * ѯ + */ + public final static ResultSet read(Object[] argments, String sql) throws Exception { + return read(sql, argments); + } + + /** + * ѯ(вѯնҪô˷治쳣׳ɵߴfinallyͷԴ) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws Exception { + System.out.println("argments=" + argments.length); + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + + /** + * + */ + public final static boolean createTable(String sql) { + return go(sql, null); + } + + /** + * ɾ + */ + public final static boolean dropTable(String sql) { + return go(sql, null); + } + + /** + * ޸ı + */ + public final static boolean alterTable(String sql) { + return go(sql, null); + } + + /** + * ˷ִDDL(,޸ı,ɾ) + */ + private final static boolean go(String sql, Object[] argments) { + boolean flag = false; + try { + flag = SqlUtil.getPs(sql, argments).execute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + if (flag) { + try { + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return flag; + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(SqlUtil.rs, SqlUtil.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + public static ArrayList> getDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + ArrayList> vecData = new ArrayList>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + System.out.println("meta"+meta.getColumnCount()); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + System.out.println("columnTypes"+i+"=="+columnNames[i]); + } + + while (rs.next()) { + HashMap dataTable = new HashMap(); + + for (int i = 1; i <= columnNames.length; i++) { + Object value = null; + switch (columnTypes[i-1]) { + case Types.NVARCHAR: + case Types.VARCHAR: + value = rs.getString(i);//columnNames[i] + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(i); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(i); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(i); + break; + case Types.CLOB: + Clob clob = rs.getClob(i); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } + dataTable.put(columnNames[i-1], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + } + vecData.add(dataTable); + } + rs.close(); + statement.close(); + return vecData; + } + public static List getArrayDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List vecData = new LinkedList(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + } + + while (rs.next()) { + Object[] result = new Object[columnNames.length]; + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } +// dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + result[i] = value; + } + vecData.add(result); + } + rs.close(); + statement.close(); + return vecData; + } +} diff --git a/src/cn/net/connor/std/processedit/gygxsqbm/TCUtil.java b/src/cn/net/connor/std/processedit/gygxsqbm/TCUtil.java new file mode 100644 index 0000000..9aa95ff --- /dev/null +++ b/src/cn/net/connor/std/processedit/gygxsqbm/TCUtil.java @@ -0,0 +1,349 @@ +package cn.net.connor.std.processedit.gygxsqbm; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.Window; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Vector; + +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JTable; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.filechooser.FileSystemView; + +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.commands.open.OpenFormDialog; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentContextList; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCQueryClause; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class TCUtil { + public static final int MINWIDTH = 1280; + public static final int MINHEIGHT = 768; + + public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + double screenWidth = screenSize.getWidth(); + double screenHeight = screenSize.getHeight(); + Dimension dialogSize = abstractAIFDialog.getSize(); + if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { + abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); + abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY())); + } + if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { + abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); + abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10); + } + /* + * if((screenWidth + * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * abstractAIFDialog.setLocation(10, 10); } + */ + } + + public static void fitToScreen(OpenFormDialog openFormDialog) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + double screenWidth = screenSize.getWidth(); + double screenHeight = screenSize.getHeight(); + Dimension dialogSize = openFormDialog.getSize(); + if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { + openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); + openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY())); + } + if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { + openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); + openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10); + } + /* + * if((screenWidth + * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * openFormDialog.setLocation(10, 10); } + */ + } + + public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{ + TCComponentBOMWindow window = null; + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + window = bomWinType.create(null); + return window; + } + + @SuppressWarnings("deprecation") + public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision) + throws Exception { + window.lock(); + TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null); + window.save(); + window.unlock(); + return bomLine; + } + public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation) + throws Exception { + TCComponentPseudoFolder pseudoFolder = null; + AIFComponentContext[] comps = parent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); + if (comp instanceof TCComponentPseudoFolder) { + if (comp.isTypeOf("PseudoFolder")) { +// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation()); + if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) { + pseudoFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + return pseudoFolder; + } + public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception { + if (revision != null) { + AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev"); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentForm) { + return (TCComponentForm) component; + } + } + } + return null; + } + + public static LinkedHashMap getlovValues(TCSession session, String lovName) throws TCException { + LinkedHashMap lovVal = new LinkedHashMap(); + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lovs = lovType.find(lovName); + if (lovs != null && lovs.length > 0) { + TCComponentListOfValues lov = lovs[0]; + ListOfValuesInfo lovInfo = lov.getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + // System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]); + lovVal.put(code[i], name[i]); + } + } + return lovVal; + } + return null; + } + + public static String getTableValue(JTable table, int row, int col){ + Object val = table.getValueAt(row, col); + if(val==null) + return ""; + else + return val.toString(); + } + public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + throw new Exception("δҵѯ " + queryName + "!"); + } + aKey = session.getTextService().getTextValues(aKey); +// for (int i = 0; i < aKey.length; i++) { +// System.out.println(aKey[i] + "===============" + aVal[i]); +// } + TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal); + return componentContextList.toTCComponentArray(); + } + public static TCComponent[] query(TCSession session, String queryName, Vector Keys, Vector Vals) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + System.out.println("δҵѯ" + queryName); + throw new Exception("Query:"+queryName+" cannot find"); + } + TCQueryClause[] qc = imancomponentquery.describe(); +// Map clauseMap = new HashMap<>(); + for(TCQueryClause c : qc) { + String key = c.getUserEntryNameDisplay(); + String value = c.getDefaultValue(); +// System.out.println(key + "==>" + c.getAttributeName()); + if(!value.trim().isEmpty() && !Keys.contains(key)) { + if(key.isEmpty()) + Keys.add(c.getAttributeName()); + else + Keys.add(key); + Vals.add(value); + } + } + int size = Keys.size(); + String[] keyA = new String[size]; + String[] valueA = new String[size]; + for(int i=0; i 0) { + Integer maxId = 0; + for (TCComponent comp : comps) { + String pid = comp.getProperty("item_id"); + System.out.println("pid:" + pid); + String pidSuffix = pid.substring(pid.length() - 3); + if (Integer.parseInt(pidSuffix) > maxId) { + maxId = Integer.parseInt(pidSuffix); + } + } + return String.format("%03d", maxId + 1); + } + return "001"; + } + + public static File saveExcelChooser() { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + System.out.println("saveExcelChooser1:" + path); + } + return dir; + } + + public static File saveExcelChooser(Window parent, String defaultFile) { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + chooser.setSelectedFile(new File(defaultFile)); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new JDialog(parent)); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + if(dir.exists()) + dir.delete(); +// System.out.println("saveExcelChooser1:" + dir.getPath()); + } + return dir; + } + + public static boolean contains(String[] array, String str) { + for(String s : array) { +// System.out.println("contains:"+s+"="+str); + if(s.equals(str)) + return true; + } + return false; + } + + public static Map executeToMap(InputStream in){ + System.out.println("Read properties file"); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); + String line = null; + Map resultMap = new LinkedHashMap<>(16); + if (reader.ready()) { + while (null != (line = reader.readLine())) { + if (line.length() <= 0 || line.startsWith("#") || !line.contains("=")) { + continue; + } + resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1)); + } + } + in.close(); + reader.close(); + return resultMap; + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR); + } + return null; + } + + public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception { + String refType = null, objType = null, fileName = null; + fileName = file.getName().toLowerCase(); + if (fileName.endsWith("xls")) { + refType = "excel"; + objType = "MSExcel"; + } else if (fileName.endsWith("xlsx")) { + refType = "excel"; + objType = "MSExcelX"; + } + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(datasetName, "description", objType); + dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType }); + return dataset; + } + + public static Vector getChildren(TCComponent parent, String relation, String name) throws Exception { + Vector result = new Vector<>(); + AIFComponentContext[] children; + if(relation==null || relation.isEmpty()) + children = parent.getChildren(); + else + children = parent.getChildren(relation); + for(AIFComponentContext c : children) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.getProperty("object_name").equals(name)) + result.add(comp); + } + return result; + } + + public static void setByPass(boolean b) { +// KUtil.setByPass(b); + } +} diff --git a/src/cn/net/connor/std/processedit/newmeprocess/PrefComponent.java b/src/cn/net/connor/std/processedit/newmeprocess/PrefComponent.java index 6921aed..656bbfc 100644 --- a/src/cn/net/connor/std/processedit/newmeprocess/PrefComponent.java +++ b/src/cn/net/connor/std/processedit/newmeprocess/PrefComponent.java @@ -221,6 +221,7 @@ public class PrefComponent { }else { System.out.println("getDynamicLOV:"+lovName); String[] lovValues = getDynamicLOV(lovComp); + lovCnt = KUtil.getLen(lovValues); this.lov = new String[lovCnt]; this.displayLov = new String[lovCnt]; @@ -705,8 +706,8 @@ public class PrefComponent { LovFilterData filter = new LovFilterData(); filter.sortPropertyName = "object_name"; filter.order = 1; - filter.numberToReturn = 100; - filter.maxResults = 100; + filter.numberToReturn = 1000; + filter.maxResults = 1000; input.lov = lov; input.filterData = filter; diff --git a/src/cn/net/connor/std/processedit/util/PrefComponent.java b/src/cn/net/connor/std/processedit/util/PrefComponent.java index 6d9de17..d882f40 100644 --- a/src/cn/net/connor/std/processedit/util/PrefComponent.java +++ b/src/cn/net/connor/std/processedit/util/PrefComponent.java @@ -245,6 +245,7 @@ public class PrefComponent { }else { System.out.println("getDynamicLOV:"+lovName); String[] lovValues = getDynamicLOV(lovComp); + System.out.println("lovValues---"+lovValues.length); lovCnt = KUtil.getLen(lovValues); this.lov = new String[lovCnt]; this.displayLov = new String[lovCnt]; @@ -831,14 +832,15 @@ public class PrefComponent { LovFilterData filter = new LovFilterData(); filter.sortPropertyName = "object_name"; filter.order = 1; - filter.numberToReturn = 100; - filter.maxResults = 100; + filter.numberToReturn = 1000; + filter.maxResults = 1000; input.lov = lov; input.filterData = filter; LOVSearchResults result = lovService.getInitialLOVValues(input); // StringBuffer sb = new StringBuffer(); // sb.append(">>"); + System.out.println("result.lovValues===="+result.lovValues.length); for (LOVValueRow row : result.lovValues) { Map map = row.propDisplayValues; // Map realmap = row.propInternalValues;