package Forms;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JOptionPane;

public class adminnform implements ActionListener {
    JFrame frame;
    JLabel id_lb = new JLabel("ID");
    JLabel fname_lb = new JLabel("First name");
    JLabel lname_lb = new JLabel("Last Name");
    JLabel email_lb = new JLabel("Email");
    JLabel telephone_lb = new JLabel("Telephone");
   // JLabel gender_lb = new JLabel("Gender");

    JTextField id_txf = new JTextField();
    JTextField first_name_txf = new JTextField();
    JTextField last_name_txf = new JTextField();
    JTextField email_txf = new JTextField();
    JTextField telephone_txf = new JTextField();

  //  String[] gender = {"Male", "Female"};
  //  JComboBox<String> genderBox = new JComboBox<>(gender);

    JButton insert_btn = new JButton("Insert");
    JButton read_btn = new JButton("Read");
    JButton update_btn = new JButton("Update");
    JButton delete_btn = new JButton("Delete");

    Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();

    public adminnform() {
        createForm();
    }

    private void createForm() {
        frame = new JFrame();
        frame.setTitle("ADMIN FORM");
        frame.setBounds(350, 100, 400, 350);
        frame.getContentPane().setLayout(null);
        frame.getContentPane().setBackground(Color.LIGHT_GRAY);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(true);
        setLocationAndSize();
    }

    private void setLocationAndSize() {
        id_lb.setBounds(10, 10, 100, 30);
        fname_lb.setBounds(10, 50, 100, 30);
        lname_lb.setBounds(10, 90, 100, 30);
        email_lb.setBounds(10, 130, 100, 30);
        telephone_lb.setBounds(10, 170, 100, 30);
       // gender_lb.setBounds(10, 210, 100, 30);

        id_txf.setBounds(160, 10, 130, 30);
        first_name_txf.setBounds(160, 50, 130, 30);
        last_name_txf.setBounds(160, 90, 130, 30);
        email_txf.setBounds(160, 130, 130, 30);
        telephone_txf.setBounds(160, 170, 130, 30);
       // genderBox.setBounds(160, 210, 130, 30);

        insert_btn.setBounds(10, 250, 85, 30);
        read_btn.setBounds(100, 250, 85, 30);
        update_btn.setBounds(190, 250, 85, 30);
        delete_btn.setBounds(280, 250, 85, 30);
        setFontForAll();
        addComponentsForFrame();
    }

    private void setFontForAll() {
        Font font = new Font("Georgia", Font.BOLD, 18);

        id_lb.setFont(font);
        fname_lb.setFont(font);
        lname_lb.setFont(font);
        email_lb.setFont(font);
        telephone_lb.setFont(font);
      //  gender_lb.setFont(font);

        id_txf.setFont(font);
        first_name_txf.setFont(font);
        last_name_txf.setFont(font);
        email_txf.setFont(font);
        telephone_txf.setFont(font);
       // genderBox.setFont(font);

        Font fonti = new Font("Georgia", Font.ITALIC, 12);

        insert_btn.setFont(fonti);
        read_btn.setFont(fonti);
        update_btn.setFont(fonti);
        delete_btn.setFont(fonti);
    }

