Compare commits

...

4 Commits

@ -9,6 +9,18 @@
id="com.langtech.plm.performancemanagement.commands.category"
name="Sample Category">
</category>
<command
categoryId="com.langtech.plm.project.ProjectECRHandler"
name="计算材料定额"
id="com.langtech.plm.project.ProjectECRHandler">
</command>
<command
categoryId="com.langtech.plm.bg.RWFPHandler"
name="查看任务分配表"
id="com.langtech.plm.bg.RWFPHandler">
</command>
<command
categoryId="com.langtech.plm.batchRename.BatchRenameHandler"
name="批量修改时间表任务名称"
@ -42,8 +54,20 @@
id="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="com.langtech.plm.bg.RWFPHandler"
commandId="com.langtech.plm.bg.RWFPHandler">
</handler>
<handler
class="com.langtech.plm.project.ProjectECRHandler"
commandId="com.langtech.plm.project.ProjectECRHandler">
</handler>
<handler
class="com.langtech.plm.batchRename.BatchRenameHandler"
commandId="com.langtech.plm.batchRename.BatchRenameHandler">
@ -88,9 +112,29 @@
id="com.langtech.plm.template.TemplateHandler"
mnemonic="S">
</command>
<command
commandId="com.langtech.plm.project.ProjectECRHandler"
id="com.langtech.plm.project.ProjectECRHandler"
mnemonic="S">
</command>
</menu>
<menu
id="com.langtech.plm.performancemanagement.menus.sampleMenu2"
label="变更管理"
mnemonic="M">
<command
commandId="com.langtech.plm.bg.RWFPHandler"
id="com.langtech.plm.bg.RWFPHandler"
mnemonic="S">
</command>
</menu>
<menu
id="com.langtech.plm.performancemanagement.menus.sampleMenu1"
label="项目管理"

