0% found this document useful (0 votes)
14 views

ATM Simulation

Uploaded by

natasha.sardar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

ATM Simulation

Uploaded by

natasha.sardar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

ATM Simulation

Submitted by

Name Enrollment No.

Natasha Sardar 12020009023127


Ayan Rath 12020009023116
Tapas Paul 12020009023098
Indrayudh Banerjee 12020009023001
Abhishek Das 12020009023039

Introduction:
ATM simulation is a java project that functions similarly to the normal atm. There are two
ways to use this system. One by a user and the other as an admin. As a user, you can
simply deposit, withdraw and check the account balance. Also, you can change your
password. As a system admin, you can control the entire system from adding a user
to adding account and deleting accounts.

SOURCE CODE:
AccountController.java
package com.mycompany.atmmanagementsys;

import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class AccountInfoController implements Initializable {

String UserID;
@FXML
private TextField uid;
@FXML
private TextField uname;
@FXML
private TextArea uaddress;
@FXML
private TextField uemail;
@FXML
private TextField uphone;
@FXML
private TextField ubalance;
@FXML
private Label welcome;
@FXML
private PasswordField oldpass;
@FXML
private PasswordField newpass;
@FXML
private PasswordField passretype;
@FXML
private Label changepassconf;
@FXML
private TextArea quotediscp;
@FXML
private TextArea quotedisai;

public void getUserID(String Id) {


UserID = Id;
}

public void StqPasswordChangePage() {


Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotediscp.setText(quote);
}

public void StqAccountInfo() {


Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotedisai.setText(quote);
}

public void AccountInfo(ActionEvent event) throws SQLException{


Connection con = DbConnection.Connection();
PreparedStatement ps = null;
ResultSet rs = null;
ps = con.prepareStatement("SELECT * FROM users WHERE id = ?");
ps.setString(1, UserID);
rs = ps.executeQuery();
while(rs.next()){
uname.setText(rs.getString("name"));
uaddress.setText(rs.getString("address"));
uemail.setText(rs.getString("email"));
uphone.setText(rs.getString("phone"));
ubalance.setText(rs.getString("balance"));
}
ps.close();
rs.close();
con.close();
}

public void ChangePassword(ActionEvent event) throws SQLException{


if(!newpass.getText().equals(passretype.getText())){
changepassconf.setText("Password Confirmation Failed");
passretype.setText("");
passretype.setStyle("-fx-border-color:red;-fx-border-width:2;-
fx-border-radius:20;-fx-background-radius:22;");
}
else if(oldpass.getText().isEmpty()||
newpass.getText().isEmpty()||passretype.getText().isEmpty()){
changepassconf.setText("Please Fill Up Everything Correctly.");
}
else{
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("UPDATE users SET
password = ? WHERE id ='"+UserID+"' AND password ='"+oldpass.getText()
+"'");
ps.setString(1, newpass.getText());
int i = ps.executeUpdate();
if(i>0){
changepassconf.setText("Password Changed.");
}
else{
changepassconf.setText("Wrong Password.");
}
oldpass.setText("");
newpass.setText("");
passretype.setText("");
passretype.setStyle("-fx-border-color: #3b5998;-fx-border-
width:2;-fx-border-radius:20;-fx-background-radius:22;");
ps.close();
con.close();
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

AddCustomerController.java
package com.mycompany.atmmanagementsys;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class AddCustomerController implements Initializable {
@FXML
private TextField cusid;
@FXML
private TextField cusname;
@FXML
private TextArea cusaddress;
@FXML
private TextField cusphone;
@FXML
private Button add;
@FXML
private Label addcusconfirm;
@FXML
private TextField cusemail;
@FXML
private TextField balance;
@FXML
private Button browse;
private File file;
@FXML
private ImageView userimage;
@FXML
private TextField cuspass;
private FileInputStream fis;
int cf;
@FXML
public void ChooseFile(ActionEvent event) {
FileChooser fc = new FileChooser();
file = fc.showOpenDialog(null);
if (file != null) {
Image image = new Image(file.toURI().toString());
userimage.setImage(image);
cf = 1;
} else {
cf = 0;
}
}
@FXML
public void AddCustomer(ActionEvent event) throws SQLException,
FileNotFoundException {
try {
if (cusid.getText().isEmpty() ||
cuspass.getText().isEmpty() || cusname.getText().isEmpty() ||
cusaddress.getText().isEmpty() || cusemail.getText().isEmpty() ||
cusphone.getText().isEmpty() || balance.getText().isEmpty()) {
addcusconfirm.setText("Please Fill Up Everything");
} else if (Integer.parseInt(balance.getText()) < 500) {
addcusconfirm.setText("Minimum Balance Requirement Is
500 Tk.");
} else {
if (cf != 1) {
addcusconfirm.setText("Please Upload An Image To
Add New Customer");
} else if (cf == 1) {
try {
Connection con = DbConnection.Connection();
PreparedStatement ps =
con.prepareStatement("INSERT INTO users VALUES (?,?,?,?,?,?,?,?)");
ps.setInt(1,
Integer.parseInt(cusid.getText()));
ps.setString(2, cuspass.getText());
ps.setString(3, cusname.getText());
ps.setString(4, cusaddress.getText());
ps.setString(5, cusemail.getText());
ps.setString(6, cusphone.getText());
ps.setString(7, balance.getText());
fis = new FileInputStream(file);
ps.setBinaryStream(8, (InputStream) fis, (int)
file.length());
int i = ps.executeUpdate();
if (i > 0) {
cusid.setText("");
cuspass.setText("");
cusname.setText("");
cusaddress.setText("");
cusemail.setText("");
cusphone.setText("");
balance.setText("");
addcusconfirm.setText("New Customer Added
Successfully");
} else {
addcusconfirm.setText("Failed To Add New
Customer");
}
ps.close();
con.close();
} catch (FileNotFoundException |
NumberFormatException | SQLException e) {
addcusconfirm.setText("Invalid Customer ID or
ID Is Not Available");
}
}
}
} catch (NumberFormatException e) {
addcusconfirm.setText("Please Enter Everything Correctly");
}
cf = 0;
Image image = new Image("/icons/usericon1.png");
userimage.setImage(image);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

OUTPUT:

AdminPageController.java

package com.mycompany.atmmanagementsys;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class AdminPageController implements Initializable {


@FXML
private Button loadcusinfo;
@FXML
private Image image;
@FXML
private TextField num;
@FXML
private TableView<CustomerData> customertable;
@FXML
private TableColumn<CustomerData,Integer> cusid;
@FXML
private TableColumn<CustomerData,String> cusname;
@FXML
private TableColumn<CustomerData,String> cusaddress;
@FXML
private TableColumn<CustomerData,String> cusemail;
@FXML
private TableColumn<CustomerData,String> cusphone;
@FXML
private TableColumn<CustomerData,Integer> cusbalance;
private ObservableList<CustomerData>data;
@FXML
private Label welcome;
String AdminID;
@FXML
private ImageView adminimage;
@FXML
private Label adminname;
@FXML
private Label adminid;
public void GetAdminID(String id) throws SQLException,
FileNotFoundException, IOException{
AdminID = id;
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM
admins WHERE id = ?");
ps.setString(1, id);
ResultSet rs = ps.executeQuery();
while(rs.next()){
adminname.setText(rs.getString("name"));
adminid.setText(rs.getString("id"));
InputStream is = rs.getBinaryStream("image");
OutputStream os = new FileOutputStream(new
File("adminimage.jpeg"));
byte[] content = new byte[1024];
int s = 0;
while((s= is.read(content))!= -1){
os.write(content, 0, s);
}
Image image = new Image("file:adminimage.jpeg");
adminimage.setImage(image);
adminimage.setFitWidth(248);
adminimage.setFitHeight(186);
Circle clip = new Circle(93,93,93);
adminimage.setClip(clip);
}
ps.close();
rs.close();
con.close();
}
@FXML
public void LoadCustomerData(ActionEvent event) throws
SQLException{
Connection con = DbConnection.Connection();
data = FXCollections.observableArrayList();
PreparedStatement ps = con.prepareStatement("SELECT * FROM users");
ResultSet rs = ps.executeQuery();
while(rs.next()){
data.add(new
CustomerData(rs.getInt("id"),rs.getString("name"),rs.getString("address
"),rs.getString("email"),rs.getString("Phone"),rs.getInt("balance")));
}
cusid.setCellValueFactory(new
PropertyValueFactory<CustomerData,Integer>("CustomerId"));
cusname.setCellValueFactory(new
PropertyValueFactory<CustomerData,String>("CustomerName"));
cusaddress.setCellValueFactory(new
PropertyValueFactory<CustomerData,String>("CustomerAddress"));
cusemail.setCellValueFactory(new
PropertyValueFactory<CustomerData,String>("CustomerEmail"));
cusphone.setCellValueFactory(new
PropertyValueFactory<CustomerData,String>("CustomerPhone"));
cusbalance.setCellValueFactory(new
PropertyValueFactory<CustomerData,Integer>("CustomerBalance"));
customertable.setItems(null);
customertable.setItems(data);
ps.close();
rs.close();
con.close();
}
@FXML
public void AddCustomerData(ActionEvent event) throws IOException{
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/AddCustomer.fxml"));
loader.load();
Parent root = loader.getRoot();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/AddCustomer.css");
Image icon = new Image("/icons/adduser.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Add Customer Page");
stage.setScene(scene);
stage.show();
}
@FXML
public void EditCustomerData(ActionEvent event) throws IOException{
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/EditCustomer.fxml"));
loader.load();
Parent root = loader.getRoot();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/EditCustomer.css");
Image icon = new Image("/icons/edituser.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Edit Customer Page");
stage.setScene(scene);
stage.show();

}
@FXML
public void DeleteCustomerData(ActionEvent event) throws
IOException{
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/DeleteCustomer.fxml"))
;
loader.load();
Parent root = loader.getRoot();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/DeleteCustomer.css");
Image icon = new Image("/icons/deleteuser.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Delete Customer Page");
stage.setScene(scene);
stage.show();
}
@FXML
public void ResetPassword(ActionEvent event) throws IOException{
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/PasswordReset.fxml"));
loader.load();
Parent root = loader.getRoot();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/PasswordReset.css");
Image icon = new Image("/icons/Password.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Passwor Reset Page");
stage.setScene(scene);
stage.show();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

BalancePageController.java
package com.mycompany.atmmanagementsys;

import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class BalancePageController implements Initializable {


@FXML
private TextField balanceinfo;
@FXML
private TextArea quotedisbp;
@FXML
private TextField withdrawamount;
@FXML
private TextField depositamount;
String UserID;
String BalanceS;
@FXML
private TextField receiverid;
@FXML
private TextField trnasamount;
@FXML
private PasswordField retypepass;
@FXML
private Label dipositconf;
@FXML
private Label withdrawinfo;
@FXML
private TextArea quotedisdp;
@FXML
private TextArea quotediswp;
@FXML
private Label transferconf;
@FXML
private TextArea quotedisbt;
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public void getUserID(String Id) {
UserID = Id;
}
public void SetBalance(String Bal) {
BalanceS = Bal;
balanceinfo.setText(BalanceS);
Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotedisbp.setText(quote);
}
public void StqDepositPage() {
Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotedisdp.setText(quote);
}
public void StqWithdrawPage() {
Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotediswp.setText(quote);
}
public void StqBalanceTransPage() {
Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotedisbt.setText(quote);
}
@FXML
public void WithdrawMoney(ActionEvent event) throws SQLException {
try {
if (withdrawamount.getText().isEmpty() ||
Integer.parseInt(withdrawamount.getText()) < 0) {
withdrawinfo.setText("Please Enter A Valid Amount");
} else {
Connection con = DbConnection.Connection();
PreparedStatement ps = null;
ResultSet rs = null;
int balance;
ps = con.prepareStatement("SELECT * FROM users WHERE id
= ?");
ps.setString(1, UserID);
rs = ps.executeQuery();
while (rs.next()) {
int NewBalance = (rs.getInt("balance") -
Integer.parseInt(withdrawamount.getText()));
if (NewBalance < 0) {
withdrawinfo.setText("Your Account Balance Is
Low");
} else {
ps = con.prepareStatement("UPDATE users SET
balance =? WHERE id = '" + UserID + "'");
ps.setInt(1, NewBalance);
ps.executeUpdate();
withdrawinfo.setText("Transaction
Successfull");
}
}
ps.close();
rs.close();
con.close();
}
} catch (NumberFormatException | SQLException e) {
withdrawinfo.setText("Invalid Database Or Number Format");
}
withdrawamount.setText("");
}
@FXML
public void Deposit(ActionEvent event) throws SQLException {
try {
if (depositamount.getText().isEmpty() ||
Integer.parseInt(depositamount.getText()) < 0) {
dipositconf.setText("Please Enter A Valid Amount");
} else {
Connection con = DbConnection.Connection();
PreparedStatement ps = null;
ResultSet rs = null;
ps = con.prepareStatement("SELECT * FROM users WHERE id
= ?");
ps.setString(1, UserID);
rs = ps.executeQuery();
while (rs.next()) {
int NewBalance = (rs.getInt("balance") +
Integer.parseInt(depositamount.getText()));
ps = con.prepareStatement("UPDATE users SET balance
=? WHERE id = '" + UserID + "'");
ps.setInt(1, NewBalance);
ps.executeUpdate();
}
dipositconf.setText("Cash Has Been Deposited");
ps.close();
rs.close();
con.close();
}
} catch (NumberFormatException | SQLException e) {
dipositconf.setText("Invalid Database Or Number Format");
}
depositamount.setText("");
}
@FXML
public void TransferMoney(ActionEvent event) throws SQLException {
try {
if (trnasamount.getText().isEmpty() ||
Integer.parseInt(trnasamount.getText()) < 0 ||
retypepass.getText().isEmpty() || receiverid.getText().isEmpty()) {
transferconf.setText("Please Fill Up Everything
Correctly.");
} else {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("SELECT *
FROM users WHERE id = ? and password = ? ");
receiverid.setStyle("-fx-border-color: #e65100;-fx-
border-width:2;-fx-border-radius:20;-fx-background-radius:22;");
ps.setString(1, UserID);
ps.setString(2, retypepass.getText());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
retypepass.setStyle("-fx-border-color: #e65100;-fx-
border-width:2;-fx-border-radius:20;-fx-background-radius:22;");
int newbalance = rs.getInt("balance") -
Integer.parseInt(trnasamount.getText());
if (newbalance < 0) {
transferconf.setText("You Dont Have Enough
Money To Transfer.");
trnasamount.setText("");
ps.close();
rs.close();
} else {
ps = con.prepareStatement("UPDATE users SET
balance = ? WHERE id = '" + UserID + "' ");
ps.setInt(1, newbalance);
ps.executeUpdate();
ps.close();
rs.close();
PreparedStatement ps2 =
con.prepareStatement("SELECT * FROM users WHERE id =?");
ps2.setString(1, receiverid.getText());
ResultSet rs2 = ps2.executeQuery();
if (rs2.next()) {
int receivernewbalance =
rs2.getInt("balance") + Integer.parseInt(trnasamount.getText());
ps2 = con.prepareStatement("UPDATE users
SET balance =? WHERE id = '" + receiverid.getText() + "' ");
ps2.setInt(1, receivernewbalance);
ps2.executeUpdate();
ps2.close();
rs2.close();
transferconf.setText("Transfer
Successfull");
receiverid.setText("");
trnasamount.setText("");
retypepass.setText("");
} else {
transferconf.setText("UserID Invalid ,
Failed To Transfer.");
receiverid.setText("");
receiverid.setStyle("-fx-border-color:red;-
fx-border-width:2;-fx-border-radius:20;-fx-background-radius:22;");
PreparedStatement pss =
con.prepareStatement("SELECT * FROM users WHERE id =?");
pss.setString(1, UserID);
ResultSet rss = pss.executeQuery();
while (rss.next()) {
int addbalance = rss.getInt("Balance")
+ Integer.parseInt(trnasamount.getText());
pss = con.prepareStatement("UPDATE
users SET balance = ? WHERE id = '" + UserID + "'");
pss.setInt(1, addbalance);
pss.executeUpdate();
}
pss.close();
rss.close();
}
}
} else {
transferconf.setText("Wrong Password Transaction
Failed.");
retypepass.setStyle("-fx-border-color:red;-fx-
border-width:2;-fx-border-radius:20;-fx-background-radius:22;");
}
con.close();
}
} catch (NumberFormatException | SQLException e) {
transferconf.setText("Invalid Database Or Number Format");
}
}
}

CustomerData.java
package com.mycompany.atmmanagementsys;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class CustomerData {


private final IntegerProperty CustomerId;
private final StringProperty CustomerName;
private final StringProperty CustomerAddress;
private final StringProperty CustomerEmail;
private final StringProperty CustomerPhone;
private final IntegerProperty CustomerBalance;
public CustomerData(Integer CustomerId,String CustomerName,String
CustomerAddress,String CustomerEmail,String CustomerPhone,Integer
CustomerBalance) {
this.CustomerId = new SimpleIntegerProperty(CustomerId);
this.CustomerName = new SimpleStringProperty(CustomerName);
this.CustomerAddress = new
SimpleStringProperty(CustomerAddress);
this.CustomerEmail = new SimpleStringProperty(CustomerEmail);
this.CustomerPhone = new SimpleStringProperty(CustomerPhone);
this.CustomerBalance = new
SimpleIntegerProperty(CustomerBalance);
}
public Integer getCustomerId(){
return CustomerId.get();
}
public String getCustomerName(){
return CustomerName.get();
}
public String getCustomerAddress(){
return CustomerAddress.get();
}
public String getCustomerEmail(){
return CustomerEmail.get();
}
public String getCustomerPhone(){
return CustomerPhone.get();
}
public Integer getCustomerBalance(){
return CustomerBalance.get();
}
}

Dbconnection.java
package com.mycompany.atmmanagementsys;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DbConnection {


public static Connection Connection() throws SQLException{
try {
Class.forName("org.sqlite.JDBC");
Connection conn =
DriverManager.getConnection("jdbc:sqlite:atmmanagementsys.sqlite");
return conn;
} catch (ClassNotFoundException ex) {

Logger.getLogger(DbConnection.class.getName()).log(Level.SEVERE, null,
ex);
return null;
}
}
}

EditCustomerController.java
package com.mycompany.atmmanagementsys;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class EditCustomerController implements Initializable {


@FXML
private ImageView cusimage;
@FXML
private TextField cusid;
@FXML
private Button load;
@FXML
private TextField cusname;
@FXML
private TextArea cusaddress;
@FXML
private TextField cusemail;
@FXML
private TextField cusphone;
@FXML
private TextField cusbalance;
private File file;
private FileInputStream fis;
@FXML
private Button chosepic;
int cp;
@FXML
private Label confirmation;
@FXML
public void ChoosePicture(ActionEvent event) {
FileChooser fc = new FileChooser();
file = fc.showOpenDialog(null);
if (file != null) {
Image image = new Image(file.toURI().toString());
cusimage.setImage(image);
cp = 1;

} else {
cp = 0;
}
}
@FXML
public void LoadCusInfo(ActionEvent event) throws SQLException,
FileNotFoundException, IOException {
try {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("Select * from
users where id = ?");
ps.setInt(1, Integer.parseInt(cusid.getText()));
ResultSet rs = ps.executeQuery();
if (rs.next()) {
cusname.setText(rs.getString("name"));
cusaddress.setText(rs.getString("address"));
cusemail.setText(rs.getString("email"));
cusphone.setText(rs.getString("phone"));

cusbalance.setText(Integer.toString(rs.getInt("balance")));
InputStream img = rs.getBinaryStream("image");
OutputStream os = new FileOutputStream(new
File("userimage.jpg"));
byte[] content = new byte[1024];
int s = 0;
while ((s = img.read(content)) != -1) {
os.write(content, 0, s);
}
Image image = new Image("file:userimage.jpg");
cusimage.setImage(image);
} else {
confirmation.setText("Customer Not Found");
}
ps.close();
rs.close();
con.close();
} catch (IOException | NumberFormatException | SQLException e)
{
confirmation.setText("Please Enter The ID Correctly");
}
}
public void EditCusInfo(ActionEvent event) throws SQLException,
FileNotFoundException {
try {
if (cusname.getText().isEmpty() ||
cusaddress.getText().isEmpty() || cusemail.getText().isEmpty() ||
cusphone.getText().isEmpty() || cusbalance.getText().isEmpty()) {
confirmation.setText("Please Fill Up Everything");
} else if (Integer.parseInt(cusbalance.getText()) < 0) {
confirmation.setText("Please Enter The Balance
Correctly");
} else {
if (cp == 1) {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("UPDATE
users SET name = ? ,address = ? ,email = ? , phone = ?,balance = ? ,
image = ? WHERE id = '" + Integer.parseInt(cusid.getText()) + "'");
ps.setString(1, cusname.getText());
ps.setString(2, cusaddress.getText());
ps.setString(3, cusemail.getText());
ps.setString(4, cusphone.getText());
ps.setInt(5,
Integer.parseInt(cusbalance.getText()));
fis = new FileInputStream(file);
ps.setBinaryStream(6, (InputStream) fis, (int)
file.length());
int i = ps.executeUpdate();
if (i > 0) {
cusname.setText("");
cusaddress.setText("");
cusemail.setText("");
cusphone.setText("");
cusbalance.setText("");
Image image = new
Image("/icons/usericon3.png");
cusimage.setImage(image);
confirmation.setText("Customer Info Updated
Successfully");
} else {
confirmation.setText("Failed To Update Customer
Info");
}
cp = 0;
ps.close();
con.close();
} else if (cp != 1) {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("UPDATE
users SET name = ? ,address = ? ,email = ? , phone = ?,balance = ?
WHERE id = '" + Integer.parseInt(cusid.getText()) + "'");
ps.setString(1, cusname.getText());
ps.setString(2, cusaddress.getText());
ps.setString(3, cusemail.getText());
ps.setString(4, cusphone.getText());
ps.setInt(5,
Integer.parseInt(cusbalance.getText()));
int j = ps.executeUpdate();
if (j > 0) {
cusname.setText("");
cusaddress.setText("");
cusemail.setText("");
cusphone.setText("");
cusbalance.setText("");
Image image = new
Image("/icons/usericon3.png");
cusimage.setImage(image);
confirmation.setText("Customer Info Updated
Successfully");
} else {
confirmation.setText("Failed To Update Customer
Info");
}
ps.close();
con.close();
}
}
} catch (FileNotFoundException | NumberFormatException |
SQLException e) {
confirmation.setText("Please Enter Everything Correctly");
}
}
public void DeleteCusInfo(ActionEvent event) throws SQLException {
try {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("DELETE FROM
users WHERE id = ?");
ps.setInt(1, Integer.parseInt(cusid.getText()));
int k = ps.executeUpdate();
if (k > 0) {
cusname.setText("");
cusaddress.setText("");
cusemail.setText("");
cusphone.setText("");
cusbalance.setText("");
Image image = new Image("/icons/usericon4.png");
cusimage.setImage(image);
confirmation.setText("Successfully Removed The
Customer");
} else {
confirmation.setText("Failed To Find The Customer");
}
ps.close();
con.close();
} catch (NumberFormatException | SQLException e) {
confirmation.setText("Please Enter The ID Correctly");
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

FXMLController.java
package com.mycompany.atmmanagementsys;

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

public class FXMLController implements Initializable {


@FXML
private TextField useridtf;
@FXML
private Label mssg;
@FXML
private Button loginb;
@FXML
private PasswordField passwordtf;
@FXML
private RadioButton userrb;
@FXML
private ToggleGroup UserOrAdmin;
@FXML
private RadioButton adminrb;
@FXML
private void Login(ActionEvent event) throws SQLException,
IOException {
Connection con = DbConnection.Connection();
PreparedStatement ps = null;
ResultSet rs = null;
if (userrb.isSelected()) {
ps = con.prepareStatement("SELECT * FROM users WHERE id = ?
and password = ?");
ps.setString(1, useridtf.getText());
ps.setString(2, passwordtf.getText());
rs = ps.executeQuery();
if (rs.next()) {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/UserPage.fxml"));
loader.load();
Parent root = loader.getRoot();
UserPageController upc = loader.getController();
upc.GetUserID(useridtf.getText(),
rs.getString("name"));
stage.setTitle("User Page");
Image icon = new Image("/icons/UserPage.png");
stage.getIcons().add(icon);
stage.setMinHeight(710);
stage.setMinWidth(1345);
stage.setMaximized(true);
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/UserPage.css");
stage.setScene(scene);
stage.show();
mssg.setText("");
Media someSound = new
Media(getClass().getResource("/audio/UserLogin.mp3").toString());
MediaPlayer mp = new MediaPlayer(someSound);
mp.play();
}
else{
mssg.setText("Wrong Password Or UserID");
}
ps.close();
rs.close();
} else if (adminrb.isSelected()) {
ps = con.prepareStatement("SELECT * FROM admins WHERE id
= ? and password = ?");
ps.setString(1, useridtf.getText());
ps.setString(2, passwordtf.getText());
rs = ps.executeQuery();
if(rs.next()) {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/AdminPage.fxml"));
loader.load();
Parent root = loader.getRoot();
AdminPageController apc = loader.getController();
apc.GetAdminID( useridtf.getText());
stage.setTitle("Admin Page");
Image icon = new Image("/icons/UserPage.png");
stage.getIcons().add(icon);
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/AdminPage.css");
stage.setScene(scene);
stage.show();
mssg.setText("");
Media someSound = new
Media(getClass().getResource("/audio/AdminLogin.mp3").toString());
MediaPlayer mp = new MediaPlayer(someSound);
mp.play();
}
else{
mssg.setText("Wrong Password Or AdminID");
}
ps.close();
rs.close();
}
con.close();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

PasswordResetController.java
package com.mycompany.atmmanagementsys;

import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.Random;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class PasswordResetController implements Initializable {


@FXML
private TextField cusid;
@FXML
private TextField cusname;
@FXML
private TextArea confirmation;
String Email, Password;
@FXML
public void PassReset(ActionEvent event) throws SQLException {
Random rnd = new Random();
int pass = 1000 + rnd.nextInt(9000);
Password = "Your New PassWord Is " + Integer.toString(pass);
if (cusid.getText().isEmpty()) {
confirmation.setText("Please Fill Up The ID First");
} else {
try {
Connection con = DbConnection.Connection();
PreparedStatement ps = con.prepareStatement("SELECT *
FROM users Where id = ?");
ps.setInt(1, Integer.parseInt(cusid.getText()));
ResultSet rs = ps.executeQuery();
if (rs.next()) {
Email = rs.getString("email");
PreparedStatement pss =
con.prepareStatement("UPDATE users SET password = ? WHERE id = '" +
cusid.getText() + "'");
pss.setString(1, Integer.toString(pass));
int i = pss.executeUpdate();
if (i > 0) {
confirmation.setText("A New Random Password Is
Set To This ID"+"\n");
final String username = "give your email
address"; // you have to change your security level
final String password = "give your email
password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication
getPasswordAuthentication() {
return new
PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("give
your email address"));

message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(Email));
message.setSubject("Password Reset");
message.setText(Password);
Transport.send(message);
confirmation.appendText("This New Password
Has Been Sent To Customer's Email");
} catch (MessagingException e) {
confirmation.setText("Could Not Send The
Email , Please Contract With An Admin "+"\n"+ "New Password :"+ pass);
}
} else {
confirmation.setText("Failed To Change Password
, Please Check Customer ID");
}
} else {
confirmation.setText("Please Enter A Valid Customer
ID");
}
ps.close();
con.close();
rs.close();
} catch (NumberFormatException | SQLException e) {
confirmation.setText("DataBase Eror Or Invalid Number
Format");
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

OUTPUT:
Quotes.java
package com.mycompany.atmmanagementsys;

import java.util.Random;

public class Quotes {


String quote ;
public String returnQuotes(){
Random ran = new Random();
int num = ran.nextInt(7);
switch (num) {
case 0:
quote = "To accomplish great things, we\n"
+ "must not only act, but also dream,\n"
+ "not only plan, but also believe.\n\n"
+ "- Anatole France";
break;
case 1:
quote = "Victory is always possible for the\n"
+ "person who refuses to\n"
+ "stop fighting.\n\n"
+ "- Napoleon Hill";
break;
case 2:
quote = "Great works are performed\n"
+ "not by strength,\n"
+ "but perseverance.\n\n"
+ "- Dr. Samuel Johnson";
break;
case 3:
quote = "Society may predict, but only you\n"
+ "can determine your destiny.\n\n"
+ "- Clair Oliver";
break;
case 4:
quote = "Success comes from having dreams\n"
+ "that are bigger than your fears.\n\n"
+ "- Terry Litwiller";
break;
case 5:
quote = "Imagination is more important\n"
+ "than knowledge.\n\n"
+ "- Albert Einstein";
break;

case 6:
quote = "Without a goal, discipline is\n"
+ "nothing but self-punishment.\n\n"
+ "- Elanor Roosevelt";
}
return quote;
}
}

UserPageController.java
package com.mycompany.atmmanagementsys;

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class UserPageController implements Initializable {


@FXML
private Label welcome;
@FXML
private TextArea quotedis;
String UserID, UserName;
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public void GetUserID(String id, String Name) throws SQLException {
welcome.setText(Name);
UserID = id;
UserName = Name;
Quotes qt = new Quotes();
String quote = qt.returnQuotes();
quotedis.setText(quote);

}
public void CheckBalance(ActionEvent event) throws SQLException,
IOException {
Connection con = DbConnection.Connection();
PreparedStatement ps = null;
ResultSet rs = null;
ps = con.prepareStatement("SELECT * FROM users WHERE id = ? AND
name = ?");
ps.setString(1, UserID);
ps.setString(2, UserName);
rs = ps.executeQuery();
while (rs.next()) {
String Balance = Integer.toString(rs.getInt("balance"));
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/BalancePage.fxml"));
loader.load();
Parent root = loader.getRoot();
BalancePageController bpc = loader.getController();
bpc.SetBalance(Balance);
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/BalancePage.css");
Image icon = new Image("/icons/DepositPage.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Balance Page");
stage.setScene(scene);
stage.show();
}
ps.close();
rs.close();
}
@FXML
public void Withdraw(ActionEvent event) throws IOException,
SQLException {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/WithdrawPage.fxml"));
loader.load();
Parent root = loader.getRoot();
BalancePageController bpc = loader.getController();
bpc.getUserID(UserID);
bpc.StqWithdrawPage();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/WithdrawPage.css");
Image icon = new Image("/icons/DepositPage.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Withdraw Page");
stage.setScene(scene);
stage.show();
}
@FXML
void DepositMoney(ActionEvent event) throws IOException {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/DepositPage.fxml"));
loader.load();
Parent root = loader.getRoot();
BalancePageController bpc = loader.getController();
bpc.getUserID(UserID);
bpc.StqDepositPage();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/DepositPage.css");
Image icon = new Image("/icons/DepositPage.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Deposite Page");
stage.setScene(scene);
stage.show();
}
@FXML
void AccountInfo(ActionEvent event) throws IOException {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/AccountInfoPage.fxml")
);
loader.load();
Parent root = loader.getRoot();
AccountInfoController aic = loader.getController();
aic.getUserID(UserID);
aic.StqAccountInfo();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/AccountInfoPage.css");
Image icon = new Image("/icons/usericon4.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Account Information");
stage.setScene(scene);
stage.show();
}
@FXML
void ChangePassword(ActionEvent event) throws IOException {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/ChangePassword.fxml"))
;
loader.load();
Parent root = loader.getRoot();
AccountInfoController aic = loader.getController();
aic.getUserID(UserID);
aic.StqPasswordChangePage();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/ChangePassword.css");
Image icon = new Image("/icons/LoginPage.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Change Password");
stage.setScene(scene);
stage.show();
}
@FXML
void BalanceTransfer(ActionEvent event) throws IOException {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();

loader.setLocation(getClass().getResource("/fxml/BalanceTransfer.fxml")
);
loader.load();
Parent root = loader.getRoot();
BalancePageController bpc = loader.getController();
bpc.getUserID(UserID);
bpc.StqBalanceTransPage();
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/BalanceTransfer.css");
Image icon = new Image("/icons/DepositPage.png");
stage.getIcons().add(icon);
stage.setResizable(false);
stage.sizeToScene();
stage.setTitle("Balance Transfer");
stage.setScene(scene);
stage.show();
}
}

You might also like