    private void addComponentsForFrame() {
        frame.add(id_lb);
        frame.add(fname_lb);
        frame.add(lname_lb);
        frame.add(email_lb);
        frame.add(telephone_lb);
      //  frame.add(gender_lb);

        frame.add(id_txf);
        frame.add(first_name_txf);
        frame.add(last_name_txf);
        frame.add(email_txf);
        frame.add(telephone_txf);
      //  frame.add(genderBox);

        frame.add(insert_btn);
        frame.add(read_btn);
        frame.add(update_btn);
        frame.add(delete_btn);

        insert_btn.addActionListener(this);
insert_btn.addActionListener(new ActionListener() {
			
			public void actionPerformed(java.awt.event.ActionEvent e) {
				try {
					Class.forName("com.mysql.cj.jdbc.Driver");	
					Connection connection=DriverManager
							.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");
					String query="INSERT INTO adminn VALUES(?,?,?,?,?)";
					PreparedStatement pStatement=connection.prepareStatement(query);
					pStatement.setInt(1,Integer.parseInt(id_txf.getText()));
					pStatement.setString(2, first_name_txf.getText());
					pStatement.setString(3, last_name_txf.getText());
					pStatement.setString(4, email_txf.getText());
					pStatement.setString(5, telephone_txf.getText());
				//	pStatement.setString(6, genderBox.getToolkit());
					pStatement.executeUpdate();
					JOptionPane.showMessageDialog(insert_btn, "data inserted well");
					pStatement.close();
					connection.close();	
				} catch (Exception e2) {
					System.out.println(e2.getMessage());
				}
				
			}
		});	
		
        read_btn.addActionListener(this);
        update_btn.addActionListener(this);
        update_btn.addActionListener(new ActionListener() {

        	public void actionPerformed(java.awt.event.ActionEvent e) {
        			try {
        				Class.forName("com.mysql.cj.jdbc.Driver");	
        				Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");
        				String sql="UPDATE adminn SET  first_name=?,last_name=?,email=?, telephone=?  WHERE id=?";
        				PreparedStatement stm=connection.prepareStatement(sql);
        			
        				stm.setString(1, first_name_txf.getText());
        				stm.setString(2, last_name_txf.getText());
        				stm.setString(3, email_txf.getText());
        				stm.setString(4, telephone_txf.getText());
        				stm.setInt(5,Integer.parseInt(id_txf.getText()));
        				
        				
        				stm.executeUpdate();
        				
        				JOptionPane.showMessageDialog(update_btn, "update data!");
        				stm.close();
        				connection.close();	
        			} catch (Exception e2) {
        				System.out.println(e2.getMessage());
        			}
        			
        		}
        				});
        delete_btn.addActionListener(this);
        delete_btn.addActionListener(new ActionListener() {
        	
        	
        	public void actionPerformed(java.awt.event.ActionEvent e) {
        		try {
        			Class.forName("com.mysql.cj.jdbc.Driver");	
        			Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");
        			String sql="DELETE FROM adminn  WHERE id=?";
        			int brtxf=Integer.parseInt(JOptionPane.showInputDialog("Enter id to delete:"));
        			
        			
        			PreparedStatement stm=connection.prepareStatement(sql);
        			
        			
        			
        			
        			stm.setInt(1,brtxf);
        			
        			JOptionPane.showMessageDialog(delete_btn, "recorded out!!!!!!!!!");
        			//Component delete;
        			stm.executeUpdate();
        			stm.close();
        			
        			connection.close();	
        		} catch (Exception e2) {
        			System.out.println(e2.getMessage());
        		}
        		
        	}
        });
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    	
        }
    

    public static void main(String[] args) {
        new adminnform();
    }
}

// genderBox.setBounds(160, 210, 130, 30);_x000D_
package Forms;_x000D_
_x000D_
import java.awt.Color;_x000D_
import java.awt.Dimension;_x000D_
import java.awt.Font;_x000D_
import java.awt.Toolkit;_x000D_
import java.awt.event.ActionEvent;_x000D_
import java.awt.event.ActionListener;_x000D_
import java.sql.Connection;_x000D_
import java.sql.DriverManager;_x000D_
import java.sql.PreparedStatement;_x000D_
_x000D_
import javax.swing.JButton;_x000D_
import javax.swing.JFrame;_x000D_
import javax.swing.JLabel;_x000D_
import javax.swing.JTextField;_x000D_
import javax.swing.JOptionPane;_x000D_
_x000D_
public class adminnform implements ActionListener {_x000D_
    JFrame frame;_x000D_
    JLabel id_lb = new JLabel("ID");_x000D_
    JLabel fname_lb = new JLabel("First name");_x000D_
    JLabel lname_lb = new JLabel("Last Name");_x000D_
    JLabel email_lb = new JLabel("Email");_x000D_
    JLabel telephone_lb = new JLabel("Telephone");_x000D_
   // JLabel gender_lb = new JLabel("Gender");_x000D_
_x000D_
    JTextField id_txf = new JTextField();_x000D_
    JTextField first_name_txf = new JTextField();_x000D_
    JTextField last_name_txf = new JTextField();_x000D_
    JTextField email_txf = new JTextField();_x000D_
    JTextField telephone_txf = new JTextField();_x000D_
_x000D_
  //  String[] gender = {"Male", "Female"};_x000D_
  //  JComboBox<String> genderBox = new JComboBox<>(gender);_x000D_
_x000D_
    JButton insert_btn = new JButton("Insert");_x000D_
    JButton read_btn = new JButton("Read");_x000D_
    JButton update_btn = new JButton("Update");_x000D_
    JButton delete_btn = new JButton("Delete");_x000D_
_x000D_
    Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();_x000D_
_x000D_
    public adminnform() {_x000D_
        createForm();_x000D_
    }_x000D_
_x000D_
    private void createForm() {_x000D_
        frame = new JFrame();_x000D_
        frame.setTitle("ADMIN FORM");_x000D_
        frame.setBounds(350, 100, 400, 350);_x000D_
        frame.getContentPane().setLayout(null);_x000D_
        frame.getContentPane().setBackground(Color.LIGHT_GRAY);_x000D_
        frame.setVisible(true);_x000D_
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);_x000D_
        frame.setResizable(true);_x000D_
        setLocationAndSize();_x000D_
    }_x000D_
