|
|
package cn.com.ebewin.ysr.dialog;
|
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.io.File;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentForm;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCProperty;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
import com.teamcenter.rac.util.iTextField;
|
|
|
|
|
|
import cn.com.ebewin.ysr.util.CommonUtil;
|
|
|
import cn.com.ebewin.ysr.util.DialogUtil;
|
|
|
import cn.com.ebewin.ysr.util.FileUtil;
|
|
|
import cn.com.ebewin.ysr.util.FormUtil;
|
|
|
import cn.com.ebewin.ysr.util.TCUtil;
|
|
|
import cn.com.ebewin.ysr.util.UIUtil;
|
|
|
|
|
|
public class RectificationPurchasingImportDialog extends JFrame {
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
DialogUtil fu = new DialogUtil(this, "整改采购件到货数据导入", "YSR8_RectificationPurchasingImportDialog");
|
|
|
HashMap<String, TCComponentForm> allECN = new HashMap<String, TCComponentForm>();
|
|
|
HashMap<String, String> allECNType = new HashMap<String, String>();
|
|
|
private int c = 0;
|
|
|
|
|
|
public RectificationPurchasingImportDialog(TCSession session) throws TCException {
|
|
|
//super(true);
|
|
|
|
|
|
fu.initializeUI(session);
|
|
|
//centerToScreen();
|
|
|
this.setLocationRelativeTo(null);
|
|
|
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
|
|
|
loadRendering();
|
|
|
addActionListener();
|
|
|
setVisible(true);
|
|
|
}
|
|
|
|
|
|
private void loadRendering() throws TCException {
|
|
|
JButton btn = (JButton)fu.allComponentMap.get("b.11.16");
|
|
|
btn.setEnabled(false);
|
|
|
btn = (JButton)fu.allComponentMap.get("b.11.17");
|
|
|
btn.setEnabled(false);
|
|
|
}
|
|
|
|
|
|
private void addActionListener() {
|
|
|
JButton btn = (JButton)fu.allComponentMap.get("b.11.14");
|
|
|
btn.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
try {
|
|
|
loadExcel();
|
|
|
} catch (Exception e1) {
|
|
|
MessageBox.post(RectificationPurchasingImportDialog.this,"出错了:\n"+e1.getMessage(),"提示",MessageBox.ERROR);
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
btn = (JButton)fu.allComponentMap.get("b.11.16");
|
|
|
btn.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
checkData();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
btn = (JButton)fu.allComponentMap.get("b.11.17");
|
|
|
btn.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
importData();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void loadExcel() throws Exception {
|
|
|
String[][] fileENames = { { ".xlsx", "MS-Excel文件(*.xlsx)" },{ ".xls", "MS-Excel文件(*.xls)" } };//lidy20190419支持xls格式
|
|
|
File file = FileUtil.openFileChooser(fileENames);
|
|
|
if (file == null) {
|
|
|
return;
|
|
|
}
|
|
|
iTextField textField = (iTextField)fu.allComponentMap.get("SJWJ");
|
|
|
textField.setText(file.getName());
|
|
|
|
|
|
UIUtil.JTableInfo ci = (FormUtil.JTableInfo)fu.allComponentInfos.get("a.21.11.11");
|
|
|
int rowCount = ci.dataTableModel.getRowCount();
|
|
|
for(int i = rowCount - 1; i >= 0; i--){
|
|
|
ci.dataTableModel.removeRow(i);
|
|
|
}
|
|
|
ci.dataTableModel.getDataVector().clear();
|
|
|
|
|
|
ci.dataTableModel.setRowCount(0);
|
|
|
//采购ID 货品ID 到货数量 到货日期
|
|
|
//序号 采购ID 货品ID 到货数量 到货日期 已到数量 要求数量 整改采购单号 采购序号 数据校验 提示信息
|
|
|
List<ArrayList<String>> listData = FileUtil.readExcel(file);
|
|
|
|
|
|
allECN.clear(); allECNType.clear();
|
|
|
|
|
|
//Integer idx = 0;
|
|
|
for (ArrayList<String> arrayList : listData) {
|
|
|
Vector<String> vec = new Vector<>();
|
|
|
String purchID = arrayList.get(1).toString();
|
|
|
Vector<String> purchIDPart = CommonUtil.split2Vector(purchID, "-");
|
|
|
if (purchIDPart.size() < 2) {
|
|
|
continue;
|
|
|
}
|
|
|
/*String ecnID = "";
|
|
|
for (int i = 0; i < purchIDPart.size() - 1; i++) {
|
|
|
ecnID += purchIDPart.get(i);
|
|
|
if (i + 1 == purchIDPart.size() - 1) {
|
|
|
|
|
|
} else {
|
|
|
ecnID += "-";
|
|
|
}
|
|
|
}*/
|
|
|
String ecnIdx = purchIDPart.get(purchIDPart.size() - 1);
|
|
|
//int ecnIdxint = Integer.parseInt(ecnIdx);
|
|
|
//kk TODO 0822
|
|
|
int ecnIdxint=getDigit(ecnIdx);
|
|
|
vec.add(arrayList.get(0));//序号
|
|
|
vec.add(purchID);//采购ID
|
|
|
vec.add(arrayList.get(3).toString());//货品ID
|
|
|
//vec.add(new DecimalFormat("#.00").format(arrayList.get(2)));//到货数量
|
|
|
vec.add(arrayList.get(4));//到货数量
|
|
|
vec.add(arrayList.get(5).toString());//到货日期
|
|
|
vec.add("");//已到数量
|
|
|
vec.add("");//要求数量
|
|
|
vec.add(arrayList.get(2));//整改采购单号
|
|
|
vec.add(Integer.toString(ecnIdxint));//采购序号
|
|
|
vec.add("");//数据校验
|
|
|
vec.add("");//提示信息
|
|
|
|
|
|
ci.dataTableModel.addRow(vec);
|
|
|
}
|
|
|
|
|
|
JButton btn = (JButton)fu.allComponentMap.get("b.11.16");
|
|
|
btn.setEnabled(ci.dataTableModel.getRowCount() > 0);
|
|
|
}
|
|
|
|
|
|
//kk TOOD 0822 提取字符串后面的数字
|
|
|
private int getDigit(String str) throws Exception {
|
|
|
int len=str.length();
|
|
|
String resStr="";
|
|
|
for(int i=len-1;i>=0;i--) {
|
|
|
char c=str.charAt(i);
|
|
|
if(Character.isDigit(c)) {
|
|
|
resStr=c+resStr;
|
|
|
}else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
int res=0;
|
|
|
// if(!"".equals(resStr)) {
|
|
|
// throw new Exception("无法从字符串中提取末尾数字:"+str);
|
|
|
// }
|
|
|
if("".equals(resStr)) {
|
|
|
throw new Exception("无法从字符串中提取末尾数字:"+str);
|
|
|
}
|
|
|
res = new Integer(resStr);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
private void checkData() {
|
|
|
UIUtil.JTableInfo ci = (FormUtil.JTableInfo)fu.allComponentInfos.get("a.21.11.11");
|
|
|
try {
|
|
|
//序号 采购ID 货品ID 到货数量 到货日期 已到数量 要求数量 整改采购单号 采购序号 数据校验 提示信息
|
|
|
for (int i = 0; i < ci.dataTableModel.getRowCount(); i++) {
|
|
|
String currFinishQuantity = ci.dataTableModel.getValueAt(i, 3).toString();
|
|
|
String ecnID = ci.dataTableModel.getValueAt(i, 7).toString();
|
|
|
String ecnIdx = ci.dataTableModel.getValueAt(i, 8).toString();
|
|
|
|
|
|
TCComponentForm ecnRevisionForm = allECN.get(ecnID);
|
|
|
System.out.println(ecnID);
|
|
|
if (ecnRevisionForm == null) {
|
|
|
TCComponentItem ecnItem = TCUtil.findItemByID(fu.session, ecnID);
|
|
|
if(ecnItem == null) {
|
|
|
ci.dataTableModel.setValueAt("×", i, 9);
|
|
|
ci.dataTableModel.setValueAt("找不到匹配的整改采购单!", i, 10);
|
|
|
continue;
|
|
|
}
|
|
|
String objectType;
|
|
|
objectType = ecnItem.getProperty("object_type");
|
|
|
if(!objectType.equalsIgnoreCase("整改采购单") && !objectType.equalsIgnoreCase("调试整改采购单")) {
|
|
|
ci.dataTableModel.setValueAt("×", i, 9);
|
|
|
ci.dataTableModel.setValueAt("找不到匹配的整改采购单!", i, 10);
|
|
|
continue;
|
|
|
}
|
|
|
allECNType.put(ecnID, objectType);
|
|
|
|
|
|
TCComponentItemRevision ecnRevision = ecnItem.getLatestItemRevision();
|
|
|
ecnRevisionForm = TCUtil.getItemRevisionMasterForm(ecnRevision);
|
|
|
allECN.put(ecnID, ecnRevisionForm);
|
|
|
}
|
|
|
if (ecnRevisionForm == null) {
|
|
|
ci.dataTableModel.setValueAt("×", i, 9);
|
|
|
ci.dataTableModel.setValueAt("找不到匹配的整改采购单!", i, 10);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
String objectType = allECNType.get(ecnID);
|
|
|
|
|
|
TCProperty ysr8_SerialNo = null, ysr8_FinishQuantity = null, ysr8_Quantity = null;
|
|
|
if (objectType.equalsIgnoreCase("整改采购单")) {
|
|
|
ysr8_SerialNo = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SerialNo");
|
|
|
ysr8_FinishQuantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_FinishQuantity");
|
|
|
ysr8_Quantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_Quantity");
|
|
|
|
|
|
} else if (objectType.equalsIgnoreCase("调试整改采购单")) {
|
|
|
ysr8_SerialNo = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SerialNo");
|
|
|
ysr8_FinishQuantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_FinishQuantity");
|
|
|
ysr8_Quantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_Quantity");
|
|
|
}
|
|
|
int[] ysr8_SerialNoVals;
|
|
|
double[] ysr8_FinishQuantityVals, ysr8_QuantityVals;
|
|
|
ysr8_SerialNoVals = ysr8_SerialNo.getIntArrayValue();
|
|
|
ysr8_FinishQuantityVals = ysr8_FinishQuantity.getDoubleArrayValue();
|
|
|
ysr8_QuantityVals = ysr8_Quantity.getDoubleArrayValue();
|
|
|
double ysr8_FinishQuantityVal = 0.0, ysr8_QuantityVal = 0.0;
|
|
|
boolean find = false;
|
|
|
for(int m = 0; m < ysr8_SerialNoVals.length; m++){
|
|
|
if (ysr8_SerialNoVals[m] == Integer.parseInt(ecnIdx)) {
|
|
|
ysr8_FinishQuantityVal = ysr8_FinishQuantityVals[m];
|
|
|
ysr8_QuantityVal = ysr8_QuantityVals[m];
|
|
|
find = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!find) {
|
|
|
ci.dataTableModel.setValueAt("×", i, 9);
|
|
|
ci.dataTableModel.setValueAt("找不到匹配采购ID的货品信息!", i, 10);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
ysr8_FinishQuantityVal += Double.parseDouble(currFinishQuantity);
|
|
|
ci.dataTableModel.setValueAt(fu.getDoubleString(ysr8_FinishQuantityVal), i, 5);//已到数量
|
|
|
ci.dataTableModel.setValueAt(fu.getDoubleString(ysr8_QuantityVal), i, 6);//要求数量
|
|
|
|
|
|
if (ysr8_FinishQuantityVal > ysr8_QuantityVal) {
|
|
|
ci.dataTableModel.setValueAt("×", i, 9);
|
|
|
ci.dataTableModel.setValueAt("到货数量之和超出要求数量,请确认!", i, 10);
|
|
|
continue;
|
|
|
} else if (ysr8_FinishQuantityVal < ysr8_QuantityVal) {
|
|
|
ci.dataTableModel.setValueAt("√", i, 9);
|
|
|
ci.dataTableModel.setValueAt("到货数量之和小于要求数量...", i, 10);
|
|
|
} else {
|
|
|
ci.dataTableModel.setValueAt("√", i, 9);
|
|
|
}
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
JButton btn = (JButton)fu.allComponentMap.get("b.11.17");
|
|
|
btn.setEnabled(true);
|
|
|
}
|
|
|
|
|
|
private void importData() {
|
|
|
final ProgressReporterDialog reporter = new ProgressReporterDialog();
|
|
|
reporter.reportProgressMessage("正在导入,请稍候...");
|
|
|
new Thread(reporter).start();
|
|
|
new Thread() {
|
|
|
public void run() {
|
|
|
fu.session.setStatus("正在导入...");
|
|
|
c = 0;
|
|
|
importData_Sub();
|
|
|
fu.session.setStatus("就绪");
|
|
|
reporter.requestCanceling();
|
|
|
MessageBox.post("导入完成,共导入"+c+"条数据", "导入结果", MessageBox.WARNING);
|
|
|
}
|
|
|
}.start();
|
|
|
// Display.getDefault().syncExec(new Runnable() {
|
|
|
// @Override
|
|
|
// public void run() {
|
|
|
// try {
|
|
|
// new ProgressMonitorDialog(null).run(true, false, new IRunnableWithProgress() {
|
|
|
// @Override
|
|
|
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
|
|
// fu.session.setStatus("正在导入...");
|
|
|
// importData_Sub();
|
|
|
// fu.session.setStatus("就绪");
|
|
|
// MessageBox.post("导入成功!", "导入结果", MessageBox.WARNING);
|
|
|
// }
|
|
|
// });
|
|
|
// } catch (InvocationTargetException | InterruptedException ex) {
|
|
|
// ex.printStackTrace();
|
|
|
// MessageBox.post("导入失败!\n" + ex.getMessage(), "导入结果", MessageBox.WARNING);
|
|
|
// }
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
//MessageBox.post(this, "导入成功!", "导入结果", MessageBox.INFORMATION);//TODO lidy20190408导入失败
|
|
|
}
|
|
|
|
|
|
private void importData_Sub() {
|
|
|
JButton btn = (JButton)fu.allComponentMap.get("b.11.17");
|
|
|
btn.setEnabled(false);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
try {
|
|
|
UIUtil.JTableInfo ci = (FormUtil.JTableInfo)fu.allComponentInfos.get("a.21.11.11");
|
|
|
// monitor.beginTask("正在导入:", ci.dataTableModel.getRowCount());
|
|
|
|
|
|
//序号 采购ID 货品ID 到货数量 到货日期 已到数量 要求数量 整改采购单号 采购序号 数据校验 提示信息
|
|
|
for (int i = 0; i < ci.dataTableModel.getRowCount(); i++) {
|
|
|
String check = ci.dataTableModel.getValueAt(i, 9).toString();
|
|
|
String ecnID = ci.dataTableModel.getValueAt(i, 7).toString();
|
|
|
String ecnIdx = ci.dataTableModel.getValueAt(i, 8).toString();
|
|
|
if (!check.equals("√")) {
|
|
|
// monitor.worked(1);
|
|
|
System.out.println(ecnID + "----" + ecnIdx + " 未通过检查检查");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
System.out.println("正在导入:" + ecnID + "----" + ecnIdx);
|
|
|
String finishDate = ci.dataTableModel.getValueAt(i, 4).toString();
|
|
|
String finishQuantity = ci.dataTableModel.getValueAt(i, 5).toString();
|
|
|
String quantity = ci.dataTableModel.getValueAt(i, 6).toString();
|
|
|
|
|
|
double finishQuantityDouble = Double.parseDouble(finishQuantity);
|
|
|
double quantityDouble = Double.parseDouble(quantity);
|
|
|
|
|
|
TCComponentForm ecnRevisionForm = allECN.get(ecnID);
|
|
|
String objectType = allECNType.get(ecnID);
|
|
|
TCProperty ysr8_SerialNo = null, ysr8_FinishQuantity = null, ysr8_SubPurchFinishDate = null;
|
|
|
if (objectType.equalsIgnoreCase("整改采购单")) {
|
|
|
ysr8_SerialNo = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SerialNo");
|
|
|
ysr8_FinishQuantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_FinishQuantity");
|
|
|
ysr8_SubPurchFinishDate = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SubPurchFinishDate");
|
|
|
|
|
|
} else if (objectType.equalsIgnoreCase("调试整改采购单")) {
|
|
|
ysr8_SerialNo = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SerialNo");
|
|
|
ysr8_FinishQuantity = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_FinishQuantity");
|
|
|
ysr8_SubPurchFinishDate = (TCProperty)ecnRevisionForm.getFormTCProperty("ysr8_SubPurchFinishDate");
|
|
|
}
|
|
|
int[] ysr8_SerialNoVals;
|
|
|
double[] ysr8_FinishQuantityVals;
|
|
|
Date[] ysr8_SubPurchFinishDateVals;
|
|
|
ysr8_SerialNoVals = ysr8_SerialNo.getIntArrayValue();
|
|
|
ysr8_FinishQuantityVals = ysr8_FinishQuantity.getDoubleArrayValue();
|
|
|
ysr8_SubPurchFinishDateVals = ysr8_SubPurchFinishDate.getDateValueArray();
|
|
|
|
|
|
CommonUtil.setByPass(true);
|
|
|
for(int m = 0; m < ysr8_SerialNoVals.length; m++){
|
|
|
if (ysr8_SerialNoVals[m] == Integer.parseInt(ecnIdx)) {
|
|
|
if (finishQuantityDouble == quantityDouble) {
|
|
|
ysr8_FinishQuantityVals[m] = finishQuantityDouble;
|
|
|
ysr8_FinishQuantity.setDoubleValueArray(ysr8_FinishQuantityVals);
|
|
|
ysr8_SubPurchFinishDateVals[m] = sdf.parse(finishDate);
|
|
|
ysr8_SubPurchFinishDate.setDateValueArray(ysr8_SubPurchFinishDateVals);
|
|
|
|
|
|
TCProperty[] formPropertyArray = new TCProperty[2];
|
|
|
formPropertyArray[0] = ysr8_FinishQuantity;
|
|
|
formPropertyArray[1] = ysr8_SubPurchFinishDate;
|
|
|
ecnRevisionForm.setTCProperties(formPropertyArray);
|
|
|
//TODO
|
|
|
String oldEnd = "0000-01-01";
|
|
|
|
|
|
int count = 0;
|
|
|
for(Date date : ysr8_SubPurchFinishDateVals) {
|
|
|
if(date!=null) {
|
|
|
count++;
|
|
|
}
|
|
|
if(date==null)
|
|
|
continue;
|
|
|
String dateTime = sdf.format(date);
|
|
|
if (oldEnd.compareTo(dateTime) < 0) {
|
|
|
oldEnd = dateTime;
|
|
|
}
|
|
|
}
|
|
|
Date ysr8_PurchFinishDate = ecnRevisionForm.getDateProperty("ysr8_PurchFinishDate");
|
|
|
if(ysr8_PurchFinishDate==null || !sdf.format(ysr8_PurchFinishDate).equals(oldEnd)) {
|
|
|
//修改
|
|
|
if(count == ysr8_SubPurchFinishDateVals.length) {
|
|
|
ecnRevisionForm.setDateProperty("ysr8_PurchFinishDate", sdf.parse(oldEnd));
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
ysr8_FinishQuantityVals[m] = finishQuantityDouble;
|
|
|
ysr8_FinishQuantity.setDoubleValueArray(ysr8_FinishQuantityVals);
|
|
|
|
|
|
TCProperty[] formPropertyArray = new TCProperty[1];
|
|
|
formPropertyArray[0] = ysr8_FinishQuantity;
|
|
|
ecnRevisionForm.setTCProperties(formPropertyArray);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
CommonUtil.setByPass(false);
|
|
|
c++;
|
|
|
// monitor.worked(1);
|
|
|
}
|
|
|
// monitor.done();
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|