@ -0,0 +1,250 @@
package com.langtech.plm.bg;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class DbPool {
public static Connection connection = null;
public static PreparedStatement ps = null;
public static ResultSet rs = null;
private static DbPool instance = null;
public static synchronized Connection getConnection(String url, String name) {
if (instance == null) {
instance = new DbPool();
}
return instance._getConnection(url, name);
}
private Connection _getConnection(String url, String name) {
try {
String sDBDriver = null;
String sConnection = null;
String sUser = null;
String sPassword = null;
Properties p = new Properties();
// InputStream is = getClass().getResourceAsStream(
// "/sqlconn.properties");
// p.load(is);
sDBDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
sConnection = "jdbc:sqlserver://" + url + ":1433; DatabaseName=" + name;// p.getProperty("Connection", "2");
sUser = "infodba";// p.getProperty("User", "");
sPassword = "infodba";// p.getProperty("Password", "");
if (sDBDriver == null || sConnection == null || sUser == null || sPassword == null) {
System.out.println("请检查数据库首选项是否配置正确");
}
Class.forName(sDBDriver);
connection = DriverManager.getConnection(sConnection, sUser, sPassword);
return connection;
} catch (Exception se) {
System.out.println(se);
}
return null;
}
public final static ResultSet read(String sql, Object[] argments) throws SQLException {
return DbPool.rs = DbPool.getPs(argments, sql).executeQuery();
}
/**
* Statement
*/
public final static PreparedStatement getPs(Object[] argments, String sql) throws SQLException {
return getPs(sql, argments);
}
/**
* Statement
*/
public final static PreparedStatement getPs(String sql, Object[] argments) throws SQLException {
DbPool.ps = DbPool.connection.prepareStatement(sql);
if (argments != null) {
for (int i = 0; i < argments.length; i++) {
DbPool.ps.setObject(i + 1, argments[i]);
}
}
return DbPool.ps;
}
/**
*
*/
public final static ResultSet read(String sql) throws SQLException {
return read(sql, null);
}
public static void executeUpdateSql(String sql) throws SQLException {
Statement st = connection.createStatement();
try {
connection.setAutoCommit(false);
// System.out.println("sql===" + sql);
int i = st.executeUpdate(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
if (st != null)
st.close();
connection.rollback();
connection.close();
} finally {
if (st != null)
st.close();
// connection.close();
}
}
public static void executeDeleteSql(String sql) throws SQLException {
Statement st = connection.createStatement();
try {
connection.setAutoCommit(false);
// System.out.println("sql===" + sql);
st.executeUpdate(sql);
connection.commit();
} catch (SQLException e) {
if (st != null)
st.close();
connection.rollback();
connection.close();
} finally {
if (st != null)
st.close();
connection.close();
}
}
/**
*
*/
public final static int write(String sql, Object[] argments) {
return update(sql, argments);
}
/**
* (Connection)
*/
public final static int update(String sql, Object[] argments) {
int i = -1;
try {
i = DbPool.getPs(argments, sql).executeUpdate();
DbPool.connection.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
free(DbPool.rs, DbPool.ps);
}
return i;
}
public static ResultSet executeSelectSql(String sql) throws SQLException {
Statement st = connection.createStatement();
try {
connection.setAutoCommit(false);
// System.out.println("sql===" + sql);
rs = st.executeQuery(sql);
// conn.commit();
} catch (SQLException e) {
if (st != null)
st.close();
connection.rollback();
connection.close();
}
return rs;
}
/**
*
*/
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(DbPool.rs, DbPool.ps);
}
/**
* ()
*/
public final static void freeAll() {
free(DbPool.rs, DbPool.ps, DbPool.connection);
}
/**
* ()
*/
public final static void free(ResultSet resultSet, Statement statement, Connection connection) {
try {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} finally {
try {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}

@ -0,0 +1,571 @@
package com.langtech.plm.bg;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
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.TCComponentProject;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.DateButton;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import com.teamcenter.soa.client.model.LovValue;
public class RWFPDialog extends JFrame implements ActionListener {
private Map<String, JTextField> textMap = new HashMap<>();
private TCSession session;
private JTable table;
private String[] header;
private ArrayList<String> gsPrefTopLine;
private LinkedHashMap<String, String> gsPrefMap = new LinkedHashMap<String, String>();
private LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<String, String>();
private LinkedHashMap<String, String> cfdjPref = new LinkedHashMap<String, String>();
private LinkedHashMap<Integer, String> lovPositionMap = new LinkedHashMap<Integer, String>();
private LinkedHashMap<String, Integer> positionFieldMap = new LinkedHashMap<String, Integer>();
private LinkedHashMap<Integer, Integer> widtheMap = new LinkedHashMap<Integer, Integer>();
//public static final int[] HEADERWIDTH = new int[] { 50, 100, 200, 200, 100, 100, 80, 80, 100, 150, 150, 150, 150,150, 150, 150, 150, 150, 150 };
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private DefaultTableModel dtm1;
private JButton yyButton = new JButton("应用");
private JButton gbButton = new JButton("关闭");
private JComboBox<String> cfdJComboBox = new JComboBox<String>();
private DateButton cfsjButton;
private JButton tzsjButton = new JButton("调整时间");
private static ArrayList<String> dateConnList = new ArrayList<String>();
private String type;
private String id;
private ArrayList<Integer> canWriteColume = new ArrayList<Integer>();
public RWFPDialog(TCSession session,String type,String id) {
// TODO Auto-generated constructor stub
this.session = session;
this.type = type;
this.id = id;
initUI();
}
public void initUI() {
// TODO Auto-generated method stub
this.setTitle("任务分配表");
this.setLayout(new BorderLayout());
String[] cfdj = session.getPreferenceService().getStringValues("Connor_ChangeTaskForm_TriggerLevelMapping");
if (cfdj == null || cfdj.length <= 0) {
MessageBox.post("请配置首选项“Connor_ChangeTaskForm_TriggerLevelMapping”", "提示 ", MessageBox.INFORMATION);
return;
}
for (int i = 0; i < cfdj.length; i++) {
String[] split = cfdj[i].split("=");
cfdjPref.put(split[0],split[1]);
cfdJComboBox.addItem(split[0]);
}
//获取首选项匹配的类型
String[] fields = session.getPreferenceService().getStringValues("Connor_ECRECNForm_Datbase_Config");
if (fields == null || fields.length <= 0) {
MessageBox.post("请配置首选项“Connor_ECRECNForm_Datbase_Config”", "提示 ", MessageBox.INFORMATION);
return;
}
for (int i = 0; i < fields.length; i++) {
if(fields[i].contains(type)) {
String[] split = fields[i].split("\\|");
if(split.length == 2) {
String[] split2 = split[1].split(";");
for (int j = 0; j < split2.length; j++) {
String[] split3 = split2[j].split("=");
positionFieldMap.put(split3[0],j);
if(split3.length == 3) {
fieldsMap.put(split3[0],split3[1]);
if(split3[2].contains("%")) {
String[] split4 = split3[2].split("%");
widtheMap.put(j, Integer.parseInt(split4[0]));
canWriteColume.add(j);
}else {
widtheMap.put(j, Integer.parseInt(split3[2]));
}
}else if(split3.length == 4) {
fieldsMap.put(split3[0],split3[1]);
System.out.println("split3[2]========"+split3[2]);
if(split3[2].contains("%")) {
String[] split4 = split3[2].split("%");
widtheMap.put(j, Integer.parseInt(split4[0]));
System.out.println("split4[0]========"+split4[0]);
canWriteColume.add(j);
}else {
widtheMap.put(j, Integer.parseInt(split3[2]));
}
lovPositionMap.put(j,split3[3]);
}
}
}
}
}
System.out.println("canWriteColume====="+canWriteColume.size());
System.out.println("fieldsMap====="+fieldsMap);
System.out.println("positionMap====="+lovPositionMap);
System.out.println("widtheMap====="+widtheMap);
Collection<String> valuesCollection = fieldsMap.values();
// 将集合转换为数组
header = valuesCollection.toArray(new String[0]);
JPanel topPanel = getTopPanel();
JScrollPane pane = getTablePanel();
pane.setBorder(BorderFactory.createTitledBorder(""));
// JPanel btnPanel = getRightPanel();
JPanel bottomPane = getBottomPanel();
this.add(topPanel, BorderLayout.NORTH);
this.add(pane, BorderLayout.CENTER);
this.add(bottomPane, BorderLayout.SOUTH);
this.createActionEvent();
this.pack();
this.setPreferredSize(new Dimension(1850, 1000));
this.validate();
this.setVisible(true);
// 设置窗口在屏幕中心
// Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
// int x = (int) screensize.getWidth() / 2 - window.getWidth() / 2;
// int y = (int) screensize.getHeight() / 2 - window.getHeight() / 2;
this.setLocationRelativeTo(null);
//设置列宽
TableColumnModel colModel = table.getColumnModel();
for (Entry<Integer, Integer> map : widtheMap.entrySet()) {
colModel.getColumn(map.getKey()).setPreferredWidth(map.getValue());
}
String[] value = session.getPreferenceService().getStringValues("LD_dbinfo2");
if (value == null || value.length == 0) {
MessageBox.post("首选项LD_dbinfo2配置有误请检查。", "提示", 2);
return;
} else {
Collections.addAll(dateConnList, value);
}
Set<String> keySet = fieldsMap.keySet();
String fieldsSql = "";
for (String string : keySet) {
fieldsSql += string + ",";
}
fieldsSql = fieldsSql.substring(0, fieldsSql.length() - 1);
System.out.println("fieldsSql=========="+fieldsSql);
String sqlString = "SELECT " + fieldsSql + " FROM LY_CHANGETASSKFORM_DETAILS where ID='" + id + "'";
System.out.println(sqlString);
Connection conn = getConn();
PreparedStatement stmt = null;
try{
stmt = conn.prepareStatement(sqlString);
ResultSet result = stmt.executeQuery();
while (result.next()) {
ArrayList<String> arList = new ArrayList<String>();
for (int i = 0; i < fieldsMap.size(); i++) {
System.out.println("result.getString(i+1)==========="+result.getString(i+1));
arList.add(result.getString(i+1) == null? result.getString(i+1) : validateAndFormatDate(result.getString(i+1)));
}
dtm1.addRow(arList.toArray(new Object[0]));
}
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
if(stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void createActionEvent() {
this.yyButton.addActionListener(this);
this.gbButton.addActionListener(this);
this.tzsjButton.addActionListener(this);
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.left.center", new JLabel("触发等级 "));
topPanel.add("1.2.left.center",cfdJComboBox);
topPanel.add("1.3.left.center", new JLabel(" 触发时间 "));
cfsjButton = new DateButton(null, "yyyy-MM-dd", false, false, false);
cfsjButton.setDate("未设置日期");
topPanel.add("1.4.left.center", cfsjButton);
topPanel.add("1.5.left.center", new JLabel(" "));
topPanel.add("1.6.left.center", tzsjButton);
topPanel.add("2.1.left.center", new JLabel(" "));
return topPanel;
}
// 查询部分
private JPanel getBottomPanel() {
// TODO Auto-generated method stub
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new PropertyLayout());
bottomPanel.add("1.1.left.center", new JLabel(" "));
bottomPanel.add("1.2.left.center", yyButton);
bottomPanel.add("1.3.left.center", new JLabel(" "));
bottomPanel.add("1.4.left.center", gbButton);
return bottomPanel;
}
private JScrollPane getTablePanel() {
// TODO Auto-generated method stub
table = getjTable(null, null, header, null, false);
table.setRowHeight(30);
// table.setPreferredSize(new Dimension(1500,400));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // 设置表格的自动调整模式为关闭自动调整
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置JTable的列宽随着列表内容的大小进行调整
// table.setPreferredSize(new Dimension(1200,400));
JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
for (Entry<Integer, String> map : lovPositionMap.entrySet()) {
JComboBox<String> jComboBox = new JComboBox<String>();
String value = map.getValue();
if(value.contains(",")) {
String[] split = value.split(",");
for (int i = 0; i < split.length; i++) {
jComboBox.addItem(split[i]);
}
}else {
jComboBox.addItem(value);
}
table.getColumnModel().getColumn(map.getKey()).setCellEditor(new DefaultCellEditor(jComboBox));
}
pane.setPreferredSize(new Dimension(1800, 850));
pane.setViewportView(table);// 为scrollPane指定显示对象为table
return pane;
}
/***
* Jtable
*
* @param partsTable
* @param dtm
* @param titleNames
* @param values
* @return
*/
public JTable getjTable(JTable partsTable, DefaultTableModel dtm, Object[] titleNames, Object[][] values,
Boolean isTable2) {
// int simpleLen = 100;
// int totleLen = 1000;
if (partsTable == null) {
partsTable = new JTable(this.getTableModel(dtm, titleNames, values));
partsTable.setRowHeight(20);
partsTable.getTableHeader().setReorderingAllowed(false);
partsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(partsTable.getModel());
partsTable.setRowSorter(sorter);
// for (int i = 0; i < titleNames.length; i++) {
// if(i==2) {
// partsTable.getColumnModel().getColumn(i).setPreferredWidth(200);
// }else {
// partsTable.getColumnModel().getColumn(i).setPreferredWidth(120);
// }
//
// }
}
return partsTable;
}
public DefaultTableModel getTableModel(DefaultTableModel dtm, Object[] titleNames, Object[][] values) {
dtm1 = null;
if (dtm == null) {
dtm1 = new DefaultTableModel(values, titleNames) {
@Override
public boolean isCellEditable(int row, int column) {
if(canWriteColume.size() > 0) {
for (int i = 0; i < canWriteColume.size(); i++) {
if(canWriteColume.get(i) == column) {
System.out.println("row=========="+row);
return true;
}
}
}
return false;
}
};
}
return dtm1;
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (source.equals(this.gbButton)) {
dispose();
}
else if(source.equals(this.yyButton)){
//保存数据
Connection conn = getConn();
PreparedStatement stmt = null;
for(int i = 0; i < table.getRowCount(); i++){
StringBuilder updateSql = new StringBuilder();
updateSql.append("update LY_CHANGETASSKFORM_DETAILS set ");
for (Entry<String, Integer> map : positionFieldMap.entrySet()) {
updateSql.append(map.getKey());
String valueAt = (String)table.getValueAt(i,map.getValue());
if(valueAt == null || valueAt.isEmpty()) {
updateSql.append("=");
updateSql.append("null,");
}else {
updateSql.append("='");
updateSql.append(table.getValueAt(i,map.getValue()));
updateSql.append("',");
}
}
//去掉最后一个,
updateSql.deleteCharAt(updateSql.length() - 1);
updateSql.append(" where ID='"+id+"' and XH='"+table.getValueAt(i,0)+"'");
try {
stmt = conn.prepareStatement(updateSql.toString());
System.out.println("updateSql========="+updateSql.toString());
stmt.execute();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
if(stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else if(source.equals(this.tzsjButton)){
gsPrefTopLine = new ArrayList<String>();
String selectedItem = (String)cfdJComboBox.getSelectedItem();
if(selectedItem == null || selectedItem.isEmpty()) {
MessageBox.post("请选择触发等级!", "提示", 2);
return;
}
Date date = cfsjButton.getDate();
if(date == null) {
MessageBox.post("请选择触发时间!", "提示", 2);
return;
}
String cfsjDate = dateFormat.format(date);
String pref = cfdjPref.get(selectedItem);
if(pref == null || pref.isEmpty()) {
MessageBox.post("未配置触发等级相关的首选项!", "提示", 2);
return;
}
String[] calculateTime = session.getPreferenceService().getStringValues(pref);
if (calculateTime == null || calculateTime.length <= 0) {
MessageBox.post("请配置首选项“"+pref+"”", "提示 ", MessageBox.INFORMATION);
return;
}
for (int i = 0; i < calculateTime.length; i++) {
String[] split = calculateTime[i].split("\\|");
if(i == 0) {
for (int j = 0; j < split.length; j++) {
gsPrefTopLine.add(split[j]);
}
}else {
gsPrefMap.put(split[0],calculateTime[i]);
}
}
System.out.println(positionFieldMap+"==================positionFieldMap");
System.out.println("gsPrefTopLine----------------"+gsPrefTopLine.size());
Integer xh = positionFieldMap.get(gsPrefTopLine.get(0));
//表里table 开始计算
for(int i = 0; i < table.getRowCount(); i++){
String xhStr = table.getValueAt(i, xh).toString();
String gsStr = gsPrefMap.get(xhStr);
if(gsStr != null && !gsStr.isEmpty() ) {
String[] split = gsStr.split("\\|");
for (int j = 1; j < gsPrefTopLine.size(); j++) {
//如果有值
System.out.println("gsPrefTopLine.get(j)========"+gsPrefTopLine.get(j));
Integer colume = positionFieldMap.get(gsPrefTopLine.get(j));
if(colume != null) {
System.out.println(positionFieldMap.get(gsPrefTopLine.get(j))+"=================positionFieldMap.get(gsPrefTopLine.get(j))");
//处理公式
String gs = split[j];
System.out.println("gs========"+gs);
if(gs.equals("N")) {
table.setValueAt(cfsjDate,i, colume);
}else {
String[] split2 = gs.split("N");
String time = calculateDate(cfsjDate, Integer.parseInt(split2[1]));
System.out.println("time============"+time);
table.setValueAt(time,i, colume);
}
}
}
}
}
//调用应用按钮
yyButton.doClick();
MessageBox.post("调整时间完成!", "提示", 2);
}
}
// 获取数据库连接
public static Connection getConn() {
Connection conn = null;
try {
conn = DbPool.getConnection(dateConnList.get(0), dateConnList.get(1));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static String calculateDate(String dateString, int daysToAdd) {
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 解析输入的日期字符串
LocalDate date;
try {
date = LocalDate.parse(dateString, formatter);
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("Invalid date format. Please use yyyy-MM-dd.", e);
}
// 增加或减少天数
LocalDate resultDate = date.plusDays(daysToAdd);
// 格式化结果日期为字符串
return resultDate.format(formatter);
}
public String validateAndFormatDate(String input) {
// 定义输入和输出的日期格式
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
try {
// 尝试解析输入的日期时间字符串
LocalDateTime dateTime = LocalDateTime.parse(input, inputFormatter);
// 转换为只包含日期的LocalDate对象
LocalDate date = dateTime.toLocalDate();
// 格式化结果日期为字符串
return date.format(outputFormatter);
} catch (DateTimeParseException e) {
// 如果解析失败,说明输入不符合指定格式,返回原始字符串
return input;
}
}
}

@ -0,0 +1,66 @@
package com.langtech.plm.bg;
import javax.swing.SwingUtilities;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class RWFPHandler extends AbstractHandler {
private AbstractAIFUIApplication app;
private TCSession session;
// private InterfaceAIFComponent target;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
app = AIFUtility.getCurrentApplication();
session = (TCSession) app.getSession();
// target = app.getTargetComponent();
// if (target == null || !(target instanceof TCComponentFolder)) {
// MessageBox.post(app.getDesktop(), "请选择系统总目录文件夹进行导入!", "导入位置选择", MessageBox.WARNING);
// return null;
// }
InterfaceAIFComponent target = app.getTargetComponent();
if(target instanceof TCComponentItem) {
TCComponentItem item = (TCComponentItem)target;
String type = item.getType();
try {
String id = item.getStringProperty("item_id");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
new RWFPDialog(session,type,id);
//d.setModal(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else {
MessageBox.post(app.getDesktop(), "请选择正确对象!", "提示", MessageBox.WARNING);
return null;
}
return null;
}
}

@ -94,7 +94,7 @@ public class CreateProjectStructDialog extends AbstractAIFDialog{
}
}
}
nameLabel = new JLabel("成品图号");
nameLabel = new JLabel("项目名称");
nameField = new JTextField();
nameField.setPreferredSize(new Dimension(200,30));
JPanel topPanel = new JPanel();
@ -215,7 +215,7 @@ public class CreateProjectStructDialog extends AbstractAIFDialog{
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
if (name.isEmpty()) {
MessageBox.post("请填写成品图号", "提示 ", MessageBox.INFORMATION);
MessageBox.post("请填写项目名称", "提示 ", MessageBox.INFORMATION);
} else {
TCComponentFolderType folderType;
try {

@ -15,7 +15,7 @@ public class DialogFrame extends JDialog {
private JComboBox<String> comboBox;
private Object syncObject;
public DialogFrame(JFrame owner,JComboBox<String> comboBox,ArrayList<String> list) {
super(owner, "Dialog Window", true); // 模态对话框
super(owner, "选择已有M", true); // 模态对话框
this.comboBox = comboBox;
this.syncObject = syncObject;
JButton button = new JButton("È·¶¨");

@ -62,8 +62,6 @@ import com.teamcenter.rac.util.PropertyLayout;
import k.util.KOrgDialog;
public class MpartDialog extends JFrame implements ActionListener {
private TCSession session;
@ -78,12 +76,12 @@ public class MpartDialog extends JFrame implements ActionListener {
private JTable t_part;
private JComboBox<String> gsdwComboBox = new JComboBox<String>();
protected DefaultTableModel tm_part;
public static final String[] HEADER = new String[] { "","序号", "ID", "名称", "件号", "是否自制", "是否存在M", "归属单位", "工艺小组", "责任人"};
public static final int[] HEADERWIDTH = new int[] { 30,40, 60, 120, 100, 60, 60, 60, 60, 100};
public static final String[] HEADER = new String[] { "", "序号", "ID", "名称", "件号", "是否自制", "是否存在M", "归属单位","责任人" };
public static final int[] HEADERWIDTH = new int[] { 30, 40, 60, 120, 100, 60, 60, 60, 100 };
private JTable t_part2;
protected DefaultTableModel tm_part2;
public static final String[] HEADER2 = new String[] { "序号", "对象" };
public static final int[] HEADERWIDTH2 = new int[] {10, 60};
public static final int[] HEADERWIDTH2 = new int[] { 10, 100 };
private ArrayList<ArrayList<Object>> valueList = new ArrayList<ArrayList<Object>>();
private HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
private ArrayList<TCComponentItemRevision> table2RevList = new ArrayList<TCComponentItemRevision>();
@ -91,6 +89,11 @@ public class MpartDialog extends JFrame implements ActionListener {
TCComponentBOMWindow view;
TCComponentItemType type;
private String[] groupSplit;
private HashMap<String, String> fieldsMap = new HashMap<String, String>();
private HashMap<String, String> typesMap = new HashMap<String, String>();
private boolean isInitialized = false;
//static TCComponentGroup group;
//static TCComponentUser user;
public MpartDialog(TCSession session, ArrayList<TCComponentItemRevision> list) throws TCException {
// TODO Auto-generated constructor stub
@ -98,33 +101,47 @@ public class MpartDialog extends JFrame implements ActionListener {
this.list = list;
viewType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
view = viewType.create(null);
type = (TCComponentItemType) session.getTypeComponent("LY6_ProductM");
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
String[] fields = session.getPreferenceService().getStringValues("LY6_EPartToMPartType");
for (int i = 0; i < fields.length; i++) {
String[] split = fields[i].split("=");
fieldsMap.put(split[0], split[1]);
String[] split2 = split[0].split(":");
typesMap.put(split2[0], split2[1]);
}
gsdwComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (!isInitialized) {
// 如果还没有初始化完成,则直接返回,不执行后续代码
return;
}
if (e.getStateChange() == ItemEvent.SELECTED) {
String selectedItem = (String) gsdwComboBox.getSelectedItem();
System.out.println("Selected Item: " + selectedItem);
// 在这里可以执行其他操作
int count = 0;
System.out.println("==========tm_part.getRowCount()=========="+tm_part.getRowCount());
for (int i = 0; i < tm_part.getRowCount(); i++) {
System.out.println("tm_part.getValueAt(i, 0).toString()========"+tm_part.getValueAt(i, 0).toString());
if (tm_part.getValueAt(i, 0).toString().equals("1")) {
tm_part.setValueAt(selectedItem, i, 7);
count++;
}
}
if (count == 0) {
MessageBox.post("请勾选数据!", "提示 ", MessageBox.INFORMATION);
return;
}
}
}
}
});
find.setPreferredSize(new Dimension(200, 30));
replace.setPreferredSize(new Dimension(200, 30));
@ -163,7 +180,6 @@ public class MpartDialog extends JFrame implements ActionListener {
factory = split[1];
}
}
gsdwComboBox.addItem("");
if (factory != null && !factory.isEmpty()) {
@ -174,13 +190,11 @@ public class MpartDialog extends JFrame implements ActionListener {
}
// this.setAlwaysOnTop(true);
// 塞值
// 获取当前组
for (int i = 0; i < list.size(); i++) {
ArrayList<Object> tempList = new ArrayList<Object>();
tempList.add(0);
@ -201,7 +215,8 @@ public class MpartDialog extends JFrame implements ActionListener {
for (int j = 0; j < split.length; j++) {
TCComponent[] search = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { revId,split[j] });
TCComponent[] search = session.search("_SearchMFKProperties", new String[] { "ID", "工厂" },
new String[] { revId, split[j] });
if (search.length > 0) {
for (int k = 0; k < search.length; k++) {
@ -235,15 +250,10 @@ public class MpartDialog extends JFrame implements ActionListener {
for (int j = 0; j < valueList.size(); j++) {
ArrayList<Object> arrayList = valueList.get(j);
tm_part.addRow(new Object[] {arrayList.get(0),arrayList.get(1),arrayList.get(2),
arrayList.get(3),arrayList.get(4),arrayList.get(5),arrayList.get(6),
arrayList.get(7),"",""});
tm_part.addRow(new Object[] { arrayList.get(0), arrayList.get(1), arrayList.get(2), arrayList.get(3),
arrayList.get(4), arrayList.get(5), arrayList.get(6), arrayList.get(7), "", "" });
}
isInitialized = true;
} catch (Exception e) {
e.printStackTrace();
return;
@ -287,7 +297,7 @@ public class MpartDialog extends JFrame implements ActionListener {
return;
}
if(tm_part.getValueAt(i, 9) == null || tm_part.getValueAt(i, 9).toString().isEmpty()) {
if (tm_part.getValueAt(i, 8) == null || tm_part.getValueAt(i, 8).toString().isEmpty()) {
MessageBox.post("请填写第" + (i + 1) + "行责任人!", "提示 ", MessageBox.INFORMATION);
return;
}
@ -299,23 +309,37 @@ public class MpartDialog extends JFrame implements ActionListener {
return;
}
for (int i = 0; i < tm_part.getRowCount(); i++) {
if (tm_part.getValueAt(i, 0).toString().equals("1")) {
try {
ArrayList<Object> arrayList = valueList.get(i);
TCComponentItemRevision rev = (TCComponentItemRevision) arrayList.get(9);
TCComponentItem eItem = rev.getItem();
String eType = eItem.getType();
System.out.println("etype=============" + eType);
type = (TCComponentItemType) session.getTypeComponent(typesMap.get(eType));
TCComponentBOMLine topLine = view.setWindowTopLine(rev.getItem(), rev, null, null);
int childrenCount = topLine.getChildrenCount();
System.out.println("childrenCount========" + childrenCount);
TCComponent[] searchLs = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { (String) arrayList.get(2),(String) tm_part.getValueAt(i, 7) });
TCComponent[] searchLs = session.search("_SearchMFKProperties", new String[] { "ID", "工厂" },
new String[] { (String) arrayList.get(2), (String) tm_part.getValueAt(i, 7) });
String ly6_sequenceNum = "";
String ly6_sequenceNum = "0";
// 去调用查询查看该工厂最大流水
if(searchLs != null && searchLs.length > 0) {
TCComponentItem mItem = (TCComponentItem)searchLs[0];
ly6_sequenceNum = mItem.getStringProperty("ly6_sequenceNum");
// if(searchLs != null && searchLs.length > 0) {
// TCComponentItem mItem = (TCComponentItem)searchLs[0];
// ly6_sequenceNum = mItem.getStringProperty("ly6_sequenceNum");
// System.out.println("ly6_sequenceNum==="+ly6_sequenceNum);
// System.out.println("pxuid==========="+mItem.getUid());
// }
//
for (int j = 0; j < searchLs.length; j++) {
TCComponentItem mItem = (TCComponentItem) searchLs[j];
System.out.println(mItem.getUid() + "===========mItem.uid");
String num = mItem.getStringProperty("ly6_sequenceNum");
System.out.println("num===" + num);
System.out.println("ly6_sequenceNum===" + ly6_sequenceNum);
ly6_sequenceNum = getLargerNumber(num, ly6_sequenceNum);
}
if (childrenCount == 0) {
@ -323,62 +347,202 @@ public class MpartDialog extends JFrame implements ActionListener {
String newID = (String) arrayList.get(2);
String newRev = type.getNewRev(null);
TCComponentItem item = type.create(newID, newRev, "LY6_ProductM", "", "", null);
TCComponentItem item = type.create(newID, newRev, typesMap.get(eType), "", "", null);
TCComponentItemRevision mRev = item.getLatestItemRevision();
item.setProperty("ly6_company", tm_part.getValueAt(i, 7).toString());
if(ly6_sequenceNum.isEmpty()) {
System.out.println("itemUid2============" + item.getUid());
if (ly6_sequenceNum.isEmpty() || ly6_sequenceNum.equals("0")) {
item.setProperty("ly6_sequenceNum", "01");
} else {
item.setProperty("ly6_sequenceNum", incrementNumber(ly6_sequenceNum));
System.out.println("itemUid3============" + item.getUid());
}
// 删除前两个对象
TCComponent delItem1 = session.stringToComponent((String) arrayList.get(2));
if (delItem1 != null) {
System.out.println("delItem1.getUid()====" + delItem1.getUid());
delItem1.delete();
}
TCComponent delItem2 = session
.stringToComponent((String) arrayList.get(2) + (String) tm_part.getValueAt(i, 7));
if (delItem1 != null) {
System.out.println("delItem2.getUid()====" + delItem2.getUid());
delItem2.delete();
}
// 给属性赋值
String fiedsStr = fieldsMap.get(eType + ":" + typesMap.get(eType));
System.out.println("fiedsStr===================" + fiedsStr);
if (fiedsStr != null && !fiedsStr.isEmpty()) {
if (fiedsStr.contains(",")) {
String[] split = fiedsStr.split(",");
System.out.println("split.length===========" + split.length);
for (int j = 0; j < split.length; j++) {
// :分割
String[] split2 = split[j].split(":");
System.out.println("split2.length=================" + split2.length);
if (split2.length == 2) {
// .分割
String[] split3 = split2[0].split("\\.");
System.out.println("split3.length=================" + split3.length);
if (split3.length == 2) {
if (split3[0].equals("item")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], eItem.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], eItem.getProperty(split3[1]));
}
}
} else if (split3[0].equals("rev")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], rev.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
System.out.println("value==========================="+rev.getProperty(split3[1]));
mRev.setProperty(split4[1], rev.getProperty(split3[1]));
}
}
}
}
}
}
} else {
// :分割
String[] split2 = fiedsStr.split(":");
if (split2.length == 2) {
// .分割
String[] split3 = split2[0].split("\\.");
System.out.println("split3.length=================" + split3.length);
if (split3.length == 2) {
if (split3[0].equals("item")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], eItem.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], eItem.getProperty(split3[1]));
}
}
} else if (split3[0].equals("rev")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], rev.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], rev.getProperty(split3[1]));
}
}
}
}
}
}
}
//设置 ly6_homemadeStatus
mRev.setProperty("ly6_homemadeStatus", "自制");
String personId = tm_part.getValueAt(i, 8).toString();
System.out.println("personId========"+personId);
mRev.setProperty("ly6_assignUser", personId == null || personId.isEmpty() ? "" : personId);
// 添加流程
if (workflowTemplate != null || !workflowTemplate.isEmpty()) {
CreateProcess(session, item, workflowTemplate);
}
// 把对象放到管理文件夹下
rev.add("LY6_relatedMPart", item);
item.getLatestItemRevision().refresh();
} else {
AIFComponentContext[] children = topLine.getChildren();
//直接创建对象
String newID = (String) arrayList.get(2);
String newRev = type.getNewRev(null);
TCComponentItem item = type.create(newID, newRev, "LY6_ProductM", "", "", null);
item.setProperty("ly6_company", tm_part.getValueAt(i, 7).toString());
if(ly6_sequenceNum.isEmpty()) {
item.setProperty("ly6_sequenceNum", "01");
}else {
item.setProperty("ly6_sequenceNum", incrementNumber(ly6_sequenceNum));
}
//把对象放到管理文件夹下
rev.add("LY6_relatedMPart",item);
item.getLatestItemRevision().refresh();
//搭建mBOM
TCComponentBOMWindowType viewType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = viewType.create(null);
TCComponentBOMLine mTopLine = view.setWindowTopLine(item, item.getLatestItemRevision(), null, null);
ArrayList<TCComponentItemRevision> addList = new ArrayList<TCComponentItemRevision>();// mbom的子
ArrayList<String> childrenList = new ArrayList<String>();// 下拉框选中的值
HashMap<String, TCComponentItemRevision> revMap = new HashMap<String, TCComponentItemRevision>();//object_String 和对应版本
for (int j = 0; j < children.length; j++) {
HashMap<String, TCComponentItemRevision> revMap = new HashMap<String, TCComponentItemRevision>();// object_String
StringBuilder errMsg = new StringBuilder();
for (int j = 0; j < children.length; j++) {
TCComponentBOMLine eLine = (TCComponentBOMLine) children[j].getComponent();
// 判断是否自制
TCComponentItemRevision eRev = eLine.getItemRevision();
String tcProperty = eRev.getTCProperty("ly6_homemadeStatus").toString();
System.out.println("ly6_homemadeStatus=======" + tcProperty);
String eId = eRev.getStringProperty("item_id");
if (tcProperty.equals("自制")) {
// 判断e下面的m是否唯一
//先循环一遍判断有没有 mpart
ArrayList<TCComponentItemRevision> list = new ArrayList<TCComponentItemRevision>();
for (int k = 0; k < groupSplit.length; k++) {
TCComponent[] search = session.search("_SearchMFKProperties",
new String[] { "ID", "工厂" }, new String[] { eId, groupSplit[k] });
for (int l = 0; l < search.length; l++) {
TCComponentItem tempItem = (TCComponentItem) search[l];
list.add(tempItem.getLatestItemRevision());
}
}
if (list.size() == 0) {
errMsg.append(eId + "对象未创建MPart"+System.lineSeparator());
}
}
}
if(errMsg.length() > 0) {
MessageBox.post(errMsg.toString(), "提示 ", MessageBox.INFORMATION);
return;
}
// 和对应版本
for (int j = 0; j < children.length; j++) {
TCComponentBOMLine eLine = (TCComponentBOMLine) children[j].getComponent();
// 判断是否自制
TCComponentItemRevision eRev = eLine.getItemRevision();
String tcProperty = eRev.getTCProperty("ly6_homemadeStatus").toString();
System.out.println("ly6_homemadeStatus=======" + tcProperty);
String eId = eRev.getStringProperty("item_id");
if (tcProperty.equals("自制")) {
//循环 选择mpart
ArrayList<TCComponentItemRevision> tempMrevList = new ArrayList<TCComponentItemRevision>();
for (int k = 0; k < groupSplit.length; k++) {
TCComponent[] search = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { eId,groupSplit[k] });
TCComponent[] search = session.search("_SearchMFKProperties",
new String[] { "ID", "工厂" }, new String[] { eId, groupSplit[k] });
for (int l = 0; l < search.length; l++) {
TCComponentItem tempItem = (TCComponentItem) search[l];
@ -386,10 +550,11 @@ public class MpartDialog extends JFrame implements ActionListener {
}
}
if(tempMrevList.size() == 0) {
MessageBox.post(eId+"对象未创建MPart", "提示 ", MessageBox.INFORMATION);
return;
}else if(tempMrevList.size() == 1) {
// if (tempMrevList.size() == 0) {
// MessageBox.post(eId + "对象未创建MPart", "提示 ", MessageBox.INFORMATION);
// return;
// } else
if (tempMrevList.size() == 1) {
// 把M放bom下
addList.add(tempMrevList.get(0));
} else if (tempMrevList.size() > 1) {
@ -397,14 +562,12 @@ public class MpartDialog extends JFrame implements ActionListener {
JComboBox<String> jComboBox = new JComboBox<String>();
for (int k = 0; k < tempMrevList.size(); k++) {
String stringProperty = tempMrevList.get(k).getStringProperty("object_string");
String stringProperty = tempMrevList.get(k)
.getStringProperty("object_string");
revMap.put(stringProperty, tempMrevList.get(k));
jComboBox.addItem(stringProperty);
}
// 创建并显示模态对话框
DialogFrame dialog = new DialogFrame(MpartDialog.this, jComboBox, childrenList);
dialog.setVisible(true);
@ -417,20 +580,158 @@ public class MpartDialog extends JFrame implements ActionListener {
}
});
}
} else {
// 不为自制则直接将EPart搭建进入MBOM中
addList.add(eRev);
}
}
// 直接创建对象
String newID = (String) arrayList.get(2);
String newRev = type.getNewRev(null);
TCComponentItem item = type.create(newID, newRev, typesMap.get(eType), "", "", null);
TCComponentItemRevision mRev = item.getLatestItemRevision();
item.setProperty("ly6_company", tm_part.getValueAt(i, 7).toString());
if (ly6_sequenceNum.isEmpty() || ly6_sequenceNum.equals("0")) {
item.setProperty("ly6_sequenceNum", "01");
} else {
item.setProperty("ly6_sequenceNum", incrementNumber(ly6_sequenceNum));
}
// 删除前两个对象
TCComponent delItem1 = session.stringToComponent((String) arrayList.get(2));
if (delItem1 != null) {
System.out.println("delItem1.getUid()====" + delItem1.getUid());
delItem1.delete();
}
TCComponent delItem2 = session
.stringToComponent((String) arrayList.get(2) + (String) tm_part.getValueAt(i, 7));
if (delItem1 != null) {
System.out.println("delItem2.getUid()====" + delItem2.getUid());
delItem2.delete();
}
// 给属性赋值
String fiedsStr = fieldsMap.get(eType + ":" + typesMap.get(eType));
System.out.println("fiedsStr===================" + fiedsStr);
if (fiedsStr != null && !fiedsStr.isEmpty()) {
if (fiedsStr.contains(",")) {
String[] split = fiedsStr.split(",");
System.out.println("split.length===========" + split.length);
for (int j = 0; j < split.length; j++) {
// :分割
String[] split2 = split[j].split(":");
System.out.println("split2.length=================" + split2.length);
if (split2.length == 2) {
// .分割
String[] split3 = split2[0].split("\\.");
System.out.println("split3.length=================" + split3.length);
if (split3.length == 2) {
if (split3[0].equals("item")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], eItem.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], eItem.getProperty(split3[1]));
}
}
} else if (split3[0].equals("rev")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], rev.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
System.out.println("value==========================="+rev.getProperty(split3[1]));
mRev.setProperty(split4[1], rev.getProperty(split3[1]));
}
}
}
}
}
}
} else {
//不为自制则直接将EPart搭建进入MBOM中
addList.add(eRev);
// :分割
String[] split2 = fiedsStr.split(":");
if (split2.length == 2) {
// .分割
String[] split3 = split2[0].split("\\.");
System.out.println("split3.length=================" + split3.length);
if (split3.length == 2) {
if (split3[0].equals("item")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], eItem.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], eItem.getProperty(split3[1]));
}
}
} else if (split3[0].equals("rev")) {
String[] split4 = split2[1].split("\\.");
if (split4.length == 2) {
if (split4[0].equals("item")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
item.setProperty(split4[1], rev.getProperty(split3[1]));
} else if (split4[0].equals("rev")) {
System.out.println("split4[1]========" + split4[1]
+ "split3[1]======" + split3[1]);
mRev.setProperty(split4[1], rev.getProperty(split3[1]));
}
}
}
}
}
}
}
//设置 ly6_homemadeStatus
mRev.setProperty("ly6_homemadeStatus", "自制");
String personId = tm_part.getValueAt(i, 8).toString();
System.out.println("personId========"+personId);
mRev.setProperty("ly6_assignUser", personId == null || personId.isEmpty() ? "" : personId);
// 把对象放到管理文件夹下
rev.add("LY6_relatedMPart", item);
item.getLatestItemRevision().refresh();
// 搭建mBOM
TCComponentBOMWindowType viewType = (TCComponentBOMWindowType) session
.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = viewType.create(null);
TCComponentBOMLine mTopLine = view.setWindowTopLine(item, item.getLatestItemRevision(),
null, null);
System.out.println("childrenList.size()=======" + childrenList.size());
for (int j = 0; j < childrenList.size(); j++) {
addList.add(revMap.get(childrenList.get(j)));
@ -461,9 +762,6 @@ public class MpartDialog extends JFrame implements ActionListener {
MessageBox.post("创建成功!", "提示 ", MessageBox.INFORMATION);
} else if (this.viewlButton.equals(source)) {
// 打开对象到结构管理器
@ -488,11 +786,13 @@ public class MpartDialog extends JFrame implements ActionListener {
}
}
} else if (this.xrButton.equals(source)) {
//KOrgDialog kOrgDialog = new KOrgDialog("");
TCComponentUser user = new KOrgDialog("").getUser();
System.out.println("Select User: " + user);
// TCComponentGroup group = kOrgDialog.getGroup();
//user = kOrgDialog.getUser();
//group = kOrgDialog.getGroup();
//System.out.println("Select User: " + user + "group===" + group);
String userName = "";
try {
userName = user.getUserName();
@ -504,17 +804,16 @@ public class MpartDialog extends JFrame implements ActionListener {
int count = 0;
for (int i = 0; i < tm_part.getRowCount(); i++) {
if (tm_part.getValueAt(i, 0).toString().equals("1")) {
tm_part.setValueAt(userName, i, 9);
tm_part.setValueAt(userName, i, 8);
count++;
}
}
if (count == 0) {
MessageBox.post("请勾选数据!", "提示 ", MessageBox.INFORMATION);
return;
}
}
}
}
@ -546,7 +845,6 @@ public class MpartDialog extends JFrame implements ActionListener {
return topPanel;
}
private JPanel getTablePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(1100, 600));
@ -566,8 +864,7 @@ public class MpartDialog extends JFrame implements ActionListener {
if (column == 5) {// 可编辑的列
return true;
}
else {
} else {
return false;
}
} else {
@ -575,20 +872,15 @@ public class MpartDialog extends JFrame implements ActionListener {
if (column == 5) {// 可编辑的列
return true;
}
else {
} else {
return false;
}
}
}
};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// 添加鼠标监听器
@ -600,8 +892,7 @@ public class MpartDialog extends JFrame implements ActionListener {
int selectColumn = t_part.getTableHeader().columnAtPoint(e.getPoint());
int selectedRow = t_part.rowAtPoint(e.getPoint());
if(selectColumn != 0)
{
if (selectColumn != 0) {
t_part2.removeAll();
tm_part2.setRowCount(0);
table2RevList.clear();
@ -618,9 +909,10 @@ public class MpartDialog extends JFrame implements ActionListener {
for (int i = 0; i < tempList.size(); i++) {
TCComponentItemRevision tcComponentItemRevision = tempList.get(i);
try {
String id = tcComponentItemRevision.getStringProperty("item_id");
System.out.println("item_id======"+id);
String objectName = tcComponentItemRevision.getStringProperty("object_string");
// String id = tcComponentItemRevision.getStringProperty("item_id");
// System.out.println("item_id======" + id);
String objectName = tcComponentItemRevision
.getStringProperty("object_string");
tm_part2.addRow(new Object[] { i + 1, objectName });
} catch (TCException e1) {
// TODO Auto-generated catch block
@ -646,10 +938,6 @@ public class MpartDialog extends JFrame implements ActionListener {
}
});
// t_part.addMouseListener(new MouseListener() {
//
// @Override
@ -765,14 +1053,6 @@ public class MpartDialog extends JFrame implements ActionListener {
// jComboBox3.addItem(split[0]);
// }
//
// // 添加鼠标监听器
// t_part.addMouseListener(new MouseAdapter() {
@ -794,28 +1074,15 @@ public class MpartDialog extends JFrame implements ActionListener {
// }
// });
// this.t_part.getTableHeader().setBackground(Color.blue);
JScrollPane scroll = new JScrollPane(t_part);
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createLoweredBevelBorder());
return panel;
}
private JPanel getTablePanel2() {
JPanel panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(200, 600));
@ -825,34 +1092,30 @@ public class MpartDialog extends JFrame implements ActionListener {
*
*/
@Override
public boolean isCellEditable(int row, int column) {
if (column == 0) {// 可编辑的列
return true;
}
else {
} else {
return false;
}
}
};
tm_part2.setDataVector(null, HEADER2);
t_part2.getTableHeader().setReorderingAllowed(false); // 设置列不可移动,否则会发生类型转换错误(第三列)
this.t_part2.setRowHeight(23);
TableColumnModel colModel = this.t_part2.getColumnModel();
int colCnt = HEADERWIDTH2.length;
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(HEADERWIDTH2[i]);
}
//t_part2.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(t_part2));
//t_part2.getColumnModel().getColumn(0).setCellRenderer(new TableCellCheckboxRenderer(t_part2));
// t_part2.getTableHeader().setDefaultRenderer(new
// CheckHeaderCellRenderer(t_part2));
// t_part2.getColumnModel().getColumn(0).setCellRenderer(new
// TableCellCheckboxRenderer(t_part2));
// t_part2.addMouseListener(new MouseListener() {
//
// @Override
@ -921,20 +1184,11 @@ public class MpartDialog extends JFrame implements ActionListener {
// }
// });
// this.t_part2.getTableHeader().setBackground(Color.blue);
JScrollPane scroll = new JScrollPane(t_part2);
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createLoweredBevelBorder());
return panel;
}
@ -943,14 +1197,13 @@ public class MpartDialog extends JFrame implements ActionListener {
TCComponentGroup group = session.getCurrentGroup();
String name = group.getTCProperty("full_name").getStringValue();
if (name.contains(".")) {
String[] split = name.split(".");
name = split[split.length];
String[] split = name.split("\\.");
name = split[split.length - 1];
System.out.println("name==============" + name);
}
return name;
}
/**
* 1011
*
@ -978,15 +1231,36 @@ public class MpartDialog extends JFrame implements ActionListener {
public static void CreateProcess(TCSession session, TCComponent target, String processName) throws TCException {
try {
TCComponentProcessType processType = (TCComponentProcessType) session.getTypeComponent("Job");
TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType)session.getTypeComponent("EPMTaskTemplate");
TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType) session
.getTypeComponent("EPMTaskTemplate");
TCComponentTaskTemplate taskTemplate = taskTemplateType.find(processName, 0);
if (taskTemplate != null) {
String name = target.getProperty("object_string");
processType.create(processName + "" + name, "", taskTemplate, new TCComponent[]{target}, new int[]{1});
TCComponent create = processType.create(processName + "" + name, "", taskTemplate,
new TCComponent[] { target }, new int[] { 1 });
System.out.println("uid===================" + create.getUid());
System.out.println("type==" + create.getType());
System.out.println("type==" + create.getStringProperty("object_type"));
}
} catch (TCException var7) {
var7.printStackTrace();
throw var7;
}
}
public String getLargerNumber(String num1, String num2) {
if (num1 == null || num1.isEmpty()) {
return num2;
}
// 将字符串转换为整数
int n1 = Integer.parseInt(num1);
int n2 = Integer.parseInt(num2);
// 比较两个整数,返回较大的一个的字符串形式
if (n1 > n2) {
return num1;
} else {
return num2;
}
}
}

@ -10,6 +10,7 @@ import com.teamcenter.rac.aif.AbstractAIFApplication;
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.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
@ -62,6 +63,19 @@ public class MpartHandler extends AbstractHandler{
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(component instanceof TCComponentBOMLine) {
TCComponentBOMLine bomLine = (TCComponentBOMLine)component;
try {
TCComponentItemRevision itemRevision = bomLine.getItemRevision();
String type = itemRevision.getType();
System.out.println("type2================"+type);
if(types[0].contains(type)) {
arrayList.add((TCComponentItemRevision)itemRevision);
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -27,7 +27,6 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jdesktop.swingx.JXDatePicker;
import com.connor.sbplm.plm1.util.TCUtil;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;

@ -0,0 +1,376 @@
package com.langtech.plm.project;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
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(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 Frame());
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.contains("#") || !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 void deleteWarning(File file) throws IOException {
FileInputStream input = null;
FileOutputStream output = null;
try {
input = new FileInputStream(file);
XWPFDocument doc = new XWPFDocument(input);
// XWPFParagraph para = doc.getParagraphs().get(0);
// System.out.println("para.getRuns:"+para.getRuns().size());
// for(XWPFRun run : para.getRuns()) {
// System.out.println("run:"+run.getText(0));
// }
doc.removeBodyElement(0);
// para.removeRun(0);
// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText());
// para.setPageBreak(false);
output = new FileOutputStream(file.getPath());
doc.write(output);
doc.close();
}catch (Exception e) {
throw e;
}finally {
if(input!=null)
input.close();
if(output!=null)
output.close();
}
}
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;
}
}

@ -25,6 +25,7 @@ import javax.swing.table.DefaultTableModel;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
@ -47,12 +48,13 @@ public class TemplateDialog extends JFrame implements ActionListener {
private JButton concelButton = new JButton("取消");
private HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
private String type;
public TemplateDialog(TCSession session, TCComponentItemRevision rev) throws TCException {
public TemplateDialog(TCSession session, TCComponentItemRevision rev, String type) throws TCException {
// TODO Auto-generated constructor stub
this.session = session;
this.rev = rev;
this.type = type;
initUI();
}
@ -88,14 +90,26 @@ public class TemplateDialog extends JFrame implements ActionListener {
// this.setAlwaysOnTop(true);
String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateType");
for (int i = 0; i < pref.length; i++) {
String[] split = pref[i].split(":");
if (pref[i].contains(type)) {
System.out.println("pref[i]======="+pref[i]+"type========="+type);
String[] split10 = pref[i].split("\\|");
System.out.println("split10========"+split10.length);
if (split10.length == 2) {
String[] split11 = split10[1].split(";");
System.out.println("split11==============="+split11.length);
for (int j = 0; j < split11.length; j++) {
String[] split = split11[j].split(":");
System.out.println("split=============="+split.length);
company.addItem(split[0]);
map.put(split[0], split[1]);
}
}
}
}
String mrselectitem = (String) company.getSelectedItem();
String mrValue = map.get(mrselectitem);
@ -158,9 +172,11 @@ public class TemplateDialog extends JFrame implements ActionListener {
// 调用查询获取模板的dwg数据集
try {
TCComponent[] items = session.search("零组件...", new String[] { "零组件 ID" }, new String[] {templateString});
TCComponent[] items = session.search("Áã×é¼þ...", new String[] { "Áã×é¼þ ID" },
new String[] { templateString });
System.out.println("items.length====" + items.length);
TCComponentItem item = null;
if (items.length > 0) {
item = (TCComponentItem) items[0];
}
@ -168,7 +184,13 @@ public class TemplateDialog extends JFrame implements ActionListener {
TCComponent[] relatedComponent = latestItemRevision.getRelatedComponents("IMAN_specification");
System.out.println("relatedComponent========" + relatedComponent.length);
for (int i = 0; i < relatedComponent.length; i++) {
rev.add("IMAN_specification",relatedComponent[i]);
if(relatedComponent[i] instanceof TCComponentDataset) {
TCComponentDataset dataset = (TCComponentDataset)relatedComponent[i];
TCComponentDataset saveAs = dataset.saveAs(rev.getStringProperty("item_id"));
rev.add("IMAN_specification", saveAs);
}
}
MessageBox.post("模板插入成功!", "提示 ", MessageBox.INFORMATION);
this.dispose();

@ -43,7 +43,7 @@ public class TemplateHandler extends AbstractHandler{
TCComponentItemRevision rev = (TCComponentItemRevision)targetComponent;
String object_type = rev.getStringProperty("object_type");
if(types.contains(object_type)) {
new TemplateDialog(session,rev);
new TemplateDialog(session,rev,object_type);
}else {
MessageBox.post("请选择首选项LY6_MEOP_TemplateObject中匹配的对象","提示",2);
return;

Loading…
Cancel
Save