@SuppressWarnings("unchecked")
  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);
    webEmployee = (WebEmployee) ZkUtils.getSessionAttribute("webEmployee");
    Map<String, String> map = new HashMap<String, String>();
    map = ZkUtils.getExecutionArgs();
    String dbId = map.get("dbId");
    currentPage = map.get("currentPage");
    aDbId = dbId;
    codeDb =
        ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService"))
            .findcodeDbByDbId(dbId, webEmployee);
    if (dbId != null) {
      dbIdTxt.setValue(codeDb.getDbId());
      dbNameTxt.setValue(codeDb.getName());
      resourcesIdTxt.setValue(codeDb.getResourcesId());
      // solr查詢語句
      String solrQuery = "";
      solrQuery += "type_id:DB";
      // resourceId
      if (codeDb.getResourcesId() != null && !codeDb.getResourcesId().trim().equals("")) {
        solrQuery += " resources_id:" + codeDb.getResourcesId();
      }
      List<ErmResourcesMainfileV> resMainDbwsList =
          ((ResourcesMainDbwsSolrSearch) SpringUtil.getBean("resourcesMainDbwsSolrSearch"))
              .resourcesMainSearch(solrQuery);
      if (resMainDbwsList.size() > 0) {
        resourcesNameTxt.setValue(resMainDbwsList.get(0).getTitle());
      }
      orderNoIbx.setValue(codeDb.getOrderNo());
      urlTxt.setValue(codeDb.getUrl());
      if (codeDb.getEzproxy() != null) {
        if (codeDb.getEzproxy().equals("Y")) {
          ezproxyRdo.setSelectedIndex(0);
        } else {
          ezproxyRdo.setSelectedIndex(1);
        }
      }
      ((ErmResourcesSuunitIdService) SpringUtil.getBean("ermResourcesSuunitIdService"))
          .findBySuunitResId(dbId);
    }

    if (dbIdTxt.getValue() == null || dbIdTxt.getValue().equals("")) {
      addSuunitBtn.setDisabled(true);
      delSuunitBtn.setDisabled(true);
    }
    flushList();
    // List<ErmResourcesSuunit> sunitList=new
    // ArrayList<ErmResourcesSuunit>();
    // sunitList=((ErmResourcesSuunitIdService) SpringUtil
    // .getBean("ermResourcesSuunitIdService")).findBySuunitResId(dbId);
    // if (sunitList.size() > 0) {
    // ListModelList<ErmResourcesSuunit> listModel = new
    // ListModelList<ErmResourcesSuunit>(sunitList);
    // listModel.setMultiple(true);
    // resMainSuunitLix.setModel(listModel);
    // }

  }
  @Listen("onClick=#editBtn")
  public void editCodeDb() {
    try {
      List<ErmCodeDb> codeDbList =
          ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService")).findAllCodeDb(webEmployee);
      String tempId = "OB";
      Long number = (long) codeDbList.size();
      number = number + 1;
      String dbId = tempId + RandomIDGenerator.fmtLong(number, 9);
      if (!aDbId.equals("") && aDbId != null) {
        codeDb.setDbId(aDbId);
      } else {
        codeDb.setDbId(dbId);
      }
      aDbId = dbId;
      dbIdTxt.setValue(dbId);
      if (dbNameTxt.getValue() != null && !"".equals(dbNameTxt.getValue())) {
        codeDb.setName(dbNameTxt.getValue());
      } else {
        ZkUtils.showExclamation(
            Labels.getLabel("webErwSource.nameZhTw") + " " + Labels.getLabel("cannottNull"),
            Labels.getLabel("warn"));
        dbNameTxt.focus();
        return;
      }
      if (resourcesIdTxt.getValue() != null) {
        codeDb.setResourcesId(resourcesIdTxt.getValue());
      }
      codeDb.setHistory("N");
      if (ezproxyRdo.getSelectedItem().getValue() != null) {
        codeDb.setEzproxy(ezproxyRdo.getSelectedItem().getValue().toString());
      }
      if (urlTxt.getValue() != null && !"".equals(urlTxt.getValue())) {
        codeDb.setUrl(urlTxt.getValue());
      }
      if (orderNoIbx.getValue() != null) {
        codeDb.setOrderNo(orderNoIbx.getValue());
      }
      codeDb.setIsDataEffid(1);
      codeDb.setLatelyChangedDate(new Date());
      codeDb.setLatelyChangedUser(webEmployee.getEmployeesn());
      ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService")).saveCodeDb(codeDb);
      ((WebSysLogService) SpringUtil.getBean("webSysLogService"))
          .editLog(
              ZkUtils.getRemoteAddr(),
              codeDb.getWebEmployee().getEmployeesn(),
              "codeDb_" + codeDb.getDbId());

      ZkUtils.showInformation(Labels.getLabel("saveOK"), Labels.getLabel("info"));
      Listbox resCodeDbLix =
          (Listbox) editErmResDataBaseWin.getParent().getFellowIfAny("resCodeDbLix");
      Textbox name = (Textbox) editErmResDataBaseWin.getParent().getFellowIfAny("nameTxt");
      Textbox dbIdParent = (Textbox) editErmResDataBaseWin.getParent().getFellowIfAny("dbIdTxt");
      List<ErmCodeDb> codeDbList1 =
          ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService"))
              .findPublisherList("", "", name.getValue(), dbIdParent.getValue(), webEmployee);
      ListModelList<ErmCodeDb> model = new ListModelList<ErmCodeDb>(codeDbList1);
      model.setMultiple(true);
      resCodeDbLix.setModel(model);
      resCodeDbLix.setActivePage(Integer.valueOf(currentPage));
      dbIdTxt.setValue(codeDb.getDbId());
      addSuunitBtn.setDisabled(false);
      delSuunitBtn.setDisabled(false);
      /*
       * String url = "ermCodeDb/ermCodeDb.zul";
       * ZkUtils.refurbishMethod(url);
       */

    } catch (WrongValueException e) {
      log.error("新增資料庫異常" + e);
    }
  }
  @Listen("onClick=#saveBtn")
  public void addCodeDb() {
    try {
      Map<String, String> map = new HashMap<String, String>();
      map = ZkUtils.getExecutionArgs();
      ErmCodeDb ermCodeDb = new ErmCodeDb();
      List<ErmCodeDb> codeDbList =
          ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService")).findAllCodeDb(webEmployee);
      String tempId = "OB";
      Long number = (long) codeDbList.size();
      number = number + 1;
      String dbId = tempId + RandomIDGenerator.fmtLong(number, 9);
      ermCodeDb.setDbId(dbId);
      aDbId = dbId;
      dbIdTxt.setValue(dbId);
      if (dbNameTxt.getValue() != null && !"".equals(dbNameTxt.getValue())) {
        ermCodeDb.setName(dbNameTxt.getValue());
      } else {
        ZkUtils.showExclamation(
            Labels.getLabel("webErwSource.nameZhTw") + " " + Labels.getLabel("cannottNull"),
            Labels.getLabel("warn"));
        dbNameTxt.focus();
        return;
      }
      if (resourcesIdTxt.getValue() != null) {
        ermCodeDb.setResourcesId(resourcesIdTxt.getValue());
      }
      ermCodeDb.setHistory("N");
      if (ezproxyRdo.getSelectedItem().getValue() != null) {
        ermCodeDb.setEzproxy(ezproxyRdo.getSelectedItem().getValue().toString());
      }
      if (urlTxt.getValue() != null && !"".equals(urlTxt.getValue())) {
        ermCodeDb.setUrl(urlTxt.getValue());
      }
      if (orderNoIbx.getValue() != null) {
        ermCodeDb.setOrderNo(orderNoIbx.getValue());
      }
      ermCodeDb.setIsDataEffid(1);
      ermCodeDb.setWebEmployee(webEmployee);
      ermCodeDb.setCreateDate(new Date());
      ((ErmCodeDbService) SpringUtil.getBean("ermCodeDbService")).saveCodeDb(ermCodeDb);

      ((WebSysLogService) SpringUtil.getBean("webSysLogService"))
          .insertLog(
              ZkUtils.getRemoteAddr(),
              ermCodeDb.getWebEmployee().getEmployeesn(),
              "codeDb_" + ermCodeDb.getDbId());
      ZkUtils.showInformation(Labels.getLabel("saveOK"), Labels.getLabel("info"));
      dbIdTxt.setValue(ermCodeDb.getDbId());
      addSuunitBtn.setDisabled(false);
      delSuunitBtn.setDisabled(false);
      String url = "ermCodeDb/ermCodeDb.zul";
      ZkUtils.refurbishMethod(url);

    } catch (WrongValueException e) {
      log.error("新增資料庫異常" + e);
    }
  }