-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerController.java
More file actions
53 lines (47 loc) · 1.69 KB
/
Copy pathCustomerController.java
File metadata and controls
53 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package controller;
import java.util.List;
import model.Customer;
import view.CustomerView;
import java.util.List;
public class CustomerController {
private Customer model;
private CustomerView view;
String customerFile = "C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\resources\\CustomerInfo.txt";
// Constructor
public CustomerController(Customer model, CustomerView view) {
this.model = model;
this.view = view;
}
// Load customer data from file
public List<Customer> getCustomerData() {
return Customer.loadCustomerData(customerFile);
}
// Display customer information using the view
// public void displayCustomerInfo(String cus_id) {
// List<Customer> customerList = getCustomerData();
// Customer matchedCustomer = null;
// for (Customer customer : customerList) {
// if (customer.getCus_id().equals(cus_id)) {
// matchedCustomer = customer;
// break;
// }
// }
// if (matchedCustomer != null) {
// view.displayCustomerInfo(matchedCustomer);
// } else {
// view.displayErrorMessage("Customer not found.");
// }
// }
// Update customer information
public void updateCustomerInfo(String cus_id, String phone_no, String address) {
List<Customer> customerList = getCustomerData();
for (Customer customer : customerList) {
if (customer.getCus_id().equals(cus_id)) {
customer.setPhone_no(phone_no);
customer.setAddress(address);
// Logic to save the updated data to the file (not shown here)
break;
}
}
}
}