Esempio n. 1
0
  // sheet Ca nhan
  private void MapTableUser(Sheet sheet) throws IOException {
    System.out.println("Table : " + sheet.getSheetName());
    String tableName = sheet.getSheetName();
    if (tableName.equals("Ca nhan")) {
      Iterator<Row> rowIterator = sheet.iterator();
      while (rowIterator.hasNext()) {
        // Get the row object
        account = new Account();
        account.setLoginId(new Date().getTime() + "");
        account.setPassword("0000");
        account.setType(Type.USER);
        account.setLastLoginTime(new Date());
        basicInformation = new BasicInformation();

        contact = new Contact();

        customer = new Customer();
        customer.setOrganizationLoginId(ManagerAuthenticate.getInstance().getOrganizationLoginId());
        String str = new Date().getTime() + "";
        customer.setCode(str);

        Row row = rowIterator.next(); //
        // Every row has columns, get the column iterator and iterate over
        // them
        Iterator<Cell> cellIterator = row.cellIterator();
        if (row.getRowNum() > 0) {
          while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            if (cell.getRow().getRowNum() == 0) {
              System.out.println("---- Column name:" + cell.getStringCellValue());
            } else {
              if (cell.getColumnIndex() == 0) {
                // firstName

                try {
                  System.out.println("STT " + cell.getRowIndex());
                  System.out.println("---- firstName: " + cell.getStringCellValue());
                  if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
                    basicInformation.setFirstName(cell.getStringCellValue());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 1) {
                // lastName
                try {
                  System.out.println("---- lastName: " + cell.getStringCellValue());
                  if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {

                    basicInformation.setLastName(
                        basicInformation.getFirstName() + " " + cell.getStringCellValue());
                    customer.setName(basicInformation.getLastName());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 2) {
                // birthday
                try {

                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- birthday " + cell.getNumericCellValue());
                    basicInformation.setBirthday(String.valueOf(cell.getNumericCellValue()));
                  } else {
                    System.out.println("---- birthday " + cell.getStringCellValue());
                    basicInformation.setBirthday(cell.getStringCellValue().toString());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 3) {
                // gender
                try {
                  System.out.println("---- gender: " + cell.getStringCellValue());
                  if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
                    basicInformation.setGender(cell.getStringCellValue());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 4) {
                // indentityCard

                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- indentityCard: " + cell.getNumericCellValue());
                    basicInformation.setPersonalId(String.valueOf(cell.getNumericCellValue()));
                  } else {
                    System.out.println("---- indentityCard: " + cell.getStringCellValue());
                    basicInformation.setPersonalId((cell.getStringCellValue()));
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // address
              if (cell.getColumnIndex() == 5) {
                System.out.println("---- address: " + cell.getStringCellValue());
                contact.setAddressNumber(cell.getStringCellValue());
              }

              // telephone
              if (cell.getColumnIndex() == 6) {

                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- telephone1: " + cell.getNumericCellValue());
                    String[] phone = String.valueOf(cell.getNumericCellValue()).split(",");
                    contact.setPhone(phone);
                  } else {
                    System.out.println("---- telephone2: " + cell.getStringCellValue());
                    String[] phone = cell.getStringCellValue().split(",");
                    contact.setPhone(phone);
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 7) {
                // mobile
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- mobile1: " + cell.getNumericCellValue());
                    String[] arraymobile = String.valueOf(cell.getNumericCellValue()).split(",");
                    contact.setMobile(arraymobile);

                  } else {
                    System.out.println("---- mobile2: " + cell.getStringCellValue());
                    String[] arraymobile = cell.getStringCellValue().split(",");
                    contact.setMobile(arraymobile);
                  }
                } catch (Exception e) {

                }
              }

              // Email
              if (cell.getColumnIndex() == 8) {
                try {
                  String string = new Date().getTime() + "";
                  int str1 = cell.getStringCellValue().length();
                  String str2 = cell.getStringCellValue();

                  System.out.println("---- Email: " + cell.getStringCellValue());
                  if (str1 > 4) {
                    account.setEmail(str2);
                  } else {
                    account.setEmail(string + "@gmail.com");
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Description
              if (cell.getColumnIndex() == 9) {
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- telephone1: " + cell.getNumericCellValue());
                    String phone = String.valueOf(cell.getNumericCellValue());
                    customer.setDescription(phone);
                  } else {
                    System.out.println("---- telephone2: " + cell.getStringCellValue());
                    customer.setDescription(cell.getStringCellValue());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }

          try {

            Profile profileBasic = new Profile();
            BasicInformation basic = this.basicInformation;
            profileBasic.put(BasicInformation.LAST_NAME, basic.getLastName());
            profileBasic.put(BasicInformation.GENDER, basic.getGender());
            profileBasic.put(BasicInformation.BIRTHDAY, basic.getBirthday());
            profileBasic.put(BasicInformation.PERSONAL_ID, basic.getPersonalId());

            Profiles profiles = new Profiles();
            profiles.setBasic(profileBasic);
            account.setProfiles(profiles);

            List<Contact> contacts = new ArrayList<Contact>();
            contacts.add(contact);
            account.setContacts(contacts);

            Account acc = AccountModelManager.getInstance().saveAccount(account);
            customer.setLoginId(acc.getLoginId());
            customer.setType("Cá nhân");
            if (contact.getMobile().length > 0) {
              customer.setMobile(contact.getMobile()[0]);
            }
            try {
              customer.setBirthDay(new SimpleDateFormat("dd/MM/yyyy").parse(basic.getBirthday()));
            } catch (Exception e) {
            }

            CustomerModelManager.getInstance().saveCustomer(customer);

          } catch (Exception e) {
          }
        }
      }
    }
  }
Esempio n. 2
0
  // sheet DN
  private void MapTableOrganization(Sheet sheet) throws IOException {
    System.out.println("Table : " + sheet.getSheetName());
    String tableName = sheet.getSheetName();
    List<String> list = new ArrayList<String>();
    if (tableName.equals("DN")) {
      Iterator<Row> rowIterator = sheet.iterator();
      while (rowIterator.hasNext()) {
        // Get the row object
        account = new Account();
        account.setLoginId(new Date().getTime() + "");
        account.setPassword("0000");
        account.setType(Type.ORGANIZATION);
        account.setLastLoginTime(new Date());
        organizationBasic = new OrganizationBasic();

        contact = new Contact();

        customer = new Customer();
        customer.setOrganizationLoginId(ManagerAuthenticate.getInstance().getOrganizationLoginId());

        Row row = rowIterator.next(); //
        // Every row has columns, get the column iterator and iterate over
        // them
        Iterator<Cell> cellIterator = row.cellIterator();
        if (row.getRowNum() > 0) {
          while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();

            if (cell.getRow().getRowNum() == 0) {
              System.out.println("---- Column name:" + cell.getStringCellValue());
            } else {
              if (cell.getColumnIndex() == 0) {
                // enterpriseName

                try {
                  System.out.println("STT " + cell.getRowIndex());
                  System.out.println("---- Enterprise Name: " + cell.getStringCellValue());
                  if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
                    customer.setName(cell.getStringCellValue());
                    organizationBasic.setName(cell.getStringCellValue());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              if (cell.getColumnIndex() == 1) {
                // enterpriseCode

                try {

                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- Enterprise code: " + cell.getNumericCellValue());
                    if (list.indexOf(String.valueOf(cell.getNumericCellValue())) > 0) {
                      customer.setCode(String.valueOf(new Date().getTime()));
                    } else {
                      customer.setCode(String.valueOf(cell.getNumericCellValue()));
                      list.add(customer.getCode());
                    }
                  } else {
                    System.out.println("---- Enterprise code: " + cell.getStringCellValue());
                    if (list.indexOf(cell.getStringCellValue()) > 0) {
                      customer.setCode(String.valueOf(new Date().getTime()));
                    } else {
                      customer.setCode(cell.getStringCellValue());
                      list.add(customer.getCode());
                    }
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Slogan
              if (cell.getColumnIndex() == 2) {
                try {
                  System.out.println("---- Slogan: " + cell.getStringCellValue());
                  organizationBasic.setSlogan(cell.getStringCellValue());

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Address
              if (cell.getColumnIndex() == 3) {
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- Address: " + cell.getNumericCellValue());
                    contact.setAddressNumber(String.valueOf(cell.getNumericCellValue()));
                  } else {
                    System.out.println("---- Address: " + cell.getStringCellValue());
                    contact.setAddressNumber(cell.getStringCellValue());
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Telephone
              if (cell.getColumnIndex() == 4) {
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- Telephone: " + cell.getNumericCellValue());

                    String[] arrayPhone = String.valueOf(cell.getNumericCellValue()).split(",");
                    contact.setPhone(arrayPhone);
                    if (arrayPhone.length > 0) {
                      customer.setMobile(arrayPhone[0]);
                    }

                  } else {
                    System.out.println("---- Telephone: " + cell.getStringCellValue());
                    String[] arrayPhone = cell.getStringCellValue().split(",");
                    contact.setPhone(arrayPhone);
                    if (arrayPhone.length > 0) {
                      customer.setMobile(arrayPhone[0]);
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Email
              if (cell.getColumnIndex() == 6) {
                try {
                  String str = new Date().getTime() + "";
                  int str1 = cell.getStringCellValue().length();
                  String str2 = cell.getStringCellValue();

                  System.out.println("---- Email: " + cell.getStringCellValue());
                  if (str1 > 4) {
                    account.setEmail(str2);
                  } else {
                    account.setEmail(str + "@gmail.com");
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Website
              if (cell.getColumnIndex() == 7) {
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    customer.setDescription(String.valueOf(cell.getNumericCellValue()));
                  } else {
                    if (cell.getStringCellValue() != null) {
                      customer.setDescription(cell.getStringCellValue());
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

              // Description
              if (cell.getColumnIndex() == 8) {
                try {
                  if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.println("---- Description: " + cell.getNumericCellValue());
                    organizationBasic.setDescription(String.valueOf(cell.getNumericCellValue()));
                  } else {
                    System.out.println("---- Description: " + cell.getStringCellValue());
                    if (cell.getStringCellValue() != null) {
                      if (cell.getStringCellValue().length() > 100) {
                        organizationBasic.setDescription(
                            cell.getStringCellValue().substring(0, 100));
                      } else {
                        organizationBasic.setDescription(cell.getStringCellValue());
                      }
                    }
                  }

                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
          try {
            if (checkAccount(account)) {
              Profile profileOrgBasic = new Profile();
              OrganizationBasic orgBasic = this.organizationBasic;
              profileOrgBasic.put(OrganizationBasic.NAME, orgBasic.getName());
              profileOrgBasic.put(OrganizationBasic.SLOGAN, orgBasic.getSlogan());
              profileOrgBasic.put(OrganizationBasic.DESCRIPTION, orgBasic.getDescription());

              Profiles profiles = new Profiles();
              profiles.setBasic(profileOrgBasic);
              account.setProfiles(profiles);

              List<Contact> contacts = new ArrayList<Contact>();
              contacts.add(contact);
              account.setContacts(contacts);

              Account acc = AccountModelManager.getInstance().saveAccount(account);
              customer.setLoginId(acc.getLoginId());
              customer.setType("Doanh nghiệp");
              customer.setAddress(contact.getAddressNumber());
              CustomerModelManager.getInstance().saveCustomer(customer);
            }
          } catch (Exception e) {

          }
        }
      }
    }
  }