Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void savePOLines(Supplier supplier, List<PO> lstPO) {
- try {
- if (supplier != null && lstPO != null) {
- if (realm.isInTransaction() == false) {
- realm.beginTransaction();
- }
- /** Duyệt danh sách PO lấy từ server */
- for (PO po : lstPO) {
- /** Nếu PO line chưa tồn tại DB local thì lưu line */
- RealmResults<PONhap> lstPONhap = realm.where(PONhap.class)
- .beginGroup()
- .equalTo("PONum", String.valueOf(po.getPONum()))
- .equalTo("LineID", String.valueOf(po.getLineID()))
- .equalTo("ItemCode", po.getItemCode())
- .equalTo("DVT", po.getDVT())
- .endGroup()
- .findAll();
- if (lstPONhap == null || lstPONhap.size() == 0) {
- String idKey = po.getPONum() + "-" + po.getLineID() + "-" + po.getItemCode();
- PONhap poNhap = new PONhap(idKey,
- supplier.getMaNCC(),
- po.getDVT_Ten() + "",
- po.getDVT() + "",
- po.getItemCode() + "",
- po.getItemName() + "",
- po.getLineID() + "",
- po.getPONum() + "",
- "",
- po.getSL_Nhap() + "",
- po.getSTT() + "",
- "0",
- false,
- po.getPrice_Imp() + "");
- realm.copyToRealm(poNhap);
- }
- }
- realm.commitTransaction();
- /** Đọc lại danh sách PO từ local */
- RealmResults<PONhap> lstPOLocal = realm.where(PONhap.class)
- .equalTo("MaNCC", supplier.getMaNCC())
- .findAll();
- if (lstPOLocal != null && lstPOLocal.size() > 0) {
- if (realm.isInTransaction() == false) {
- realm.beginTransaction();
- }
- /** Duyệt danh sách PO nhập từ local nếu không tồn tại trên server thì xoá line local */
- for (PONhap poNhap : lstPOLocal) {
- Boolean wasExisted = false;
- for (PO po : lstPO) {
- if (po.getPONum() == Integer.valueOf(poNhap.getPONum()) &&
- po.getLineID() == Integer.valueOf(poNhap.getLineID()) &&
- po.getItemCode().compareTo(poNhap.getItemCode()) == 0 &&
- po.getDVT().compareTo(poNhap.getDVT()) == 0) {
- wasExisted = true;
- }
- }
- if (wasExisted == false) {
- poNhap.deleteFromRealm();
- }
- }
- realm.commitTransaction();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement