package Frame; import ColorAndFont.English; import ColorAndFont.UIColor; import ColorAndFont.buttonTitle; import Company.Dell_tbCompany; import Company.tb_company; import DataBase.DatabaseManagement; import Method.GetNowTime; import PbuliClass.*; import tbDataModel.TbDepartment; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.Iterator; import java.util.List; import java.util.Vector; public class CompanyController extends jinternalFrame { private static final long serialVersionUID = 1L; JPanel northJpanel=null;//±±²¿Ãæ°å JTextField searchFileld=null;//ËÑË÷Îı¾¿ò JButtonModel search=null;//ËÑË÷°´Å¥ JButtonModel shuaxin=null;//ˢа´Å¥ JButtonModel xin_zeng=null;//ÐÂÔö°´Å¥ JButtonModel xiu_gai=null;//Ð޸İ´Å¥ JButtonModel delete=null;//ɾ³ý°´Å¥ JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥ JTable table=null;//ÉêÃ÷±í¸ñ Vector> rowData=null; DefaultTableModel tableModel;//±í¸ñÄ£ÐÍ int selectedRow;//±»Ñ¡ÖеÄÐÐ List list; TbDepartment departmentInfo=null; Container rq; JScrollPane gd; public CompanyController() { rowData=new Vector>(); String title="¹«Ë¾¹ÜÀí"; if(Systems.sys().getLanguage().equals("English")) { title="Department management"; } this.setTitle(title); rq=getContentPane();//»ñÈ¡ÈÝÆ÷ rq.setLayout(new BorderLayout()); rq.setBackground(UIColor.getNorth_color()); rq.add(getNorthJpanel(),BorderLayout.NORTH); rq.add(getGd()); this.setFrameIcon(new ImageIcon("image/icon/bumenicon.png"));//ÉèÖô°Ìåͼ±ê } //»ñÈ¡±±²¿Ãæ°å public JPanel getNorthJpanel() { if(northJpanel==null) { northJpanel=new JPanel(); Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷ topicBox.add(getSearchFileld());//Ìí¼ÓËÑË÷Îı¾¿ò topicBox.add(Box.createHorizontalStrut(3));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getSearch()); topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getShuaxin()); topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getXin_zeng()); topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getXiu_gai()); topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getDelete());//Ìí¼Óɾ³ý°´Å¥ topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getDeleteAll());//Ìí¼Óɾ³ýÈ«²¿°´Å¥ northJpanel.add(topicBox ); } return northJpanel; } //»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨ public JTextField getSearchFileld() { if(searchFileld==null){ searchFileld=new JTextField(10); searchFileld.addKeyListener(new KeyListener() { //¼üÅÌʼþ¼àÌý public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { int keyCode=e.getKeyCode(); if(keyCode==KeyEvent.VK_ENTER) { getSearch().doClick();//ËÑË÷°´Å¥±»µã»÷ } } public void keyPressed(KeyEvent e) { } }); } return searchFileld; } //»ñÈ¡ËÑË÷°´Å¥µÄ·½·¨ public JButtonModel getSearch() { if(search==null){ search=new JButtonModel("ËÑË÷"); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String serch=getSearchFileld().getText(); if(Dell_tbCompany.get_company(serch)==null) { ShowMessage.zidingyi("ÄãËÑË÷µÄ"+serch+"²»´æÔÚ£¡"); return; } int num=table.getRowCount();//±í¸ñ×ÜÐÐÊý if(num >0 ) { for (int i = 0; i < num; i++) {//ɾ³ýËùÓÐÐÐ tableModel.removeRow(0); } //½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ getRowData(Dell_tbCompany.get_companyList(serch)); } } }); } return search; } //»ñȡˢа´Å¥µÄ·½·¨ public JButtonModel getShuaxin() { if(shuaxin==null){ shuaxin=new JButtonModel(buttonTitle.getRefresh()); shuaxin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateTable(); } }); } return shuaxin; } //»ñÈ¡Ð޸İ´Å¥µÄ·½·¨ public JButtonModel getXiu_gai() { if(xiu_gai==null){ xiu_gai=new JButtonModel(buttonTitle.getAlert()); xiu_gai.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int selectedRow=table.getSelectedRow();//±»Ñ¡ÖÐÐеÄË÷Òý if(selectedRow !=(-1)) { new Xiu_gai_Dialog("Ð޸Ĺ«Ë¾ÐÅÏ¢"); } else { ShowMessage.zidingyi("ÇëÑ¡ÖÐÐèÒªÐ޸ĵÄÐУ¡"); return; } updateTable(); } }); } return xiu_gai; } //ÐÂÔö°´Å¥ public JButtonModel getXin_zeng() { if(xin_zeng==null){ xin_zeng=new JButtonModel(buttonTitle.getAddOne()); xin_zeng.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new xin_zeng_dialog("ÐÂÔö¹«Ë¾¶Ô»°¿ò"); } }); } return xin_zeng; } //»ñȡɾ³ý°´Å¥µÄ·½·¨ public JButtonModel getDelete() { if(delete==null){ delete=new JButtonModel(buttonTitle.getDelete()); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ int ok=0; if(selectedRows.length !=0) { for(int i=0;i list ) { Iterator iterator = list.iterator();//´´½¨µü´úÆ÷ while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ tb_company depa= (tb_company) iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ Vector rowV = new Vector(); rowV.add( depa.getCompanyName());// ¹«Ë¾Ãû³Æ rowV.add(depa.getAddtime());// Ìí¼Óʱ¼ä rowData.add(rowV);// Ïò±í¸ñ¶ÔÏóÌí¼ÓÐÐÊý¾Ý } } //»ñÈ¡¸ñµÄ·½·¨ @SuppressWarnings("serial") public JTable getTable() {//»ñÈ¡table if(table==null) { String[] name1= {"¹«Ë¾Ãû³Æ","Ìí¼Óʱ¼ä"};//±í¸ñÁÐÃû String[] name2= {"Department Name","Add Time"};//±í¸ñÁÐÃû String[] columnNames= English.columnNames(name1, name2); //Ìí¼Ó±í¸ñÁÐÏòÁ¿ Vector columnName=new Vector<>(); for(int i=0;i