📄 jpanelsql.java
字号:
// Tina POS is a point of sales application designed for touch screens.// Copyright (C) 2005 Adrian Romero Corchado.// http://sourceforge.net/projects/tinapos//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USApackage net.adrianromero.sql;import java.sql.SQLException;import java.util.ArrayList;import javax.swing.JComponent;import javax.swing.JPanel;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import net.adrianromero.data.loader.BaseSentence;import net.adrianromero.basic.BasicException;import net.adrianromero.data.loader.DataResultSet;import net.adrianromero.data.loader.Datas;import net.adrianromero.data.loader.MetaSentence;import net.adrianromero.data.loader.SerializerReadBasic;import net.adrianromero.data.loader.SerializerWriteBasic;import net.adrianromero.data.loader.StaticSentence;import net.adrianromero.tpv.forms.AppView;import net.adrianromero.tpv.forms.JPanelView;import net.adrianromero.tpv.panels.*;public class JPanelSQL extends JPanel implements JPanelView { private ArrayList m_aHistory; private int m_iHistoryIndex; private int m_iResultIndex; private AppView m_App; /** Creates new form JPanelSQL */ public JPanelSQL(AppView oApp) { m_App = oApp; m_aHistory = new ArrayList(); m_aHistory.add(""); m_iHistoryIndex = 0; initComponents(); m_iResultIndex = 0; addResultTab(); DefaultMutableTreeNode rootnode = new DefaultMutableTreeNode("The Java Series"); SQLDatabase db = new SQLDatabase("Tina POS database"); try { BaseSentence sent = new MetaSentence(m_App.getSession(), "getTables" , new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING}) , new SerializerReadBasic(new Datas[] {Datas.STRING, Datas.STRING, Datas.STRING, Datas.STRING, Datas.STRING})); DataResultSet rs = sent.openExec( new Object[] {null, null}); while (rs.next()) { Object[] aTable = (Object[]) rs.getCurrent(); db.addTable((String) aTable[2]); } rs.close(); sent.closeExec(); sent = new MetaSentence(m_App.getSession(), "getColumns" , new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING, Datas.STRING}) , new SerializerReadBasic(new Datas[] {Datas.STRING, Datas.STRING, Datas.STRING, Datas.STRING, Datas.STRING})); rs = sent.openExec(new Object[] {null, null, null}); while (rs.next()) { Object[] aColumn = (Object[]) rs.getCurrent(); SQLTable t = db.getTable((String) aColumn[2]); if (t != null) { t.addColumn((String) aColumn[3]); } } rs.close(); sent.closeExec(); } catch (BasicException e) { // e.printStackTrace(); } DefaultTreeModel tm = new DefaultTreeModel(db); m_jTreeDB.setModel(tm); statusButtons(); } public JComponent getComponent() { return this; } public String getTitle() { return null; } public void activate() throws BasicException { } public boolean deactivate() { return true; } private void addResultTab() { m_iResultIndex++; m_TabbedPane.addTab("Resultset " + Integer.toString(m_iResultIndex), new JPanelSQLResult()); m_TabbedPane.setSelectedIndex(m_TabbedPane.getTabCount() - 1); m_jtabdelete.setEnabled(m_TabbedPane.getTabCount() > 1); } private void statusButtons() { m_jForward.setEnabled(m_iHistoryIndex < m_aHistory.size() - 1); m_jBack.setEnabled(m_iHistoryIndex > 0); } private boolean executeSentence(BaseSentence sent) { return executeSentence(sent, null); } private boolean executeSentence(BaseSentence sent, Object params) { JPanelSQLResult panresult = (JPanelSQLResult) m_TabbedPane.getSelectedComponent(); return panresult.executeSentence(sent, params); } private void insertProductCategories() { try { for( int i = 100; i < 50000; i++) { String sentence = "INSERT INTO m_product_category(" + " m_product_category_id," + " ad_client_id," + " ad_org_id," + " isactive, " + " created, createdby, " + " updated, updatedby, " + " value, " + " name, " + " description, " + " isdefault, plannedmargin, a_asset_group_id) VALUES " + "(" + Integer.toString(i + 1000000) + " ," + " 1000000, " + " 0, " + "'Y', " + " '2007-01-01', 100, " + " '2007-01-01', 100, " + " 'Fictious Category no " + Integer.toString(i) +"' ," + " 'Fictious Category Name no " + Integer.toString(i) +"' ," + " null," + " 'N'," + " 0," + " null)"; System.out.println(i); System.out.println(sentence); BaseSentence sent = new StaticSentence(m_App.getSession(), sentence); sent.exec(); } } catch (BasicException e) { e.printStackTrace(); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); m_jtxtSQL = new javax.swing.JTextArea(); jScrollPane4 = new javax.swing.JScrollPane(); m_jTreeDB = new javax.swing.JTree(); m_jForward = new javax.swing.JButton(); m_jBack = new javax.swing.JButton(); m_TabbedPane = new javax.swing.JTabbedPane(); jButton2 = new javax.swing.JButton(); m_jtabdelete = new javax.swing.JButton(); m_jbegintrans = new javax.swing.JButton(); m_jcommit = new javax.swing.JButton(); m_jrollback = new javax.swing.JButton(); setLayout(null); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/adrianromero/images/launch.png"))); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -