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

public class changeadress implements ActionListener {
   private adresspanel fields;
   private JTextArea output;
   private Connection connection;

   public changeadress( Connection c, adresspanel f, JTextArea o )
   {
      connection = c;
      fields = f;
      output = o;
   }

   public void actionPerformed( ActionEvent e )
   {
try {
         Statement statement = connection.createStatement();
          if ( ! fields.sira_no.getText().equals( "" ) )
         {
          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 ( !a[1].equals( "" ) &&
              !a[0].equals( "" ) )
         {
            String query = "UPDATE REHBER SET ";
            query+="alfabe='";query+=fields.alfabe.getText();
query+="',channel_no ='";query+=fields.channel_no.getText();
query+="',müsteri_tipi ='";query+=fields.müsteri_tipi.getText();
query+="',firma_acik_unvani ='";query+=fields.firma_acik_unvani.getText();
query+="',fatura_adresi1 ='";query+=fields.fatura_adresi1.getText();
query+="',fatura_adresi2 ='";query+=fields.fatura_adresi2.getText();
query+="',fatura_adresi3 ='";query+=fields.fatura_adresi3.getText();
query+="',telefon_1 ='";query+=fields.telefon_1.getText();
query+="',telefon_2 ='";query+=fields.telefon_2.getText();
query+="',telefon_3 ='";query+=fields.telefon_3.getText();
query+="',yetkili_kisi ='";query+=fields.yetkili_kisi.getText();
query+="',telefon_GSM ='";query+=fields.telefon_GSM.getText();
query+="',email ='";query+=fields.email.getText();
query+="',web ='";query+=fields.web.getText();
query+="',urun_sevk_adresi1 ='";query+=fields.urun_sevk_adresi1.getText();
query+="',urun_sevk_adresi2 ='";query+=fields.urun_sevk_adresi2.getText();
query+="',banka_hesap1 ='";query+=fields.banka_hesap1.getText();
query+="',banka_hesap2 ='";query+=fields.banka_hesap2.getText();	
query+="',ek_not ='";query+=fields.ek_not.getText();
query+="' WHERE sira_no=";query+=fields.sira_no.getText();
            output.append( "\nquery is send : " +
            connection.nativeSQL( query ) + "\n" );
            int result = statement.executeUpdate( query );
            if ( result == 1 )
               output.append( "\nrecord is changed successfully \n" );
            else {
               output.append( "\nrecord change process is unsucsessfull\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("");
                 }
            statement.close();
         }   //
         } //end of if
         else
            output.append( "\nsadece mevcut veriler değiştirilebilir.\n" );
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
      }
   }
}

