main
李建辉 4 months ago
parent cfcde4773b
commit 277a5d42b3

@ -5,5 +5,7 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/mssql-jdbc-7.0.0.jre8.jar"/>
<classpathentry kind="lib" path="lib/ojdbc8.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -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

@ -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

Binary file not shown.

Binary file not shown.

@ -55,6 +55,7 @@
<command name="标准工序略图" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT"/>
<command name="下料工序略图" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT"/>
<command name="创建原材料BOM" id="cn.net.connor.std.processedit.commands.CreateBOMViewHandler"/>
<command name="工艺工序编码申请" id="cn.net.connor.std.processedit.gygxsqbm.GYBMSQHandler"/>
<command name="工艺分工" id="ProcessDivisionHandler"/>
<command name="工序分工" id="GXDivisionHandler"/>
@ -86,6 +87,7 @@
<handler commandId="GXDivisionHandler" class="cn.net.connor.std.processedit.ldy.GXDivisionHandler"/>
<handler commandId="ProcessMultiplexHandler" class="cn.net.connor.std.processedit.ldy.ProcessMultiplexHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" class="cn.net.connor.std.processedit.commands.CreateBOMViewHandler"/>
<handler commandId="cn.net.connor.std.processedit.gygxsqbm.GYBMSQHandler" class="cn.net.connor.std.processedit.gygxsqbm.GYBMSQHandler"/>
</extension>
@ -168,6 +170,9 @@
<command commandId="GXDivisionHandler" id="GXDivisionHandler" mnemonic="S"/>
<command commandId="ProcessMultiplexHandler" id="ProcessMultiplexHandler" mnemonic="S"/>
<command commandId="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" id="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" mnemonic="S"/>
<command commandId="cn.net.connor.std.processedit.gygxsqbm.GYBMSQHandler" id="cn.net.connor.std.processedit.gygxsqbm.GYBMSQHandler" mnemonic="S"/>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command commandId="cn.net.connor.std.processedit.commands.NewProcessCommand" icon="icons/meprocess_16.png" id="popups.newprocess">

@ -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<TCComponent> target = new ArrayList<>();
ArrayList<TCComponent> 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<String[]> 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;
}
}

@ -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<TCComponent> revs;
private ArrayList<String[]> options;
private StringBuilder msg;
private HashMap<String, String> classmap;
public GYBMSQOperation(TCSession session, ArrayList<TCComponent> revs, ArrayList<String[]> 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<String[], String[]> 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<HashMap<String, Object>> 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<HashMap<String, Object>> 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()<len) {
value = "0"+value;
}
}
return value;
}
private String getProp(TCComponent comp, String prop) throws Exception {
try {
return comp.getStringProperty(prop);
}catch(Exception e) {
return comp.getProperty(prop);
}
}
}

@ -0,0 +1,687 @@
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 SqlTIUtil {
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 SqlTIUtil() {
}
/**
* 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 List<HashMap<String, Object>> getDBInfo(Connection connection, String sql) throws Exception {
if (connection == null) {
throw new Exception("无法获取数据库连接信息");
}
List<HashMap<String, Object>> vecData = new ArrayList<HashMap<String, Object>>();
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<String, Object> dataTable = new HashMap<String, Object>();
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<Object[]> getArrayDBInfo(Connection connection, String sql) throws Exception {
if (connection == null) {
throw new Exception("无法获取数据库连接信息");
}
List<Object[]> vecData = new LinkedList<Object[]>();
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;
}
}

@ -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<HashMap<String, Object>> getDBInfo(Connection connection, String sql) throws Exception {
if (connection == null) {
throw new Exception("无法获取数据库连接信息");
}
ArrayList<HashMap<String, Object>> vecData = new ArrayList<HashMap<String, Object>>();
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<String, Object> dataTable = new HashMap<String, Object>();
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<Object[]> getArrayDBInfo(Connection connection, String sql) throws Exception {
if (connection == null) {
throw new Exception("无法获取数据库连接信息");
}
List<Object[]> vecData = new LinkedList<Object[]>();
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;
}
}

@ -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||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
* 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||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
* 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<String, String> getlovValues(TCSession session, String lovName) throws TCException {
LinkedHashMap<String, String> lovVal = new LinkedHashMap<String, String>();
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<String> Keys, Vector<String> 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<String, String> 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<size; i++) {
keyA[i] = Keys.get(i);
valueA[i] = Vals.get(i);
System.out.println(keyA[i] + ":" + valueA[i]);
}
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(keyA, valueA);
return componentContextList.toTCComponentArray();
}
public static String getSerialNo(TCSession session, String itemId, String objectType) throws Exception {
TCComponent[] comps = null;
if (objectType.equals("")) {
comps = query(session, "零组件 ID", new String[] { "ItemID" }, new String[] { itemId + "*" });
} else {
comps = query(session, "零组件...", new String[] { "ItemID", "Type" }, new String[] { itemId + "*", objectType });
}
// System.out.println("getSerialNo comps.len:" + (comps == null ? 0 : comps.length));
if (comps.length > 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<String, String> executeToMap(InputStream in){
System.out.println("Read properties file");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
String line = null;
Map<String, String> 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<TCComponent> getChildren(TCComponent parent, String relation, String name) throws Exception {
Vector<TCComponent> 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);
}
}

@ -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;

@ -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<String, String[]> map = row.propDisplayValues;
// Map<String, String[]> realmap = row.propInternalValues;

Loading…
Cancel
Save