main
李建辉 11 months ago
parent 7f030fa8e3
commit aabd198422

@ -0,0 +1,537 @@
package com.connor.plm.txdp;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
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.FileOutputStream;
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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
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.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.DateButton;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class TXDPFram extends JFrame implements ActionListener {
private TCSession session;
protected DefaultTableModel tm_part;
private static ArrayList<String> dateConnList = new ArrayList<String>();
private String[] prefs;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private JTextField pathJTextField = new JTextField(30);
private JButton outputButton = new JButton("选择");
private JTextField xjjTextField = new JTextField(30);
private JTextField edmTextField = new JTextField(30);
private Workbook workbook;
public TXDPFram(TCSession session) {
// TODO Auto-generated constructor stub
this.session = session;
prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT");
initUI();
}
private String sqlString = "";
private void initUI() {
// TODO Auto-generated method stub
try {
this.setTitle("WMS集成默认物料维护界面");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(550, 175));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 550) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 300) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.btnIn.addActionListener(this);
}
private List<TCComponent> compList = new ArrayList<TCComponent>();
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.btnIn.equals(source)) {
//导入的逻辑
String pathJTextFieldStr = pathJTextField.getText();
// if(pathJTextFieldStr == null || pathJTextFieldStr.isEmpty()) {
// MessageBox.post("请选择需要导入的Excel。", "提示", 2);
// return;
// }
FileInputStream input = null;
try {
SqlUtil.SRMGetTCDataConnection(prefs);
//
//
//
// if(!pathJTextFieldStr.contains(".xlsx")) {
// MessageBox.post("请选择.xlsx格式的Excel。", "提示", 2);
// return;
// }
//
// //判断是否填写宽度和距离
// if(xjjTextField == null || xjjTextField.getText().isEmpty()) {
// MessageBox.post("请填写 “下夹件宽度” 后再导入!", "提示", 2);
// return;
// }
//
// if(edmTextField == null || edmTextField.getText().isEmpty()) {
// MessageBox.post("请填写 “轭断面距离” 后导入!", "提示", 2);
// return;
// }
File file = new File("D://a.xlsx");
input = new FileInputStream(file);
workbook = new XSSFWorkbook(input);
int numberOfSheets = workbook.getNumberOfSheets();
System.out.println("numberOfSheets========================"+numberOfSheets);
//判断是五柱还是三柱
String producttype = "";
String drawingno = "";
if(numberOfSheets == 8) {
producttype = "三柱";
}else if(numberOfSheets == 10) {
producttype = "五柱";
}
if(producttype.equals("三柱")) {
Sheet sheet0 = workbook.getSheet("数据输入");
Sheet sheet1 = workbook.getSheet("中柱剪切单1");
Sheet sheet2 = workbook.getSheet("中柱剪切单2");
Sheet sheet3 = workbook.getSheet("中柱剪切单3");
Sheet sheet4 = workbook.getSheet("边柱剪切单");
Sheet sheet5 = workbook.getSheet("轭剪切单");
int lastRowNum = sheet0.getLastRowNum();
System.out.println("lastRowNum==================="+lastRowNum);
//组织数据输入表
if(sheet0 != null) {
//table1
Row row2 = sheet0.getRow(2);
Row row3 = sheet0.getRow(3);
Row row4 = sheet0.getRow(4);
Row row5 = sheet0.getRow(5);
Row row6 = sheet0.getRow(6);
drawingno = getCellValue(row2.getCell(5));
if(drawingno == null || drawingno.isEmpty()) {
MessageBox.post("图纸代号不可为空!", "提示", 2);
return;
}
String insertSqlT1 = "INSERT INTO CHINT_IRON_CORE_SUM(\"lower_clamp_width\",\"yoke_section_distance\",\"drawingno\",\"producttype\",\"productmodel\",\"workcode\",\"core_angle_weight\",\"core_netdiameter\",\"mo\",\"hw\",\"core_cross_secarea\",\"core_filmthick_ness\",\"lamination_coefficient\",\"material_code\",\"reference_cross_sectional_area\",\"stepping_eccentricity_1\",\"stepping_eccentricity_2\",\"stepping_eccentricity_3\",\"step_mode\",\"net_core_weight\") VALUES('"+
xjjTextField.getText()+"','"+
edmTextField.getText()+"','"+
drawingno+"','"+
producttype+"','"+
getCellValue(row2.getCell(3))+"','"+
getCellValue(row2.getCell(7))+"','"+
getCellValue(row3.getCell(10))+"','"+
getCellValue(row4.getCell(3))+"','"+
getCellValue(row4.getCell(5))+"','"+
getCellValue(row4.getCell(7))+"','"+
getCellValue(row4.getCell(10))+"','"+
getCellValue(row5.getCell(3))+"','"+
getCellValue(row5.getCell(5))+"','"+
getCellValue(row5.getCell(7))+"','"+
getCellValue(row5.getCell(10))+"','"+
getCellValue(row6.getCell(3))+"','"+
getCellValue(row6.getCell(4))+"','"+
getCellValue(row6.getCell(5))+"','"+
getCellValue(row6.getCell(7))+"','"+
getCellValue(row6.getCell(10))+"')";
System.out.println("insertSqlT1======="+insertSqlT1);
SqlUtil.update(insertSqlT1);
//table2
for (int i = 8; i < sheet0.getLastRowNum(); i++) {
//判断该行是否为空数据
Row row = sheet0.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(3));
if(cellValue == null || cellValue.isEmpty()) {
break;
}else {
String insertSqlT2 = "INSERT INTO CHINT_IRON_CORE_SUM_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"thickness_perstage\",\"main_column_width\",\"yoke_offset\",\"oil_passage\",\"yoke_width\",\"cumulative_stage_thickness\",\"cross_sectional_area\",\"number_pieces\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"')";
System.out.println("insertSqlT2======="+insertSqlT2);
SqlUtil.update(insertSqlT2);
}
}
}
}
//中柱
if(sheet1 != null) {
getJqd(sheet1,drawingno,producttype);
}
if(sheet2 != null) {
getJqd(sheet2,drawingno,producttype);
}
if(sheet3 != null) {
getJqd(sheet3,drawingno,producttype);
}
//边柱
if(sheet4 != null) {
for (int i =2; i < sheet4.getLastRowNum(); i++) {
//判断该行是否为空数据
Row row = sheet4.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
break;
}else {
String insertSqlBz = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
"边柱"+"')";
System.out.println("insertSqlBz======="+insertSqlBz);
SqlUtil.update(insertSqlBz);
}
}
}
}
//轭
if(sheet5 != null) {
for (int i =2; i < sheet5.getLastRowNum(); i++) {
//判断该行是否为空数据
System.out.println("i-====================================="+i);
Row row = sheet5.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
break;
}else {
String insertSqlE = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
"轭"+"')";
System.out.println("insertSqlE======="+insertSqlE);
SqlUtil.update(insertSqlE);
}
}
}
}
}else if(producttype.equals("五柱")) {
}else {
MessageBox.post("模板sheet页数有问题,判断不出是三柱还是五柱!", "提示", 2);
return;
}
} catch (IOException e2) {
e2.printStackTrace();
}
MessageBox.post("导入成功!", "提示", 2);
}
}
private JButton btnIn;
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
btnIn = new JButton("导入");
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(""));
topPanel.add("2.2.center", new JLabel(""));
topPanel.add("2.3.center", btnIn);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel("文件存放位置:"));
topPanel.add("2.2.left.center", pathJTextField);
topPanel.add("2.3.left.center", outputButton);
topPanel.add("3.1.left.center", new JLabel("下夹件宽度:"));
topPanel.add("3.2.left.center",xjjTextField );
topPanel.add("4.1.left.center", new JLabel("轭断面距离:"));
topPanel.add("4.2.left.center", edmTextField);
// 注册输出按钮的点击事件监听器
outputButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 创建文件选择器
JFileChooser fileChooser = new JFileChooser();
// 设置文件选择器只能选择文件夹
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(topPanel);
if (result == JFileChooser.APPROVE_OPTION) {
// 获取用户选择的路径
String selectedPath = fileChooser.getSelectedFile().getPath();
// 输出用户选择的路径
System.out.println("用户选择的路径:" + selectedPath);
pathJTextField.setText(selectedPath);
}
}
});
return topPanel;
}
public String getCellValue(Cell cell) {
if(cell == null) {
return "";
}else {
int cellType = cell.getCellType();
System.out.println("cellType="+cellType+"===cell.getRowIndex()="+cell.getRowIndex()+"===cell.getColumnIndex()="+cell.getColumnIndex());
if(cellType == 1) {//string
return cell.getStringCellValue();
}else if(cellType == 3 || cellType == 0) {//num
double numericCellValue = cell.getNumericCellValue();
if(numericCellValue == 0.0) {
return ""; }
return cell.getNumericCellValue()+"";
}else if(cellType == 2) {
// 检查单元格是否是公式类型
// 创建FormulaEvaluator
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// 评估公式
CellValue valueEval = evaluator.evaluate(cell);
//System.out.println("valueEval.getCellType()============================================"+valueEval.getCellType());
if(valueEval.getCellType() == 1) {
return valueEval.getStringValue();
}else if(valueEval.getCellType() == 0) {//num
double numericCellValue = valueEval.getNumberValue();
if(numericCellValue == 0.0) {
return ""; }
return valueEval.getNumberValue()+"";
}
}
}
return "";
}
public void getJqd(Sheet sheet,String drawingno,String producttype) {
//table2
for (int i = 2; i < sheet.getLastRowNum(); i+=6) {
//判断该行是否为空数据
Row row = sheet.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
break;
}else {
String insertSqlZz = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"joint_number\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
getCellValue(row.getCell(11))+"','"+
"中柱"+"')";
System.out.println("insertSqlZz======="+insertSqlZz);
SqlUtil.update(insertSqlZz);
List<String> initialElements = Arrays.asList(drawingno,producttype,getCellValue(row.getCell(1)),getCellValue(row.getCell(2)),getCellValue(row.getCell(3)),getCellValue(row.getCell(4)),getCellValue(row.getCell(5)),getCellValue(row.getCell(6)),getCellValue(row.getCell(7)),getCellValue(row.getCell(8)));
ArrayList<String> list = new ArrayList<>(initialElements);
getJqdRow(sheet,list,i+1);
getJqdRow(sheet,list,i+2);
getJqdRow(sheet,list,i+3);
getJqdRow(sheet,list,i+4);
getJqdRow(sheet,list,i+5);
}
}
}
}
public void getJqdRow(Sheet sheet,ArrayList<String> list,int i){
Row row = sheet.getRow(i);
String insertSqlZz = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"joint_number\",\"a\",\"c\",\"classification\") VALUES('"+
list.get(0)+"','"+
list.get(1)+"','"+
list.get(2)+"','"+
list.get(3)+"','"+
list.get(4)+"','"+
list.get(5)+"','"+
list.get(6)+"','"+
list.get(7)+"','"+
list.get(8)+"','"+
list.get(9)+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
getCellValue(row.getCell(11))+"','"+
"中柱"+"')";
System.out.println("insertSqlZz======="+insertSqlZz);
SqlUtil.update(insertSqlZz);
}
}

@ -0,0 +1,41 @@
package com.connor.plm.txdp;
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.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCSession;
public class TXDPHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
try {
new TXDPFram(session);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}
Loading…
Cancel
Save