package Frame; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; 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.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; import ColorAndFont.English; import ColorAndFont.UIColor; import ColorAndFont.buttonTitle; import DataBase.DatabaseManagement; import Method.GetNowTime; import PbuliClass.ImExport; import PbuliClass.JButtonModel; import PbuliClass.JlableModel; import PbuliClass.ShowMessage; import PbuliClass.Systems; import PbuliClass.WarningMessage; import PbuliClass.greateTables; import PbuliClass.jinternalFrame; /**´ËÀàÓÃÓÚÓû§¹ÜÀí*/ @SuppressWarnings("rawtypes") public class UserManage extends jinternalFrame { /** * */ private static final long serialVersionUID = 1L; JPanel northJpanel=null;//±±²¿Ãæ°å JTextField searchFileld=null;//ËÑË÷Îı¾¿ò JButtonModel search=null;//ËÑË÷°´Å¥ JButtonModel shuaxin=null;//ˢа´Å¥ JButtonModel xiu_gai=null;//Ð޸İ´Å¥ JButtonModel delete=null;//ɾ³ý°´Å¥ JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥ JButtonModel outport=null;//µ¼³ö±í¸ñ°´Å¥ JButtonModel add=null; JTable table=null;//ÉêÃ÷±í¸ñ Vector rowData=null; DefaultTableModel tableModel;//±í¸ñÄ£ÐÍ int selectedRow;//±»Ñ¡ÖеÄÐÐ List list; public UserManage() { rowData=new Vector(); String title="Óû§¹ÜÀí"; if(Systems.sys().getLanguage().equals("English")) { title="User Management"; } this.setTitle(title); Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷ rq.setLayout(new BorderLayout()); rq.setBackground(Color.white); rq.add(getNorthJpanel(),BorderLayout.NORTH); rq.add(getGd()); this.setFrameIcon(new ImageIcon("image/icon/usericon.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(getAdd());//Ìí¼Óˢа´Å¥ 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(buttonTitle.getSerch()); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Ö´ÐÐSQL²éѯÓï¾ä»ñµÃµÄ½á¹û¼¯ try { if(getSearchFileld().getText().length()>=1) { String go=getSearchFileld().getText(); String serch="select id,username,superuser,deleteq,alertq,deleteall,justlook,addtime " + "from tb_user where username like'"+go+"%'"; updateSerch(serch); } } catch (Exception er) { er.printStackTrace(); } } }); } 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 getAdd() { if(add==null){ add=new JButtonModel(buttonTitle.getAddOne()); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new add_Dialog(buttonTitle.getAddOne()); } }); } return add; } /**»ñÈ¡Ð޸İ´Å¥µÄ·½·¨*/ 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[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ if(selectedRows.length !=0) { new xiu_gai("ÐÞ¸ÄÓû§ÐÅÏ¢"); } else { ShowMessage.zidingyi("ÇëÑ¡ÖÐÐèÒªÐ޸ĵÄÐУ¡"); } updateTable(); } }); } return xiu_gai; } /**»ñȡɾ³ý°´Å¥µÄ·½·¨*/ 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 row = new Vector<>(); for(int i=0;i columnName=new Vector<>(); for(int i=0;i15) { ShowMessage.zidingyi("Óû§Ãû¹ý³¤£¡"); return; } String pass1= String.valueOf(passwordText.getPassword()); String pass2= String.valueOf(password2Text.getPassword()); if(pass1.equals("")) { ShowMessage.zidingyi("ÃÜÂë²»ÄÜΪ¿Õ£¡"); return; } if(!pass1.equals(pass2)) { ShowMessage.zidingyi("Á½´ÎÊäÈëµÄÃÜÂë²»Ò»ÑùÇë´ÓÐÂÊäÈëÃÜÂ룡"); return; } String justlook="·ñ"; String deletet="·ñ"; String alertt="·ñ"; String deleteallt="·ñ"; String superuser="·Ã¿Í"; if(manage.isSelected()) { superuser="¹ÜÀíÔ±"; } if(fang_ke.isSelected()) { justlook="ÊÇ"; } if(delete.isSelected()) { deletet="ÊÇ"; } if(alert.isSelected()) { alertt="ÊÇ"; } if(alldelete.isSelected()) { deleteallt="ÊÇ"; } insertData(name, pass1, superuser, deletet, alertt, deleteallt, justlook); } }); } return que_ding; } public void insertData(String name,String pass1,String superuser,String deletet,String alertt,String deleteallt,String justlook) { String insertSql="INSERT tb_user VALUES (default,'"+name+ "',PASSWORD('"+pass1+ "'),'"+superuser+ "','"+deletet+ "','"+alertt+ "','"+deleteallt+ "','"+justlook+ "','"+GetNowTime.now()+"')"; int ok=DatabaseManagement.update(insertSql); if(ok==1) { updateTable();//ˢбí¸ñ ShowMessage.zidingyi("Êý¾ÝдÈë³É¹¦£¡"); }else { ShowMessage.zidingyi("дÈëÊý¾Ý¿â³ö´í£¡"); } } /**»ñȡȡÏû°´Å¥µÄ·½·¨*/ 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 getUserNameText() { if(userNameText==null) { userNameText=new JTextField(25); } return userNameText; } /**¹Ø±Õ¶Ô»°¿ò·½·¨*/ public void closeTagDialog() { this.dispose(); } } class xiu_gai extends add_Dialog{ /** * */ private static final long serialVersionUID = 1L; String xu_hao; public xiu_gai(String title) { super(title); // TODO ×Ô¶¯Éú³ÉµÄ¹¹Ô캯Êý´æ¸ù selectedRow=table.getSelectedRow(); xu_hao=(String)table.getValueAt(selectedRow,0); String name=(String)table.getValueAt(selectedRow,1); getUserNameText().setText(name); getUserNameText().setEnabled(false); String row3=(String)table.getValueAt(selectedRow,2); String row4=(String)table.getValueAt(selectedRow,3); String row5=(String)table.getValueAt(selectedRow,4); String row6=(String)table.getValueAt(selectedRow,5); if(row3.equals("¹ÜÀíÔ±")) { manage.setSelected(true); }else { fang_ke.setSelected(true); } if(row4.equals("ÊÇ")) { delete.setSelected(true); } if(row5.equals("ÊÇ")) { alert.setSelected(true); } if(row6.equals("ÊÇ")) { alldelete.setSelected(true); } } /**»ñȡȷ¶¨°´Å¥µÄ·½·¨*/ public JButtonModel getQue_ding() { if(que_ding==null){ que_ding=new JButtonModel("È·¶¨"); que_ding.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String pass1= String.valueOf(passwordText.getPassword()); String pass2= String.valueOf(password2Text.getPassword()); if(pass1.equals("")) { ShowMessage.zidingyi("ÃÜÂë²»ÄÜΪ¿Õ£¡"); return; } if(!pass1.equals(pass2)) { ShowMessage.zidingyi("Á½´ÎÊäÈëµÄÃÜÂë²»Ò»ÑùÇë´ÓÐÂÊäÈëÃÜÂ룡"); return; } String justlook="·ñ"; String deletet="·ñ"; String alertt="·ñ"; String deleteallt="·ñ"; String superuser="·Ã¿Í"; if(manage.isSelected()) { superuser="¹ÜÀíÔ±"; } if(fang_ke.isSelected()) { justlook="ÊÇ"; } if(delete.isSelected()) { deletet="ÊÇ"; } if(alert.isSelected()) { alertt="ÊÇ"; } if(alldelete.isSelected()) { deleteallt="ÊÇ"; } String update="UPDATE tb_user SET password=PASSWORD('"+pass1+ "'),superuser='"+superuser+ "',deleteq='"+deletet+ "',alertq='"+alertt+ "',deleteall='"+deleteallt+ "',justlook='"+justlook+ "'where id='"+xu_hao+"'"; ShowMessage.save(DatabaseManagement.update(update)); updateTable();//ˢбí¸ñ } }); } return que_ding; } } }