Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. private void savePOLines(Supplier supplier, List<PO> lstPO) {
  2. try {
  3. if (supplier != null && lstPO != null) {
  4.  
  5. if (realm.isInTransaction() == false) {
  6. realm.beginTransaction();
  7. }
  8.  
  9. /** Duyệt danh sách PO lấy từ server */
  10. for (PO po : lstPO) {
  11.  
  12. /** Nếu PO line chưa tồn tại DB local thì lưu line */
  13. RealmResults<PONhap> lstPONhap = realm.where(PONhap.class)
  14. .beginGroup()
  15. .equalTo("PONum", String.valueOf(po.getPONum()))
  16. .equalTo("LineID", String.valueOf(po.getLineID()))
  17. .equalTo("ItemCode", po.getItemCode())
  18. .equalTo("DVT", po.getDVT())
  19. .endGroup()
  20. .findAll();
  21. if (lstPONhap == null || lstPONhap.size() == 0) {
  22. String idKey = po.getPONum() + "-" + po.getLineID() + "-" + po.getItemCode();
  23. PONhap poNhap = new PONhap(idKey,
  24. supplier.getMaNCC(),
  25. po.getDVT_Ten() + "",
  26. po.getDVT() + "",
  27. po.getItemCode() + "",
  28. po.getItemName() + "",
  29. po.getLineID() + "",
  30. po.getPONum() + "",
  31. "",
  32. po.getSL_Nhap() + "",
  33. po.getSTT() + "",
  34. "0",
  35. false,
  36. po.getPrice_Imp() + "");
  37.  
  38. realm.copyToRealm(poNhap);
  39. }
  40. }
  41. realm.commitTransaction();
  42.  
  43. /** Đọc lại danh sách PO từ local */
  44. RealmResults<PONhap> lstPOLocal = realm.where(PONhap.class)
  45. .equalTo("MaNCC", supplier.getMaNCC())
  46. .findAll();
  47. if (lstPOLocal != null && lstPOLocal.size() > 0) {
  48.  
  49. if (realm.isInTransaction() == false) {
  50. realm.beginTransaction();
  51. }
  52.  
  53. /** 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 */
  54. for (PONhap poNhap : lstPOLocal) {
  55. Boolean wasExisted = false;
  56. for (PO po : lstPO) {
  57. if (po.getPONum() == Integer.valueOf(poNhap.getPONum()) &&
  58. po.getLineID() == Integer.valueOf(poNhap.getLineID()) &&
  59. po.getItemCode().compareTo(poNhap.getItemCode()) == 0 &&
  60. po.getDVT().compareTo(poNhap.getDVT()) == 0) {
  61. wasExisted = true;
  62. }
  63. }
  64. if (wasExisted == false) {
  65. poNhap.deleteFromRealm();
  66. }
  67. }
  68. realm.commitTransaction();
  69. }
  70.  
  71. }
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement