package Frame; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; 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.Arrays; 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.JPanel; 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 PbuliClass.JButtonModel; import PbuliClass.JlableModel; import PbuliClass.OutButton; import PbuliClass.ShowMessage; import PbuliClass.Systems; import PbuliClass.WarningMessage; import PbuliClass.greateTables; import PbuliClass.jinternalFrame; import Xunjian.Dell_xunjianset; import fence.Fences; import tbDataModel.TbFence; import tbDataModel_Dell.Dell_Fenceinout; import tbDataModel_Dell.Dell_Polygon; import tbDataModel_Dell.Dell_tbline; @SuppressWarnings("rawtypes") public class FenceTable extends jinternalFrame { /** * */ private static final long serialVersionUID = 1L; JPanel northJpanel=null;//±±²¿Ãæ°å JButtonModel jbut;//°´Å¥Ä£ÐÍ JTextField searchFileld=null;//ËÑË÷Îı¾¿ò JButtonModel search=null;//ËÑË÷°´Å¥ JButtonModel shuaxin=null;//ˢа´Å¥ JButtonModel xiu_gai=null;//Ð޸İ´Å¥ JButtonModel delete=null;//ɾ³ý°´Å¥ JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥ JButtonModel jtb_qiyongfence=null;//ÆôÓÃΧÀ¸ JButtonModel jtb_stopfence=null;//ÔÝÍ£ÆôÓÃΧÀ¸ JScrollPane gd; JTable table=null;//ÉêÃ÷±í¸ñ Vector rowData=null; DefaultTableModel tableModel;//±í¸ñÄ£ÐÍ int selectedRow;//±»Ñ¡ÖеÄÐÐ List list=null;//½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ ; Container rq; public FenceTable() { rowData=new Vector(); String title="ΧÀ¸Áбí"; if(Systems.sys().getLanguage().equals("English")) { title="Fence list"; } this.setTitle(title); rq=getContentPane();//»ñÈ¡ÈÝÆ÷ rq.setLayout(new BorderLayout()); rq.setBackground(Color.white); rq.add(getNorthJpanel(),BorderLayout.NORTH); rq.add(getGd()); this.setFrameIcon(new ImageIcon("image/icon/fenceicon.png"));//ÉèÖô°Ìåͼ±ê this.setBounds(175,0,980,610); } /**»ñÈ¡±±²¿Ãæ°å*/ 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(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getShuaxin());//Ìí¼Óˢа´Å¥ topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getXiu_gai());//Ìí¼ÓÐ޸İ´Å¥ topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getDelete());//Ìí¼Óɾ³ý°´Å¥ topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getDeleteAll());//Ìí¼Óɾ³ýÈ«²¿°´Å¥ topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getOutport());//Ìí¼Óµ¼³ö°´Å¥ topicBox.add(Box.createHorizontalStrut(10)); topicBox.add(getJtb_qiyongfence()); topicBox.add(Box.createHorizontalStrut(10)); topicBox.add(getJtb_jtb_stopfence()); 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(); updateSerch(go); } } 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 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) { String type = (String) getTable().getValueAt(getSelectedRow(), 1); if ("¶¨Î»ÇøÓò".equals(type)){ ShowMessage.zidingyi_24("¶¨Î»ÇøÓòΧÀ¸ÇëÔÚÇøÓòÉèÖÃÐÞ¸Ä"); return; } new Xiu_gai_Dialog("ÐÞ¸ÄΧÀ¸ÐÅÏ¢"); } 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=0;j--){//ÕâÊǹؼü´úÂë tableModel.removeRow(selectedRows[j]);//ɾ³ýÈÎÒⱻѡÖÐÐÐ } table.setModel(tableModel);//¸üбí¸ñÄ£ÐÍ ShowMessage.zidingyi(selectedRows.length+"Ìõ¼Ç¼ɾ³ý³É¹¦£¡"); }else { ShowMessage.zidingyi( "ÇëÑ¡ÖÐÐèҪɾ³ýµÄÐУ¡"); } updateTable(); } }); } return delete; } /**»ñȡȫ²¿É¾³ý°´Å¥µÄ·½·¨*/ public JButtonModel getDeleteAll() { if(deleteAll==null){ deleteAll=new JButtonModel(buttonTitle.getDeleteall()); deleteAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2 WarningMessage warning=new WarningMessage(); warning.setMessage("Ñ¡Ôñɾ³ýÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿É¾³ýÈ·¶¨Âð£¿"); int warn=warning.getwarMss(northJpanel ); int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý if(tagnum!=0 && warn==0) { String deleteSql="TRUNCATE TABLE tb_fence"; String deleteSql2="TRUNCATE TABLE tb_line"; DatabaseManagement.update(deleteSql);// ɾ³ýËùÓмǼ DatabaseManagement.update(deleteSql2);// ɾ³ýËùÓмǼ Fences.delete_all_fence(); Dell_xunjianset.deleteall(); Dell_Fenceinout.delteall(); Dell_Polygon.delete_all(); Dell_tbline.delete_all(); ShowMessage.zidingyi("È«²¿É¾³ý³É¹¦£¡"); } rq.repaint(); } }); } return deleteAll; } /**»ñÈ¡µ¼³ö±í¸ñ°´Å¥µÄ·½·¨*/ public JButtonModel getOutport() { OutButton.setAddtime("addtime"); OutButton.setDataName("tb_fence"); return new OutButton().get_ouotport_button(); } /**»ñÈ¡¹ö¶¯Ãæ°åµÄ·½·¨*/ public JScrollPane getGd() { gd=new JScrollPane(getTable()); gd.getViewport().setBackground(UIColor.getNorth_color()); return gd; } /**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/ public void getRowData(Vector fences) { for(int i=0;i row = new Vector<>(); TbFence info=fences.get(i); row.add(info.getFloor()); row.add(info.getType()); row.add(info.getName()); row.add(info.getBumen()); row.add(info.getShape()); row.add(info.getZuobiao()); row.add(info.getStart()); row.add(info.getStop()); row.add(info.getColor()); String baoliu7=info.getBaoliu7(); if(baoliu7==null || baoliu7.equals("0")) { baoliu7="²»ÆôÓÃ"; }else { baoliu7="ÆôÓÃ"; } row.add(baoliu7); row.add(info.getBaoliu12());//ΧÀ¸µ×²¿¸ß row.add(info.getBaoliu11());//ΧÀ¸¶¥²¿¸ß row.add(info.getAddtime()); tableModel.addRow(row);// Ïò±í¸ñ¶ÔÏóÌí¼ÓÐÐÊý¾Ý } } /**»ñÈ¡±í¸ñµÄ·½·¨*/ @SuppressWarnings("serial") public JTable getTable() { if(table==null) { String[] name1= {"ͼ²ã","ÀàÐÍ","Ãû³Æ","¹ØÁª²¿ÃÅ","ÐÎ×´","ÓÐЧ·¶Î§","ÉúЧʱ¼ä", "ʧЧʱ¼ä","ÑÕÉ«","ÊÇ·ñÆôÓÃ","µ×¸ß","¶¥¸ß","ʱ¼ä"};//±í¸ñÁÐÃû String[] name2= { "Layer", "Fence Type","Fence Name", "Associated Object", "Shape","Valid Range", "Effective Time", "Expiration Time", "Color ","bottom","top","Add Time"};//±í¸ñÁÐÃû String[] columnNames=English.columnNames(name1, name2); //Ìí¼Ó±í¸ñÁÐÏòÁ¿ Vector columnName=new Vector<>(); for(int i=0;i departmentBox=null;//Ñ¡Ôñ²¿ÃÅÀàÐÍÏÂÀ­¿ò JTextField fenceNameText=null;//ΧÀ¸Ãû³ÆÊäÈëÎı¾¿ò JTextField fenceArea=null;//ΧÀ¸ÇøÓò JTextField start_time_text;//ÉúЧʱ¼ä JTextField stop_time_text;//ʧЧʱ¼ä JTextField jt_bottom;//µ×²¿¸ß¶È JTextField jt_top;//¶¥²¿¸ß¶È String id; 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-370;//´°Ìåx0×ø±ê int y0=height-175;//´°Ìåy0×ø±ê Container rq=getContentPane(); rq.add(getMb()); this.setTitle(title); this.setBounds(x0, y0,800,450); this.setVisible(true); } /**»ñȡȷ¶¨°´Å¥µÄ·½·¨*/ public JButtonModel getQue_ding() { if(que_ding==null){ que_ding=new JButtonModel("È·¶¨"); String shape = (String) getTable().getValueAt(getSelectedRow(), 4); String type = (String) getTable().getValueAt(getSelectedRow(), 1); que_ding.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String bumen=(String)departmentBox.getSelectedItem();//¹ØÁª¶ÔÏó String name=fenceNameText.getText().trim();//ΧÀ¸Ãû³Æ String zuobiao=fenceArea.getText().trim();//ΧÀ¸ÇøÓò String regex="[0-9]{1,2}:[0-9]{1,2}:[0-5]{0,1}[0-9]{1}";//ʱ¼äµÄÕýÔò±í´ïʽ String start=start_time_text.getText().trim();//ΧÀ¸ÉúЧ¿ªÊ¼Ê±¼ä String stop=stop_time_text.getText().trim();//ΧÀ¸Ê§Ð§Ê±¼ä String baoliu11=jt_top.getText().trim();//ΧÀ¸¶¥²¿¸ß String baoliu12=jt_bottom.getText().trim();//ΧÀ¸µ×²¿¸ß if("".equals(baoliu11)) { baoliu11="-1"; } if("".equals(baoliu12)) { baoliu12="-1"; } if("".equals(name)) { ShowMessage.zidingyi("ΧÀ¸Ãû³Æ²»ÄÜΪ¿Õ"); return; } if("".equals(zuobiao)) { ShowMessage.zidingyi("ΧÀ¸ÇøÓò²»ÄÜΪ¿Õ"); return; } if(stop.equals(start)) { ShowMessage.zidingyi("ʱ¼ä²»ÄÜÏàµÈ£¡"); return; } if(!start.matches(regex) || !stop.matches(regex)) { ShowMessage.zidingyi("ÇëÊäÈëÕýÈ·µÄʱ¼ä¸ñʽ¡¾Ê±£º·Ö£ºÃë¡¿"); return; } if ("һάÏß".equals(shape)&&"¶¨Î»ÇøÓò".equals(type)){ String[] ziduan={"px","py","lineId"}; String[] split = zuobiao.split(";"); int length = split.length; int[] xj=new int[length]; int[] yj=new int[length]; for (int i = 0; i1&&!("".equals(split1[1]))) { xj[i] = Integer.parseInt(split1[0]); yj[i] = Integer.parseInt(split1[1]); } else{ ShowMessage.zidingyi_24("×ø±ê¸ñʽ²»ÕýÈ·£¡"); return; } } String[] zhi={Arrays.toString(xj),Arrays.toString(yj),name}; boolean tb_line = DatabaseManagement.fast_alert_dbase("tb_line", ziduan, zhi); if (tb_line){ Dell_tbline.alert(xj,xj,name); } } String[] split = zuobiao.split(";"); int length = split.length; String[] split2 = zuobiao.split(","); int length1 = split2.length; if (shape.equals("¾ØÐÎ")&&length1<4){ ShowMessage.zidingyi_24("×ø±ê¸ñʽ²»ÕýÈ·£¡"); return; } for (int i = 0; i getDepartmentBox() { if(departmentBox==null) { departmentBox=new JComboBox<>();//´´½¨ÏÂÀ­¿ò¶ÔÏó departmentBox.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå ComboBoxModel coModel=new DefaultComboBoxModel<>(getDepartMentName());//ÏÂÀ­ÁбíÄ£ÐÍ Object bum=getTable().getValueAt(getSelectedRow(), 3); departmentBox.setModel(coModel); departmentBox.setSelectedItem(bum);//ÉèÖÃĬÈϱ»Ñ¡ÖÐÏî departmentBox.updateUI();//¸üÐÂUI } return departmentBox; } /**»ñÈ¡ËùÓв¿ÃÅÃû³Æ·½·¨*/ public Vector getDepartMentName(){ List list = DatabaseManagement.get_alldate_indatabase("tb_department");//½«²¿ÃÅÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ Iterator iterator = list.iterator();//´´½¨µü´úÆ÷ Vector departMentName= new Vector<>(); departMentName.add("È«²¿¶ÔÏó"); while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ List info = (List) iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ String tagId=(String) info.get(1);//±êÇ©ID departMentName.add(tagId); } return departMentName; } } public JButtonModel getJtb_qiyongfence() { if(jtb_qiyongfence==null) { jtb_qiyongfence=new JButtonModel("ÆôÓÃΧÀ¸"); jtb_qiyongfence.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ if(selectedRows.length !=0) { for(int i=0;i