package de.nplusc.upidgen;


import de.nplusc.izc.tools.IOtools.DBWriter;
import de.nplusc.izc.tools.baseTools.Tools;
import javax.swing.UnsupportedLookAndFeelException;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author LH
 */
public class UpdateAssistant extends javax.swing.JFrame
{

    /**
     * Creates new form UpdateAssistant
     */
    int mode = 1;
    private static DBWriter UPIDb = PublicStorage.dbc;
    public UpdateAssistant()
    {
        initComponents();
        btnMFID.setSelected(true);
        btnMFIDActionPerformed(null);
    }

    public boolean patchDb()
    {
        //INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger')
        
        
        String Query = "";
        if(mode==1)
        {
            
            Query="INSERT INTO mfids VALUES('"+txfMFID_SRC.getText()+"','"+txfDescrip.getText()+"')";
        }
        if(mode==2)
        {
            Query="INSERT INTO psc (MFID,PSC,descrip)VALUES('"+txfMFID_SRC.getText()+"','"+txfPSC.getText()+"','"+txfDescrip.getText()+"')";
        }
        if(mode==3)
        {
            Query="INSERT INTO srcs VALUES("+txfMFID_SRC.getText()+",'"+txfDescrip.getText()+"')";
        }
        Tools.DebugHelperPrint(Query, true, "UpidTK.enableDebug");
        return UPIDb.write(Query);
       // return false;
    }
    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CatBgrp = new javax.swing.ButtonGroup();
        btnMFID = new javax.swing.JRadioButton();
        btnPSC = new javax.swing.JRadioButton();
        btnSRC = new javax.swing.JRadioButton();
        txfMFID_SRC = new javax.swing.JTextField();
        txfPSC = new javax.swing.JTextField();
        txfDescrip = new javax.swing.JTextField();
        lblPSC_SRC = new javax.swing.JLabel();
        lblPSC = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        add = new javax.swing.JButton();
        x1t = new javax.swing.JButton();
        addandX1t = new javax.swing.JButton();

        CatBgrp.add(btnMFID);
        btnMFID.setText("MFID");
        btnMFID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMFIDActionPerformed(evt);
            }
        });

        CatBgrp.add(btnPSC);
        btnPSC.setText("PSC");
        btnPSC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPSCActionPerformed(evt);
            }
        });

        CatBgrp.add(btnSRC);
        btnSRC.setText("SRC");
        btnSRC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSRCActionPerformed(evt);
            }
        });

        lblPSC_SRC.setText("---");

        lblPSC.setText("PSC (bei spezialvermerk \"--\" verwenden)");

        jLabel3.setText("Beschreibung");

        add.setText("Hinzufügen");
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });

        x1t.setText("Abbrechen");
        x1t.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                x1tActionPerformed(evt);
            }
        });

        addandX1t.setText("Hinzufügen und beenden");
        addandX1t.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addandX1tActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txfDescrip, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txfMFID_SRC)
                                        .addComponent(lblPSC_SRC, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblPSC)
                                        .addComponent(txfPSC, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(x1t)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(add)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(addandX1t))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(123, 123, 123)
                                .addComponent(btnMFID)
                                .addGap(18, 18, 18)
                                .addComponent(btnPSC)
                                .addGap(18, 18, 18)
                                .addComponent(btnSRC)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnMFID)
                    .addComponent(btnPSC)
                    .addComponent(btnSRC))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPSC_SRC)
                    .addComponent(lblPSC))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfMFID_SRC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txfPSC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addGap(6, 6, 6)
                .addComponent(txfDescrip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(add)
                    .addComponent(x1t)
                    .addComponent(addandX1t))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSRCActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSRCActionPerformed
    {//GEN-HEADEREND:event_btnSRCActionPerformed
       mode=3;
       txfPSC.setVisible(false);
       lblPSC.setVisible(false);
       lblPSC_SRC.setText("Source-Number");
    }//GEN-LAST:event_btnSRCActionPerformed

    private void btnMFIDActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnMFIDActionPerformed
    {//GEN-HEADEREND:event_btnMFIDActionPerformed
        mode=1;
        txfPSC.setVisible(false);
        lblPSC.setVisible(false);
        lblPSC_SRC.setText("MFID");
    }//GEN-LAST:event_btnMFIDActionPerformed

    private void btnPSCActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnPSCActionPerformed
    {//GEN-HEADEREND:event_btnPSCActionPerformed
        mode=2;
        txfPSC.setVisible(true);
        lblPSC.setVisible(true);
        lblPSC_SRC.setText("MFID");
    }//GEN-LAST:event_btnPSCActionPerformed

    private void addActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addActionPerformed
    {//GEN-HEADEREND:event_addActionPerformed
        patchDb();
        txfDescrip.setText("");
        txfMFID_SRC.setText("");
        txfPSC.setText("");
    }//GEN-LAST:event_addActionPerformed

    private void addandX1tActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addandX1tActionPerformed
    {//GEN-HEADEREND:event_addandX1tActionPerformed
        patchDb();
        this.setVisible(false);
    }//GEN-LAST:event_addandX1tActionPerformed

    private void x1tActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_x1tActionPerformed
    {//GEN-HEADEREND:event_x1tActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_x1tActionPerformed

    /**
     * @param args the command line arguments
     */
    @SuppressWarnings("CallToThreadDumpStack")
    public static void main(String args[])
    {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel.
         * For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex)
        {
            Tools.DebugHelperPrint("Init.fail(\"UpidAssistantInit\")", true, "UpidTK.enableDebug");
            ex.printStackTrace();
        }

        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable()
        {

            public void run()
            {
                new UpdateAssistant().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup CatBgrp;
    private javax.swing.JButton add;
    private javax.swing.JButton addandX1t;
    private javax.swing.JRadioButton btnMFID;
    private javax.swing.JRadioButton btnPSC;
    private javax.swing.JRadioButton btnSRC;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lblPSC;
    private javax.swing.JLabel lblPSC_SRC;
    private javax.swing.JTextField txfDescrip;
    private javax.swing.JTextField txfMFID_SRC;
    private javax.swing.JTextField txfPSC;
    private javax.swing.JButton x1t;
    // End of variables declaration//GEN-END:variables
}
