๐Ÿ“ฆ 0372hoanghoccode / ko-co

๐Ÿ“„ CMND_BUS.java ยท 60 lines
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
54
55
56
57
58
59
60package BUS;

import java.util.ArrayList;

import DAO.CMND_DAO;

import DTO.CMND;


public class CMND_BUS {
    private final CMND_DAO cmnd_dao = new CMND_DAO();
    private ArrayList<CMND> list_cmnd = new ArrayList<>();


    public CMND_BUS() {
        list_cmnd = cmnd_dao.getList();
    }
    
    public ArrayList<CMND> getList() {
        return list_cmnd;
    }


    public int insertCMND(CMND cmnd) {
        int result = cmnd_dao.insert(cmnd);
        if (result > 0) {
            list_cmnd.add(cmnd);
        }
        return result;
    }

    public int updateCMND(CMND cmnd) {
        int result = cmnd_dao.update(cmnd);
        if (result > 0) {
            for (CMND c : list_cmnd) {
                if (c.getSoCmnd().equals(cmnd.getSoCmnd())) {
                    c.setNoiCap(cmnd.getNoiCap());
                    c.setNgayCap(cmnd.getNgayCap());
                    break;
                }
            }
        }
        return result;
    }

    public int delCMND(String soCmnd) { // del by soCmnd
        int result = cmnd_dao.del(soCmnd);
        if (result > 0) {
            for (CMND c : list_cmnd) {
                if (c.getSoCmnd().equals(soCmnd)) {
                    list_cmnd.remove(c);
                    break;
                }
            }
        }
        return result;
    }

}