⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 农业银行ATM对帐查询系统后台类包的源代码,实现了FTP,数据库管理等等功能
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            //:test:System.out.println("DBTableName:"+DBTableName);            sql = sq.getInsertString(DBSourceName,DBTableName,columnTypeName,columnValue);            //增加一条            doRunSQL ins = new doRunSQL();            ins.doRunSQL(DBSourceName,sql);            //取返回信息            errMsg=ins.getErrMsg();            if(errMsg.equals("success")){              //增加成功:              //tv.insertTableRows(columnValue,rowNum);              tv.addTableRows();              JOptionPane.showMessageDialog(this,"已成功增加一行!",                  "成功信息",                  JOptionPane.INFORMATION_MESSAGE);            }            //增加失败:            else{              errMsg=getErrMsg(errMsg);              JOptionPane.showMessageDialog(this,"增加失败:\n"+errMsg,                  "错误提示",                  JOptionPane.ERROR_MESSAGE);            }          }        }        else{          Vector KeyValue = new Vector();          for(int i=0;i<KeyAt.size();i++)            KeyValue.addElement(jTableMode.getValueAt(rowNum,Integer.parseInt(KeyAt.elementAt(i).toString())).toString());          if(jTableMode.isEditing()){            jTableMode.getCellEditor().stopCellEditing();            jTableMode.setRowSelectionInterval(rowNum,rowNum);          }          //修改当前行          int n = JOptionPane.showConfirmDialog(              this ,"确定修改当前行?",              "确认提示",              JOptionPane.YES_NO_OPTION);          if (n == JOptionPane.YES_OPTION) {            //确定修改            //取当前行的值            columnValue.removeAll(columnValue);            for(count=1;count<=colCount;count++){              columnValue.addElement(jTableMode.getValueAt(rowNum,count-1));              //:test:System.out.println(columnValue.elementAt(count-1));            }            //取SQL语句            //:输入:tablename,vector colname,vector columntype,vector columnvalue            //:Vector keyvalue,Vector key,Vector keytype            //:输出:string sql            getSQLstring se = new getSQLstring();            //:test:System.out.println("seDBTableName:"+DBTableName);            //:test:System.out.println("seKey:"+Key);            //:test:System.out.println("seKeyType:"+KeyType);            //:test:System.out.println("KeyValue:"+KeyValue);            sql = se.getUpdateString(DBSourceName,DBTableName,columnNames,columnTypeName,columnValue,KeyValue,Key,KeyType);            //修改当前行            doRunSQL upd = new doRunSQL();            upd.doRunSQL(DBSourceName,sql);            //取得返回信息            errMsg=upd.getErrMsg();            if(errMsg.equals("success")){              //编辑成功:              //tv.updateTableRows(rowNum,columnValue);              JOptionPane.showMessageDialog(this,"已成功修改当前行!",                  "成功信息",                  JOptionPane.INFORMATION_MESSAGE);            }            else{              //编辑失败:              errMsg=getErrMsg(errMsg);              JOptionPane.showMessageDialog(this,"修改失败:\n"+errMsg,                  "错误提示",                  JOptionPane.ERROR_MESSAGE);            }          }        }      }    }  }//刷新回滚  public void refreshButton_mouseClicked(){    if(jTableMode!=null)    {      DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent();      DBTableName=node.toString();      //:test:System.out.println("DBTableName="+DBTableName);      //:test:System.out.println(node.toString());      //处理当前点击节点为叶子节点事件      if (node.isLeaf()) {        //取得当前表关键字,唯一        getKey.getKey(DBTableName);        Key=getKey.getKey();        //:test:System.out.println("Key="+Key);        //取得当前节点路径        TreePath pathnode = (TreePath)jTree1.getLeadSelectionPath();        //取得当前数据源        DBSourceName=pathnode.getPathComponent(1).toString();        //:test:System.out.println("DBSourceName="+DBSourceName);        //:test:System.out.println(pathnode.toString());        pubView(pathnode,node,Key,false,"");        //置视点于编辑后的行        if(curRow==-1){          //未选中行,不响应        }        else{          //:test:System.out.println("tableHigh:"+tableHigh);          JViewport jsp=JScroll.getViewport();          jTableMode.setRowSelectionInterval(curRow,curRow);          if(rowTotal!=0)            jsp.setViewPosition(new Point(0,curRow*tableHigh/rowTotal));          jsp.setView(jTableMode);        }      }    }  }//jButtonConExec点击响应  public void jButtonConExec_mouseClicked(){    String SqlStm = "";    int len = pubDBFID.size();    //执行SQL查询语句并显示于Table中    DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent();    DBTableName=node.toString();    //:test:System.out.println("DBTableName="+DBTableName);    //取得当前节点路径    TreePath pathnode = (TreePath)jTree1.getLeadSelectionPath();    //取得当前数据源    DBSourceName=pathnode.getPathComponent(1).toString();    //:test:System.out.println("DBSourceName="+DBSourceName);    //:test:System.out.println(pathnode.toString());    if(len>0){      //取得当前TEXTAREA中的值      pubFValues.removeAllElements();      for(int i=1;i<=len;i++){        if(i==1)pubFValues.addElement(jTextCon1.getText().trim());        if(i==2)pubFValues.addElement(jTextCon2.getText().trim());        if(i==3)pubFValues.addElement(jTextCon3.getText().trim());        if(i==4)pubFValues.addElement(jTextCon4.getText().trim());        if(i==5)pubFValues.addElement(jTextCon5.getText().trim());        if(i==6)pubFValues.addElement(jTextCon6.getText().trim());        if(i==7)pubFValues.addElement(jTextCon7.getText().trim());        if(i==8)pubFValues.addElement(jTextCon8.getText().trim());      }      getSQLstring selectSql=new getSQLstring();      SqlStm = selectSql.getQueryString(DBSourceName,DBTableName,pubFValues,pubDBFName,pubDBFType,pubDBFOperator);      //取得当前表关键字,唯一      getKey.getKey(DBTableName);      Key=getKey.getKey();      //:test:System.out.println("Key="+Key);      SqlStm=SqlStm+" order by "+Key.elementAt(0);      pubView(pathnode,node,Key,true,SqlStm);    }  }//jButtonInpExec点击响应  public void jButtonInpExec_mouseClicked(){    String SqlStm = "";    String judgeQuery = "";    SqlStm = jTextInp.getText().trim();    if(SqlStm.length()>6){      judgeQuery = SqlStm.substring(0,6);      //:test:System.out.println("judgeQuery:"+judgeQuery);      //是否Select查询语句      if(judgeQuery.equalsIgnoreCase("SELECT")){        judgeQuery = SqlStm.substring(6).trim();        judgeQuery = judgeQuery.substring(0,1);        //语法正确        if(judgeQuery.equals("*"))        {          //:test:System.out.println("SqlStmIs:"+SqlStm);          //执行SQL查询语句并显示于Table中          DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent();          DBTableName=node.toString();          //:test:System.out.println("DBTableName="+DBTableName);          //取得当前表关键字,唯一          getKey.getKey(DBTableName);          Key=getKey.getKey();          //:test:System.out.println("Key="+Key);          //取得当前节点路径          TreePath pathnode = (TreePath)jTree1.getLeadSelectionPath();          //取得当前数据源          DBSourceName=pathnode.getPathComponent(1).toString();          //:test:System.out.println("DBSourceName="+DBSourceName);          //:test:System.out.println(pathnode.toString());          pubView(pathnode,node,Key,true,SqlStm);        }        else{          //查询语法错误          JOptionPane.showMessageDialog(this,"请输入正确的SQL语句(Select * from ...)",                                        "查询语句不规范",                                        JOptionPane.WARNING_MESSAGE);        }      }      else{        //查询语法错误        JOptionPane.showMessageDialog(this,"请输入正确的SQL语句(Select * from ...)",                                      "查询语句不规范",                                      JOptionPane.WARNING_MESSAGE);      }    }    else{      //查询语法错误      JOptionPane.showMessageDialog(this,"请输入正确的SQL语句(Select * from ...)",                                    "查询语句不规范",                                    JOptionPane.WARNING_MESSAGE);    }  }//jButtonConClear点击响应  public void jButtonConClear_mouseClicked(){    //重置所有的控件,初始化面板中所有变量    jTextCon1.setText("");    jTextCon2.setText("");    jTextCon3.setText("");    jTextCon4.setText("");    jTextCon5.setText("");    jTextCon6.setText("");    jTextCon7.setText("");    jTextCon8.setText("");  }//jButtonConExec点击响应  public void jButtonInpClear_mouseClicked(){    jTextInp.setText("");  }//调用的公用模块//清空当前所有数据显示,重新载入  public void pubView(TreePath pathnode,DefaultMutableTreeNode node,Vector Key,boolean ok,String sql){  contentPane.removeAll();  contentPane.add(treeView, null);  contentPane.add(navToolBar, null);  contentPane.add(jTabbedPane1,null);  jButtonConExec.setEnabled(true);  jButtonInpExec.setEnabled(true);  //:test:System.out.println("DBSourceName="+DBSourceName);  //:test:System.out.println(pathnode.toString());  tv=null;  //取得TableValues值  tv=new TableValues(pathnode,node,Key,ok,sql);  //取得关键字列  KeyAt=tv.getKeyAt();  //取得关键字类型  KeyType=tv.getKeyType();  //取得所有列名称  columnNames=tv.getAllColumnName();  //取得所有列类型  columnTypeName=tv.getAllColumnTypeName();  //System.out.println("KeyType:"+KeyType);  //System.out.println("KeyAt="+KeyAt);  //定义JTable并设置属性/响应事件  jTableMode = new JTable(tv);  jTableMode.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);  jTableMode.setAutoscrolls(true);  jTableMode.setRowSelectionAllowed(true);   //允许行选择  jTableMode.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  jTableMode.addMouseListener(new java.awt.event.MouseAdapter(){    public void mouseClicked(MouseEvent etm){      jTableMode_mouseClicked();    }  });  //初始化JScrollPane并设置属性  JScroll = new JScrollPane(jTableMode);  JScroll.setAutoscrolls(true);  JScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);  JScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);  JScroll.setViewportBorder(BorderFactory.createEtchedBorder());  JScroll.setBounds(new Rectangle(190, 224, 590, 340));  //显示与清除  if(tv.getColumnCount()==0){    navToolBar.setVisible(false);    JOptionPane.showMessageDialog(this,"查询无结果,检查数据表,连接,主键或查询语句正确否",          "查询无结果",          JOptionPane.ERROR_MESSAGE);  }  contentPane.add(JScroll,null);  JScroll.remove(jTableMode);  jTableMode.removeAll();}//当前TABLE点击响应事件,取得各参数值  public void jTableMode_mouseClicked(){    rowTotal=jTableMode.getRowCount();    curRow=jTableMode.getSelectedRow();    curCol=jTableMode.getSelectedColumn();  }//取得返回信息  public String getErrMsg(String err){    int len=err.length();    int m=0;    String tmpStr="";    while((len-40)>0){      tmpStr=tmpStr+errMsg.substring(m,m+40)+"\n";      m=m+40;      len=len-40;    }    return tmpStr;  }//:处理各BUTTONS响应事件结束//******************************************************************************//******************************************************************************//TableCellEditor的必需函数开始:  public void addCellEditorListener(CellEditorListener listener){    listenerList.add(CellEditorListener.class,listener);  }  public void removeCellEditorListener(CellEditorListener listener){    listenerList.remove(CellEditorListener.class,listener);  }  public void cancelCellEditing(){    CellEditorListener listener;    Object[] listeners=listenerList.getListenerList();    for(int i=0;i<listeners.length;i++){      if(listeners[i]==CellEditorListener.class){        listener=(CellEditorListener)listeners[i+1];        listener.editingCanceled(changeEvent);      }    }  }  public boolean stopCellEditing(){    CellEditorListener listener;    Object[] listeners=listenerList.getListenerList();    for(int i=0;i<listeners.length;i++){      if(listeners[i]==CellEditorListener.class){        listener=(CellEditorListener)listeners[i+1];        listener.editingStopped(changeEvent);      }    }    return true;  }  public boolean isCellEditable(EventObject event){    return true;  }  public boolean shouldSelectCell(EventObject event){    return true;  }  public Object getCellEditorValue(){    return temp.getText();  }  public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column){    temp.setText((String)value);    return temp;  }//:TableCellEditor的必需函数结束//******************************************************************************}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -