main
李建辉 6 months ago
parent 6276640680
commit 07dfccd9b6

@ -110,6 +110,7 @@ public class QDRWChooseDialog extends JFrame implements ActionListener {
String selectedItem = (String) objectComboBox.getSelectedItem(); String selectedItem = (String) objectComboBox.getSelectedItem();
ArrayList<String> arrayList = map.get(selectedItem); ArrayList<String> arrayList = map.get(selectedItem);
new QDRWDialog((TCSession)app.getSession(),arrayList.get(0),arrayList.get(1)); new QDRWDialog((TCSession)app.getSession(),arrayList.get(0),arrayList.get(1));
System.out.println("newnewnwenew");
this.dispose(); this.dispose();
} else if (this.concelButton.equals(source)) { } else if (this.concelButton.equals(source)) {
this.dispose(); this.dispose();

@ -1,6 +1,8 @@
package com.langtech.plm.bg; package com.langtech.plm.bg;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -45,6 +47,8 @@ import javax.swing.JTable;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.RowSorter; import javax.swing.RowSorter;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel; import javax.swing.table.TableModel;
@ -95,7 +99,7 @@ public class QDRWDialog extends JFrame implements ActionListener {
private DateButton jhksS; private DateButton jhksS;
private DateButton jhwcB; private DateButton jhwcB;
private DateButton jhwcS; private DateButton jhwcS;
private JTextField idField = new JTextField(); private JTextField idField = new JTextField(30);
private JButton ssButton = new JButton("搜索"); private JButton ssButton = new JButton("搜索");
private JButton ckButton = new JButton("查看任务分配表"); private JButton ckButton = new JButton("查看任务分配表");
private JButton qrqdButton = new JButton("确认启动"); private JButton qrqdButton = new JButton("确认启动");
@ -104,7 +108,7 @@ public class QDRWDialog extends JFrame implements ActionListener {
private String pref; private String pref;
private String taskName; private String taskName;
private ArrayList<Integer> canWriteColume = new ArrayList<Integer>(); private ArrayList<Integer> canWriteColume = new ArrayList<Integer>();
private ArrayList<String> sqlField = new ArrayList<String>(); private ArrayList<String> sqlField;
public QDRWDialog(TCSession session,String pref,String taskName) { public QDRWDialog(TCSession session,String pref,String taskName) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
this.session = session; this.session = session;
@ -124,15 +128,10 @@ public class QDRWDialog extends JFrame implements ActionListener {
return; return;
} }
//获取首选项匹配的类型
String[] fields = session.getPreferenceService().getStringValues("Connor_ECRECNForm_Datbase_Config");
if (fields == null || fields.length <= 0) {
MessageBox.post("请配置首选项“Connor_ECRECNForm_Datbase_Config”", "提示 ", MessageBox.INFORMATION);
return;
}
String[] split2 = fields[0].split(";");
String[] split2 = prefs[0].split(";");
for (int j = 0; j < split2.length; j++) { for (int j = 0; j < split2.length; j++) {
String[] split3 = split2[j].split("="); String[] split3 = split2[j].split("=");
positionFieldMap.put(split3[0],j); positionFieldMap.put(split3[0],j);
@ -234,7 +233,6 @@ public class QDRWDialog extends JFrame implements ActionListener {
jhwcB.setDate("未设置日期"); jhwcB.setDate("未设置日期");
jhwcS = new DateButton(null, "yyyy-MM-dd", false, false, false); jhwcS = new DateButton(null, "yyyy-MM-dd", false, false, false);
jhwcS.setDate("未设置日期"); jhwcS.setDate("未设置日期");
topPanel.add("1.1.left.center", new JLabel("ID ")); topPanel.add("1.1.left.center", new JLabel("ID "));
topPanel.add("1.2.left.center",idField); topPanel.add("1.2.left.center",idField);
topPanel.add("1.3.left.center", new JLabel(" 计划开始早于 ")); topPanel.add("1.3.left.center", new JLabel(" 计划开始早于 "));
@ -273,6 +271,8 @@ public class QDRWDialog extends JFrame implements ActionListener {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // 设置表格的自动调整模式为关闭自动调整 table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // 设置表格的自动调整模式为关闭自动调整
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置JTable的列宽随着列表内容的大小进行调整 // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置JTable的列宽随着列表内容的大小进行调整
// table.setPreferredSize(new Dimension(1200,400)); // table.setPreferredSize(new Dimension(1200,400));
// 设置自定义渲染器
table.setDefaultRenderer(Object.class, new CustomColorRenderer());
JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
for (Entry<Integer, String> map : lovPositionMap.entrySet()) { for (Entry<Integer, String> map : lovPositionMap.entrySet()) {
@ -350,18 +350,62 @@ public class QDRWDialog extends JFrame implements ActionListener {
dispose(); dispose();
} }
else if(source.equals(this.ckButton)){ else if(source.equals(this.ckButton)){
// int selectedRow = table.getSelectedRow();
if(selectedRow < 0) {
MessageBox.post("请选择某一行!", "提示", 2);
}
String selectId = (String)table.getValueAt(selectedRow,0);
String selectType = (String)table.getValueAt(selectedRow,1);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
new QDRWRWFPDialog(session,selectType,selectId);
//d.setModal(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}else if(source.equals(this.qrqdButton)){ }else if(source.equals(this.qrqdButton)){
}else if(source.equals(this.ssButton)){ }else if(source.equals(this.ssButton)){
table.removeAll();
dtm1.setRowCount(0);
String condition = "";
String ids = idField.getText();
String jhksBStr = jhksB.getText();
String jhksSStr = jhksS.getText();
String jhwcBStr = jhwcB.getText();
String jhwcSStr = jhwcS.getText();
System.out.println("jhksBStr======="+jhksBStr);
String condition = ""; if(!jhksBStr.contains("未设置")) {
if(condition == null || condition.isEmpty()) { condition += "and JHKS >= '"+ jhksBStr +"' ";
MessageBox.post("请填写条件。", "提示", 2); }
if(!jhksSStr.contains("未设置")) {
condition += "and JHKS <= '"+ jhksSStr +"' ";
}
if(!jhwcBStr.contains("未设置")) {
condition += "and JHJS >= '"+ jhwcBStr +"' ";
}
if(!jhwcSStr.contains("未设置")) {
condition += "and JHJS <= '"+ jhwcSStr +"' ";
}
if(ids == null || ids.isEmpty()) {
MessageBox.post("请填写条件!", "提示", 2);
return; return;
} }
String ids = idField.getText();
if(ids != null && !ids.isEmpty()) { if(ids != null && !ids.isEmpty()) {
if(ids.contains(";")) { if(ids.contains(";")) {
String[] split = ids.split(";"); String[] split = ids.split(";");
@ -389,7 +433,7 @@ public class QDRWDialog extends JFrame implements ActionListener {
} else { } else {
Collections.addAll(dateConnList, value); Collections.addAll(dateConnList, value);
} }
sqlField = new ArrayList<String>();
Set<String> keySet = fieldsMap.keySet(); Set<String> keySet = fieldsMap.keySet();
String fieldsSql = ""; String fieldsSql = "";
for (String string : keySet) { for (String string : keySet) {
@ -427,24 +471,26 @@ public class QDRWDialog extends JFrame implements ActionListener {
tempList.add(fieldMap); tempList.add(fieldMap);
} }
tempMap1.put(xh,tempList); tempMap1.put(xh,tempList);
valueMap.put(id,tempMap1);
} }
System.out.println(valueMap.toString()); System.out.println(valueMap.toString());
for (Entry<String, LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>>> map : valueMap.entrySet()) { for (Entry<String, LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>>> map : valueMap.entrySet()) {
ArrayList<String> tableList = new ArrayList<String>(); ArrayList<String> tableList = new ArrayList<String>();
for (Entry<String, String> tempMap : fieldsMap.entrySet()) { for (Entry<String, String> tempMap : fieldsMap.entrySet()) {
String pref = tempMap.getValue(); String pref = tempMap.getKey();
String[] split = pref.split("\\."); String[] split = pref.split("\\.");
LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>> value2 = map.getValue(); LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>> value2 = map.getValue();
ArrayList<LinkedHashMap<String, String>> arrayList = value2.get(split[0]); ArrayList<LinkedHashMap<String, String>> arrayList = value2.get(split[0]);
for (int i = 0; i < arrayList.size(); i++) { if(arrayList != null) {
LinkedHashMap<String, String> linkedHashMap = arrayList.get(i); for (int i = 0; i < arrayList.size(); i++) {
if(linkedHashMap.containsKey(split[1])) { LinkedHashMap<String, String> linkedHashMap = arrayList.get(i);
tableList.add(linkedHashMap.get(split[1])); if(linkedHashMap.containsKey(split[1])) {
System.out.println("linkedHashMap.get(split[1])==============="+linkedHashMap.get(split[1])); tableList.add(linkedHashMap.get(split[1]));
}
} }
} }
} }
dtm1.addRow(tableList.toArray(new Object[0])); dtm1.addRow(tableList.toArray(new Object[0]));
} }
@ -520,4 +566,27 @@ public class QDRWDialog extends JFrame implements ActionListener {
} }
} }
// 自定义渲染器
static class CustomColorRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
// 调用父类方法获取默认渲染组件
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
// 设置你想要的颜色逻辑
if (value == null || "".equals(value.toString().trim())) {
setBackground(Color.LIGHT_GRAY); // 空值或空字符串使用浅灰色背景
setForeground(Color.DARK_GRAY); // 深灰色前景
} else {
setBackground(isSelected ? table.getSelectionBackground() : Color.WHITE); // 默认选择或白色背景
setForeground(isSelected ? table.getSelectionForeground() : Color.BLACK); // 默认选择或黑色前景
}
return this;
}
}
} }

@ -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 QDRWRWFPDialog 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 QDRWRWFPDialog(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;
}
}
}
Loading…
Cancel
Save