import java.io.*; import java.beans.*; import java.awt.*; import java.awt.Window; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.JOptionPane; import javax.swing.plaf.*; import javax.swing.event.*; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.DefaultListModel; import javax.swing.JTable; import javax.swing.table.*; import java.text.*; import java.sql.*; import java.net.*; import java.net.URL; import java.util.*; import java.util.List; import java.util.Vector; import java.util.ResourceBundle; import oracle.jdbc.driver.*; public class ProI_RVR_31 implements ListSelectionListener { public static void main(String[] args) { new ProI_RVR_31(); } public ProI_RVR_31() { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }; container=new JFrame("ProI/ProductView Rev-Ver-Release"); container.addWindowListener(l); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2)); int x=(int)(frameSize.width/2); int y=(int)(frameSize.height/2); container.setBounds(x,y,frameSize.width,frameSize.height); container.getContentPane().setLayout( new BorderLayout() ); JPanel dbconn = new JPanel(); dbconn.setLayout(new BorderLayout()); dbconn.add(buildDBconnPanel(), BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout ( new FlowLayout(FlowLayout.CENTER) ); ButCon = new JButton("Check ProI"); ButCon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chk_proi(); }}); buttonPanel.add(ButCon); ButvCon = new JButton("Check PView"); ButvCon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chk_pview(); }}); buttonPanel.add(ButvCon); PdfBut = new JButton("Create PDF"); PdfBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CreatePDF(); }}); buttonPanel.add(PdfBut); ResBut = new JButton("Reset All"); ResBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setResetAll(); }}); buttonPanel.add(ResBut); cancel = new JButton("EXIT"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CancelPressed(); }}); buttonPanel.add(cancel); container.getContentPane().add(dbconn, BorderLayout.NORTH); container.getContentPane().add(buttonPanel, BorderLayout.SOUTH); container.pack(); container.setVisible(true); } public JPanel buildDBconnPanel() { JPanel DBconnGrid = new JPanel(); GridBagLayout gbc0 = new GridBagLayout(); DBconnGrid.setLayout(gbc0); // Input Panel JPanel ObjFilePanel = new JPanel(); JLabel ObjFileLabel = new JLabel ("Enter File To Search For: "); ObjFile = new JTextField("File Name",15); ObjFilePanel.add(ObjFileLabel); ObjFilePanel.add(ObjFile); // Output Panel JPanel DBoutPanel = new JPanel(); DBoutPanel.setLayout( new FlowLayout() ); JPanel resultPanel = new JPanel(); resultPanel.setLayout(new BorderLayout()); JLabel resultLabel = new JLabel ("Output"); resultPanel.add(resultLabel, BorderLayout.NORTH); resultField = new JTextArea(6,34); JScrollPane rtextScroller = new JScrollPane(resultField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); resultPanel.add(rtextScroller, BorderLayout.SOUTH); DBoutPanel.add(resultPanel); // Table Panel JPanel tbl_StgPanel = new JPanel(); tbl_StgPanel.setLayout(new BorderLayout()); DefaultTableModel tableModel = new DefaultTableModel(); table = new JTable(tableModel); JScrollPane scrollPane = new JScrollPane( table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(400, 130)); JLabel tbl_StgLabel = new JLabel(" Index Table: "); tbl_StgPanel.add(tbl_StgLabel, BorderLayout.NORTH); tbl_StgPanel.add(scrollPane, BorderLayout.SOUTH); // Part Number Panel (JLabel(2), JTextArea & JTextField) JPanel PnumJl_StgPanel = new JPanel(); PnumJl_StgPanel.setLayout(new BorderLayout()); JLabel PnumJl_StgLabel = new JLabel(" Part Number: "); PnumJl_StgPanel.add(PnumJl_StgLabel, BorderLayout.NORTH); PlistModel = new DefaultListModel(); PnumJList = new JList(PlistModel); PnumJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); PnumJList.addListSelectionListener(this); PtextScroller = new JScrollPane( PnumJList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); PtextScroller.setPreferredSize(new Dimension(400, 130)); PnumJl_StgPanel.add(PtextScroller); PnumField = new JTextField(14); PnumField.setEditable(false); PnumJl_StgPanel.add(PnumField, BorderLayout.SOUTH); DBconnGrid.add(ObjFilePanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); DBconnGrid.add(DBoutPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); DBconnGrid.add(tbl_StgPanel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); DBconnGrid.add(PnumJl_StgPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); return DBconnGrid; } public void chk_proi() { String url = "jdbc:oracle:thin:@engsrvr:1525:ilnk"; String user = "system"; String pwd = "manager"; obStgGet = getObjFile(); // String query = "select pi.piname,piv.pivrev,piv.pivver,rl.rlname from pdm.PDM_PRODUCTITEM pi, pdm.PDM_BRANCH br, pdm.PDM_PRODUCTITEMVERSION piv, pdm.PDM_PIVRL pivrl, pdm.PDM_RELEASELEVEL rl where pi.piid=br.piid and br.brid=piv.brid and piv.pivid=pivrl.pivid and pivrl.rlid=rl.rlid and pi.piname LIKE '\%"+obStgGet+"\%' order by piname,pivrev,pivver"; // String query = "select pi.piname,piv.pivrev,piv.pivver,rl.rlname from pdm.PDM_PRODUCTITEM pi, pdm.PDM_BRANCH br, pdm.PDM_PRODUCTITEMVERSION piv, pdm.PDM_PIVRL pivrl, pdm.PDM_RELEASELEVEL rl where pi.piid=br.piid and br.brid=piv.brid and piv.pivid=pivrl.pivid and pivrl.rlid=rl.rlid and pi.piname LIKE '"+obStgGet+"' order by piname,pivrev,pivver"; String query = "select pi.piname,piv.pivrev,piv.pivver,rl.rlname from pdm.PDM_PRODUCTITEM pi, pdm.PDM_BRANCH br, pdm.PDM_PRODUCTITEMVERSION piv, pdm.PDM_PIVRL pivrl, pdm.PDM_RELEASELEVEL rl where pi.piid=br.piid and br.brid=piv.brid and piv.pivid=pivrl.pivid and pivrl.rlid=rl.rlid and pi.piname LIKE '%"+obStgGet+"%' order by piname,pivrev,pivver"; Connection connection = null; Statement statement = null; resultField.setText(""); fulV = new Vector(); try { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); } catch (SQLException ex) {;} try { connection = DriverManager.getConnection (url, user, pwd); displayWarning(connection.getWarnings()); connection.clearWarnings(); // Get the DatabaseMetaData object and display // some information about the connection DatabaseMetaData dma = connection.getMetaData (); // Create a Statement object so we can submit // SQL statements to the driver statement = connection.createStatement(); fulV.addElement( htbd ); fulV.addElement( "
" + query + "

" ); // Submit a query, creating a ResultSet object ResultSet resultSet = statement.executeQuery(query); println(""); fulV.addElement( tbls ); //
if (resultSet != null) // Display all columns and rows from the result set displayResultSet (resultSet); else println("The result is empty"); fulV.addElement( tble+"
" ); //
fulV.addElement( bdht ); finText = new String[ fulV.size() ]; fulV.copyInto( finText ); resultSet.close(); // Close the result set } catch (SQLException ex) { // A SQLException was generated. Catch it and display the error information. println ("\n*** SQLException caught ***\n"); while (ex != null) { println("SQLState: " + ex.getSQLState()); println("Message: " + ex.getMessage()); println("Vendor: " + ex.getErrorCode()); ex = ex.getNextException (); println(""); } } catch (java.lang.Exception ex) { ex.printStackTrace(); // Got some other type of exception. } try { statement.close(); // Close the statement connection.close(); // Close the connection } catch (SQLException ex) { // A SQLException was generated. Catch it and display the error information. println ("\n*** SQLException caught ***\n"); while (ex != null) { println("SQLState: " + ex.getSQLState()); println("Message: " + ex.getMessage()); println("Vendor: " + ex.getErrorCode()); ex = ex.getNextException (); println(""); } } catch (java.lang.Exception ex) { ex.printStackTrace(); // Got some other type of exception. } } public void chk_pview() { if ( PnumJList.getModel().getSize() > 0 ) { PnumJList.setModel(PlistModel = new DefaultListModel()); PnumField.setText(""); } obStgGet = getObjFile(); edObjStg = obStgGet + ".drw.d.ed"; // 10000838.drw.d.ed fulV = new Vector(); String[] ncrLocal = rtnNcrStgN(); for (x = 0; x < ncrLocal.length; x++) { CurFileStg = ncrLocal[x]; System.out.println("Scanning File: " + ncrLocal[x]); try { System.out.println("Try: Scanning File: " + ncrLocal[x]); FileInputStream fis = new FileInputStream(ncrLocal[x]); InputStreamReader isr = new InputStreamReader(fis); LineNumberReader reader = new LineNumberReader(isr); lines = new Vector(); String aLine = reader.readLine(); while( aLine != null ) { lines.addElement( aLine ); aLine = reader.readLine(); } fulText = new String[ lines.size() ]; lines.copyInto( fulText ); reader.close(); } catch (IOException exc2) { System.out.println( "FTP Exception: " + ncrLocal[x] + " not found." ); //exc2.printStackTrace(); } if ( lines.size() == 0 ) { System.out.println("File: " + ncrLocal[x] + " has 0 size."); } else { stgRead(); } } } public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (PnumJList.getSelectedIndex() != -1) { entV = new Vector(); PnumSnm = PnumJList.getSelectedValue().toString(); PnumField.setText(""); PnumField.setText(PnumSnm); PnumJList.clearSelection(); finText = new String[ entV.size() ]; entV.copyInto( finText ); } } } public void stgRead( ) { Vector entV = new Vector(); for ( i = 0; i < fulText.length; i++) { if ( fulText[i].indexOf("0 0 Object") > 0 && fulText[i+1].indexOf(".drw") > 0 ) { int spPosRL = fulText[i+25].lastIndexOf("0 0 "); cnRL = fulText[i+25].substring(spPosRL+4,fulText[i+25].length()); System.out.println("Release Level(cnRL):" + cnRL); int spPosIW = cnRL.lastIndexOf("WORK"); int spPosPT = cnRL.lastIndexOf("PROTO"); int spPosPR = cnRL.lastIndexOf("PROD"); int spPosER = cnRL.lastIndexOf("ENG"); int spPosOB = cnRL.lastIndexOf("OBS"); if ( spPosIW >= 0 ) { cnRL = "IW"; } else if ( spPosPT >= 0 ) { cnRL = "PT"; } else if ( spPosPR >= 0 ) { cnRL = "PR"; } else if ( spPosER >= 0 ) { cnRL = "ER"; } else if ( spPosOB >= 0 ) { cnRL = "OB"; } int spPosRev = fulText[i+7].lastIndexOf("0 0 "); cnRev = fulText[i+7].substring(spPosRev+4,fulText[i+7].length()); int spPosVer = fulText[i+10].lastIndexOf("0 0 "); cnVer = fulText[i+10].substring(spPosVer+4,fulText[i+10].length()); // CurFileStg & Full File Path: // \\fs1\Company\LJett\plt2pdf\9D629\7002501.drw.d.ed // 123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789- int pthLn = path_var.length(); int tmpPos1 = CurFileStg.lastIndexOf(".drw.d.ed"); String fofi1 = CurFileStg.substring(pthLn+1,tmpPos1); int tmpPos2 = fofi1.lastIndexOf("\\"); int fofi1Ln = fofi1.length(); // path_var: // \\fs1\Company\LJett\plt2pdf // 123456789-123456789-1234567 // pthLn:27 String foldStg = fofi1.substring(0,tmpPos2); String fileStg = fofi1.substring(tmpPos2+1,fofi1Ln); String rvrStg = fileStg+"_"+cnRev+"."+cnVer+"_"+cnRL+"@"+foldStg; System.out.println("Full File Path: " + CurFileStg); System.out.println("path_var: " + path_var); System.out.println("obStgGet: " + obStgGet); System.out.println("tmpPos1: " + tmpPos1 + " tmpPos2: " + tmpPos2); System.out.println("pthLn: " + pthLn); System.out.println("foldStg: " + foldStg + " fileStg: " + fileStg); System.out.println("rvrStg: " + rvrStg); entV.addElement( rvrStg ); PlistModel.addElement(rvrStg); i = fulText.length; } } finText = new String[ entV.size() ]; entV.copyInto( finText ); } public void CreatePDF () { // 10000830_D.0_PR@5575 PdfStgGet = getPltStg(); int psLn = PdfStgGet.length(); int PosPdf = PdfStgGet.lastIndexOf("@"); // 10000830_D.0_PR String drwStg = PdfStgGet.substring(0,PosPdf); System.out.println("drwStg: " + drwStg); // 10000830_D.0 int PosUnd1 = drwStg.lastIndexOf("_"); String undStg1 = drwStg.substring(0,PosUnd1); System.out.println("undStg1: " + undStg1); // 10000830 int PosUnd2 = undStg1.lastIndexOf("_"); String drwStgF = undStg1.substring(0,PosUnd2); System.out.println("drwStgF: " + drwStgF); // 5575 String foldsh1 = PdfStgGet.substring(PosPdf+1,psLn); System.out.println("foldsh1: " + foldsh1); // \\fs1\Company\LJett\plt2pdf+\\+foldsh1 String PltF1 = path_var+"\\"+foldsh1+"\\"+drwStgF+".plt"; System.out.println("Full Plt File Path: " + PltF1); String s = null; try { // String wordpad = ("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\""); String plt2pdfStg = path_var+"\\plt2pdf_07.bat "+PltF1+" "+path_var+"\\"+drwStg+".pdf"; System.out.println("plt2pdfStg: " + plt2pdfStg); Process p = Runtime.getRuntime().exec("cmd /C "+plt2pdfStg); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((s = stdInput.readLine()) != null) { System.out.println( s ); } } catch (IOException e) { System.out.println("Exception: " ); e.printStackTrace(); System.exit(-1); } } public String[] creTArray(String toArray, String splitChar) { StringTokenizer token1 = new StringTokenizer(toArray,splitChar); int number1 = token1.countTokens(); String[] newArray = new String[ number1 ]; for (int i = 0; i < number1; i++) { String st = token1.nextToken(); newArray[i] = st; } return newArray; } public String getDateStg() { SimpleDateFormat df = new SimpleDateFormat ("MMddyy_HHmmss", Locale.getDefault()); java.util.Date tm = new java.util.Date(); String dtStg = df.format(tm); return dtStg; } public void setResetAll() { resultField.setText(""); PnumField.setText(""); ObjFile.setText(""); DefaultTableModel tableModel = new DefaultTableModel(); table = new JTable(tableModel); if ( PnumJList.getModel().getSize() > 0 ) { PnumJList.setModel(PlistModel = new DefaultListModel()); } } public void print(String str) { if (str != null) resultField.append(str); } public void println(String str) { if (str != null) resultField.append(str); resultField.append("\n"); } public void println(long value) { resultField.append( java.lang.Long.toString(value) ); resultField.append( "\n" ); } public void CancelPressed() { System.exit(0); } public String getPltStg() { getPltStg = PnumField.getText(); return getPltStg; } public String getObjFile() { ofStg = ObjFile.getText(); return ofStg; } public String getdataOut() { dataOutStg = resultField.getText(); return dataOutStg; } public String[] rtnNcrStgN() { ncrV = new Vector(); fulNcr = null; File aFile = new File(path_var); if(!aFile.exists()) System.out.println("Directory: " + path_var + " does not exist"); else if(!aFile.isDirectory()) System.out.println( path_var + " is not a directory" ); else{ PrintDir(0, aFile); System.out.println( "1) Found: " + path_var); } fulNcr = new String[ ncrV.size() ]; ncrV.copyInto( fulNcr ); return fulNcr; } public void PrintDir(int indent, File aFile){ File[] theFiles = aFile.listFiles(); Vector vec = new Vector(); obStgGet = getObjFile(); // 10000838 or 70002501 for(int y=0; y= 0 && spPos2 >= 0 ) { System.out.println( " z: " + z + " 2) Found: " + fileStg); ncrV.addElement( fileStg ); } } } int count = 0; while(count != vec.size()){ PrintDir(indent+1, (File)vec.elementAt(count)); count++; } } //------------------------------------------------------------------- // displayWarning // Displays warnings. Returns true if a warning existed //------------------------------------------------------------------- public boolean displayWarning(SQLWarning sqlWarning) throws SQLException { boolean warning = false; // If a SQLWarning object was given, display the warning messages. // Note that there could be multiple warnings chained together if (sqlWarning != null) { println ("\n *** Warning ***\n"); warning = true; while (sqlWarning != null) { println ("SQLState: " + sqlWarning.getSQLState()); println ("Message: " + sqlWarning.getMessage()); println ("Vendor: " + sqlWarning.getErrorCode()); println(""); sqlWarning = sqlWarning.getNextWarning(); } } return warning; } //------------------------------------------------------------------- // displayResultSet // Displays all columns and rows in the given result set //------------------------------------------------------------------- public void displayResultSet(ResultSet resultSet) throws SQLException { int i; Vector columnNames = new Vector(); Vector data = new Vector(); // Get the ResultSetMetaData. ResultSetMetaData resultSetMetaData = resultSet.getMetaData (); // Get the number of columns in the result set int numCols = resultSetMetaData.getColumnCount (); // Display column headings for (i=1; i<=numCols; i++) { if (i > 1) print("|"); String colname = resultSetMetaData.getColumnName(i); columnNames.addElement( colname ); fulV.addElement( colname ); print(colname); if ( i < numCols ) fulV.addElement( tdes ); // } println(""); // Display data, fetching until end of the result set while (resultSet.next()) { Vector row = new Vector(numCols); fulV.addElement( tdres ); // // Loop through each column, getting the column data and displaying for (i=1; i<=numCols; i++) { tmpStg = resultSet.getString(i); if (i > 1) print("|"); row.addElement( tmpStg ); fulV.addElement( tmpStg ); print(tmpStg); if ( i < numCols ) fulV.addElement( tdes ); // } println(""); data.addElement( row ); // Fetch the next result set row } ( (DefaultTableModel) table.getModel()).setDataVector(data, columnNames); } JFrame container; JTable table; JList PnumJList; JTextArea resultField; JTextField PnumField, ObjFile; JButton ResBut, ButCon, ButvCon, PdfBut, cancel, ok; JScrollPane PtextScroller; ListSelectionModel listSelectionModel; DefaultListModel PlistModel; Vector colNmV, rowsV, ncrV, lines, flines, entV; Vector fulV = new Vector(); int cntr, scntr, nctr, rcntr, h, i, j, k, x, y, z, mtPos = 0; String path_var = "D:\\Dev\\HTML\\datajett.com\\public_html\\Java\\plt2pdf"; // String path_var = "\\\\pview\\Storage"; // String path_var = "\\\\fs1\\Company\\LJett\\plt2pdf"; // String gs_path = "X:\\LJett\\gstools\\"; // String sh_path = "X:\\PDF_Shared"; String url, query, user, pwd, get_url, tmpStg, dtStg, outnmStg, outnmStg2; String dataOutStg, ofStg, fileStg, tfulStg, cnRL, cnRev, cnVer, getPltStg; String obStgGet, edObjStg, PnumSnm, CurFileStg, PltLoc, PdfStgGet; String[] fulNcr = null; String[] finText, fulText; String htbd = "ProI_RVR_05_Output"; String bdht = ""; String tdes = ""; String tbls = "
"; String tble = "
"; String tdres = ""; /* N 13 12 0 0 Object V 14 12 0 0 7002501.drw P 15 1 1 N 16 15 0 0 Branch V 17 15 0 0 main P 18 1 1 N 19 18 0 0 Revision V 20 18 0 0 G P 21 1 1 N 22 21 0 0 Version V 23 21 0 0 0 P 24 1 1 N 25 24 0 0 Type V 26 24 0 0 STANDARD P 27 1 1 N 28 27 0 0 TimeStamp V 29 27 0 0 11-28-2005 9:24:28 P 30 1 1 N 31 30 0 0 FolderPath V 32 30 0 0 Root Folder/LINCOLN FOOD/EQUIPMENT/Low Profile P 33 1 1 N 34 33 0 0 Description V 35 33 0 0 NA P 36 1 1 N 37 36 0 0 Release Level V 38 36 0 0 IN WORK P 39 1 1 N 40 39 0 0 Chkd V 41 39 0 0 IE */ }