// Chromis POS - The New Face of Open Source POS // Copyright (c) (c) 2015-2016 // http://www.chromis.co.uk // // This file is part of Chromis POS // // Chromis POS 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 3 of the License, or // (at your option) any later version. // // Chromis POS 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 Chromis POS. If not, see <http://www.gnu.org/licenses/>. // CSV Import Panel added by JDL - February 2013 // Additonal library required - javacsv package uk.chromis.pos.imports; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.swing.JComponent; import javax.swing.JPanel; import uk.chromis.basic.BasicException; import uk.chromis.pos.forms.AppConfig; import uk.chromis.pos.forms.AppLocal; import uk.chromis.pos.forms.AppProperties; import uk.chromis.pos.forms.AppView; import uk.chromis.pos.forms.JPanelView; import uk.chromis.pos.util.AltEncrypter; /** * * */ public class JPanelCSVCleardb extends JPanel implements JPanelView { private Connection con; private Statement stmt; private String SQL; /** * * @param oApp */ public JPanelCSVCleardb(AppView oApp) { this(oApp.getProperties()); } /** * * @param props */ public JPanelCSVCleardb(AppProperties props) { initComponents(); jMessageBox.setText("Performing this action, will clear all " + "data in the CSVImport table. \n\n" + "It is recommended that this is performed before " + "running a new import. \n"); } /** * * @return */ @Override public String getTitle() { return AppLocal.getIntString("Menu.CSVReset"); } /** * * @return */ @Override public JComponent getComponent() { return this; } /** * * @throws BasicException */ @Override public void activate() throws BasicException { // connect to the database String db_user = (AppConfig.getInstance().getProperty("db.user")); String db_url = (AppConfig.getInstance().getProperty("db.URL")); String db_password = (AppConfig.getInstance().getProperty("db.password")); if (db_user != null && db_password != null && db_password.startsWith("crypt:")) { // the password is encrypted AltEncrypter cypher = new AltEncrypter("cypherkey" + db_user); db_password = cypher.decrypt(db_password.substring(6)); } try { con = DriverManager.getConnection(db_url, db_user, db_password); stmt = (Statement) con.createStatement(); } catch (Exception e) { } } /** * * @return */ @Override public boolean deactivate() { try { stmt.close(); con.close(); } catch (Exception e) { } return (true); } /** * 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() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jMessageBox = new javax.swing.JTextPane(); jButtonCleardb = new javax.swing.JButton(); jEnableButton = new eu.hansolo.custom.SteelCheckBox(); setPreferredSize(new java.awt.Dimension(420, 240)); jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pos_messages"); // NOI18N jLabel1.setText(bundle.getString("label.csvresetimport")); // NOI18N jMessageBox.setEditable(false); jMessageBox.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jScrollPane1.setViewportView(jMessageBox); jButtonCleardb.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jButtonCleardb.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uk/chromis/images/sale_delete.png"))); // NOI18N jButtonCleardb.setText(bundle.getString("label.csvclearlog")); // NOI18N jButtonCleardb.setEnabled(false); jButtonCleardb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCleardbActionPerformed(evt); } }); jEnableButton.setText(bundle.getString("label.csvenableclear")); // NOI18N jEnableButton.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { jEnableButtonItemStateChanged(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addGroup(layout.createSequentialGroup() .addComponent(jEnableButton, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButtonCleardb))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButtonCleardb) .addComponent(jEnableButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(32, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void jButtonCleardbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCleardbActionPerformed SQL = "DELETE FROM CSVIMPORT"; try { stmt.executeUpdate(SQL); jMessageBox.setText("Import Data Cleared."); jButtonCleardb.setEnabled(false); jEnableButton.setSelected(false); } catch (Exception e) { } }//GEN-LAST:event_jButtonCleardbActionPerformed private void jEnableButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jEnableButtonItemStateChanged if (jEnableButton.isSelected()) { jButtonCleardb.setEnabled(true); } else { jButtonCleardb.setEnabled(false); } }//GEN-LAST:event_jEnableButtonItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonCleardb; private eu.hansolo.custom.SteelCheckBox jEnableButton; private javax.swing.JLabel jLabel1; private javax.swing.JTextPane jMessageBox; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }