
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

public class inputadress implements ActionListener {
   private adresspanel fields;
   private JTextArea output;
   private Connection connection;
   public inputadress( Connection c, adresspanel f,JTextArea o )
   {  connection = c;
      fields = f;
      output = o;
   }
   public void actionPerformed( ActionEvent e )
   {
      try {
         Statement statement = connection.createStatement();
          String a[]=new String[20];
                a[0]=fields.alfabe.getText();
                a[1]=fields.sira_no.getText();
                a[2]=fields.channel_no.getText();
                a[3]=fields.müsteri_tipi.getText();
                a[4]=fields.firma_acik_unvani.getText();
                a[5]=fields.fatura_adresi1.getText();
                a[6]=fields.fatura_adresi2.getText();
                a[7]=fields.fatura_adresi3.getText();
                a[8]=fields.telefon_1.getText();
                a[9]=fields.telefon_2.getText();
                a[10]=fields.telefon_3.getText();
                a[11]=fields.yetkili_kisi.getText();
                a[12]=fields.telefon_GSM.getText();
                a[13]=fields.email.getText();
                a[14]=fields.web.getText();
                a[15]=fields.urun_sevk_adresi1.getText();
                a[16]=fields.urun_sevk_adresi2.getText();
                a[17]=fields.banka_hesap1.getText();
                a[18]=fields.banka_hesap2.getText();	
                a[19]=fields.ek_not.getText();
          for(int i=0;i<a.length;i++)
          {
          if(a[i].equals("")) a[i]=" ";
          }
         if ( !fields.telefon_1.getText().equals( "" ) &&
              !fields.firma_acik_unvani.getText().equals( "" ) ) {
            String query = "INSERT INTO REHBER (" +
                "alfabe"+
"channel_no,"+
"müsteri_tipi,"+  
"firma_acik_unvani,"+  
"fatura_adresi1,"+  
"fatura_adresi2,"+  
"fatura_adresi3,"+   
"telefon_1,"+   
"telefon_3,"+   
"yetkili_kisi,"+   
"telefon_GSM,"+  
"email,"+  
"web,"+   
"urun_sevk_adresi1,"+   
"urun_sevk_adresi2,"+   
"banka_hesap1,"+   
"banka_hesap2,"+   
"ek_not)"+
               " VALUES ('";
                query+=a[0]+ "', '";
                query+=a[1]+ "', '" ;
                query+=a[2]+ "', '" ;
                query+=a[3]+ "', '" ;
                query+=a[4]+ "', '" ;
                query+=a[5]+ "', '" ;
                query+=a[6]+ "', '" ;
                query+=a[7]+ "', '" ;
                query+=a[8]+ "', '" ;
                query+=a[9]+ "', '" ;
                query+=a[10]+ "', '" ;
                query+=a[11]+ "', '" ;
                query+=a[12]+ "', '" ;
                query+=a[13]+ "', '" ;
                query+=a[14]+ "', '" ;
                query+=a[15]+ "', '" ;
                query+=a[16]+ "', '" ;
                query+=a[17]+ "', '" ;
                query+=a[18]+ "', '" ;
                query+=a[19]+ "')";
            output.append( "\nSQL query is sent: " +
                           connection.nativeSQL( query )
                           + "\n" );
            int result = statement.executeUpdate( query );

            if ( result == 1 )
               output.append( "\nQuery operated successfully\n" );
            else {
               output.append( "\nQuery gives error\n" );
               fields.alfabe.setText("");
fields.channel_no.setText("");
fields.müsteri_tipi.setText("");
fields.firma_acik_unvani.setText("");
fields.fatura_adresi1.setText("");
fields.fatura_adresi2.setText("");
fields.fatura_adresi3.setText("");
fields.telefon_1.setText("");
fields.telefon_2.setText("");
fields.telefon_3.setText("");
fields.yetkili_kisi.setText("");
fields.email.setText("");
fields.web.setText("");
fields.urun_sevk_adresi1.setText("");
fields.urun_sevk_adresi2.setText("");
fields.banka_hesap1.setText("");
fields.banka_hesap2.setText("");	
fields.ek_not.setText("");
            }
         }
         else
            output.append( "\nat least name and last name should be entered  " +
                           "push the add button\n" );
         statement.close();
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
      }
   }
}

