|
|
package com.connor.mdbksplm.util;
|
|
|
|
|
|
import java.awt.Component;
|
|
|
import java.awt.Dialog;
|
|
|
import java.awt.Window;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import javax.swing.JFileChooser;
|
|
|
import javax.swing.JTable;
|
|
|
import javax.swing.filechooser.FileSystemView;
|
|
|
import javax.swing.table.TableColumn;
|
|
|
|
|
|
|
|
|
import com.teamcenter.rac.aifrcp.AIFUtility;
|
|
|
import com.teamcenter.rac.kernel.ListOfValuesInfo;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
|
import com.teamcenter.rac.kernel.TCComponentForm;
|
|
|
import com.teamcenter.rac.kernel.TCComponentICO;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
import com.teamcenter.rac.kernel.TCComponentListOfValues;
|
|
|
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCPreferenceService;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.kernel.TCUserService;
|
|
|
import com.teamcenter.rac.kernel.ics.ICSProperty;
|
|
|
import com.teamcenter.rac.kernel.ics.ICSPropertyDescription;
|
|
|
import com.teamcenter.rac.stylesheet.AbstractRendering;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
import com.teamcenter.rac.util.Utilities;
|
|
|
|
|
|
|
|
|
public class ConnorUtils {
|
|
|
//TCµÄ·þÎñ
|
|
|
public static TCPreferenceService service;
|
|
|
public static TCSession session;
|
|
|
public static TCUserService userService;
|
|
|
static {
|
|
|
if (session == null) {
|
|
|
session = (TCSession) (AIFUtility.getCurrentApplication().getSession());
|
|
|
}
|
|
|
if (service == null)
|
|
|
service = session.getPreferenceService();
|
|
|
}
|
|
|
|
|
|
public static boolean isEmpty(String str) {
|
|
|
return str == null || "".equals(str.trim());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ½«ÈÕÆÚ¶ÔÏóת»»Îª×Ö·û´®
|
|
|
* @param sdf SimpleDateFormat¶ÔÏó
|
|
|
* @param date ÈÕÆÚ¶ÔÏó
|
|
|
* @return ÈÕÆÚµÄ×Ö·û´®¶ÔÏó
|
|
|
*/
|
|
|
public static String getDate2String(SimpleDateFormat sdf, Date date) {
|
|
|
if (sdf == null || date == null) {
|
|
|
return "";
|
|
|
}
|
|
|
return sdf.format(date);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* »ñÈ¡¶àÖµµÃÊ×Ñ¡Ïî
|
|
|
*
|
|
|
* @param prefName Ê×ÏÈÏîÃû³Æ
|
|
|
* @param split ·Ö¸î·û
|
|
|
* @return HashMapÐÎʽµÄÊ×Ñ¡ÏîÄÚÈÝ
|
|
|
*/
|
|
|
public static LinkedHashMap<String, String> getPrefStrHashMap(String prefName, String split) {
|
|
|
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
|
|
String[] strs = service.getStringArray(TCPreferenceService.TC_preference_site, prefName);
|
|
|
if (strs != null) {
|
|
|
for (String str : strs) {
|
|
|
String temp[] = str.split(split);
|
|
|
if(temp!=null) {
|
|
|
if(temp.length==2) {
|
|
|
map.put(temp[0], temp[1]);
|
|
|
}else {
|
|
|
map.put(temp[0],"");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
/**
|
|
|
* »ñÈ¡¶àÖµµÄÊ×Ñ¡Ïî
|
|
|
*
|
|
|
* @param prefName Ê×ÏÈÏîÃû³Æ
|
|
|
* @param split ·Ö¸î·û
|
|
|
* @return
|
|
|
*/
|
|
|
public static HashMap<String, List<String>> getPrefListHashMap(String prefName, String split) {
|
|
|
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
|
|
|
String[] strs = service.getStringArray(TCPreferenceService.TC_preference_site, prefName);
|
|
|
if (strs != null) {
|
|
|
for (String str : strs) {
|
|
|
String temp[] = str.split(split);
|
|
|
if(temp!=null) {
|
|
|
if(map.containsKey(temp[0])) {
|
|
|
List<String> list = map.get(temp[0]);
|
|
|
if(list==null) {
|
|
|
list = new ArrayList<String>();
|
|
|
}
|
|
|
if(temp.length==2) {
|
|
|
list.add(temp[1]);
|
|
|
}else {
|
|
|
list.add("");
|
|
|
}
|
|
|
}else {
|
|
|
List<String> list = new ArrayList<String>();
|
|
|
if(temp.length==2) {
|
|
|
list.add(temp[1]);
|
|
|
}else {
|
|
|
list.add("");
|
|
|
}
|
|
|
map.put(temp[0], list);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
public static String getPrefValue(String prefName){
|
|
|
return service.getStringValue(prefName);
|
|
|
}
|
|
|
|
|
|
public static String[] getPrefValues(String prefName){
|
|
|
return service.getStringValues(prefName);
|
|
|
}
|
|
|
|
|
|
public static void setByPass(boolean val) {
|
|
|
try {
|
|
|
if (userService == null) {
|
|
|
userService = ConnorUtils.session.getUserService();
|
|
|
}
|
|
|
Object[] obj = new Object[1];
|
|
|
obj[0] = "";
|
|
|
if (val) {
|
|
|
userService.call("Connor_set_bypass", obj);
|
|
|
} else {
|
|
|
userService.call("Connor_close_bypass", obj);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ͨ¹ýpuid»ñȡģ°å
|
|
|
* @param templetePuid Ä£°åµÄpuid
|
|
|
*
|
|
|
* @return Ä£°åÎļþ
|
|
|
*
|
|
|
*/
|
|
|
public static File getTempleteData(String templetePuid){
|
|
|
|
|
|
if(templetePuid==null) {
|
|
|
return null;
|
|
|
}
|
|
|
File file = null;
|
|
|
try {
|
|
|
TCComponentDataset dataset = (TCComponentDataset) session.stringToComponent(templetePuid);
|
|
|
String[] types = dataset.getProperty("ref_names").split(",");
|
|
|
String temp = System.getenv("temp");
|
|
|
File[] files = dataset.getFiles(types[0],temp);
|
|
|
if(files!=null && files.length>0) {
|
|
|
file = files[0];
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
MessageBox.post("´íÎó£º"+e.getMessage(),"´íÎó", 2);
|
|
|
return null;
|
|
|
}
|
|
|
if(file == null || !file.exists()) {
|
|
|
MessageBox.post("Êý¾Ý¼¯µÄpuid£º"+templetePuid+"µÄÄ£°åÏÂÔØÊ§°Ü","´íÎó", 2);
|
|
|
return null;
|
|
|
}
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
public static Connection getOracleConnection() {
|
|
|
Connection connection=null;
|
|
|
try {
|
|
|
// ¼ÓÔØÇý¶¯³ÌÐò
|
|
|
Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
|
String[] dbinfos = ConnorUtils.getPrefValues("OA_GET_COST_Conn");
|
|
|
String user = dbinfos[0];
|
|
|
String password = dbinfos[1];
|
|
|
String url = "jdbc:oracle:thin:@" + dbinfos[2];
|
|
|
connection = DriverManager.getConnection(url, user, password);
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
}
|
|
|
return connection;
|
|
|
}
|
|
|
|
|
|
public static Connection getSqlServerConnection() {
|
|
|
Connection connection=null;
|
|
|
try {
|
|
|
// ¼ÓÔØÇý¶¯³ÌÐò
|
|
|
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
|
|
String[] dbinfos = ConnorUtils.getPrefValues("MT_dbinfo");
|
|
|
String user = dbinfos[0];
|
|
|
String password = dbinfos[1];
|
|
|
String url = "jdbc:sqlserver://"+dbinfos[3] +":1433;DataBaseName=" + dbinfos[2];
|
|
|
connection = DriverManager.getConnection(url, user, password);
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
}
|
|
|
return connection;
|
|
|
}
|
|
|
|
|
|
public static Connection getERPConnection() {
|
|
|
Connection connection=null;
|
|
|
try {
|
|
|
// ¼ÓÔØÇý¶¯³ÌÐò
|
|
|
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
|
|
String[] dbinfos = ConnorUtils.getPrefValues("MT_ERP_DBinfo");
|
|
|
String user = dbinfos[0];
|
|
|
String password = dbinfos[1];
|
|
|
String url = "jdbc:sqlserver://"+dbinfos[3] +";DataBaseName=" + dbinfos[2];
|
|
|
connection = DriverManager.getConnection(url, user, password);
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
MessageBox.post("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬Ê§°ÜÔÒò£º"+e.getMessage(),"Ìáʾ",MessageBox.INFORMATION);
|
|
|
}
|
|
|
return connection;
|
|
|
}
|
|
|
|
|
|
public static void ChangeValue(String[] value1,String[] value2) {
|
|
|
String[] temp;
|
|
|
temp = value1;
|
|
|
value1 = value2;
|
|
|
value2 = temp;
|
|
|
}
|
|
|
/**
|
|
|
* ´ò¿ªÎļþ¹ÜÀíÆ÷
|
|
|
* @param parent
|
|
|
* @return
|
|
|
*/
|
|
|
public static File chooseDirectory(Component parent) {
|
|
|
FileSystemView fsv = FileSystemView.getFileSystemView();
|
|
|
String deskPath = fsv.getHomeDirectory().getPath();
|
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
|
fileChooser.setCurrentDirectory(new File(deskPath));
|
|
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
|
int state = fileChooser.showOpenDialog(parent);
|
|
|
if (state == 1) {
|
|
|
return null;
|
|
|
}
|
|
|
return fileChooser.getSelectedFile();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ¸ù¾ÝÎļþÀàÐ͹ýÂËÎļþ
|
|
|
*/
|
|
|
public static File chooseFile(Component parent,String type) {
|
|
|
FileSystemView fsv = FileSystemView.getFileSystemView();
|
|
|
String deskPath = fsv.getHomeDirectory().getPath();
|
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
|
fileChooser.setCurrentDirectory(new File(deskPath));
|
|
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
|
MyFileFilter mFilter = new MyFileFilter(type);
|
|
|
fileChooser.addChoosableFileFilter(mFilter);
|
|
|
fileChooser.setFileFilter(mFilter);
|
|
|
int state = fileChooser.showOpenDialog(parent);
|
|
|
if (state == 1) {
|
|
|
return null;
|
|
|
}
|
|
|
return fileChooser.getSelectedFile();
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void HiddenCell(int column,JTable table) {
|
|
|
TableColumn tc = table.getTableHeader().getColumnModel().getColumn(column);
|
|
|
tc.setMaxWidth(0);
|
|
|
tc.setPreferredWidth(0);
|
|
|
tc.setWidth(0);
|
|
|
tc.setMinWidth(0);
|
|
|
table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
|
|
|
table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
|
|
|
}
|
|
|
|
|
|
public static void post(Component var0,String value,String title) {
|
|
|
Dialog var16 = Utilities.getParentDialog(var0);
|
|
|
if (var16 != null) {
|
|
|
MessageBox.post(var16, value, title, 2);
|
|
|
} else {
|
|
|
MessageBox.post(Utilities.getParentFrame(var0), value, title, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// »ñµÃlovÖµ
|
|
|
public static Map<String, String> getLOVs(String lovName) {
|
|
|
Map<String, String> map = new LinkedHashMap<String, String>();
|
|
|
map.put("", "");
|
|
|
try {
|
|
|
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
|
|
|
TCComponentListOfValues[] lov = lovType.find(lovName);
|
|
|
if (lov.length > 0) {
|
|
|
ListOfValuesInfo listOfValues = lov[0].getListOfValues();
|
|
|
String[] realval = listOfValues.getStringListOfValues();
|
|
|
for (int i = 0; i < realval.length; i++) {
|
|
|
String disval = listOfValues.getDisplayableValue(realval[i]);
|
|
|
map.put(disval, realval[i]);
|
|
|
}
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
public static TCComponent getLatestReleaseRevison(TCComponent component) throws Exception{
|
|
|
TCComponent[] revisions = component.getTCProperty("revision_list").getReferenceValueArray();
|
|
|
for (int i = revisions.length-1; i >= 0; i--) {
|
|
|
TCComponent[] release_statuas = revisions[i].getReferenceListProperty("release_status_list");
|
|
|
if (release_statuas!=null && release_statuas.length > 0) {
|
|
|
return revisions[i];
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public static TCComponent getLastReleaseRevisonFormByStatus(TCComponent component) throws Exception{
|
|
|
String[] cpxpzt_status = session.getPreferenceService().getStringValues("Cpxpzt");
|
|
|
TCComponent[] revisions = component.getTCProperty("revision_list").getReferenceValueArray();
|
|
|
for (int i = revisions.length-1; i >= 0; i--) {
|
|
|
TCComponent[] release_statuses = revisions[i].getReferenceListProperty("release_status_list");
|
|
|
if (release_statuses!=null && release_statuses.length > 0) {
|
|
|
for(TCComponent release_status:release_statuses) {
|
|
|
for(String sxx_value:cpxpzt_status) {
|
|
|
if (release_status.getStringProperty("object_name").equals(sxx_value)) {
|
|
|
return revisions[i].getReferenceListProperty("IMAN_master_form_rev")[0];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public static boolean isDigit(String str) {
|
|
|
if (ConnorUtils.isEmpty(str)) {
|
|
|
return false;
|
|
|
}
|
|
|
char[] chars = str.toCharArray();
|
|
|
int len = chars.length;
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
char c = chars[i];
|
|
|
if (!(c >= '0' && c <= '9')) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static boolean isNumericzidai(String str) {
|
|
|
Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]*");
|
|
|
Matcher isNum = pattern.matcher(str);
|
|
|
if (!isNum.matches()) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static void getClassification(TCComponentItemRevision rev) {
|
|
|
try {
|
|
|
TCComponentICO[] icos = rev.getClassificationObjects();
|
|
|
if(icos==null || icos.length==0) {
|
|
|
return;
|
|
|
}
|
|
|
for(int i=0;i<icos.length;i++) {
|
|
|
System.out.println(icos[i].getClassId());
|
|
|
ICSPropertyDescription[] desc = icos[i].getICSPropertyDescriptors();
|
|
|
for (int j = 0; j < desc.length; j++) {
|
|
|
System.out.println("·ÖÀàÊôÐÔÃû³Æ0£º"+desc[j].getId());
|
|
|
System.out.println("·ÖÀàÊôÐÔÃû³Æ3£º"+desc[j].getName());
|
|
|
}
|
|
|
ICSProperty[] oldICSProps = icos[i].getICSProperties(true);
|
|
|
for (int j = 0; j < oldICSProps.length; j++) {
|
|
|
System.out.println("·ÖÀàÊôÐÔID:"+oldICSProps[j].getId()+"·ÖÀàÊôÐÔÖµ£º"+oldICSProps[j].getValue());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static int length(String value) {
|
|
|
int valueLength = 0;
|
|
|
String chinese = "[\u0391-\uFFE5]";
|
|
|
/* »ñÈ¡×Ö¶ÎÖµµÄ³¤¶È£¬Èç¹ûº¬ÖÐÎÄ×Ö·û£¬Ôòÿ¸öÖÐÎÄ×Ö·û³¤¶ÈΪ2£¬·ñÔòΪ1 */
|
|
|
for (int i = 0; i < value.length(); i++) {
|
|
|
/* »ñȡһ¸ö×Ö·û */
|
|
|
String temp = value.substring(i, i + 1);
|
|
|
/* ÅжÏÊÇ·ñΪÖÐÎÄ×Ö·û */
|
|
|
if (temp.matches(chinese)) {
|
|
|
/* ÖÐÎÄ×Ö·û³¤¶ÈΪ2 */
|
|
|
valueLength += 2;
|
|
|
} else {
|
|
|
/* ÆäËû×Ö·û³¤¶ÈΪ1 */
|
|
|
valueLength += 1;
|
|
|
}
|
|
|
}
|
|
|
return valueLength;
|
|
|
}
|
|
|
}
|