_x000D_
    private void setLocationAndSize() {_x000D_
        id_lb.setBounds(10, 10, 100, 30);_x000D_
        fname_lb.setBounds(10, 50, 100, 30);_x000D_
        lname_lb.setBounds(10, 90, 100, 30);_x000D_
        email_lb.setBounds(10, 130, 100, 30);_x000D_
        telephone_lb.setBounds(10, 170, 100, 30);_x000D_
       // gender_lb.setBounds(10, 210, 100, 30);_x000D_
_x000D_
        id_txf.setBounds(160, 10, 130, 30);_x000D_
        first_name_txf.setBounds(160, 50, 130, 30);_x000D_
        last_name_txf.setBounds(160, 90, 130, 30);_x000D_
        email_txf.setBounds(160, 130, 130, 30);_x000D_
        telephone_txf.setBounds(160, 170, 130, 30);_x000D_
       // genderBox.setBounds(160, 210,<SUF>
_x000D_
        insert_btn.setBounds(10, 250, 85, 30);_x000D_
        read_btn.setBounds(100, 250, 85, 30);_x000D_
        update_btn.setBounds(190, 250, 85, 30);_x000D_
        delete_btn.setBounds(280, 250, 85, 30);_x000D_
        setFontForAll();_x000D_
        addComponentsForFrame();_x000D_
    }_x000D_
_x000D_
    private void setFontForAll() {_x000D_
        Font font = new Font("Georgia", Font.BOLD, 18);_x000D_
_x000D_
        id_lb.setFont(font);_x000D_
        fname_lb.setFont(font);_x000D_
        lname_lb.setFont(font);_x000D_
        email_lb.setFont(font);_x000D_
        telephone_lb.setFont(font);_x000D_
      //  gender_lb.setFont(font);_x000D_
_x000D_
        id_txf.setFont(font);_x000D_
        first_name_txf.setFont(font);_x000D_
        last_name_txf.setFont(font);_x000D_
        email_txf.setFont(font);_x000D_
        telephone_txf.setFont(font);_x000D_
       // genderBox.setFont(font);_x000D_
_x000D_
        Font fonti = new Font("Georgia", Font.ITALIC, 12);_x000D_
_x000D_
        insert_btn.setFont(fonti);_x000D_
        read_btn.setFont(fonti);_x000D_
        update_btn.setFont(fonti);_x000D_
        delete_btn.setFont(fonti);_x000D_
    }_x000D_
