package Frame; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.Toolkit; 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; import javax.swing.Box; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import ColorAndFont.English; import ColorAndFont.UIColor; import ColorAndFont.buttonTitle; import DataBase.DatabaseManagement; import Method.GetNowTime; import PbuliClass.JButtonModel; import PbuliClass.JlableModel; import PbuliClass.OutButton; import PbuliClass.ShowMessage; import PbuliClass.Systems; import PbuliClass.WarningMessage; import PbuliClass.greateTables; import PbuliClass.jinternalFrame; import tbDataModel.TbDepartment; import tbDataModel_Dell.Dell_Tbicon; import tbDataModel_Dell.Department; import tbDataModel_Dell.Department_Dell; @SuppressWarnings("rawtypes") public class DepartMentManage 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 DepartMentManage() { 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());//Ìí¼Óɾ³ýÈ«²¿°´Å¥ topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getOutport());//Ìí¼Óµ¼³ö°´Å¥ 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(Department_Dell.serch_department(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(Department_Dell.serch_department(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("Ð޸IJ¿ÃÅÐÅÏ¢"); } 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 columnName=new Vector<>(); for(int i=0;i vc ) { Iterator iterator = vc.iterator();//´´½¨µü´úÆ÷ while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ Department depa= iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ Vector row = new Vector(); row.add(depa.getDepart_name()); row.add(depa.getDepart_image()); row.add(depa.getAddtime()); tableModel.addRow(row); } } /**ˢбí¸ñ·½·¨*/ public void updateTable() { if(tableModel !=null) { tableModel.getDataVector().clear(); getRowData(Department_Dell.getDepartment_vector()); gd.validate(); } } /**»ñÈ¡±í¸ñ±»Ñ¡ÖеÄÐз½·¨*/ public int getSelectedRow() { selectedRow=getTable().getSelectedRow(); return selectedRow; } /**ËÑË÷·½·¨*/ public void updateSerch(String serch) { int tagnum=getTable().getRowCount();//±í¸ñ×ÜÐÐÊý if(tagnum !=0 ) { for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ tableModel.removeRow(0); } list = DatabaseManagement.serch(serch);//½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ getRowData(list); } } //ÄÚ²¿Àà class Xiu_gai_Dialog extends JDialog{ /** * */ private static final long serialVersionUID = 1L; JlableModel bumen=new JlableModel(" ²¿ÃÅÃû³Æ£º "); JlableModel iconName=new JlableModel(" Ñ¡Ôñͼ±ê£º"); JButtonModel que_ding=null;//È·¶¨°´Å¥ JButtonModel qu_xiao=null;//È¡Ïû°´Å¥ JPanel mb=null;//ÉêÃ÷Ò»¸öÃæ°å JComboBox comboBox=null;//Ñ¡Ôñ²¿ÃÅÀàÐÍÏÂÀ­¿ò JTextField bumenName;//²¿ÃÅÃû³Æ public Xiu_gai_Dialog(String title) { this.setAlwaysOnTop(true);//×ÜÊÇÖö¥ Toolkit toolkit = getToolkit();// »ñµÃ´°Ì幤¾ß°ü Dimension screenSize = toolkit.getScreenSize();// »ñÈ¡ÆÁÄ»´óС int width = (int) (screenSize.width* 0.5);// ¼ÆËã´°Ìåпí¶È int height = (int) (screenSize.height * 0.5);// ¼ÆËã´°Ìåпí¶È int x0=width-175;//´°Ìåx0×ø±ê int y0=height-175;//´°Ìåy0×ø±ê Container rq=getContentPane(); rq.add(getMb()); this.setTitle(title); this.setBounds(x0, y0, 260,180); this.setVisible(true); } /**»ñȡȷ¶¨°´Å¥µÄ·½·¨*/ public JButtonModel getQue_ding() { if(que_ding==null){ que_ding=new JButtonModel("È·¶¨"); que_ding.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name=getBumenNameText().getText().trim();//²¿ÃÅÃû³Æ String iconAdress="image/targeticon/"+(String)getComboBox().getSelectedItem();//ͼ±êÍêÕûµØÖ· String updateSQL="UPDATE tb_department SET iconadress='"+iconAdress+"'where departmentName='"+name+"'"; if(DatabaseManagement.update(updateSQL) !=0) { Department_Dell.alert_department(name,iconAdress, new ImageIcon(iconAdress)); updateTable();//ˢбí¸ñ ShowMessage.zidingyi("Êý¾ÝÐ޸ijɹ¦£¡"); }else { ShowMessage.zidingyi("дÈëÊý¾Ý¿â³ö´í£¡"); } } }); } return que_ding; } /**»ñȡȡÏû°´Å¥µÄ·½·¨*/ public JButtonModel getQu_xiao() { if(qu_xiao==null){ qu_xiao=new JButtonModel("È¡Ïû"); qu_xiao.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeTagDialog(); } }); } return qu_xiao; } /**»ñÈ¡²¿ÃÅÃû³Æ*/ public JTextField getBumenNameText() { if(bumenName==null) { bumenName=new JTextField(10); bumenName.setText((String)getTable().getValueAt(getSelectedRow(),0)); bumenName.setEnabled(false); } return bumenName; }; /**¹Ø±Õ¶Ô»°¿ò·½·¨*/ public void closeTagDialog() { this.dispose(); } /**»ñÈ¡Ãæ°å*/ public JPanel getMb() { if(mb==null){ mb=new JPanel(); mb.setLayout(new GridLayout(3, 1,5,5)); JPanel mb1=new JPanel(); mb1.setLayout(new FlowLayout(FlowLayout.LEFT)); JPanel mb2=new JPanel(); mb2.setLayout(new FlowLayout(FlowLayout.LEFT)); JPanel mb3=new JPanel(); mb3.setLayout(new FlowLayout(FlowLayout.CENTER)); mb1.add(bumen); mb1.add(getBumenNameText()); mb2.add(iconName); mb2.add(getComboBox()); mb3.add(getQue_ding()); mb3.add(getQu_xiao()); mb.add(mb1); mb.add(mb2); mb.add(mb3); } return mb; } /**»ñȡѡÔñͼ±êÏÂÀ­¿ò*/ public JComboBox getComboBox() { if(comboBox==null) { comboBox=new JComboBox<>();//´´½¨ÏÂÀ­¿ò¶ÔÏó comboBox.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå ComboBoxModel coModel=new DefaultComboBoxModel<>(Dell_Tbicon.icon_name());//ÏÂÀ­ÁбíÄ£ÐÍ comboBox.setModel(coModel); } return comboBox; } } //ÐÂÔöÄÚ²¿Àà class xin_zeng_dialog extends Xiu_gai_Dialog{ /** * */ private static final long serialVersionUID = 1L; public xin_zeng_dialog(String title) { super(title); } /**»ñÈ¡²¿ÃÅÃû³Æ*/ public JTextField getBumenNameText() { if(bumenName==null) { bumenName=new JTextField(10); bumenName.setEnabled(true); } return bumenName; }; /**»ñȡȷ¶¨°´Å¥µÄ·½·¨*/ public JButtonModel getQue_ding() { if(que_ding==null){ que_ding=new JButtonModel("È·¶¨"); que_ding.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name=getBumenNameText().getText().trim();//²¿ÃÅÃû³Æ if(Department_Dell.get_department(name) !=null) { ShowMessage.zidingyi(name+"²¿ÃÅÃû³ÆÒѾ­´æÔÚ²»ÄÜÖØ¸´Ìí¼Ó£¡"); return; } String iconAdress="image/targeticon/"+(String)getComboBox().getSelectedItem();//ͼ±êÍêÕûµØÖ· if(name.equals("")) { ShowMessage.zidingyi("²¿ÃÅÃû³Æ²»ÄÜΪ¿Õ"); return; } String[] ziduan= {"departmentName","iconadress","addtime"}; String[] zhi= {name,iconAdress,GetNowTime.now()}; if(DatabaseManagement.insertfast("tb_department", ziduan, zhi)) { Department_Dell.add_department(name,iconAdress, new ImageIcon(iconAdress)); updateTable();//ˢбí¸ñ ShowMessage.zidingyi("Êý¾ÝдÈë³É¹¦£¡"); }else { ShowMessage.zidingyi("дÈëÊý¾Ý¿â³ö´í£¡"); } } }); } return que_ding; } } }