commit 28621556b1ee850b1125e37024eb9e2da85f966b Author: lijh Date: Tue Mar 10 15:57:59 2026 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..75fd5c4 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..24d35fc --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.langtech.plm.performancemanagement + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6ece8 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..644e24f --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Performancemanagement +Bundle-SymbolicName: com.langtech.plm.performancemanagement;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: com.langtech.plm.performancemanagement.Activator +Bundle-Vendor: LANGTECH +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + com.teamcenter.rac.aifrcp;bundle-version="13000.1.0", + com.teamcenter.rac.tcapps;bundle-version="13000.1.0", + com.teamcenter.rac.ui;bundle-version="13000.1.0", + com.teamcenter.rac.ui.views;bundle-version="13000.1.0", + com.teamcenter.rac.util;bundle-version="13000.1.0", + com.teamcenter.rac.common;bundle-version="13000.1.0", + com.teamcenter.rac.kernel;bundle-version="13000.1.0", + com.teamcenter.rac.external;bundle-version="13000.1.0", + org.apache.poi.39;bundle-version="3.9.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Automatic-Module-Name: com.langtech.plm.performancemanagement +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: sqlServerLib/sqljdbc4.jar, + ., + sqlServerLib/swingx-1.6.1.jar +Export-Package: com.langtech.plm.form, + com.langtech.plm.performancemanagement, + com.langtech.plm.performancemanagement.dialogs, + com.langtech.plm.performancemanagement.handlers, + com.langtech.plm.performancemanagement.operations, + com.langtech.plm.performancemanagement.util, + com.microsoft.sqlserver.jdbc, + com.teamcenter.rac.stylesheet, + microsoft.sql diff --git a/README.md b/README.md new file mode 100644 index 0000000..69ccaa4 --- /dev/null +++ b/README.md @@ -0,0 +1,132 @@ +功能描述 + +# 操作触发 + +选中项目文件夹,点击“绩效报表”菜单,输出该项目的绩效报表(Excel) + +# 首选项配置 + +## ld_billboards_uid + +```text +单值:报表模板的puid +``` + + + +## ld_postCoefficient + +```text +多值,描述岗位组对应的岗位系数,形式: +岗位组=岗位系数 +绘图组=1 +三维组=1.05 + +``` + + + +## ld_taskNature + +``` +多值,描述任务性质对应的任务系数,形式: +任务性质=任务系数 +全新=10 +可复制修改=5 +临时=2.5 +EC=2.5 + +``` + + + +## ld_taskDifficulty + +``` +多值,描述任务难度对应的难度系数,形式: +任务难度=难度系数 +子项目=0.1 +简单=1 +一般=1.25 +较难=1.5 +很难=2 +``` + + + +## ld_urgency + +``` +多值,描述紧急度对应的紧急系数,形式: +紧急度=紧急系数 +一般=1 +紧急=1.25 +超紧急=1.5 + +``` + + + +## ld_overtime + +``` +多值,超时扣分配置,形式: +严重程度:天数区间:扣分比例,其中"()"代表开区间,"[]"代表闭区间 +如: +一般:(0,1]:0.2 +严重:(1,2]:0.33 +超严重:(2,3]:0.5 +未定义:(3,1000):0.6 +``` + + + +## ld_processReview + +``` +多值,描述流程信息配置,用户获取特定流程节点的分派人和处理人,形式: +新品任务项名称=流程名称:审核节点名称 +铸件资料=001铸件资料流程:铸件资料审核 +``` + + + +## ld_requestTime + +``` +多值,描述任务要求完成时间对应的公式,形式: +新品任务项名称=公式,E和F必须放在运算符前面,例如 +铸件资料=E-10 +PPAP文件=F+1 +其中,E代表流程发起时间,F代表工艺程序结束时间(数据库表维护) + +``` + + + +## ld_sqlserver + +``` +多值,描述sqlserver数据库连接信息 +第一行:数据库用户名 +第二行:数据库密码 +第三行:登录url +第四行:驱动 +第五行:表名 + +infodba +infodba +jdbc:microsoft:sqlserver://10.10.22.39:1433;DatabaseName=TC13 +com.microsoft.jdbc.sqlserver.SQLServerDriver +TASK_REQUIREMENT +``` + + + +## Connor_JXFolder + +``` +多值,描述现有的项目归档文件夹与绩效管理要求的任务包对应,形式: +任务包名称=一级文件夹名称/二级文件夹名称/三级文件夹名称/……. +``` + diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..c2d9872 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/com/ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..8f2f621 --- /dev/null +++ b/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + sqlServerLib/sqljdbc4.jar,\ + sqlServerLib/swingx-1.6.1.jar diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..0e13b82 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sqlServerLib/sqljdbc4.jar b/sqlServerLib/sqljdbc4.jar new file mode 100644 index 0000000..d6b7f6d Binary files /dev/null and b/sqlServerLib/sqljdbc4.jar differ diff --git a/sqlServerLib/swingx-1.6.1.jar b/sqlServerLib/swingx-1.6.1.jar new file mode 100644 index 0000000..b0bcc87 Binary files /dev/null and b/sqlServerLib/swingx-1.6.1.jar differ diff --git a/src/com/langtech/plm/form/ChooseDialog.java b/src/com/langtech/plm/form/ChooseDialog.java new file mode 100644 index 0000000..4bfb2f0 --- /dev/null +++ b/src/com/langtech/plm/form/ChooseDialog.java @@ -0,0 +1,147 @@ +package com.langtech.plm.form; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableModel; + +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.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +public class ChooseDialog extends JFrame implements ActionListener { + + protected DefaultTableModel tm_part; + private JComboBox objectComboBox = new JComboBox(); + private JButton okButton = new JButton("ȷ"); + private JButton concelButton = new JButton("ȡ"); + private String[] strings; + private int row; + private int column; + + public ChooseDialog(String[] strings,int row,int column,DefaultTableModel tm_part) { + // TODO Auto-generated constructor stub + this.strings = strings; + this.row = row; + this.column = column; + this.tm_part = tm_part; + initUI(); + } + + + + public void initUI() { + // TODO Auto-generated method stub + try { + this.setTitle("ѡԱ"); + 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(350, 150)); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // ȡĻߴ + int screenWidth = screenSize.width; // ȡĻ + int screenHeight = screenSize.height; // ȡĻ߶ + int x = (screenWidth - 350) / 2; // FrameϽx + int y = (screenHeight - 150) / 2; // FrameϽy + this.setLocation(x, y); // Frameλ + + // this.setLocationRelativeTo(null); + this.createActionEvent(); + this.pack(); + + // this.validate(); + this.setVisible(true); + +// this.setAlwaysOnTop(true); + + //ֵ + for (int i = 0; i < strings.length; i++) { + objectComboBox.addItem(strings[i]); + } + + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + // Ӽ + public void createActionEvent() { + + this.okButton.addActionListener(this); + this.concelButton.addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + Object source = e.getSource(); + System.out.println("source==>+" + source); + if (this.okButton.equals(source)) { + String selectedItem = (String) objectComboBox.getSelectedItem(); + tm_part.setValueAt(selectedItem, row, column); + this.dispose(); + } else if (this.concelButton.equals(source)) { + this.dispose(); + } + + } + + private JPanel getBtnPanel() { + JPanel topPanel = new JPanel(); + topPanel.setLayout(new PropertyLayout()); + topPanel.add("1.1.center", new JLabel("")); + topPanel.add("2.1.center", new JLabel(" ")); + topPanel.add("2.2.center", okButton); + topPanel.add("2.3.center", new JLabel("")); + topPanel.add("2.4.center", concelButton); + topPanel.add("3.1.center", new JLabel("")); + topPanel.add("4.1.center", new JLabel("")); + 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("3.1.left.center", new JLabel("")); + topPanel.add("4.1.left.center", new JLabel("")); + + topPanel.add("5.1.left.center", new JLabel(" ѡԱ")); + topPanel.add("5.2.left.center", objectComboBox); + + return topPanel; + } + +} diff --git a/src/com/langtech/plm/form/DbPool.java b/src/com/langtech/plm/form/DbPool.java new file mode 100644 index 0000000..858f785 --- /dev/null +++ b/src/com/langtech/plm/form/DbPool.java @@ -0,0 +1,250 @@ +package com.langtech.plm.form; + +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +public class DbPool { + + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; + + private static DbPool instance = null; + + public static synchronized Connection getConnection(String url, String name) { + if (instance == null) { + instance = new DbPool(); + } + return instance._getConnection(url, name); + } + + private Connection _getConnection(String url, String name) { + try { + String sDBDriver = null; + String sConnection = null; + String sUser = null; + String sPassword = null; + Properties p = new Properties(); +// InputStream is = getClass().getResourceAsStream( +// "/sqlconn.properties"); +// p.load(is); + sDBDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; + sConnection = "jdbc:sqlserver://" + url + ":1433; DatabaseName=" + name;// p.getProperty("Connection", "2"); + sUser = "infodba";// p.getProperty("User", ""); + sPassword = "infodba";// p.getProperty("Password", ""); + + if (sDBDriver == null || sConnection == null || sUser == null || sPassword == null) { + + System.out.println("ݿѡǷȷ"); + + } + + Class.forName(sDBDriver); + connection = DriverManager.getConnection(sConnection, sUser, sPassword); + return connection; + } catch (Exception se) { + System.out.println(se); + } + return null; + } + + public final static ResultSet read(String sql, Object[] argments) throws SQLException { + return DbPool.rs = DbPool.getPs(argments, sql).executeQuery(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws SQLException { + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws SQLException { + DbPool.ps = DbPool.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + DbPool.ps.setObject(i + 1, argments[i]); + } + } + return DbPool.ps; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws SQLException { + return read(sql, null); + } + + public static void executeUpdateSql(String sql) throws SQLException { + Statement st = connection.createStatement(); + try { + connection.setAutoCommit(false); + // System.out.println("sql===" + sql); + int i = st.executeUpdate(sql); + } catch (SQLException e) { + System.out.println(e.getMessage()); + if (st != null) + st.close(); + connection.rollback(); + connection.close(); + } finally { + if (st != null) + st.close(); + // connection.close(); + } + + } + + public static void executeDeleteSql(String sql) throws SQLException { + Statement st = connection.createStatement(); + try { + connection.setAutoCommit(false); + // System.out.println("sql===" + sql); + st.executeUpdate(sql); + connection.commit(); + } catch (SQLException e) { + if (st != null) + st.close(); + connection.rollback(); + connection.close(); + } finally { + if (st != null) + st.close(); + connection.close(); + } + + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + i = DbPool.getPs(argments, sql).executeUpdate(); + DbPool.connection.commit(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + free(DbPool.rs, DbPool.ps); + } + return i; + } + + public static ResultSet executeSelectSql(String sql) throws SQLException { + Statement st = connection.createStatement(); + try { + connection.setAutoCommit(false); + // System.out.println("sql===" + sql); + rs = st.executeQuery(sql); + // conn.commit(); + } catch (SQLException e) { + if (st != null) + st.close(); + connection.rollback(); + connection.close(); + } + return rs; + + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(DbPool.rs, DbPool.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(DbPool.rs, DbPool.ps, DbPool.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + } +} diff --git a/src/com/langtech/plm/form/JButtonEditor.java b/src/com/langtech/plm/form/JButtonEditor.java new file mode 100644 index 0000000..f14b6e2 --- /dev/null +++ b/src/com/langtech/plm/form/JButtonEditor.java @@ -0,0 +1,30 @@ +package com.langtech.plm.form; +import javax.swing.*; +import javax.swing.table.*; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class JButtonEditor extends AbstractCellEditor implements TableCellEditor { + private JButton button; + private int row; + private int column; + + public JButtonEditor(String text, ActionListener actionListener) { + button = new JButton(text); + button.addActionListener(actionListener); + } + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) { + this.row = row; + this.column = column; + button.setText(value.toString()); + return button; + } + + public Object getCellEditorValue() { + return new String(button.getText()); + } +} \ No newline at end of file diff --git a/src/com/langtech/plm/form/LD6_NewProdForm.java b/src/com/langtech/plm/form/LD6_NewProdForm.java new file mode 100644 index 0000000..4b8e7e2 --- /dev/null +++ b/src/com/langtech/plm/form/LD6_NewProdForm.java @@ -0,0 +1,459 @@ +package com.langtech.plm.form; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.ComboBoxEditor; +import javax.swing.DefaultButtonModel; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +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.renderer.DefaultTableRenderer; +import org.jdesktop.swingx.renderer.FormatStringValue; +import org.jdesktop.swingx.renderer.StringValue; +import org.jdesktop.swingx.table.DatePickerCellEditor; + + +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCFormProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.stylesheet.AbstractRendering; +import com.teamcenter.rac.util.MessageBox; + +@SuppressWarnings("deprecation") +public class LD6_NewProdForm extends AbstractRendering { + private static ArrayList dateConnList = new ArrayList(); + protected DefaultTableModel tm_part; + protected JTable t_part; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + public static final String[] HEADER = new String[] { "", "Ʒ", "", "ƷҪ", "", "λ", "", "׳̶", + "̶", "ҵʱ/Сʱ", "ʵҵʱ/Сʱ", "Ҫʱ", "ʵʱ", "ע" }; + public static final int[] HEADERWIDTH = new int[] { 40, 60, 120, 100, 60, 60, 60, 60, 100, 100, 100, 120, 120, + 120 }; + + private static final long serialVersionUID = 1L; + private static Date refreshDate = null; + private TCSession session; + private Hashtable indices; + TCComponentForm tcForm; + private List allComponents = new ArrayList(); + private TCComponentForm arg0; + private String[] assignee;//ѡָ + JButton jComboBox_fpr = new JButton(); + public LD6_NewProdForm(TCComponentForm arg0) throws Exception { + super(arg0); + this.arg0 = arg0; + Date currDate = new Date(); + if (refreshDate == null) { + arg0.refresh(); + refreshDate = currDate; + } else { + long diff = currDate.getTime() - refreshDate.getTime(); + long minutes = diff / 1000 / 60; + if (minutes >= 1) { + arg0.refresh(); + refreshDate = currDate; + } + } + + this.session = null; + this.session = arg0.getSession(); + this.tcForm = arg0; + indices = new Hashtable(); + + initializeUI(); + loadRendering(); + + } + + private void initializeUI() { + try { + //ȡѡ + String[] form_defoult_value = session.getPreferenceService().getStringValues("LD6_NewProdForm_defoult_value"); + assignee = form_defoult_value[1].split("-");// + setLayout(new BorderLayout()); + setBackground(new JLabel("").getBackground()); + JTabbedPane tabPane = new JTabbedPane(); + tabPane.addTab("", getProjectManInfoPanel()); + add(BorderLayout.WEST, new JLabel(" ")); + add(BorderLayout.CENTER, tabPane); + add(BorderLayout.EAST, new JLabel(" ")); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private JScrollPane getProjectManInfoPanel() { + + JScrollPane returnPanel = new JScrollPane(); + returnPanel.setViewportView(getTablePanel()); + return returnPanel; + } + + @SuppressWarnings("unchecked") + @Override + public void loadRendering() throws TCException { + System.out.println("loadForm------------------------start"); + + + + // ݿȾtable + String formUid = arg0.getUid(); + + String[] value2 = session.getPreferenceService().getStringValues("LD_dbinfo2"); + + if (value2 == null || value2.length == 0) { + MessageBox.post("ѡLD_dbinfo顣", "ʾ", 2); + return; + } else { + Collections.addAll(dateConnList, value2); + } + + Connection conn = getConn(); + // MES:дݿ + String selectSql = "SELECT * FROM LD6_NewProdForm_VALUES WHERE FormUid = ?"; + System.out.println(selectSql); + + List lists = new ArrayList(); + try (PreparedStatement stmt = conn.prepareStatement(selectSql)) { + + // ִв + stmt.setString(1, formUid); + ResultSet result = stmt.executeQuery(); + while (result.next()) { + LD6_NewProdForm_Bean ld6_NewProdForm_Bean = new LD6_NewProdForm_Bean(result.getString(1), + result.getString(2), result.getString(3), result.getString(4), result.getString(5), + result.getString(6), result.getString(7), result.getString(8), result.getString(9), + result.getString(10), result.getString(11), result.getString(12), result.getDate(13), + result.getDate(14), result.getString(15),result.getDate(16),result.getString(17),result.getString(18)); + System.out.println(ld6_NewProdForm_Bean); + lists.add(ld6_NewProdForm_Bean); + } + + } catch (SQLException e1) { + e1.printStackTrace(); + } + + // lists + for (int i = 0; i < lists.size(); i++) { + LD6_NewProdForm_Bean ld6_NewProdForm_Bean = lists.get(i); + + tm_part.addRow(new Object[] { i + 1, ld6_NewProdForm_Bean.getNewProductTaskItem(), + ld6_NewProdForm_Bean.getAssignee(), ld6_NewProdForm_Bean.getNewProductTaskDescription(), + ld6_NewProdForm_Bean.getProcessor(), ld6_NewProdForm_Bean.getPositionGroup(), + ld6_NewProdForm_Bean.getTaskNature(), ld6_NewProdForm_Bean.getDifficultyLevel(), + ld6_NewProdForm_Bean.getUrgencyLevelCode(), ld6_NewProdForm_Bean.getEstimatedBusinessHours(), + ld6_NewProdForm_Bean.getActualBusinessHours(), ld6_NewProdForm_Bean.getDueDate(), + ld6_NewProdForm_Bean.getCompletionDate(), ld6_NewProdForm_Bean.getRemarks() }); + + } + } + + /** + * (non-Javadoc) + * + * @see com.teamcenter.rac.form.AbstractTCForm#saveForm() + */ + @SuppressWarnings("unchecked") + @Override + public void saveRendering() { + System.out.println(""); + // ݱ浽ݿ + Connection conn = getConn(); + // MES:дݿ + String updateSql = "UPDATE LD6_NewProdForm_VALUES SET NewProductTaskItem = ?,Assignee = ?,NewProductTaskDescription = ?,Processor = ?,PositionGroup = ?,TaskNature = ?,DifficultyLevel = ?,UrgencyLevelCode = ?,EstimatedBusinessHours = ?,ActualBusinessHours = ?,DueDate = ?,Remarks = ? WHERE FormUid = ? AND NewProductTaskItem = ?"; + + for (int j = 0; j < t_part.getRowCount(); j++) { + // ӱݵݿ + try (PreparedStatement stmt = conn.prepareStatement(updateSql)) { + stmt.setString(1, (String) t_part.getValueAt(j, 1)); + stmt.setString(2, (String) t_part.getValueAt(j, 2)); + stmt.setString(3, (String) t_part.getValueAt(j, 3)); + stmt.setString(4, (String) t_part.getValueAt(j, 4)); + stmt.setString(5, (String) t_part.getValueAt(j, 5)); + stmt.setString(6, (String) t_part.getValueAt(j, 6)); + stmt.setString(7, (String) t_part.getValueAt(j, 7)); + stmt.setString(8, (String) t_part.getValueAt(j, 8)); + stmt.setString(9, (String) t_part.getValueAt(j, 9)); + stmt.setString(10, (String) t_part.getValueAt(j, 10)); + + //java.util.date תJava.sql.date + java.sql.Date date = new java.sql.Date(((java.util.Date)t_part.getValueAt(j, 11)).getTime()); + + stmt.setDate(11, date); + //stmt.setDate(12, new java.sql.Date(10000000)); + stmt.setString(12, (String) t_part.getValueAt(j, 13)); + stmt.setString(13, arg0.getUid()); + stmt.setString(14, (String) t_part.getValueAt(j, 1)); + // ִв + stmt.executeUpdate(); + System.out.println("ɹ"); + } catch (SQLException e1) { + e1.printStackTrace(); + } + + } + + } + + private JPanel getTablePanel() { + JPanel panel = new JPanel(new BorderLayout()); + tm_part = new DefaultTableModel(); + t_part = new JTable(tm_part) { + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public boolean isCellEditable(int row, int column) { + if (column == 2 || column == 0 || column == 1 || column == 5 || column == 12) {// ɱ༭ + return false; + } +// else if(column == 2) { +// +// if(assignee[row].contains("")) { +// return true; +// }else { +// return false; +// } +// +// } + else { + return true; + } + + + } + + + }; + tm_part.setDataVector(null, HEADER); + t_part.getTableHeader().setReorderingAllowed(false); // вƶᷢת󣨵У + this.t_part.setRowHeight(23); + + TableColumnModel colModel = this.t_part.getColumnModel(); + int colCnt = HEADERWIDTH.length; + colModel.getColumn(0).setMaxWidth(HEADERWIDTH[0]); + for (int i = 0; i < colCnt; i++) { + colModel.getColumn(i).setPreferredWidth(HEADERWIDTH[i]); + } + // ȡѡֵ + String[] ld_taskNature = session.getPreferenceService().getStringValues("ld_taskNature");// + String[] ld_taskDifficulty = session.getPreferenceService().getStringValues("ld_taskDifficulty");// ׳̶ + String[] ld_urgency = session.getPreferenceService().getStringValues("ld_urgency");// ̶ + + Map ld_taskNatureMap = new HashMap(); + Map ld_taskDifficultyMap = new HashMap(); + Map ld_urgencyMap = new HashMap(); + + // ֵ + + JComboBox jComboBox1 = new JComboBox(); + JComboBox jComboBox2 = new JComboBox(); + JComboBox jComboBox3 = new JComboBox(); + for (int i = 0; i < ld_taskNature.length; i++) { + String[] split = ld_taskNature[i].split("="); + ld_taskNatureMap.put(split[0], Double.parseDouble(split[1])); + jComboBox1.addItem(split[0]); + } + + for (int i = 0; i < ld_taskDifficulty.length; i++) { + String[] split = ld_taskDifficulty[i].split("="); + ld_taskDifficultyMap.put(split[0], Double.parseDouble(split[1])); + jComboBox2.addItem(split[0]); + } + + for (int i = 0; i < ld_urgency.length; i++) { + String[] split = ld_urgency[i].split("="); + ld_urgencyMap.put(split[0], Double.parseDouble(split[1])); + jComboBox3.addItem(split[0]); + } + +// JButtonEditor buttonEditor = new JButtonEditor("Button Text", new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent e) { +// // ﴦť¼ +// +// } +// }); + + //t_part.getColumnModel().getColumn(2).setCellEditor(buttonEditor); + t_part.getColumnModel().getColumn(6).setCellEditor(new DefaultCellEditor(jComboBox1)); + t_part.getColumnModel().getColumn(7).setCellEditor(new DefaultCellEditor(jComboBox2)); + t_part.getColumnModel().getColumn(8).setCellEditor(new DefaultCellEditor(jComboBox3)); + + +// jComboBox_fpr.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent e) { +// if (((String) jComboBox_fpr.getSelectedItem()).isEmpty()) { +// // ָһεѡ +// +// jComboBox_fpr.setSelectedIndex(jComboBox_fpr.getSelectedIndex() - 1); +// } +// } +// }); + + StringValue sv = new FormatStringValue(sdf); + TableCellRenderer r = new DefaultTableRenderer(sv); + t_part.getColumnModel().getColumn(11).setCellEditor(new DatePickerCellEditor(sdf)); + t_part.getColumnModel().getColumn(11).setCellRenderer(r); + + + // + t_part.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2 && t_part.columnAtPoint(e.getPoint()) == 2) { // жǷ˫ڵڶ + int row = t_part.rowAtPoint(e.getPoint()); + int column = t_part.columnAtPoint(e.getPoint()); + if (column == 2) { + // ȡ˫ĵԪ + String value = (String) t_part.getModel().getValueAt(row, column); + // ﴦ˫¼ + System.out.println("Double-clicked on cell: Row=" + row + ", Column=" + column + ", Value=" + value); + // Ӹ߼˫¼ + String string = assignee[row]; + if(string.contains("")) { + String[] split = string.split(""); + new ChooseDialog(split,row,column,tm_part); + } + + } + } + } + }); + + //Ӵ˼ + tm_part.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + if (e.getType() == TableModelEvent.UPDATE) { + int row = e.getFirstRow(); + int column = e.getColumn(); + + if(column == 4) { + String value = (String)tm_part.getValueAt(row, column); + System.out.println("Cell changed at row " + row + ", column " + column + ": new value = " + value); + String[] split = value.split("-"); + if(split.length == 2) { + tm_part.setValueAt(split[1], row, column+1); + }else { + MessageBox.post("밴涨ĸʽ:-λ顱д", "ʾ", 2); + } + + } + } + } + }); + + this.t_part.getTableHeader().setBackground(Color.blue); + + + + + + + + JScrollPane scroll = new JScrollPane(t_part); + panel.add(BorderLayout.CENTER, scroll); + + + panel.setBorder(BorderFactory.createLoweredBevelBorder()); + return panel; + } + + // ȡݿ + 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; + } + + + + + +// class CustomCellEditor extends DefaultCellEditor { +// private JComboBox comboBox; +// +// public CustomCellEditor(JComboBox comboBox) { +// super(comboBox); +// this.comboBox = comboBox; +// comboBox.addMouseListener(new MouseAdapter() { +// @Override +// public void mouseClicked(MouseEvent e) { +//// // õѡееֵ +// int r = t_part.getSelectedRow(); +// int c = t_part.getSelectedColumn(); +// if(c == 2) { +// +// +// if(assignee[r].contains("")) { +// String[] split = assignee[r].split(""); +// jComboBox_fpr.removeAllItems(); +// for (int i = 0; i < split.length; i++) { +// jComboBox_fpr.addItem(split[i]); +// } +// //t_part.getColumnModel().getColumn(2).setCellEditor(new CustomCellEditor(tempCom)); +// }else { +// //JComboBox tempCom = new JComboBox(); +// jComboBox_fpr.removeAllItems(); +// jComboBox_fpr.addItem(assignee[r]); +// //t_part.getColumnModel().getColumn(2).setCellEditor(new CustomCellEditor(tempCom)); +// } +// +// } +// } +// }); +// } +// +// } + + + +} diff --git a/src/com/langtech/plm/form/LD6_NewProdForm_Bean.java b/src/com/langtech/plm/form/LD6_NewProdForm_Bean.java new file mode 100644 index 0000000..426633a --- /dev/null +++ b/src/com/langtech/plm/form/LD6_NewProdForm_Bean.java @@ -0,0 +1,212 @@ +package com.langtech.plm.form; + +import java.sql.Date; + + + +public class LD6_NewProdForm_Bean { + + private String clientProductFolderName; + private String clientProductFolderPUID; + private String newProductTaskItem; + private String assignee; + private String newProductTaskDescription; + private String processor; + private String positionGroup; + private String taskNature; + private String difficultyLevel; + private String urgencyLevelCode; + private String estimatedBusinessHours; + private String actualBusinessHours; + private Date dueDate; + private Date completionDate; + private String remarks; + private Date TaskAssignmentDate; + private String CustomerName; + private String FormUid; + // Getters and Setters (Accessors and Mutators) + + + public String getClientProductFolderName() { + return clientProductFolderName; + } + + public LD6_NewProdForm_Bean(String clientProductFolderName, String clientProductFolderPUID, + String newProductTaskItem, String assignee, String newProductTaskDescription, String processor, + String positionGroup, String taskNature, String difficultyLevel, String urgencyLevelCode, + String estimatedBusinessHours, String actualBusinessHours, Date dueDate, Date completionDate, + String remarks, Date taskAssignmentDate, String customerName, String formUid) { + super(); + this.clientProductFolderName = clientProductFolderName; + this.clientProductFolderPUID = clientProductFolderPUID; + this.newProductTaskItem = newProductTaskItem; + this.assignee = assignee; + this.newProductTaskDescription = newProductTaskDescription; + this.processor = processor; + this.positionGroup = positionGroup; + this.taskNature = taskNature; + this.difficultyLevel = difficultyLevel; + this.urgencyLevelCode = urgencyLevelCode; + this.estimatedBusinessHours = estimatedBusinessHours; + this.actualBusinessHours = actualBusinessHours; + this.dueDate = dueDate; + this.completionDate = completionDate; + this.remarks = remarks; + TaskAssignmentDate = taskAssignmentDate; + CustomerName = customerName; + FormUid = formUid; + } + + public Date getTaskAssignmentDate() { + return TaskAssignmentDate; + } + + public void setTaskAssignmentDate(Date taskAssignmentDate) { + TaskAssignmentDate = taskAssignmentDate; + } + + public String getCustomerName() { + return CustomerName; + } + + public void setCustomerName(String customerName) { + CustomerName = customerName; + } + + public String getFormUid() { + return FormUid; + } + + public void setFormUid(String formUid) { + FormUid = formUid; + } + + public void setClientProductFolderName(String clientProductFolderName) { + this.clientProductFolderName = clientProductFolderName; + } + + public String getClientProductFolderPUID() { + return clientProductFolderPUID; + } + + public void setClientProductFolderPUID(String clientProductFolderPUID) { + this.clientProductFolderPUID = clientProductFolderPUID; + } + + public String getNewProductTaskItem() { + return newProductTaskItem; + } + + public void setNewProductTaskItem(String newProductTaskItem) { + this.newProductTaskItem = newProductTaskItem; + } + + public String getAssignee() { + return assignee; + } + + public void setAssignee(String assignee) { + this.assignee = assignee; + } + + public String getNewProductTaskDescription() { + return newProductTaskDescription; + } + + public void setNewProductTaskDescription(String newProductTaskDescription) { + this.newProductTaskDescription = newProductTaskDescription; + } + + public String getProcessor() { + return processor; + } + + public void setProcessor(String processor) { + this.processor = processor; + } + + public String getPositionGroup() { + return positionGroup; + } + + public void setPositionGroup(String positionGroup) { + this.positionGroup = positionGroup; + } + + public String getTaskNature() { + return taskNature; + } + + public void setTaskNature(String taskNature) { + this.taskNature = taskNature; + } + + public String getDifficultyLevel() { + return difficultyLevel; + } + + public void setDifficultyLevel(String difficultyLevel) { + this.difficultyLevel = difficultyLevel; + } + + public String getUrgencyLevelCode() { + return urgencyLevelCode; + } + + public void setUrgencyLevelCode(String urgencyLevelCode) { + this.urgencyLevelCode = urgencyLevelCode; + } + + public String getEstimatedBusinessHours() { + return estimatedBusinessHours; + } + + public void setEstimatedBusinessHours(String estimatedBusinessHours) { + this.estimatedBusinessHours = estimatedBusinessHours; + } + + public String getActualBusinessHours() { + return actualBusinessHours; + } + + public void setActualBusinessHours(String actualBusinessHours) { + this.actualBusinessHours = actualBusinessHours; + } + + public Date getDueDate() { + return dueDate; + } + + public void setDueDate(Date dueDate) { + this.dueDate = dueDate; + } + + + + public Date getCompletionDate() { + return completionDate; + } + + public void setCompletionDate(Date completionDate) { + this.completionDate = completionDate; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + @Override + public String toString() { + return "LD6_NewProdForm_Bean [clientProductFolderName=" + clientProductFolderName + ", clientProductFolderPUID=" + + clientProductFolderPUID + ", newProductTaskItem=" + newProductTaskItem + ", assignee=" + assignee + + ", newProductTaskDescription=" + newProductTaskDescription + ", processor=" + processor + + ", positionGroup=" + positionGroup + ", taskNature=" + taskNature + ", difficultyLevel=" + + difficultyLevel + ", urgencyLevelCode=" + urgencyLevelCode + ", estimatedBusinessHours=" + + estimatedBusinessHours + ", actualBusinessHours=" + actualBusinessHours + ", dueDate=" + dueDate + + ", completionDate=" + completionDate + ", remarks=" + remarks + "]"; + } + +} \ No newline at end of file diff --git a/src/com/langtech/plm/form/QueryNewProdFormFram.java b/src/com/langtech/plm/form/QueryNewProdFormFram.java new file mode 100644 index 0000000..e082358 --- /dev/null +++ b/src/com/langtech/plm/form/QueryNewProdFormFram.java @@ -0,0 +1,808 @@ +package com.langtech.plm.form; + +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.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.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.AIFComponentContext; +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 QueryNewProdFormFram extends JFrame implements ActionListener { + + private TCSession session; + private JTable table; + private String[] header = new String[] { "ȫѡ", "", "Ʒ", "ϱ", "Ʒ", "ͬʱ", "ƻ", "κ", "", + "ERP" }; + protected DefaultTableModel tm_part; + private static ArrayList dateConnList = new ArrayList(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + private JTextField pathJTextField = new JTextField(30); + private JTextField ljhField = new JTextField(15); + private JTextField fprzhField = new JTextField(15); + private JTextField clrField = new JTextField(15); + private JTextField gwzField = new JTextField(15); + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + private DateButton TaskassignmentStartButton; + private DateButton TaskassignmentEndButton; + private DateButton CompletionDateStartButton; + private DateButton CompletionDateEndButton; + private JButton btnQry; + private JButton outputButton = new JButton("ѡ"); + private JButton cleanButton1 = new JButton(""); + private JButton cleanButton2 = new JButton(""); + private JButton cleanButton3 = new JButton(""); + private JButton cleanButton4 = new JButton(""); + private JTextField cpdmField; + + // -ϵ map + private HashMap ld_taskNatureMap = new HashMap(); + private HashMap ld_taskDifficultyMap = new HashMap(); + private HashMap ld_positionGroupMap = new HashMap(); + private HashMap ld_demeritMap = new HashMap(); + + public QueryNewProdFormFram(TCSession session) { + // TODO Auto-generated constructor stub + this.session = session; + initUI(); + } + +// private String sqlString = "delete ML_CREATEORDERBOM where STATUS='2' and PRODUCTID=? and MATERIALNO=? " +// + "and OBJECTNAME=? and PRODPLANO=? and BATCHNO=?" +// + " and FACTORY=? and REPCODE=? and PRODORDERO=?"; + private String sqlString = ""; + + private void initUI() { + // TODO Auto-generated method stub + try { + this.setTitle("ѯЧ"); + this.setLayout(new BorderLayout()); + + JPanel topPanel = getTopPanel(); + + // JScrollPane pane = getTablePanel(); + // pane.setBorder(BorderFactory.createTitledBorder("")); +// JPanel btnPanel = getRightPanel(); + JPanel btnPanel = getBtnPanel(); + + this.add(topPanel, BorderLayout.NORTH); + // this.add(pane,BorderLayout.CENTER); + this.add(btnPanel, BorderLayout.SOUTH); + this.setPreferredSize(new Dimension(800, 292)); + int width2 = this.getWidth(); + int height2 = this.getHeight(); + 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.btnDis.addActionListener(this); + this.btnOk.addActionListener(this); + + } + + private List compList = new ArrayList(); + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + Object source = e.getSource(); + System.out.println("source==>+" + source); + if (this.btnDis.equals(source)) { + this.dispose(); + } else if (source.equals(this.btnOk)) { + File model_file = null; + File output_file = null; + String[] value2 = session.getPreferenceService().getStringValues("LD_dbinfo2"); + + if (value2 == null || value2.length == 0) { + MessageBox.post("ѡLD_dbinfo顣", "ʾ", 2); + return; + } else { + Collections.addAll(dateConnList, value2); + } + + // ȡ + getCalculate(); + sqlString = "SELECT * FROM LD6_NewProdForm_VALUES WHERE 1=1 "; + + // 1.ѯ + getQuerySQL(); + System.out.println(sqlString); + Connection conn = getConn(); + + List lists = new ArrayList(); + try (PreparedStatement stmt = conn.prepareStatement(sqlString)) { + + ResultSet result = stmt.executeQuery(); + while (result.next()) { + LD6_NewProdForm_Bean ld6_NewProdForm_Bean = new LD6_NewProdForm_Bean(result.getString(1), + result.getString(2), result.getString(3), result.getString(4), result.getString(5), + result.getString(6), result.getString(7), result.getString(8), result.getString(9), + result.getString(10), result.getString(11), result.getString(12), result.getDate(13), + result.getDate(14), result.getString(15), result.getDate(16), result.getString(17), + result.getString(18)); + System.out.println(ld6_NewProdForm_Bean); + // д˵ + if (ld6_NewProdForm_Bean.getProcessor() != null + && ld6_NewProdForm_Bean.getProcessor().contains("-")) { + lists.add(ld6_NewProdForm_Bean); + } + + } + + } catch (SQLException e1) { + e1.printStackTrace(); + } + + if (lists.size() == 0) { + MessageBox.post("δ鵽ݣ޷", "ʾ", 2); + return; + } else { + // ݵ߼ + + InputStream input; + String targetPath = null; + try { + String[] lD6_NewProdForm_ModelUid = session.getPreferenceService() + .getStringValues("LD6_NewProdForm_ModelUid"); + + if (lD6_NewProdForm_ModelUid == null || lD6_NewProdForm_ModelUid.length == 0) { + MessageBox.post("ѡLD6_NewProdForm_ModelUid顣", "ʾ", 2); + return; + } else { + String pathJTextFieldStr = pathJTextField.getText(); + if(pathJTextFieldStr == null || pathJTextFieldStr.isEmpty()) { + MessageBox.post("ѡҪ·", "ʾ", 2); + return; + } + + TCComponentDataset excel = (TCComponentDataset) session + .stringToComponent(lD6_NewProdForm_ModelUid[0]); + + model_file = ((TCComponentDataset) excel).getTcFiles()[0].getFmsFile(); + String date = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()); + String fileName = "Чѯ_" + date + ".xlsx"; + + // Դļ· + Path sourcePath = Paths.get(model_file.getPath()); // 滻ΪԴļ· + // Ŀļ· + // targetPath = System.getProperty("user.home")+"\\Desktop"+"\\"+fileName; + targetPath = pathJTextFieldStr + "\\" + fileName; + // ʹFiles.copy()ļ + + // Files.copy(sourcePath, targetPath); + // ÿд + // makeFileWritable(System.getProperty("user.home")+"\\Desktop"+"\\"+fileName); + // output_file = new + // File(System.getProperty("user.home")+"\\Desktop"+"\\"+fileName); + + } + + + //ȡļе + + + input = new FileInputStream(model_file); + XSSFWorkbook wb = new XSSFWorkbook(input);// ( + XSSFSheet sheet = wb.getSheetAt(0); + sheet.getSheetName(); + for (int i = 0; i < lists.size(); i++) { + LD6_NewProdForm_Bean ld6_NewProdForm_Bean = lists.get(i); + + TCComponent component = session.stringToComponent(ld6_NewProdForm_Bean.getClientProductFolderPUID()); + AIFComponentContext[] whereReferenced = component.whereReferenced(); + String object_name = ""; + for (int j = 0; j < whereReferenced.length; j++) { + String type = whereReferenced[j].getComponent().getProperty("object_type"); + System.out.println("type============="+type); + if(type.equals("LD6_Customer") || type.equals("ͻļ")) { + object_name = whereReferenced[j].getComponent().getProperty("object_name"); + } + } + System.out.println("name====="+object_name); + int row = i + 2; + XSSFRow titleRow = sheet.getRow(row); + setCellValue(titleRow, 0, i + 1 + "", sheet, row); + // ź߼ + String[] split = ld6_NewProdForm_Bean.getClientProductFolderName().split("_"); + setCellValue(titleRow, 1, + split.length == 2 ? split[0] : ld6_NewProdForm_Bean.getClientProductFolderName(), sheet, + row); + setCellValue(titleRow, 2, + split.length == 2 ? split[1] : ld6_NewProdForm_Bean.getClientProductFolderName(), sheet, + row); + // 1 + //setCellValue(titleRow, 3, ld6_NewProdForm_Bean.getCustomerName(), sheet, row); + setCellValue(titleRow, 3, object_name, sheet, row); + + setCellValue(titleRow, 4, ld6_NewProdForm_Bean.getNewProductTaskItem(), sheet, row); + setCellValue(titleRow, 5, ld6_NewProdForm_Bean.getAssignee(), sheet, row); + setCellValue(titleRow, 6, ld6_NewProdForm_Bean.getNewProductTaskDescription(), sheet, row); + setCellValue(titleRow, 7, ld6_NewProdForm_Bean.getProcessor(), sheet, row); + setCellValue(titleRow, 8, ld6_NewProdForm_Bean.getPositionGroup(), sheet, row); + setCellValue(titleRow, 9, ld6_NewProdForm_Bean.getTaskNature(), sheet, row); + setCellValue(titleRow, 10, ld6_NewProdForm_Bean.getDifficultyLevel(), sheet, row); + setCellValue(titleRow, 11, ld6_NewProdForm_Bean.getUrgencyLevelCode(), sheet, row); + setCellValue(titleRow, 12, ld6_NewProdForm_Bean.getEstimatedBusinessHours(), sheet, row); + setCellValue(titleRow, 13, ld6_NewProdForm_Bean.getActualBusinessHours(), sheet, row); + + setCellValue(titleRow, 14, ld6_NewProdForm_Bean.getTaskAssignmentDate() == null ? "" + : sdf.format(ld6_NewProdForm_Bean.getTaskAssignmentDate()), sheet, row); + if (ld6_NewProdForm_Bean.getTaskAssignmentDate() != null) { + // תΪLocalDate + LocalDate localDate = ld6_NewProdForm_Bean.getTaskAssignmentDate().toLocalDate(); + // ȡ + int year = localDate.getYear(); + int month = localDate.getMonthValue() - 1; + WeekFields weekFields = WeekFields.of(Locale.getDefault()); + int weekOfYear = localDate.get(weekFields.weekOfWeekBasedYear()); + + setCellValue(titleRow, 15, year + "", sheet, row); + setCellValue(titleRow, 16, month + "", sheet, row); + setCellValue(titleRow, 17, weekOfYear + "", sheet, row); + } + + setCellValue(titleRow, 18, ld6_NewProdForm_Bean.getDueDate() == null ? "" + : sdf.format(ld6_NewProdForm_Bean.getDueDate()), sheet, row); + if (ld6_NewProdForm_Bean.getDueDate() != null) { + // תΪLocalDate + LocalDate localDate = ld6_NewProdForm_Bean.getDueDate().toLocalDate(); + // ȡ + int year = localDate.getYear(); + int month = localDate.getMonthValue() - 1; + WeekFields weekFields = WeekFields.of(Locale.getDefault()); + int weekOfYear = localDate.get(weekFields.weekOfWeekBasedYear()); + + setCellValue(titleRow, 19, year + "", sheet, row); + setCellValue(titleRow, 20, month + "", sheet, row); + setCellValue(titleRow, 21, weekOfYear + "", sheet, row); + } + + setCellValue(titleRow, 22, ld6_NewProdForm_Bean.getCompletionDate() == null ? "" + : sdf.format(ld6_NewProdForm_Bean.getCompletionDate()), sheet, row); + if (ld6_NewProdForm_Bean.getCompletionDate() != null) { + // תΪLocalDate + LocalDate localDate = ld6_NewProdForm_Bean.getCompletionDate().toLocalDate(); + // ȡ + int year = localDate.getYear(); + int month = localDate.getMonthValue() - 1; + // int day = localDate.getDayOfMonth(); + + // ȡݵĵڼ + WeekFields weekFields = WeekFields.of(Locale.getDefault()); + int weekOfYear = localDate.get(weekFields.weekOfWeekBasedYear()); + setCellValue(titleRow, 23, year + "", sheet, row); + setCellValue(titleRow, 24, month + "", sheet, row); + setCellValue(titleRow, 25, weekOfYear + "", sheet, row); + setCellValue(titleRow, 26, "", sheet, row);// ״̬ + } + + java.sql.Date dueDate = ld6_NewProdForm_Bean.getDueDate(); + java.sql.Date completionDate = ld6_NewProdForm_Bean.getCompletionDate(); + // ÷ + Double score = null; + String gwz = ld6_NewProdForm_Bean.getPositionGroup();// λ + String rwxz = ld6_NewProdForm_Bean.getTaskNature();// + String nycd = ld6_NewProdForm_Bean.getDifficultyLevel();// ׳̶ + if (completionDate != null && gwz != null && !gwz.isEmpty() && rwxz != null && !rwxz.isEmpty() + && nycd != null && !nycd.isEmpty()) { + score = ld_positionGroupMap.get(gwz) * ld_taskNatureMap.get(rwxz) + * ld_taskDifficultyMap.get(nycd); + setCellValue(titleRow, 27, score == null ? "" : score + "", sheet, row);// ÷ + } else if (completionDate == null) { + setCellValue(titleRow, 27, "0", sheet, row);// ÷ + } + + // 㳬ʱ۷ + + if (score != null && dueDate != null && completionDate != null) { + // ʱͼƻʱ֮ + + // ȽǷʱ + // Ƚ + int result = dueDate.compareTo(completionDate); + + // жϽ + if (result < 0) {// + System.out.println("Completion date is after Due date."); + // java.sql.DateתΪjava.time.LocalDate + LocalDate dueDateLD = dueDate.toLocalDate(); + LocalDate completionDateLD = completionDate.toLocalDate(); + + // ֮ + long daysBetween = ChronoUnit.DAYS.between(dueDateLD, completionDateLD); + if (daysBetween == 1) { + System.out.println("1"); + Double csdf = score * ld_demeritMap.get("һ"); + setCellValue(titleRow, 28, csdf + "", sheet, row);// ʱ۷ + } else if (daysBetween == 2) { + System.out.println("2"); + Double csdf = score * ld_demeritMap.get(""); + setCellValue(titleRow, 28, csdf + "", sheet, row);// ʱ۷ + } else if (daysBetween == 3) { + System.out.println("3"); + Double csdf = score * ld_demeritMap.get(""); + setCellValue(titleRow, 28, csdf + "", sheet, row);// ʱ۷ + } else if (daysBetween > 3) { + setCellValue(titleRow, 28, "", sheet, row);// ʱ۷ + } + } + + } + + setCellValue(titleRow, 29, ld6_NewProdForm_Bean.getRemarks(), sheet, row); + + } +// // п +// for (int i = 0; i <= lists.size(); i++) { // A-N +// sheet.autoSizeColumn(i); +// } + + // дļ + try (FileOutputStream outputStream = new FileOutputStream(new File(targetPath))) { + wb.write(outputStream); + } catch (FileNotFoundException e1) { + System.err.println("Ŀļδҵ: " + targetPath); + e1.printStackTrace(); + } catch (IOException e2) { + System.err.println("дļʱ: " + targetPath); + e2.printStackTrace(); + } + + this.dispose(); + MessageBox.post("ɹ" + lists.size() + "ݣ", "ʾ", 2); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + + } + + } + + private void getCalculate() { + // TODO Auto-generated method stub + String[] ld_taskNature = session.getPreferenceService().getStringValues("ld_taskNature");// + String[] ld_taskDifficulty = session.getPreferenceService().getStringValues("ld_taskDifficulty");// ׳̶ + String[] ld_positionGroup = session.getPreferenceService().getStringValues("ld_positionGroup");// λϵ + String[] ld_demerit = session.getPreferenceService().getStringValues("ld_demerit");// ʱ۷ + for (int i = 0; i < ld_positionGroup.length; i++) { + ld_positionGroupMap.put(ld_positionGroup[i].split("=")[0], + Double.parseDouble(ld_positionGroup[i].split("=")[1])); + } + + for (int i = 0; i < ld_taskNature.length; i++) { + ld_taskNatureMap.put(ld_taskNature[i].split("=")[0], Double.parseDouble(ld_taskNature[i].split("=")[1])); + } + + for (int i = 0; i < ld_taskDifficulty.length; i++) { + ld_taskDifficultyMap.put(ld_taskDifficulty[i].split("=")[0], + Double.parseDouble(ld_taskDifficulty[i].split("=")[1])); + } + + for (int i = 0; i < ld_demerit.length; i++) { + ld_demeritMap.put(ld_demerit[i].split("=")[0], Double.parseDouble(ld_demerit[i].split("=")[1])); + } + } + +// public int getWeekOfMonth(int day) { +// if(day % 7 != 0) { +// return day / 7 + 1; +// }else { +// return day / 7; +// } +// } +// + + /** + * ļд + * + * @param filePath + */ + public static void makeFileWritable(String filePath) { + File file = new File(filePath); + if (!file.exists()) { + System.out.println("File does not exist."); + return; + } + try { + // ļдtrue ʾдfalse ʾдnull ʾʹϵͳĬֵ + boolean success = file.setWritable(true, false); // ڶʾǷֻıļߵȨ + if (success) { + System.out.println("File permissions set to writable."); + } else { + System.out.println("Failed to set file as writable."); + } + } catch (SecurityException se) { + System.err.println("Security exception: " + se.getMessage()); + } + } + + public static void setCellValue(XSSFRow row, int colum, String str, XSSFSheet sheet, int rowNum) { + if (row == null) { + // еһл߸ʾ + row = sheet.createRow(rowNum); + } + XSSFCell cell = row.getCell(colum); + if (cell == null) { + cell = row.createCell(colum); + } + cell.setCellValue(str); + } + + private void getQuerySQL() { + // TODO Auto-generated method stub + String cpwjjmc = ljhField.getText(); + if (!cpwjjmc.isEmpty()) { + // ֵ + if (cpwjjmc.contains(";") || cpwjjmc.contains("")) { + String[] split = cpwjjmc.split(";"); + if (split.length == 0) { + split = cpwjjmc.split(""); + } + for (int i = 0; i < split.length; i++) { + sqlString += "AND ClientProductFolderName LIKE '%" + split[i] + "%' "; + } + } else { + sqlString += "AND ClientProductFolderName LIKE '%" + cpwjjmc + "%' "; + } + } + + String fprzh = fprzhField.getText(); + if (!fprzh.isEmpty()) { + sqlString += "AND Assignee LIKE '%" + fprzh + "%' "; + } + + String clr = clrField.getText(); + if (!clr.isEmpty()) { + sqlString += "AND Processor = '%" + clr + "%' "; + } + + String gwz = gwzField.getText(); + if (!gwz.isEmpty()) { + sqlString += "AND PositionGroup = '%" + gwz + "%' "; + } + + if (TaskassignmentStartButton.getDate() != null) { + sqlString += "AND TaskAssignmentDate <='" + dateFormat.format(TaskassignmentStartButton.getDate()) + "' "; + } + + if (TaskassignmentEndButton.getDate() != null) { + sqlString += "AND TaskAssignmentDate >='" + dateFormat.format(TaskassignmentEndButton.getDate()) + "' "; + } + + if (CompletionDateStartButton.getDate() != null) { + sqlString += "AND CompletionDate <='" + dateFormat.format(CompletionDateStartButton.getDate()) + "' "; + } + + if (CompletionDateEndButton.getDate() != null) { + sqlString += "AND CompletionDate >='" + dateFormat.format(CompletionDateEndButton.getDate()) + "' "; + } + + } + + private JButton btnOk; + private JButton btnDis; + + private JPanel getBtnPanel() { + JPanel topPanel = new JPanel(); + topPanel.setLayout(new PropertyLayout()); + btnOk = new JButton(""); + btnDis = new JButton("ȡ"); + topPanel.add("1.1.center", btnOk); + + topPanel.add("1.2.center", btnDis); + 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",field); + topPanel.setBorder(BorderFactory.createTitledBorder("ѯ")); + + topPanel.add("1.1.left.center", new JLabel(" ")); + topPanel.add("2.1.left.center", getJLabel("ţ")); + topPanel.add("2.2.left.center", ljhField); + topPanel.add("2.3.left.center", cleanButton1); + + topPanel.add("2.4.left.center", getJLabel("˺ţ")); + topPanel.add("2.5.left.center", fprzhField); + topPanel.add("2.6.left.center", cleanButton2); + + topPanel.add("3.1.left.center", getJLabel("ˣ")); + topPanel.add("3.2.left.center", clrField); + topPanel.add("3.3.left.center", cleanButton3); + + topPanel.add("3.4.left.center", getJLabel("λ飺")); + topPanel.add("3.5.left.center", gwzField); + topPanel.add("3.6.left.center", cleanButton4); + + + + + + TaskassignmentStartButton = new DateButton(dateFormat); + TaskassignmentEndButton = new DateButton(dateFormat); + TaskassignmentStartButton.setDate("δ"); + TaskassignmentEndButton.setDate("δ"); + CompletionDateStartButton = new DateButton(dateFormat); + CompletionDateEndButton = new DateButton(dateFormat); + CompletionDateStartButton.setDate("δ"); + CompletionDateEndButton.setDate("δ"); +// startButton.set + topPanel.add("4.1.left.center", getJLabelDate("ʱ䣨ڣ")); + topPanel.add("4.2.left.center", TaskassignmentStartButton); + topPanel.add("4.3.left.center", new JLabel(" ")); // ӿΪ + + topPanel.add("4.4.center.center", getJLabelDate("ʱ䣨ڣ")); + topPanel.add("4.5.left.center", TaskassignmentEndButton); + topPanel.add("5.1.left.center", getJLabelDate("ʵʱ䣨ڣ")); + topPanel.add("5.2.left.center", CompletionDateStartButton); + topPanel.add("5.3.left.center", new JLabel(" ")); // ӿΪ + + topPanel.add("5.4.center.center", getJLabelDate("ʵʱ䣨ڣ")); + topPanel.add("5.5.left.center", CompletionDateEndButton); + + topPanel.add("6.1.left.center", new JLabel("")); + + + topPanel.add("7.1.left.center", new JLabel("·")); + topPanel.add("7.2.left.center", pathJTextField); + topPanel.add("7.3.left.center", outputButton); + + + // ť + cleanButton1.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + ljhField.setText(""); + } + }); + + cleanButton2.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + fprzhField.setText(""); + } + }); + + cleanButton3.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + clrField.setText(""); + } + }); + + cleanButton4.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + gwzField.setText(""); + } + }); + // עťĵ¼ + outputButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // ļѡ + JFileChooser fileChooser = new JFileChooser(); + // ļѡֻѡļ + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int result = fileChooser.showOpenDialog(topPanel); + if (result == JFileChooser.APPROVE_OPTION) { + // ȡûѡ· + String selectedPath = fileChooser.getSelectedFile().getPath(); + // ûѡ· + System.out.println("ûѡ·" + selectedPath); + pathJTextField.setText(selectedPath); + } + } + }); + return topPanel; + } + +// private JScrollPane getTablePanel() { +// // TODO Auto-generated method stub +// table = getJTable(null, null, header, null); +// table.setRowHeight(30); +// //table.setPreferredSize(new Dimension(1200,400)); +// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // ñԶģʽΪرԶ +// table.getColumnModel().getColumn(0).setPreferredWidth(50); +// table.addMouseListener(new MouseListener() { +// +// @Override +// public void mouseReleased(MouseEvent e) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void mousePressed(MouseEvent e) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void mouseExited(MouseEvent e) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void mouseEntered(MouseEvent e) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void mouseClicked(MouseEvent e) { +// // TODO Auto-generated method stub +// int selectColumn = table.getTableHeader().columnAtPoint(e.getPoint()); +// int selectedRow = table.rowAtPoint(e.getPoint()); +//// System.out.println("selectColumn==>"+selectColumn); +// if(selectColumn != 0) +// { +// return; +// }else { +// Object valueAt = table.getValueAt(selectedRow, selectColumn); +// if(valueAt.toString().equals("1")) { +// table.setValueAt("0", selectedRow, selectColumn); +// }else { +// table.setValueAt("1", selectedRow, selectColumn); +// } +// } +// } +// }); +// JScrollPane pane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); +// pane.setPreferredSize(new Dimension(1200,400)); +// pane.setViewportView(table);//ΪscrollPaneָʾΪtable +// return pane; +// } +// private DefaultTableModel map; +// public JTable getJTable(JTable partsTable, DefaultTableModel dtm, Object[] titleNames, Object[][] values) { +// int simpleLen = 150; +//// int totleLen = 1000; +// if (partsTable == null) { +// map = new DefaultTableModel(values, titleNames) { +// @Override +// public boolean isCellEditable(int row, int column) { +// return false; +// } +// }; +// +// partsTable = new JTable(map) ; +// +// partsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); +//// Adapter1 adapter = new Adapter1(partsTable); +// partsTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(partsTable)); +//// setDefaultRenderer(new CheckHeaderCellRenderer(table)); +// +// partsTable.setRowHeight(30); +// // //ʾȾ +// partsTable.getColumnModel().getColumn(0).setCellRenderer(new TableCellCheckboxRenderer(partsTable)); +//// partsTable.setDefaultRenderer(Object.class, renderer); +// partsTable.getTableHeader().setReorderingAllowed(false); +//// if (simpleLen * titleNames.length >= totleLen) { +// for (int i = 0; i < titleNames.length; i++) { +// partsTable.getColumnModel().getColumn(i).setPreferredWidth(simpleLen); +// } +// partsTable.setAutoResizeMode(0); +//// } else { +//// partsTable.setAutoResizeMode(1); +//// } +// } +// +// //++ +// return partsTable; +// } + private JLabel getJLabel(String name) { + JLabel label = new JLabel(name); + label.setPreferredSize(new Dimension(100, 30)); + return label; + } + + private JLabel getJLabelDate(String name) { + JLabel label = new JLabel(name); + label.setPreferredSize(new Dimension(140, 30)); + return label; + } + + // ȡݿ + 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; + } + +} diff --git a/src/com/langtech/plm/form/QueryNewProdFormHandler.java b/src/com/langtech/plm/form/QueryNewProdFormHandler.java new file mode 100644 index 0000000..30fa1fa --- /dev/null +++ b/src/com/langtech/plm/form/QueryNewProdFormHandler.java @@ -0,0 +1,35 @@ +package com.langtech.plm.form; + +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 QueryNewProdFormHandler 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() { + + new QueryNewProdFormFram(session); + + } + }.start(); + + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + + return null; + } +} diff --git a/src/com/langtech/plm/performancemanagement/Activator.java b/src/com/langtech/plm/performancemanagement/Activator.java new file mode 100644 index 0000000..67636fc --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/Activator.java @@ -0,0 +1,44 @@ +package com.langtech.plm.performancemanagement; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.langtech.plm.performancemanagement"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/src/com/langtech/plm/performancemanagement/dialogs/TaskFolderMatchingDialog.java b/src/com/langtech/plm/performancemanagement/dialogs/TaskFolderMatchingDialog.java new file mode 100644 index 0000000..8400f04 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/dialogs/TaskFolderMatchingDialog.java @@ -0,0 +1,114 @@ +package com.langtech.plm.performancemanagement.dialogs; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.filechooser.FileSystemView; + +import com.langtech.plm.performancemanagement.operations.TaskFolderMatchingOperation; +import com.langtech.plm.performancemanagement.util.ProgressBarThread; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.PropertyLayout; + +public class TaskFolderMatchingDialog extends AbstractAIFDialog implements ActionListener { + private AbstractAIFApplication app; + private TCSession session; + private JLabel fileLabel; + private JTextField fileField; + private JButton searchButton; + private JButton okButton; + private JButton celButton; + ProgressBarThread wait; + TCComponent target; + private JFileChooser jFileChooser; + +// ͬһĹ췽DzǶ + public TaskFolderMatchingDialog(AbstractAIFApplication app, TCComponent target) { + super(false);// ǧ + this.app = app; + this.session = (TCSession) app.getSession(); + this.target = target; + } + + public void initUI() { + FileSystemView fsv = FileSystemView.getFileSystemView(); + String deskPath = fsv.getHomeDirectory().getPath(); + this.setSize(new Dimension(500, 300)); + this.setTitle("Ч"); + this.fileLabel = new JLabel("·:"); + this.fileField = new JTextField(deskPath); + this.fileField.setEditable(false); + this.searchButton = new JButton("..."); + this.searchButton.addActionListener(this); + this.okButton = new JButton("ȷ"); + this.okButton.addActionListener(this); + this.celButton = new JButton("ȡ"); + this.celButton.addActionListener(this); + JPanel centerJPanel = new JPanel(new PropertyLayout()); + centerJPanel.add("1.1.left.top", this.fileLabel); + centerJPanel.add("1.2.left.top", this.fileField); + centerJPanel.add("1.3.left.top", this.searchButton); + JPanel rootJPanel = new JPanel(new FlowLayout()); + rootJPanel.add(okButton); + rootJPanel.add(celButton); + this.setLayout(new BorderLayout()); + this.add(centerJPanel, BorderLayout.CENTER); + this.add(rootJPanel, BorderLayout.SOUTH); + this.centerToScreen(); + this.pack(); + this.showDialog(); +// ʼļѡ + this.jFileChooser = new JFileChooser(); +// õǰļѡĬϵ· + this.jFileChooser.setCurrentDirectory(new File(deskPath)); + } + + @Override + public void run() { + initUI(); + } + + public void selectFileButtonEvent() { + // 趨ֻѡļ + jFileChooser.setFileSelectionMode(1);// ֻѡ· + // ˾ǴļѡĴ + int state = jFileChooser.showOpenDialog(null); + if (state == 1) { + return; + } else { + // fΪѡ񵽵Ŀ¼,Ĵ + File f = jFileChooser.getSelectedFile(); + fileField.setText(f.getAbsolutePath()); + } + } + + public void actionPerformed(ActionEvent arg0) { + Object sourceObj = arg0.getSource(); + if (sourceObj.equals(this.searchButton)) { + selectFileButtonEvent(); + } else if (sourceObj.equals(this.okButton)) { + this.disposeDialog(); + this.dispose(); + String filePath = this.fileField.getText(); + wait = new ProgressBarThread(" ", "ִУԵ..."); + wait.start(); + TaskFolderMatchingOperation operation = new TaskFolderMatchingOperation(filePath, target, session, wait); + this.session.queueOperation(operation); + } else { + this.disposeDialog(); + this.dispose(); + } + } +} diff --git a/src/com/langtech/plm/performancemanagement/handlers/TaskFolderMatchingHandler.java b/src/com/langtech/plm/performancemanagement/handlers/TaskFolderMatchingHandler.java new file mode 100644 index 0000000..e85671a --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/handlers/TaskFolderMatchingHandler.java @@ -0,0 +1,44 @@ +package com.langtech.plm.performancemanagement.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.langtech.plm.performancemanagement.dialogs.TaskFolderMatchingDialog; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +/** + * ѡĿļУЧ ݿάҪ + * + * + */ +public class TaskFolderMatchingHandler extends AbstractHandler { + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCComponent target = null; + target = (TCComponent) app.getTargetComponent(); + // ѡĿͣ򱨴 + + if(target==null) { + MessageBox.post("ѡͻƷļ", "", MessageBox.INFORMATION); + }else { + + String type = target.getType(); + if (type.equals("LD6_CusProdFolder") || type.equals("ͻƷļ")) { + TaskFolderMatchingDialog dialog = new TaskFolderMatchingDialog(app, target); + new Thread(dialog).start(); + } else { + MessageBox.post("ѡͻƷļ", "", MessageBox.INFORMATION); + } + } + return null; + } + +} diff --git a/src/com/langtech/plm/performancemanagement/operations/TaskFolderMatchingOperation.java b/src/com/langtech/plm/performancemanagement/operations/TaskFolderMatchingOperation.java new file mode 100644 index 0000000..8138ea7 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/operations/TaskFolderMatchingOperation.java @@ -0,0 +1,569 @@ +package com.langtech.plm.performancemanagement.operations; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.langtech.plm.performancemanagement.util.ProgressBarThread; +import com.langtech.plm.performancemanagement.util.SqlUtil; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.FileUtility; +import com.teamcenter.rac.util.MessageBox; + +public class TaskFolderMatchingOperation extends AbstractAIFOperation { +// private AbstractAIFApplication app; + private String filePath; + private TCSession session; + + private ProgressBarThread wait; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + TCComponent target; + Date processStartDate = null; + Date processEndDate = null; + + public TaskFolderMatchingOperation(String filePath, TCComponent target, TCSession session, ProgressBarThread wait) { + this.filePath = filePath; + this.target = target; + this.session = session; + this.wait = wait; + } + + @Override + public void executeOperation() throws Exception { + String[] ldSqlServer = session.getPreferenceService().getStringValues("ld_sqlserver"); + if (!getMessageInfo(ldSqlServer, "ld_sqlserver")) { + return; + } + + // 鱨ģǷڣѡld_billboards_uid + String ldBillboardsUid = session.getPreferenceService().getStringValue("ld_billboards_uid"); + if (!getMessageboxInfo(ldBillboardsUid, "ld_billboards_uid")) { + return; + } + TCComponent billboard = null; + try { + billboard = session.stringToComponent(ldBillboardsUid); + } catch (TCException e) { + e.printStackTrace(); + MessageBox.post("֪ͨԱѡld_billboards_uidǷ", "", MessageBox.INFORMATION); + return; + } + if (billboard == null) { + MessageBox.post("֪ͨԱѡld_billboards_uidǷ", "", MessageBox.INFORMATION); + return; + } + // ȡλϵ Ѷϵ Ŷϵ Ҫʱ乫ʽѡ + String[] ldPostCoefficient = session.getPreferenceService().getStringValues("ld_postCoefficient"); + String[] ldTaskNature = session.getPreferenceService().getStringValues("ld_taskNature");// ʶӦϵ + String[] ldTaskDifficulty = session.getPreferenceService().getStringValues("ld_taskDifficulty");// Ѷϵ + String[] ldUrgency = session.getPreferenceService().getStringValues("ld_urgency"); + // ʱ + String[] ldOvertime = session.getPreferenceService().getStringValues("ld_overtime");// صȼ:䣨[0,0]:۷ϵ;һ:(0,1]:1/5;:(1,2]:1/3;:(2,3]:1/2;δ:[3,1000):0.6 + // Ϣó =:˽ڵ + String[] ldProcessReview = session.getPreferenceService().getStringValues("ld_processReview"); + // Ҫʱ乫ʽ ֵʽ Ʒ=Ҫʱ乫ʽ =E-30 E̷ʱ Fճʱ + String[] ldRequestTime = session.getPreferenceService().getStringValues("ld_requestTime"); + if (!getMessageInfo(ldPostCoefficient, "ld_processReview")) { + return; + } + if (!getMessageInfo(ldTaskNature, "ld_taskNature")) { + return; + } + if (!getMessageInfo(ldUrgency, "ld_urgency")) { + return; + } + if (!getMessageInfo(ldTaskDifficulty, "ld_taskDifficulty")) { + return; + } + if (!getMessageInfo(ldProcessReview, "ld_processReview")) { + return; + } + if (!getMessageInfo(ldOvertime, "ld_overtime")) { + return; + } + if (!getMessageInfo(ldRequestTime, "ld_requestTime")) { + return; + } + Map postCoefficientMap = new HashMap();// λλϵ + Map taskNatureMap = new HashMap();// ʣϵ + Map taskDifficultyMap = new HashMap();// ѶȣѶϵ + Map urgencyMap = new HashMap();// ̶ȣ̶ϵ + Map processReviewMap = new HashMap();// ƣָɵĽڵ + Map severityIntervalMap = new HashMap();// 䣻ֵ۷ϵ + Map requestTimeMap = new HashMap();// Ʒƣֵʽ + for (int i = 0; i < ldPostCoefficient.length; i++) { + String value = ldPostCoefficient[i]; + postCoefficientMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldRequestTime.length; i++) { + String value = ldRequestTime[i]; + requestTimeMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldTaskNature.length; i++) { + String value = ldTaskNature[i]; + taskNatureMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldTaskDifficulty.length; i++) { + String value = ldTaskDifficulty[i]; + taskDifficultyMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldUrgency.length; i++) { + String value = ldUrgency[i]; + urgencyMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldProcessReview.length; i++) { + String value = ldProcessReview[i]; + processReviewMap.put(value.split("=")[0], value.split("=")[1]); + } + for (int i = 0; i < ldOvertime.length; i++) { + String dayInterval = ldOvertime[i].split(":")[1]; +// String severity = ldOvertime[i].split(":")[0]; + String point = ldOvertime[i].split(":")[2]; + severityIntervalMap.put(dayInterval, point); + } + // رúҪ + String billboardAddress = downLoadFile(billboard); + // TODO ȡսʱ + String targetName = ""; + try { + targetName = target.getProperty("object_name"); + } catch (TCException e) { + e.printStackTrace(); + } + getProcessTime(targetName);// E F + if (processEndDate == null || processStartDate == null) { + MessageBox.post("ǷûߵؿͻƷļƺ͹ճʱ", "", MessageBox.INFORMATION); + return; + } + // ȡ ֯ + // ȱײṹ + String path = ""; + String link = "/"; + List taskPathList = new ArrayList(); + Map folderMap = new HashMap();// ļв㼶ṹ ֵļж + getAllFolderPath(target, path, link, taskPathList, folderMap); + // ȡѡConnor_JXFolder + Map> packageMap = new HashMap>(); + String connorJXFolderPreference = "Connor_JXFolder"; + String[] ConnorJXFolders = session.getPreferenceService().getStringValues(connorJXFolderPreference); + if (!getMessageInfo(ConnorJXFolders, connorJXFolderPreference)) { + return; + } + for (int i = 0; i < ConnorJXFolders.length; i++) { + String[] values = ConnorJXFolders[i].split("="); + String[] folders = values[1].split(";"); + List folderList = Arrays.asList(folders); + packageMap.put(values[0], folderList); + } + // ȡϢ + File file = new File(billboardAddress); + XSSFWorkbook workbook = null; + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + workbook = new XSSFWorkbook(fis); + } catch (IOException e) { + e.printStackTrace(); + } + XSSFSheet sheet = workbook.getSheet("Ʒ"); + int rowNum = sheet.getLastRowNum(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HHmm"); + for (int i = 1; i < rowNum; i++) { + XSSFRow row = sheet.getRow(i); + String cellBValue = row.getCell(1).getStringCellValue().trim();// + List folderList = packageMap.get(cellBValue); + if (folderList != null && folderList.size() > 0) { + String folderPath = folderList.get(0); + System.out.println("" + folderPath); + TCComponent folder = folderMap.get(folderPath); + if (folder == null) { + continue; + } + // "", "׳̶", "̶", "ҵʱ(Сʱ)", + String[] properties = new String[] { "object_desc", "ld6_WorkFold01", "ld6_WorkFold02", + "ld6_WorkFold03", "ld6_WorkFold04", "fnd0AllWorkflows" }; + TCProperty[] tcproperties = null; + try { + tcproperties = folder.getTCProperties(properties); + } catch (TCException e) { + e.printStackTrace(); + } + // ƷҪ + String objectDesc = tcproperties[0].getStringValue(); + String taskNature = tcproperties[1].getDisplayValue(); + String difficulty = tcproperties[2].getDisplayValue(); + String urgency = tcproperties[3].getDisplayValue(); + String ratedBusinessHours = tcproperties[4].getStringValue(); + String taskNatureCoefficient = taskNatureMap.get(taskNature); + String taskDifficultyCoefficient = taskDifficultyMap.get(difficulty); + String urgencyCoefficient = urgencyMap.get(urgency); + String postCoefficient = "";// + // ȡϢ + String processReview = processReviewMap.get(cellBValue); + System.out.println("processReview:" + processReview); + if (processReview.length() == 0) { + continue; + } + String processName = processReview.split(":")[0]; + String reviewName = processReview.split(":")[1]; + String assignee = "";// ָfnd0Assigneeûоתָ߼̽ߣͬη + String assigner = "";// ָfnd0Assignerûоתûֵȡָ + String assigneeGroup = "";// ָߵ + String status = "";// ״̬ +// String startData = "";// ̿ʼʱ + String endDateValue = "";// ̽ʱ + String actualHours = "";// ʵҵʱ + String deductPoints = "";// ʱ۷ +// String remark = "";// עʱûԼ + String assignStartDay = "";// ʱ + String requestEndDay = "";// Ҫʱ + row.getCell(5).setCellValue(objectDesc); + row.getCell(8).setCellValue(taskNature); + row.getCell(9).setCellValue(difficulty); + row.getCell(10).setCellValue(urgency); + row.getCell(11).setCellValue(ratedBusinessHours); + TCComponent[] workflows = tcproperties[5].getReferenceValueArray(); + for (int j = 0; j < workflows.length; j++) { + TCComponent workflow = workflows[j]; + try { + String[] workflowProperties = new String[] { "object_name", "fnd0ActuatedInteractiveTsks", + "fnd0EndDate", "fnd0StartDate", "fnd0Status" }; + TCProperty[] workflowTcProperties = workflow.getTCProperties(workflowProperties); + String workflowName = workflowTcProperties[0].getDisplayValue(); + TCComponent[] reviews = workflowTcProperties[1].getReferenceValueArray(); + if (workflowName.equals(processName)) { + for (int k = 0; k < reviews.length; k++) { + TCComponent review = reviews[k]; + String typeName = review.getType(); + System.out.println("̽ڵͣ" + typeName); + if (typeName.equals("ǩ") || typeName.equals("Signoff")) {// fnd0AliasTaskName;ִߣfnd0Performer + // fnd0AssigneeGroupRole owning_group + String[] reviewProperties = new String[] { "fnd0AliasTaskName", "fnd0Performer", + "owning_group", "fnd0Assigner", "fnd0Assignee" }; + TCProperty[] reviewTcProperties = review.getTCProperties(reviewProperties); + String aliasTaskName = reviewTcProperties[0].getDisplayValue(); + System.out.println("aliasTaskName:" + aliasTaskName); + if (aliasTaskName.contains(":")) { + String reviewNodeName = aliasTaskName.split(":")[0].trim(); + System.out.println("reviewNodeName:" + reviewNodeName); + System.out.println("reviewName:" + reviewName); + if (reviewNodeName.equals(reviewName)) { + assignee = reviewTcProperties[4].getDisplayValue(); + assigneeGroup = reviewTcProperties[2].getDisplayableValue(); + System.out.println("λ飺" + assigneeGroup); + TCProperty assigneeProperty = reviewTcProperties[3]; + if (assigneeProperty.getDisplayValue().length() > 0) { + assigner = assigneeProperty.getDisplayValue(); + } else { + assigner = assignee; + } + + row.getCell(4).setCellValue(assigner); + row.getCell(6).setCellValue(assignee); + row.getCell(7).setCellValue(assigneeGroup); + } + } + status = workflowTcProperties[4].getDisplayValue().equals("") ? "" : "δ"; + + row.getCell(16).setCellValue(status); + endDateValue = workflowTcProperties[2].getDisplayValue(); + Date startDate = workflowTcProperties[3].getDateValue(); + + assignStartDay = new SimpleDateFormat("yyyy-MM-dd").format(processStartDate); + Date endDate = workflowTcProperties[2].getDateValue(); + actualHours = "" + (endDate.getTime() - startDate.getTime()) / 1000 / 3600; + float point = (float) 0.0; + + row.getCell(12).setCellValue(actualHours); + row.getCell(13).setCellValue(assignStartDay); + row.getCell(15).setCellValue(endDateValue); + if (status.equals("")) { + ZoneId zoneId = ZoneId.systemDefault(); + Instant instantEnd = endDate.toInstant(); +// Instant instantProcessEnd = processEndDate.toInstant(); + LocalDate localEndDate = instantEnd.atZone(zoneId).toLocalDate(); +// LocalDate localProcessEndDate = instantProcessEnd.atZone(zoneId).toLocalDate(); + // TODO 趨ҪʱlocalEndDate + String formation = requestTimeMap.get(cellBValue); + System.out.println("formation:" + formation); + Date formateDate = null; + if (formation.contains("E")) { + formateDate = processStartDate; + } else if (formation.contains("F")) { + formateDate = processEndDate; + } + Instant instantFormateDate = formateDate.toInstant(); + LocalDate localFormateDate = instantFormateDate.atZone(zoneId).toLocalDate(); + if (formation.contains("+")) { + long daysToAdd = Long.valueOf(formation.split("+")[1]); + System.out.println("daysToAdd:" + daysToAdd); + localFormateDate = localFormateDate.plusDays(daysToAdd); + } else if (formation.contains("-")) { + + long daysToMinus = Long.valueOf(formation.split("-")[1]); + System.out.println("ǰ" + localFormateDate); + localFormateDate = localFormateDate.minusDays(daysToMinus); + System.out.println("" + localFormateDate); + System.out.println("daysToMinus:" + daysToMinus); + } + requestEndDay = new SimpleDateFormat("yyyy-MM-dd").format( + Date.from(localFormateDate.atStartOfDay().atZone(zoneId).toInstant())); + row.getCell(14).setCellValue(requestEndDay); +// requestEndDay = sdf.format(Date.from(instantFormateDate)); + long diff = localEndDate.toEpochDay() - localFormateDate.toEpochDay(); + System.out.println("diff:" + diff); + String overtimeCoefficient = "";// ۷ϵ + postCoefficient = postCoefficientMap.get(assigneeGroup); + for (Map.Entry me : severityIntervalMap.entrySet()) { + String interval = me.getKey(); + System.out.println("interval:" + interval); + String startDay = interval.split(",")[0]; + String endDay = interval.split(",")[1]; + boolean condition1 = false; + boolean condition2 = false; + if (startDay.startsWith("[")) { + int startInt = Integer + .valueOf(startDay.substring(1, startDay.length())); + System.out.println("startInt:" + startInt); + condition1 = diff >= startInt ? true : false; + } else if (startDay.startsWith("(")) { + int startInt = Integer + .valueOf(startDay.substring(1, startDay.length())); + System.out.println("startInt:" + startInt); + condition1 = diff > startInt ? true : false; + } + if (endDay.endsWith("]")) { + int endInt = Integer.valueOf(endDay.substring(0, endDay.length() - 1)); + System.out.println("endInt:" + endInt); + condition2 = diff <= endInt ? true : false; + } else if (endDay.endsWith(")")) { + int endInt = Integer.valueOf(endDay.substring(0, endDay.length() - 1)); + + System.out.println("endInt:" + endInt); + condition2 = diff < endInt ? true : false; + } + if (condition1 == true && condition2 == true) { + overtimeCoefficient = me.getValue(); + } else { + continue; + } + } + System.out.println("overtimeCoefficient:" + overtimeCoefficient); + System.out.println("postCoefficient:" + postCoefficient); + System.out.println("taskNatureCoefficient:" + taskNatureCoefficient); + System.out.println("taskDifficultyCoefficient:" + taskDifficultyCoefficient); + System.out.println("urgencyCoefficient:" + urgencyCoefficient); + if (!overtimeCoefficient.equals("")) { + point = 1 * Float.valueOf(overtimeCoefficient) + * Float.valueOf(postCoefficient) + * Float.valueOf(taskNatureCoefficient) + * Float.valueOf(taskDifficultyCoefficient) + * Float.valueOf(urgencyCoefficient); + deductPoints = point + ""; + + + row.getCell(17).setCellValue(deductPoints); + } + } + } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + } + } else { + continue; + } + } + // + String fileName = "Ч" + sdf.format(new Date()) + ".xlsx"; + filePath = filePath + File.separator + fileName; + try { + FileOutputStream os = new FileOutputStream(filePath); + workbook.write(os); + os.close(); + fis.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + wait.setBool(true); + wait.interrupt(); + MessageBox.post("ɣ" + filePath, "", MessageBox.INFORMATION); + + } + + /** + * ͨݷʽȡսʱ + * + * @throws SQLException + * @throws ParseException + */ + private void getProcessTime(String targetName) throws SQLException, ParseException { + String[] ldSqlServer = session.getPreferenceService().getStringValues("ld_sqlserver"); + String databaseName = ldSqlServer[0]; + String databasePassword = ldSqlServer[1]; + String databaseUrl = ldSqlServer[2]; + String databaseDriver = ldSqlServer[3]; + String tableName = ldSqlServer[4]; + SqlUtil.getConnection(databaseName, databasePassword, databaseUrl, databaseDriver); + String searchQuestion = ""; + + String folderName = targetName; + searchQuestion = SqlUtil.getSelectSql_1(tableName, "proj_cus_prod_folder", folderName); + ResultSet set = SqlUtil.read(searchQuestion);// ִ + System.out.println(searchQuestion); + set = SqlUtil.read(searchQuestion);// ִ + String projProgEnd = ""; + String projProgStart = ""; + if (set.next()) { + projProgEnd = set.getString("proj_prog_end");// ճ ַ洢ʽ2023/12/14 + projProgStart = set.getString("proj_prog_start");// ճʼ ַ洢ʽ2023/12/14 + } + + // رݿ + SqlUtil.freeAll();// + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + processStartDate = sdf.parse(projProgStart); + processEndDate = sdf.parse(projProgEnd); + } + + /** + * ѡǷ + * + * @param preferenceValue ѡֵ + * @param preferenceName ѡ + * @return ûþͷfalse + */ + private boolean getMessageInfo(String[] preferenceValue, String preferenceName) { + if (preferenceValue == null || preferenceValue.length == 0) { + MessageBox.post("֪ͨԱѡ" + preferenceName + "Ƿ", "", MessageBox.INFORMATION); + return false; + } + return true; + } + + /** + * ѡǷ + * + * @param preferenceValue ѡֵ + * @param preferenceName ѡ + * @return ûþͷfalse + */ + private boolean getMessageboxInfo(String preferenceValue, String preferenceName) { + if (preferenceValue == null || preferenceValue.length() == 0) { + MessageBox.post("֪ͨԱѡ" + preferenceName + "Ƿ", "", MessageBox.INFORMATION); + return false; + } + return true; + } + + /** + * ѭĿļµļУӵϺmap + * + * @param target ļ + * @param path ļ· + * @param link ӷ + * @param taskPathList · + * @param folderMap · + */ + private void getAllFolderPath(TCComponent target, String path, String link, List taskPathList, + Map folderMap) { + try { + TCComponent[] contents = target.getRelatedComponents("contents"); + for (int i = 0; i < contents.length; i++) { + TCComponent content = contents[i]; + String contentType = content.getType(); + String mergePath = ""; + if (contentType.equals("LD6_ProjMaFolder")) { + + TCComponent[] childContents = content.getRelatedComponents("contents"); + + if (path.length() > 0) { + mergePath = path + link; + } + mergePath = mergePath + content.getProperty("object_name"); + if (childContents.length > 0) { + getAllFolderPath(content, mergePath, link, taskPathList, folderMap); + } else { + taskPathList.add(mergePath); + System.out.println("mergePath:" + mergePath); + folderMap.put(mergePath, content); + } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + } + + /** + * ļ + * + * @param ݼ + * @return صļ + */ + public String downLoadFile(TCComponent comp) { + if (comp == null) { + return ""; + } + String value = ""; + String tempPath = System.getenv("TEMP"); + if (tempPath == null) { + tempPath = ""; + } else if (!tempPath.endsWith("\\")) { + tempPath = tempPath + "\\"; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + try { + if (comp instanceof TCComponentDataset) { + TCComponentTcFile[] tcFiles = ((TCComponentDataset) comp).getTcFiles(); + File file = null; + System.out.println("tcFiles:" + tcFiles.length); + if (tcFiles != null && tcFiles.length != 0) { + file = tcFiles[0].getFmsFile(); + String fileName = file.getName(); + System.out.println("fileName:" + fileName); + String fileDix = fileName.substring(fileName.lastIndexOf("."), fileName.length()); + fileName = tempPath + sdf.format(new Date()) + fileDix; + File dirFile = new File(fileName); + FileUtility.copyFile(file, dirFile); + return fileName; + } + } + } catch (TCException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return value; + } + +} diff --git a/src/com/langtech/plm/performancemanagement/util/ProgressBar.java b/src/com/langtech/plm/performancemanagement/util/ProgressBar.java new file mode 100644 index 0000000..c134268 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/util/ProgressBar.java @@ -0,0 +1,171 @@ +/** + * @file ProgressBar.java + * + * @brief Create progress bar + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 25-July-2008 Yanghui this class is used to create + * progress bar. + */ +package com.langtech.plm.performancemanagement.util; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.Timer; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.rac.util.Registry; + +/** + * @class ProgressBar + * @brief Create progress bar + * @author Yanghui + */ +public class ProgressBar extends AbstractAIFDialog implements ActionListener { + /** + * @var ProgressBar.progressbar + * @brief JProgressBar + */ + private JProgressBar progressbar; + + /** + * @var ProgressBar.label + * @brief label used to tips + */ + private JLabel label; + + /** + * @var ProgressBar.timer + * @brief timer used to timing operation + */ + private Timer timer; + + /** + * @var ProgressBar.bool + * @brief bool used to flag thread return + */ + private boolean bool = false; + + /** + * @var Progressbar.registry + * @brief Registry + */ + private Registry registry; + + /** + * @fn public ProgressBar() + * @brief constructor + * @param[in] null + */ + private String showLable = null ; + public ProgressBar(String showlable) { + super(true); + showLable = showlable; + this.setAlwaysOnTop(true); + } + + /** + * @fn public void setBool(boolean bool) + * @brief set bool value + * @param[in] bool + * @param[out] null + */ + public void setBool(boolean bool) { + this.bool = bool; + } + + /** + * @fn private void initUI() + * @brief createDialog method + * @param[in] null + * @param[out] null + */ + public void initUI() { + Container container = getContentPane(); + JPanel mainPanel = new JPanel(new PropertyLayout()); + this.label = new JLabel(showLable, JLabel.CENTER); + this.progressbar = new JProgressBar(); + this.progressbar.setOrientation(JProgressBar.HORIZONTAL); + this.progressbar.setMinimum(0); + this.progressbar.setMaximum(100); + this.progressbar.setValue(0); + this.progressbar.setPreferredSize(new Dimension(200, 15)); + this.progressbar.setBorderPainted(true); + this.timer = new Timer(50, (ActionListener) this); + this.timer.setRepeats(false); + mainPanel.add("1.1.center", new JLabel(" ")); + mainPanel.add("2.1.center", label); + mainPanel.add("3.1.center", progressbar); + mainPanel.add("4.1.center", new JLabel(" ")); + container.add(mainPanel); + pack(); + setLocation(500, 200); + TaskThread thread = new TaskThread(this); + thread.start(); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + bool = true; + } + }); + this.setVisible(true); + } + + /** + * @class TaskThread + * @brief Create progressbar + * + */ + class TaskThread extends Thread { + private ProgressBar bar; + + public TaskThread(ProgressBar bar) { + this.bar = bar; + } + + public void run() { + if (bool == false) { + // Set Status is running. + // session.setStatus(registry.getString("export Running")); + } + for (int i = 0; i < i + 1; i++) { + timer.start(); + int value = progressbar.getValue(); + if (value < 100) { + value = value + 5; + progressbar.setValue(value); + } else { + timer.stop(); + progressbar.setValue(0); + } + try { + sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (bool == true) { + bar.setVisible(false); + bar.dispose(); + return; + + } + + } + } + } + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/com/langtech/plm/performancemanagement/util/ProgressBarThread.java b/src/com/langtech/plm/performancemanagement/util/ProgressBarThread.java new file mode 100644 index 0000000..f408542 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/util/ProgressBarThread.java @@ -0,0 +1,41 @@ +/** + * @file ProgressBarThread.java + * + * @brief control progressBar. + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 08-Auguest-2008 Yanghui this class is used to control + * progress bar. + */ +package com.langtech.plm.performancemanagement.util; + +/** + * @class ProgressBarThread + * @brief Create progress bar thread + * @author Yanghui + */ +public class ProgressBarThread extends Thread { + + private ProgressBar bar; + + private String title; + + public ProgressBarThread(String title,String showLable) { + this.title = title; + bar = new ProgressBar(showLable); + } + + public void run() { + bar.setTitle(title); + bar.initUI(); + } + + public void setBool(boolean bool) { + bar.setBool(true); + bar.setAlwaysOnTop(false); + } +} diff --git a/src/com/langtech/plm/performancemanagement/util/SqlUtil.java b/src/com/langtech/plm/performancemanagement/util/SqlUtil.java new file mode 100644 index 0000000..f05a544 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/util/SqlUtil.java @@ -0,0 +1,819 @@ +package com.langtech.plm.performancemanagement.util; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.Registry; + +/** + * ֹ̳final,ֹ󽨶˽й췽,ΪʹС PreparedStatementResultSetС + * + * @author hub 2015-02-06 + */ +public final class SqlUtil { + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; + private static Registry reg = Registry.getRegistry("com.langtech.plm.performancemanagement.util.database"); + + /** + * ˽йnew󣬷ֹö + */ + private SqlUtil() { + + } + + static { + String driver = reg.getString("SQLSERVER_DRIVER"); // һעɹ޸ãҪ建ע + if (driver == null) { + driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; + } + driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; + + System.out.println("driver " + driver); + try { + Class.forName(driver); + } catch (ClassNotFoundException e) { + System.out.println("SQLSERVER DRIVER IS EXCEPTION"); + e.printStackTrace(); + } + } + + /** + * ݿ + */ + public static Connection getConnection() { + try { + String driver_temp = reg.getString("SQLSERVER_DRIVER"); + String url = reg.getString("SQLSERVER_URL");// getProperties("URL"); + String dbName = reg.getString("SQLSERVER_NAME");// Util.getProperties("dbName"); + String dbPassword = reg.getString("SQLSERVER_PASSWORD");// Util.getProperties("dbPassword"); + // String driver_temp = + // "com.microsoft.jdbc.sqlserver.SQLServerDriver"; + // String url = + // "jdbc:microsoft:sqlserver://10.200.1.33:1433;DatabaseName=ecology";// + // getProperties("URL"); + // String dbName = "tc";// Util.getProperties("dbName"); + // String dbPassword = "Tc123456";// + // Util.getProperties("dbPassword"); + System.out.println("SQLSERVER_DRIVER:" + driver_temp); + System.out.println("SQLSERVER_URL:" + url); + System.out.println("SQLSERVER_NAME:" + dbName); + System.out.println("SQLSERVER_PASSWORD:" + dbPassword); + // int a=1; + // if(a==1){ + // return connection; + // } + + if (driver_temp == null || url == null || dbName == null || dbPassword == null) { + + MessageBox.post("ݿѡǷȷ", "ʾ", MessageBox.ERROR); + + } + // else{ + // MessageBox.post(driver_temp+" | "+url+" | "+dbName+" | + // "+dbPassword,"ʾ",MessageBox.ERROR); + // + // } + System.out.println(url + dbName + dbPassword); + connection = DriverManager.getConnection(url, dbName, dbPassword); + // connection.setAutoCommit(false);//sqlserverݿʱע + } catch (SQLException e) { + System.out.println(" CONNECT EXCEPTION"); + e.printStackTrace(); + return null; + // MessageBox.post("ORACEL CONNECT EXCEPTION + // \n"+e.getMessage(),"ERROR",MessageBox.ERROR); + } + return connection; + } + + /** + * ݿ + */ + public static Connection getConnection(String dbName, String dbPassword, String url, String driverTemp) { + try { + + if (driverTemp == null || url == null || dbName == null || dbPassword == null) { + + MessageBox.post("ݿѡǷȷ", "ʾ", MessageBox.ERROR); + + } + // else{ + // MessageBox.post(driver_temp+" | "+url+" | "+dbName+" | + // "+dbPassword,"ʾ",MessageBox.ERROR); + // + // } + System.out.println(url +":"+ dbName +":"+ dbPassword); + connection = DriverManager.getConnection(url, dbName, dbPassword); +// connection.setAutoCommit(false); + } catch (SQLException e) { + System.out.println("SQLSERVER CONNECT EXCEPTION"); + e.printStackTrace(); + return null; + // MessageBox.post("ORACEL CONNECT EXCEPTION + // \n"+e.getMessage(),"ERROR",MessageBox.ERROR); + } + return connection; + } + + /** + * ݿ + */ + public static Connection getConnection(String url, String dbName, String dbPassword) { + try { + String driver_temp = reg.getString("SQLSERVER_DRIVER"); + + System.out.println(url + dbName + dbPassword); + connection = DriverManager.getConnection(url, dbName, dbPassword); + connection.setAutoCommit(false); + } catch (SQLException e) { + System.out.println("ORACEL CONNECT EXCEPTION"); + e.printStackTrace(); + // MessageBox.post("ORACEL CONNECT EXCEPTION + // \n"+e.getMessage(),"ERROR",MessageBox.ERROR); + return null; + } + return connection; + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql(String tableName, String[] selectElement, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT "); + if (selectElement != null) { + for (String element : selectElement) { + valuesSB.append(element).append(","); + } + valuesSB.delete(valuesSB.length() - 1, valuesSB.length()); + } + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql_1(String tableName, String selectElement, String keyword) { + StringBuffer valuesSB = new StringBuffer("SELECT *"); + + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE "); + valuesSB.append(selectElement); + valuesSB.append(" = '"); + valuesSB.append(keyword); + valuesSB.append("'"); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql_2(String tableName, String[] selectElement, Object[] keyword) { + StringBuffer valuesSB = new StringBuffer("SELECT *"); + + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE "); + for (int i = 0; i < keyword.length; i++) { + valuesSB.append(selectElement[i]); + valuesSB.append(" = '"); + valuesSB.append(keyword[i]); + valuesSB.append("'"); + if (i < keyword.length - 1) { + valuesSB.append(" and "); + } + + } + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql_3(String tableName, String selectElement, String keyword) { + StringBuffer valuesSB = new StringBuffer("SELECT *"); + + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE "); + valuesSB.append(selectElement); + valuesSB.append(" = '"); + valuesSB.append(keyword); + valuesSB.append("'"); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param args + * @return + */ + public static String getSelectSql(String tableName, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT * FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴӸ + * + * @param tableName + * @param args + * @param args2 + * @return + */ + public static String getUpdataSQL(String tableName, String[] args, String[] args2) { + StringBuffer updateSB = new StringBuffer("UPDATE "); + updateSB.append(tableName); + updateSB.append(" SET "); + // ƴӸ + for (int i = 0; i < args.length; i++) { + if (args[i].toUpperCase().equals("OPERATE_TIME") || args[i].toUpperCase().equals("LAST_UPDATE_DATE")) { + updateSB.append(args[i]).append("=to_date(?,'yyyy-MM-dd HH24:mi:ss') ,"); + } else { + updateSB.append(args[i]).append("=? ,"); + } + } + updateSB.delete(updateSB.length() - 2, updateSB.length()); + ; + updateSB.append(" WHERE "); + for (int i = 0; i < args2.length; i++) { + updateSB.append(args2[i]).append("=? AND "); + } + updateSB.delete(updateSB.length() - 4, updateSB.length()); + return updateSB.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql_1(String tableName, String[] column, Object[] value) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && column != null && column.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < column.length; i++) { + insertSql.append(column[i]); + if (i < column.length - 1) { + insertSql.append(", "); + } + } + } else { + return null; + } + if (tableName != null && value != null && value.length > 0) { + System.out.println(value.length); + for (int i = 0; i < value.length; i++) { + if ((value[i] + "").trim().equals("")) { + value[i] = ""; + } + if (i == 0) { + values.append(value[i]); + } else { + + values.append("'" + value[i] + "'"); + } + if (i < value.length - 1) { + values.append(","); + } + } + } + // insertSql.delete(insertSql.length() - 2, insertSql.length()); + // values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql_2(String tableName, String[] column, Object[] value) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && column != null && column.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < column.length; i++) { + insertSql.append(column[i]); + if (i < column.length - 1) { + insertSql.append(", "); + } + } + } else { + return null; + } + if (tableName != null && value != null && value.length > 0) { + System.out.println(value.length); + for (int i = 0; i < value.length; i++) { + if ((value[i] + "").trim().equals("")) { + value[i] = ""; + } + if (i == 1) { + values.append(value[i]); + } else { + + values.append("'" + value[i] + "'"); + } + if (i < value.length - 1) { + values.append(","); + } + } + } + // insertSql.delete(insertSql.length() - 2, insertSql.length()); + // values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql_3(String tableName, String[] column, Object[] value) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && column != null && column.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < column.length; i++) { + insertSql.append(column[i]); + if (i < column.length - 1) { + insertSql.append(", "); + } + } + } else { + return null; + } + if (tableName != null && value != null && value.length > 0) { +// System.out.println(value.length); + for (int i = 0; i < value.length; i++) { + if ((value[i] + "").trim().equals("")) { + value[i] = ""; + } + if (i == 3) { + values.append(value[i]); + } else { + + values.append("'" + value[i] + "'"); + } + if (i < value.length - 1) { + values.append(","); + } + } + } + // insertSql.delete(insertSql.length() - 2, insertSql.length()); + // values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * ƴSQLdelete + * + * @param tableName + * @param args + * @return + */ + public static String getDelete(String tableName, String column, String value) { + StringBuffer deleteSql = new StringBuffer("delete from "); + deleteSql.append(tableName); + deleteSql.append(" where "); + deleteSql.append(column); + deleteSql.append("='"); + deleteSql.append(value); + deleteSql.append("'"); + + return deleteSql.toString(); + } + + /** + * ƴSQLupdate + * + * @param tableName + * @param args + * @return + */ + public static String getUpdate(String tableName, String[] column, String[] value, String[] columns, + Object[] values) { + StringBuffer updateSql = new StringBuffer("update "); + updateSql.append(tableName); + updateSql.append(" set "); + // TODO ʣֶ + System.out.println("columns.length---->" + columns.length); + System.out.println("values.length---->" + values.length); + for (int i = 0; i < columns.length; i++) { + updateSql.append(""); + updateSql.append(columns[i]); + updateSql.append("="); + updateSql.append("'"); + updateSql.append(values[i]); + if (i == values.length - 1) { + updateSql.append("' "); + } else { + updateSql.append("', "); + } + } + + updateSql.append(" where "); + for (int i = 0; i < column.length; i++) { + updateSql.append(column[i]); + updateSql.append("='"); + updateSql.append(value[i]); + updateSql.append("'"); + if (i < column.length - 1) { + updateSql.append(" and "); + } + + } +// updateSql.append(column); +// updateSql.append("='"); +// updateSql.append(value); +// updateSql.append("'"); + + return updateSql.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql(String tableName, String... args) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && args != null && args.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < args.length; i++) { + insertSql.append(args[i]); + insertSql.append(", "); + if (args[i].toUpperCase().equals("COMMIT_TIME") || args[i].toUpperCase().equals("CREATE_DATE") + || args[i].toUpperCase().equals("INVALID_DATE")) { + values.append("to_date(?,'yyyy-MM-dd HH24:mi:ss'), "); + } else { + values.append("?, "); + } + + } + } else { + return null; + } + insertSql.delete(insertSql.length() - 2, insertSql.length()); + values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * õݿ + * + * @param tableName + * @param args + * @param args2 + * @return ƴӺĴݿ + */ + public final static String GetCreateTableSQL(String tableName, String[] args, String[] args2) { + + if (args == null || args2 == null || args.length != args2.length) { + System.out.println("THE INPUT PRAGREMS IS ERROR"); + return null; + } + StringBuffer createSQL = new StringBuffer("create table "); + createSQL.append(tableName); + createSQL.append("("); + for (int i = 0; i < args.length; i++) { + createSQL.append(args[i] + " "); + createSQL.append(args2[i] + ", "); + } + createSQL.delete(createSQL.length() - 2, createSQL.length()); + createSQL.append(")"); + return createSQL.toString(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql) throws SQLException { + return getPs(sql, null); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws SQLException { + // System.out.println("PreparedStatement getPs"); + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws SQLException { + // System.out.println("PreparedStatement getPs2"); + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * + */ + public final static int write(String sql) { + return write(sql, null); + } + + /** + * + */ + public final static int write(Object[] argments, String sql) { + return write(sql, argments); + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql) { + return delete(sql, null); + } + + /** + * ɾ + */ + public final static int delete(Object[] argments, String sql) { + return delete(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql, Object[] argments) { + return update(sql, argments); + } + + /** + * ޸ + */ + public final static int update(String sql) { + return update(sql, null); + } + + /** + * ޸ + */ + public final static int update(String[] argments, String sql) { + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + PreparedStatement ps = SqlUtil.getPs(argments, sql); + i = ps.executeUpdate(); + // 2015-11-19 + SqlUtil.connection.commit(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (Exception e1) { + e1.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + return i; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws SQLException { + // System.out.println("ResultSet read"); + return read(sql, null); + } + + /** + * ѯ + */ + public final static ResultSet read(Object[] argments, String sql) throws SQLException { + return read(sql, argments); + } + + /** + * ѯ(вѯնҪô˷治쳣׳ɵߴfinallyͷԴ) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws SQLException { + // System.out.println("ResultSet read2"); + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + + /** + * + */ + public final static boolean createTable(String sql) { + return go(sql, null); + } + + /** + * ɾ + */ + public final static boolean dropTable(String sql) { + return go(sql, null); + } + + /** + * ޸ı + */ + public final static boolean alterTable(String sql) { + return go(sql, null); + } + + /** + * ˷ִDDL(,޸ı,ɾ) + */ + private final static boolean go(String sql, Object[] argments) { + boolean flag = false; + try { + flag = SqlUtil.getPs(sql, argments).execute(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + if (flag) { + try { + SqlUtil.connection.commit(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return flag; + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(SqlUtil.rs, SqlUtil.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + } + + // public void findsth(String searchpart){ + // + // } +} diff --git a/src/com/langtech/plm/performancemanagement/util/database.properties b/src/com/langtech/plm/performancemanagement/util/database.properties new file mode 100644 index 0000000..f015d02 --- /dev/null +++ b/src/com/langtech/plm/performancemanagement/util/database.properties @@ -0,0 +1,20 @@ +# +#ORACEL_NAME=tc +# +#ORACEL_PASSWORD=Tc123456 +# +##ORACEL_URL=jdbc:oracle:thin:@192.168.1.248:1521:TOPPROD +# +#ORACEL_URL=jdbc:microsoft:sqlserver://10.200.1.33:1433;DatabaseName=ecology +# +#ORACEL_DRIVER=com.microsoft.jdbc.sqlserver.SQLServerDriver + +SQLSERVER_NAME=infodba + +SQLSERVER_PASSWORD=infodba + +#ORACEL_URL=jdbc:oracle:thin:@192.168.1.248:1521:TOPPROD + +SQLSERVER_URL=jdbc:sqlserver://10.10.22.39:1433;DatabaseName=TC13 + +SQLSERVER_DRIVER=com.microsoft.sqlserver.jdbc.SQLServerDriver \ No newline at end of file diff --git a/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties b/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties new file mode 100644 index 0000000..93ef268 --- /dev/null +++ b/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties @@ -0,0 +1 @@ +LD6_NewProdForm.FORMJAVARENDERING=com.langtech.plm.form.LD6_NewProdForm \ No newline at end of file