_x000D_
    private void addComponentsForFrame() {_x000D_
        frame.add(id_lb);_x000D_
        frame.add(fname_lb);_x000D_
        frame.add(lname_lb);_x000D_
        frame.add(email_lb);_x000D_
        frame.add(telephone_lb);_x000D_
      //  frame.add(gender_lb);_x000D_
_x000D_
        frame.add(id_txf);_x000D_
        frame.add(first_name_txf);_x000D_
        frame.add(last_name_txf);_x000D_
        frame.add(email_txf);_x000D_
        frame.add(telephone_txf);_x000D_
      //  frame.add(genderBox);_x000D_
_x000D_
        frame.add(insert_btn);_x000D_
        frame.add(read_btn);_x000D_
        frame.add(update_btn);_x000D_
        frame.add(delete_btn);_x000D_
_x000D_
        insert_btn.addActionListener(this);_x000D_
insert_btn.addActionListener(new ActionListener() {_x000D_
			_x000D_
			public void actionPerformed(java.awt.event.ActionEvent e) {_x000D_
				try {_x000D_
					Class.forName("com.mysql.cj.jdbc.Driver");	_x000D_
					Connection connection=DriverManager_x000D_
							.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");_x000D_
					String query="INSERT INTO adminn VALUES(?,?,?,?,?)";_x000D_
					PreparedStatement pStatement=connection.prepareStatement(query);_x000D_
					pStatement.setInt(1,Integer.parseInt(id_txf.getText()));_x000D_
					pStatement.setString(2, first_name_txf.getText());_x000D_
					pStatement.setString(3, last_name_txf.getText());_x000D_
					pStatement.setString(4, email_txf.getText());_x000D_
					pStatement.setString(5, telephone_txf.getText());_x000D_
				//	pStatement.setString(6, genderBox.getToolkit());_x000D_
					pStatement.executeUpdate();_x000D_
					JOptionPane.showMessageDialog(insert_btn, "data inserted well");_x000D_
					pStatement.close();_x000D_
					connection.close();	_x000D_
				} catch (Exception e2) {_x000D_
					System.out.println(e2.getMessage());_x000D_
				}_x000D_
				_x000D_
			}_x000D_
		});	_x000D_
		_x000D_
        read_btn.addActionListener(this);_x000D_
        update_btn.addActionListener(this);_x000D_
        update_btn.addActionListener(new ActionListener() {_x000D_
_x000D_
        	public void actionPerformed(java.awt.event.ActionEvent e) {_x000D_
        			try {_x000D_
        				Class.forName("com.mysql.cj.jdbc.Driver");	_x000D_
        				Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");_x000D_
        				String sql="UPDATE adminn SET  first_name=?,last_name=?,email=?, telephone=?  WHERE id=?";_x000D_
        				PreparedStatement stm=connection.prepareStatement(sql);_x000D_
        			_x000D_
        				stm.setString(1, first_name_txf.getText());_x000D_
        				stm.setString(2, last_name_txf.getText());_x000D_
        				stm.setString(3, email_txf.getText());_x000D_
        				stm.setString(4, telephone_txf.getText());_x000D_
        				stm.setInt(5,Integer.parseInt(id_txf.getText()));_x000D_
        				_x000D_
        				_x000D_
        				stm.executeUpdate();_x000D_
        				_x000D_
        				JOptionPane.showMessageDialog(update_btn, "update data!");_x000D_
        				stm.close();_x000D_
        				connection.close();	_x000D_
        			} catch (Exception e2) {_x000D_
        				System.out.println(e2.getMessage());_x000D_
        			}_x000D_
        			_x000D_
        		}_x000D_
        				});_x000D_
        delete_btn.addActionListener(this);_x000D_
        delete_btn.addActionListener(new ActionListener() {_x000D_
        	_x000D_
        	_x000D_
        	public void actionPerformed(java.awt.event.ActionEvent e) {_x000D_
        		try {_x000D_
        			Class.forName("com.mysql.cj.jdbc.Driver");	_x000D_
        			Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/revenuesystem","root","");_x000D_
        			String sql="DELETE FROM adminn  WHERE id=?";_x000D_
        			int brtxf=Integer.parseInt(JOptionPane.showInputDialog("Enter id to delete:"));_x000D_
        			_x000D_
        			_x000D_
        			PreparedStatement stm=connection.prepareStatement(sql);_x000D_
        			_x000D_
        			_x000D_
        			_x000D_
        			_x000D_
        			stm.setInt(1,brtxf);_x000D_
        			_x000D_
        			JOptionPane.showMessageDialog(delete_btn, "recorded out!!!!!!!!!");_x000D_
        			//Component delete;_x000D_
        			stm.executeUpdate();_x000D_
        			stm.close();_x000D_
        			_x000D_
        			connection.close();	_x000D_
        		} catch (Exception e2) {_x000D_
        			System.out.println(e2.getMessage());_x000D_
        		}_x000D_
        		_x000D_
        	}_x000D_
        });_x000D_
        _x000D_
    }_x000D_
_x000D_
    @Override_x000D_
    public void actionPerformed(ActionEvent e) {_x000D_
    	_x000D_
        }_x000D_
    _x000D_
_x000D_
    public static void main(String[] args) {_x000D_
        new adminnform();_x000D_
    }_x000D_
}_x000D_
