修改功能

main
ChenZichaoczc 5 months ago
parent 04aff3093f
commit fc7596dfae

@ -59,6 +59,12 @@
name="提取属性到Word、Excel"
id="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</command>
<command
categoryId="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeCommand"
name="修改配方生效时间"
id="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeCommand">
</command>
</extension>
<extension
@ -103,6 +109,11 @@
class="com.langtech.plm.tqsx.KHandler"
commandId="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</handler>
<handler
class="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeHandler"
commandId="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
@ -117,9 +128,11 @@
id="com.langtech.plm.synchronize.SynchronizeHandler"
mnemonic="S">
</command>
<command
commandId="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeCommand"
id="com.langtech.plm.modifyEffectiveTime.ModifyEffectiveTimeHandler"
mnemonic="S">
</command>
</menu>
@ -141,8 +154,6 @@
</command>
</menu>
<menu
id="com.langtech.plm.performancemanagement.menus.sampleMenu1"
label="项目管理"
@ -158,8 +169,6 @@
id="com.langtech.plm.createProjectStruct.CreateProjectStructHandler"
mnemonic="S">
</command>
</menu>
</menuContribution>

@ -5,6 +5,7 @@ import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
@ -65,6 +66,7 @@ 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.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
@ -73,6 +75,8 @@ import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import com.teamcenter.soa.client.model.LovValue;
import k.util.KOrgDialog;
public class QDRWRWFPDialog extends JFrame implements ActionListener {
private Map<String, JTextField> textMap = new HashMap<>();
@ -86,7 +90,8 @@ public class QDRWRWFPDialog extends JFrame implements ActionListener {
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 };
// 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("应用");
@ -97,19 +102,27 @@ public class QDRWRWFPDialog extends JFrame implements ActionListener {
private static ArrayList<String> dateConnList = new ArrayList<String>();
private String type;
private String id;
private String objectString;
private boolean readOnly;
private ArrayList<Integer> canWriteColume = new ArrayList<Integer>();
public QDRWRWFPDialog(TCSession session,String type,String id) {
private ArrayList<Integer> choosePersonColume = new ArrayList<Integer>();
public QDRWRWFPDialog(TCSession session, String type, String id) {
// TODO Auto-generated constructor stub
this.session = session;
this.type = type;
this.id = id;
//this.objectString = objectString;
//this.readOnly = readOnly;
initUI();
}
public void initUI() {
// TODO Auto-generated method stub
this.setTitle("任务分配表");
yyButton.setEnabled(false);
tzsjButton.setEnabled(false);
this.setTitle(objectString+"变更任务分配表");
this.setLayout(new BorderLayout());
String[] cfdj = session.getPreferenceService().getStringValues("Connor_ChangeTaskForm_TriggerLevelMapping");
@ -118,7 +131,7 @@ public class QDRWRWFPDialog extends JFrame implements ActionListener {
return;
}
for (int i = 0; i < cfdj.length; i++) {
for (int i = 0; i < cfdj.length; i++) {
String[] split = cfdj[i].split("=");
if(split[0].equals(type)) {
@ -132,6 +145,7 @@ for (int i = 0; i < cfdj.length; i++) {
}
}
//获取首选项匹配的类型
String[] fields = session.getPreferenceService().getStringValues("Connor_ECRECNForm_Datbase_Config");
if (fields == null || fields.length <= 0) {
@ -153,6 +167,11 @@ for (int i = 0; i < cfdj.length; i++) {
String[] split4 = split3[2].split("%");
widtheMap.put(j, Integer.parseInt(split4[0]));
canWriteColume.add(j);
}else if(split3[2].contains("#")) {
String[] split4 = split3[2].split("#");
widtheMap.put(j, Integer.parseInt(split4[0]));
choosePersonColume.add(j);
canWriteColume.add(j);
}else {
widtheMap.put(j, Integer.parseInt(split3[2]));
}
@ -165,6 +184,11 @@ for (int i = 0; i < cfdj.length; i++) {
widtheMap.put(j, Integer.parseInt(split4[0]));
System.out.println("split4[0]========"+split4[0]);
canWriteColume.add(j);
}else if(split3[2].contains("#")) {
String[] split4 = split3[2].split("#");
widtheMap.put(j, Integer.parseInt(split4[0]));
choosePersonColume.add(j);
canWriteColume.add(j);
}else {
widtheMap.put(j, Integer.parseInt(split3[2]));
}
@ -175,11 +199,16 @@ for (int i = 0; i < cfdj.length; i++) {
}
}
System.out.println("choosePersonColume====="+choosePersonColume.size());
System.out.println("canWriteColume====="+canWriteColume.size());
System.out.println("fieldsMap====="+fieldsMap);
System.out.println("positionMap====="+lovPositionMap);
System.out.println("widtheMap====="+widtheMap);
if(fieldsMap.size() == 0) {
MessageBox.post("该类型未匹配到首选项!", "提示 ", MessageBox.INFORMATION);
return;
}
Collection<String> valuesCollection = fieldsMap.values();
// 将集合转换为数组
@ -241,7 +270,7 @@ for (int i = 0; i < cfdj.length; i++) {
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));
//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]));
@ -266,7 +295,6 @@ for (int i = 0; i < cfdj.length; i++) {
}
}
public void createActionEvent() {
this.yyButton.addActionListener(this);
this.gbButton.addActionListener(this);
@ -280,7 +308,7 @@ for (int i = 0; i < cfdj.length; i++) {
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.left.center", new JLabel("触发等级 "));
topPanel.add("1.2.left.center",cfdJComboBox);
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);
@ -318,16 +346,38 @@ for (int i = 0; i < cfdj.length; i++) {
for (Entry<Integer, String> map : lovPositionMap.entrySet()) {
JComboBox<String> jComboBox = new JComboBox<String>();
String value = map.getValue();
if(value.contains(",")) {
if (value.contains(",")) {
String[] split = value.split(",");
for (int i = 0; i < split.length; i++) {
jComboBox.addItem(split[i]);
}
}else {
} else {
jComboBox.addItem(value);
}
table.getColumnModel().getColumn(map.getKey()).setCellEditor(new DefaultCellEditor(jComboBox));
}
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 || e.getClickCount() == 1) { // 判断是否双击并且是在第二列
int row = table.rowAtPoint(e.getPoint());
int column = table.columnAtPoint(e.getPoint());
System.out.println("column========"+column);
if (choosePersonColume.contains(column)) {
System.out.println("1111111111111111111111111111111");
try {
TCComponentUser user = new KOrgDialog("").getUser();
System.out.println("user============"+user.getUserName());
table.setValueAt(user.getUserName()+"("+user.getUserId()+")", row, column);
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
});
pane.setPreferredSize(new Dimension(1800, 850));
pane.setViewportView(table);// 为scrollPane指定显示对象为table
return pane;
@ -373,10 +423,9 @@ for (int i = 0; i < cfdj.length; i++) {
dtm1 = new DefaultTableModel(values, titleNames) {
@Override
public boolean isCellEditable(int row, int column) {
if(canWriteColume.size() > 0) {
if (canWriteColume.size() > 0) {
for (int i = 0; i < canWriteColume.size(); i++) {
if(canWriteColume.get(i) == column) {
System.out.println("row=========="+row);
if (canWriteColume.get(i) == column) {
return true;
}
}
@ -397,32 +446,44 @@ for (int i = 0; i < cfdj.length; i++) {
if (source.equals(this.gbButton)) {
dispose();
}
else if(source.equals(this.yyButton)){
//保存数据
} else if (source.equals(this.yyButton)) {
// 保存数据
Connection conn = getConn();
PreparedStatement stmt = null;
for(int i = 0; i < table.getRowCount(); i++){
//遍历一遍判断是否涉及更改
Integer sfsjgg = positionFieldMap.get("SFSJGG");
for (int i = 0; i < table.getRowCount(); i++) {
String valueAt = (String)table.getValueAt(i, sfsjgg);
System.out.println("valueAt============="+valueAt);
if(valueAt == null || valueAt.isEmpty()) {
int row = i+1;
MessageBox.post("第"+row+"行的是否涉及变更未填写!", "提示", 2);
return;
}
}
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()) {
String valueAt = (String) table.getValueAt(i, map.getValue());
if (valueAt == null || valueAt.isEmpty()) {
updateSql.append("=");
updateSql.append("null,");
}else {
} else {
updateSql.append("='");
updateSql.append(table.getValueAt(i,map.getValue()));
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)+"'");
updateSql.append(" where ID='" + id + "' and XH='" + table.getValueAt(i, 0) + "'");
try {
stmt = conn.prepareStatement(updateSql.toString());
System.out.println("updateSql========="+updateSql.toString());
System.out.println("updateSql=========" + updateSql.toString());
stmt.execute();
} catch (SQLException e1) {
// TODO Auto-generated catch block
@ -431,94 +492,93 @@ for (int i = 0; i < cfdj.length; i++) {
}
try {
if(stmt != null) {
if (stmt != null) {
stmt.close();
}
if(conn != null) {
if (conn != null) {
conn.close();
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else if(source.equals(this.tzsjButton)){
MessageBox.post("应用完成!", "提示", 2);
} else if (source.equals(this.tzsjButton)) {
gsPrefTopLine = new ArrayList<String>();
String selectedItem = (String)cfdJComboBox.getSelectedItem();
if(selectedItem == null || selectedItem.isEmpty()) {
String selectedItem = (String) cfdJComboBox.getSelectedItem();
if (selectedItem == null || selectedItem.isEmpty()) {
MessageBox.post("请选择触发等级!", "提示", 2);
return;
}
Date date = cfsjButton.getDate();
if(date == null) {
if (date == null) {
MessageBox.post("请选择触发时间!", "提示", 2);
return;
}
String cfsjDate = dateFormat.format(date);
String pref = cfdjPref.get(selectedItem);
if(pref == null || pref.isEmpty()) {
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);
MessageBox.post("请配置首选项“" + pref + "”", "提示 ", MessageBox.INFORMATION);
return;
}
for (int i = 0; i < calculateTime.length; i++) {
String[] split = calculateTime[i].split("\\|");
if(i == 0) {
if (i == 0) {
for (int j = 0; j < split.length; j++) {
gsPrefTopLine.add(split[j]);
}
}else {
gsPrefMap.put(split[0],calculateTime[i]);
} else {
gsPrefMap.put(split[0], calculateTime[i]);
}
}
System.out.println(positionFieldMap+"==================positionFieldMap");
System.out.println("gsPrefTopLine----------------"+gsPrefTopLine.size());
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++){
// 表里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() ) {
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));
// 如果有值
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))");
//处理公式
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 {
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);
System.out.println("time============" + time);
table.setValueAt(time, i, colume);
}
}
}
}
}
//调用应用按钮
// 调用应用按钮
yyButton.doClick();
MessageBox.post("调整时间完成!", "提示", 2);
}

@ -0,0 +1,94 @@
package com.langtech.plm.modifyEffectiveTime;
import org.jdesktop.swingx.JXDatePicker;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EventObject;
public class DatePickerEditor extends AbstractCellEditor implements TableCellEditor {
private JXDatePicker datePicker;
private JTable table;
private int row;
private int column;
public DatePickerEditor() {
datePicker = new JXDatePicker();
// 设置日期格式
datePicker.setFormats(new SimpleDateFormat("yyyy-MM-dd"));
datePicker.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
fireEditingStopped();
}
});
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
this.table = table;
this.row = row;
this.column = column;
System.out.println("getTableCellEditorComponent: "+value);
if (value instanceof Date) {
datePicker.setDate((Date) value);
} else {
datePicker.setDate(null);
}
return datePicker;
}
@Override
public Object getCellEditorValue() {
try {
// 获取用户输入的文本
String text = datePicker.getEditor().getText();
if (text.trim().isEmpty()) {
return null;
}
// 尝试将输入解析为日期
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setLenient(false); // 严格解析日期格式
return format.parse(text);
} catch (Exception e) {
// 如果解析失败,打印错误信息并返回当前日期选择器的值
System.err.println("Invalid date format: " + e.getMessage());
}
// 返回日期选择器当前的值
return datePicker.getDate();
}
@Override
public boolean isCellEditable(EventObject anEvent) {
return true;
}
@Override
public boolean stopCellEditing() {
System.out.println("stopCellEditing: " + datePicker.getDate());
fireEditingStopped();
return true;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return true;
}
@Override
public void cancelCellEditing() {
super.cancelCellEditing();
}
}

@ -0,0 +1,265 @@
package com.langtech.plm.modifyEffectiveTime;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import org.jdesktop.swingx.JXDatePicker;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCUserService;
import com.teamcenter.rac.util.MessageBox;
public class ModifyEffectiveTimeDialog extends JFrame implements Runnable {
private JTable table;
private JButton okButton;
private boolean flag;
private final String title;
private final String[] columnNames;
private Object[][] data;
private int[] dateIndex;
private boolean pass;
public static void main(String[] args) {
}
public ModifyEffectiveTimeDialog(String title, Object... args) {
this.title = title;
this.columnNames = (String[]) args[0];
this.data = (Object[][]) args[1];
this.dateIndex = (int[]) args[2];
this.pass = (boolean) args[3];
}
@Override
public void run() {
// TODO Auto-generated method stub
initUI();
}
public void setWithHeight(int with, int height) {
this.setSize(with, height);
}
public void initUI() {
this.setTitle(title);
// 初始化所有信息
initializationComponent();
// 添加内容到JFrame 并设置它的位置
JPanel bottomPanel = getBottomPanel();
// 创建表格和滚动条
JPanel tableScrollPane = createTable();
tableScrollPane.setPreferredSize(new Dimension(700, 200)); // 设置滚动条的大小
this.getContentPane().add(tableScrollPane, BorderLayout.CENTER);
this.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
// 设置窗口居中
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// 设置可见性
this.setVisible(true);
}
public void initializationComponent() {
okButton = new JButton("应用");
okButton.setEnabled(pass);
}
public JPanel createTable() {
JPanel panel = new JPanel(new BorderLayout(10, 10));
panel.setBorder(new EmptyBorder(20, 20, 10, 20));
// 创建 DefaultTableModel 实例
DefaultTableModel model = new DefaultTableModel(data, columnNames) {
@Override
public boolean isCellEditable(int row, int column) {
if (column == 0) {
return false;
}
return true;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 1) {
return Date.class;
}
return super.getColumnClass(columnIndex);
}
};
table = new JTable(model);
// 设置行高
table.setRowHeight(25); // 设置行高为30像素
table.setFont(new Font("微软雅黑", Font.PLAIN, 12));
// 禁用列重排序
table.getTableHeader().setReorderingAllowed(false);
// 禁用自动调整列宽
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// 设置表格填满视口高度
// table.setFillsViewportHeight(true);
// 设置列宽
TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(0).setPreferredWidth(300);
columnModel.getColumn(1).setPreferredWidth(143);
table.removeColumn(columnModel.getColumn(columnModel.getColumnCount() - 1));
// 自定义渲染器,使所有列居中对齐
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
((JLabel) c).setHorizontalAlignment(SwingConstants.CENTER); // 设置文本居中对齐
return c;
}
};
// 应用居中对齐渲染器
for (int i = 0; i < columnModel.getColumnCount(); i++) {
columnModel.getColumn(i).setCellRenderer(centerRenderer);
}
// 自定义渲染器
TableCellRenderer dateRenderer = (JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column) -> {
JXDatePicker datePicker = new JXDatePicker();
if (value instanceof Date) {
datePicker.setFormats(new SimpleDateFormat("yyyy-MM-dd"));
datePicker.setDate((Date) value);
}
return datePicker;
};
// 自定义编辑器
TableCellEditor dateEditor = new DatePickerEditor();
// 为 IssueDate 和 MaterialDeliveryTime 列设置日期选择器
for (int index : dateIndex) {
// 设置渲染器和编辑器
table.getColumnModel().getColumn(index).setCellRenderer(dateRenderer);
table.getColumnModel().getColumn(index).setCellEditor(dateEditor);
}
// 创建 JScrollPane 并设置水平滚动条始终可见
JScrollPane scrollPane = new JScrollPane(table);
// scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// 添加表格到中心区域
panel.add(scrollPane, BorderLayout.CENTER);
return panel;
}
public JPanel getBottomPanel() {
// TODO Auto-generated method stub
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 70, 10));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(-10, 0, 10, 0));
bottomPanel.add(this.okButton);
// 添加监听
okButton.addActionListener(e -> {
flag = true;
List<String[]> tableData = getTableData();
if (tableData != null) {
tableData.forEach(rowData -> {
System.out.println(Arrays.toString(rowData));
});
}
if (flag) {
MessageBox.post("修改成功! ", "Info", MessageBox.INFORMATION);
this.dispose(); // 关闭窗口
} else {
MessageBox.post("生效时间不允许超出两行", "Error", MessageBox.ERROR);
}
});
return bottomPanel;
}
public List<String[]> getTableData() {
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rowCount = model.getRowCount();
int columnCount = model.getColumnCount();
List<String[]> tableData = new ArrayList<>();
int count = 0;
for (int row = 0; row < rowCount; row++) {
Object obj = model.getValueAt(row, 1);
if (obj instanceof Date && obj != null) {
count++;
if (count == 3) {
flag = false;
return null;
}
}
}
setByPass(true);
try {
for (int row = 0; row < rowCount; row++) {
String name = (String) model.getValueAt(row, 0);
Object obj = model.getValueAt(row, 1);
System.out.println("name: " + name + " || date: " + obj);
TCComponentItemRevision rev = (TCComponentItemRevision) model.getValueAt(row, 2);
rev.setDateProperty("ly6_deadline", (Date) obj);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
MessageBox.post(e.getMessage(), "Error", MessageBox.ERROR);
}
setByPass(false);
return tableData;
}
@SuppressWarnings("deprecation")
public void setByPass(boolean pass) {
TCUserService userservice = null;
if (userservice == null) {
userservice = ((TCSession) AIFUtility.getCurrentApplication().getSession()).getUserService();
}
Object[] obj = new Object[1];
obj[0] = "origin";
try {
if (pass) {
userservice.call("CONNOR_open_bypass", obj);
System.out.println("旁路已开启");
} else {
userservice.call("CONNOR_close_bypass", obj);
System.out.println("旁路已关闭");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,165 @@
package com.langtech.plm.modifyEffectiveTime;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
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.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class ModifyEffectiveTimeHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
TCPreferenceService preferenceService = session.getPreferenceService();
String[] preValues = preferenceService.getStringValues("LY__FormulaDeadLine_Config");
if ((preValues != null && preValues.length < 3) || preValues == null) {
MessageBox.post("LY__FormulaDeadLine_Config配置错误", "Error", MessageBox.ERROR);
return null;
}
String[] types = preValues[0].split(";");
String[] childTypes = preValues[1].split(";");
String[] permissionPeo = preValues[2].split(";");
TCComponent targetComponent = (TCComponent)app.getTargetComponent();
String targetType = "";
try {
if(targetComponent instanceof TCComponentItemRevision) {
targetType = targetComponent.getType();
}else if(targetComponent instanceof TCComponentBOMLine) {
targetType = ((TCComponentBOMLine) targetComponent).getItemRevision().getType();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean isExist = false;
System.out.println("当前类型:" + targetType);
for (String type : types) {
System.out.println("当前配置类型:" + type);
if (type.equals(targetType)) {
isExist = true;
break;
}
}
if (!isExist) {
MessageBox.post("请选择指定类型的牌号版本执行修改配方生效日期功能", "Error", MessageBox.ERROR);
return null;
}
boolean pass = false;
String userName = session.getUserName();
System.out.println("当前用户:" + userName);
for (String name : permissionPeo) {
System.out.println("当前配置用户:" + name);
if (userName.equals(name)) {
pass = true;
break;
}
}
Object[][] data = null;
try {
List<TCComponentItemRevision> revList = getChildBom(session, targetComponent, childTypes);
data = new Object[revList.size()][];
for (int i = 0; i < revList.size(); i++) {
TCComponentItemRevision tempRev = revList.get(i);
Object[] tempData = new Object[3];
tempData[0] = tempRev.getProperty("object_string");
tempData[1] = parseDate(tempRev.getProperty("ly6_deadline"));
tempData[2] = tempRev;
data[i] = tempData;
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 表格列标题
String[] columnNames = new String[] { "对象", "生效时间", "TCComponent" };
int[] dateIndex = new int[] { 1 };
ModifyEffectiveTimeDialog dialog = new ModifyEffectiveTimeDialog("修改配方生效时间", columnNames, data, dateIndex,
pass);
dialog.setWithHeight(500, 300);
new Thread(dialog).start();
return null;
}
public List<TCComponentItemRevision> getChildBom(TCSession session, TCComponent targetComponent,
String[] childTypes) throws TCException {
// TODO Auto-generated method stub
TCComponentBOMLine topLine = null;
if (targetComponent instanceof TCComponentItemRevision) {
TCComponentItemRevision rev = (TCComponentItemRevision) targetComponent;
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = winType.create(null);
topLine = view.setWindowTopLine(rev.getItem(), rev, null, null);
} else if (targetComponent instanceof TCComponentBOMLine) {
topLine = ((TCComponentBOMLine) targetComponent);
}
boolean hasChildren = topLine.hasChildren();
List<TCComponentItemRevision> revList = new ArrayList<TCComponentItemRevision>();
if (!hasChildren) {
return revList;
}
String revType = "";
AIFComponentContext[] childrena = topLine.getChildren();
for (AIFComponentContext children : childrena) {
TCComponentBOMLine component = (TCComponentBOMLine) children.getComponent();
TCComponentItemRevision itemRevision = component.getItemRevision();
// revType = itemRevision.getProperty("object_type");
revType = itemRevision.getType();
System.out.println("子类对象类型getType()获取的值:" + revType);
for (String type : childTypes) {
System.out.println("子类配置对象类型:" + type);
if (revType.equals(type)) {
revList.add(itemRevision);
break;
}
}
}
return revList;
}
public Date parseDate(String dateString) {
if (dateString == null || dateString.isEmpty()) {
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
}

@ -595,6 +595,7 @@ public class MpartDialog extends JFrame implements ActionListener {
ArrayList<Object> tempList = new ArrayList<Object>();
tempList.add(tempMrevList.get(k));
tempList.add(sl);
//tempList.add("1");
revMap.put(stringProperty, tempList);
jComboBox.addItem(stringProperty);
}

@ -7,6 +7,12 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@ -308,7 +314,6 @@ public class CalculateDialog extends JFrame implements ActionListener {
topBomLine.unlock();
view.close();
this.zjdTextField.setText(outlineDiameter != null ? outlineDiameter : "");
this.lkcTextField.setText(outlineLength != null ? outlineLength : "");
this.qdycdTextField.setText(cuttingLength != null ? cuttingLength : "");
@ -342,8 +347,9 @@ public class CalculateDialog extends JFrame implements ActionListener {
// 计算结果
double result = (lkcValue + qdycdValue + cdmycdValue) * kzljsValue + jtycdValue;
System.out.println("图纸轮廓长:"+lkcValue+"切断用长度:"+qdycdValue+"车端面用长度:"+cdmycdValue+"可制零件数:"+kzljsValue+"夹头用长度:"+jtycdValue);
return String.valueOf(result);
// double cm = result / 10.0;
String formattedCm = String.format("%.2f", result);
return formattedCm;
}
/**
@ -361,9 +367,40 @@ public class CalculateDialog extends JFrame implements ActionListener {
}
double result = zcValue / kzljsValue;
System.out.println("总长:"+zcValue+"可制零件数:"+kzljsValue);
return String.valueOf(result);
// double cm = result / 10.0;
String format = String.format("%.2f", result);
return format;
}
private void downLoadFile(File file) throws Exception {
FileInputStream inputStream = new FileInputStream(file);
// 指定文件保存的本地路径
String localFilePath = "C:\\"+file.getName();
try {
// 创建目标路径
Path path = Paths.get(localFilePath);
// 将输入流写入到本地文件
Files.copy(inputStream, path);
System.out.println("文件已成功保存: "+localFilePath);
} catch (Exception e) {
e.printStackTrace();
System.out.println("保存文件时发生错误!");
} finally {
// 关闭输入流以释放资源
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* uidEXCEL
* uiditem
@ -393,9 +430,17 @@ public class CalculateDialog extends JFrame implements ActionListener {
//获取当前版本的规范关系下的数据集
TCComponent[] referenceListProperty = tcComponentItemRevision.getReferenceListProperty("IMAN_specification");
if(referenceListProperty.length>0) {
//获取数据集下具体的引用文件
System.out.println("规范关系下的数据集数量:"+referenceListProperty.length);
//获取第一个数据集下具体的引用文件
TCComponentTcFile[] tcFiles = ((TCComponentDataset)referenceListProperty[0]).getTcFiles();
if (tcFiles.length > 0) {
// System.out.println("数据集下引用文件的数量" + tcFiles.length);
File file = tcFiles[0].getFmsFile();
// if (file.exists()) {
// System.out.println("开始下载!");
// downLoadFile(file);
// }
System.out.println("获取到数据集文件:"+file.getName());
// 根据横截面积获取数据集-excel表中对应的条目数据辅助时间、固定时间、切割时间
FileInputStream fis = new FileInputStream(file);
Workbook workbook = new HSSFWorkbook(fis);
@ -404,9 +449,11 @@ public class CalculateDialog extends JFrame implements ActionListener {
for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
//获取表中每行的第一个值,即:直径
double diam = row.getCell(0).getNumericCellValue();
// double diam = row.getCell(0).getNumericCellValue();
String diam = row.getCell(0).getStringCellValue();
// 根据规格匹配数据集表中的直径
if (diam == Double.parseDouble(this.ggTextField.getText())){
if (diam.equals(this.ggTextField.getText())){
// if (diam == Double.parseDouble(this.ggTextField.getText())){
System.out.println("=========》直径匹配成功!开始获取辅助工时和标准工时"+"=========》当前行号:"+(i+1)+",当前行的直径:"+diam);
//获取第11列的值标准工时
this.bzgsTextField.setText(row.getCell(10).getStringCellValue());
@ -415,6 +462,11 @@ public class CalculateDialog extends JFrame implements ActionListener {
break;
}
}
workbook.close();
}else {
System.out.println("获取数据集文件失败!");
}
}
}
@ -536,10 +588,11 @@ public class CalculateDialog extends JFrame implements ActionListener {
densityNum = Double.parseDouble(this.density);
}
double siglengthNum = Double.parseDouble(this.djcdTextField.getText());
System.out.println("53456");
double result = crossSectionNum * densityNum * siglengthNum;
System.out.println("横截面:"+crossSectionNum+",密度:"+densityNum+",单件长度:"+siglengthNum);
return String.valueOf(result);
double kg = result / 10000.0;
String formattedKg = String.format("%.2f", kg);
return formattedKg;
}
/**

Loading…
Cancel
Save