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

/*
 * frmCustomer.java
 *
 * Created on Dec 20, 2013, 1:42:40 PM
 */

/**
 *
 * @author pooja
 */
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class frmCustomer extends javax.swing.JFrame {

    /** Creates new form frmCustomer */
    public frmCustomer() {
        initComponents();
    }

    /** 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() {

        lblCustId = new javax.swing.JLabel();
        txtCustId = new javax.swing.JTextField();
        btnSubmit = new javax.swing.JButton();
        lblCustName = new javax.swing.JLabel();
        lblCustAdd = new javax.swing.JLabel();
        txtCustName = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtCustAdd = new javax.swing.JTextArea();
        lblCustMob = new javax.swing.JLabel();
        txtCustMob = new javax.swing.JTextField();
        lblCustMail = new javax.swing.JLabel();
        txtCustMail = new javax.swing.JTextField();
        lblProdId = new javax.swing.JLabel();
        txtProdId = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Customer Information");
        setLocationByPlatform(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblCustId.setText("Customer Id :");
        lblCustId.setName("lblCustId"); // NOI18N
        getContentPane().add(lblCustId, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 30, -1, -1));

        txtCustId.setName(""); // NOI18N
        getContentPane().add(txtCustId, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 20, 140, -1));
        txtCustId.getAccessibleContext().setAccessibleName("");

        btnSubmit.setText("SUBMIT");
        btnSubmit.setName("btnSubmit"); // NOI18N
        btnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitActionPerformed(evt);
            }
        });
        getContentPane().add(btnSubmit, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 310, -1, -1));

        lblCustName.setText("Customer Name :");
        lblCustName.setName(""); // NOI18N
        getContentPane().add(lblCustName, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 60, -1, -1));

        lblCustAdd.setText("Address : ");
        lblCustAdd.setName(""); // NOI18N
        getContentPane().add(lblCustAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 100, -1, -1));

        txtCustName.setName(""); // NOI18N
        getContentPane().add(txtCustName, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 60, 140, -1));
        txtCustName.getAccessibleContext().setAccessibleName("");

        txtCustAdd.setColumns(20);
        txtCustAdd.setRows(5);
        jScrollPane1.setViewportView(txtCustAdd);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 100, -1, -1));

        lblCustMob.setText("Mobile : ");
        getContentPane().add(lblCustMob, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 200, -1, -1));

        txtCustMob.setName("txtCustMob"); // NOI18N
        getContentPane().add(txtCustMob, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 200, 140, -1));

        lblCustMail.setText("Email Id : ");
        getContentPane().add(lblCustMail, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 240, -1, -1));
        lblCustMail.getAccessibleContext().setAccessibleName("lblCustMail");

        getContentPane().add(txtCustMail, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 240, 140, -1));

        lblProdId.setText("Product Id : ");
        getContentPane().add(lblProdId, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 280, -1, -1));
        getContentPane().add(txtProdId, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 280, 140, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cro4ky_Yin_Yang1.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 610, 460));

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

    private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
     
                String url="jdbc:odbc:SPC";
		Connection con;
		Statement stmt;
                String sql;
	        sql="insert into db_accessadmin.tblCustomer(CustId,CustName,Address,mobno,EmailId,ProductId) " +
                        "values('"+txtCustId.getText()+"','"+txtCustName.getText()+"','"+txtCustAdd.getText()+"',"+
                        "'"+txtCustMob.getText()+"','"+txtCustMail.getText()+"','"+txtProdId.getText()+"');";

		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e)
		{
			System.err.print("ClassNotFoundException :");
			System.err.print(e.getMessage());
		}

		try
		{
			con=DriverManager.getConnection(url);
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
			JOptionPane.showMessageDialog(null,"Record inserted successfully");
			stmt.close();
			con.close();

		}
		catch(SQLException ex)
		{

                    	JOptionPane.showMessageDialog(null,ex);
			JOptionPane.showMessageDialog(null,"Record not inserted!");
		}  
        
        // TODO add your handling code here:

    }//GEN-LAST:event_btnSubmitActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmCustomer().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSubmit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCustAdd;
    private javax.swing.JLabel lblCustId;
    private javax.swing.JLabel lblCustMail;
    private javax.swing.JLabel lblCustMob;
    private javax.swing.JLabel lblCustName;
    private javax.swing.JLabel lblProdId;
    private javax.swing.JTextArea txtCustAdd;
    private javax.swing.JTextField txtCustId;
    private javax.swing.JTextField txtCustMail;
    private javax.swing.JTextField txtCustMob;
    private javax.swing.JTextField txtCustName;
    private javax.swing.JTextField txtProdId;
    // End of variables declaration//GEN-END:variables

}
