package ControlLayer;
import java.sql.SQLException;
import DBLayer.DBConnection;
import DBLayer.DBCustomer;
import DBLayer.IFDBCustomer;
import ModelLayer.City;
import ModelLayer.Customer;
import DBLayer.*;
public class ControlCustomer {
//Search for customer
public Customer findCustomer(String cpr)
{
IFDBCustomer dbcustomerObj = new DBCustomer();
return dbcustomerObj.searchCustomer(cpr, true);
}
//update customer
public int updateCustomer(String CPR,String firstName, String lastName, String address,int zipcode, String phoneNumber)
{
IFDBCustomer dbcustomerObj = new DBCustomer();
Customer customer = new Customer(CPR);
IFDBCity dbcityObj=new DBCity();
City city=new City();
//customer.setCPR(CPR);
customer.setFirtName(firstName);
customer.setLastName(lastName);
customer.setAddress(address);
city=dbcityObj.findCity(zipcode,false);
customer.setCity(city);
customer.setPhoneNumber(phoneNumber);
return dbcustomerObj.updateCustomer(customer,CPR);
}
//insert customer
public void insertCustomer(String CPR,String firstName, String lastName, String address,int zipcode, String phoneNumber) throws Exception
{
Customer customerObj = new Customer();
customerObj.setCPR(CPR);
customerObj.setFirtName(firstName);
customerObj.setLastName(lastName);
customerObj.setAddress(address);
customerObj.setCity(new City(zipcode));
customerObj.setPhoneNumber(phoneNumber);
DBConnection.startTransaction();
try{
DBCustomer dbCustomerObj = new DBCustomer();
dbCustomerObj.insertCustomer(customerObj);
}
catch(SQLException ex){
DBConnection.rollbackTransaction();
}
DBConnection.commitTransaction();
}
//public static void main(String[] args) throws Exception{
// ControlCustomer ctr=new ControlCustomer();
// Customer cst= new Customer();
// City city=new City();
// IFDBCustomer custom=new DBCustomer();
// IFDBCity asd=new DBCity();
// ctr.updateCustomer("9209287220","Zlatimir","Zahariev","HaveKrogen 20A",2140,"50374723");
//}
//delete customer
public void deleteCustomer(String cpr){
IFDBCustomer dbcustomerObj = new DBCustomer();
dbcustomerObj.delete(cpr);
}
}