Esempio n. 1
0
  @Override
  public void handleEvent(BaseEvent be) {
    // TODO Auto-generated method stub

    if (be.getType().equals(Events.Select)) {
      // 会员充值
      if (be.getSource().equals(addfinace)) {
        AddFinace_acc addfinace_acc = new AddFinace_acc();
        addfinace_acc.setIsnew(0);
        addfinace_acc.showDialog();
      }
      if (be.getSource().equals(d.getButtonById(Dialog.NO))) {
        close();
      } else if (be.getSource().equals(d.getButtonById(Dialog.YES))) {
        passwordc_t.clearInvalid();

        String passwordc = (passwordc_t.getValue() == null ? "" : passwordc_t.getValue());
        String password = (password_t.getValue() == null ? "" : password_t.getValue());
        if ((!passwordc.equals(password))) {

          passwordc_t.markInvalid("两次录入密码不一致");
          MessageBox.alert("提示", "两次密码录入不一致", null);
          return;
        }
        if (w.isValid()) {

          CommandSyncContainer list = new CommandSyncContainer();
          CommandSyncsql commandsql = new CommandSyncsql();

          // 保存
          commandsql.getV().addAll(store._trySave(0));
          // 更新ccode
          /** 不得已才如此操作,因为ccode的ccode字段是与其他操作管理的字段,和ccodepanel里的做法一直, 默认与icode同值 */
          GWT.log(
              "update ccode set ccode =icode where s_cardno='"
                  + cardno_t.getValue()
                  + "' and cname='"
                  + cname_t.getValue()
                  + "'",
              null);
          commandsql
              .getV()
              .add(
                  "update ccode set ccode =icode where s_cardno='"
                      + cardno_t.getValue()
                      + "' and cname='"
                      + cname_t.getValue()
                      + "'");

          list.add(commandsql);

          final com.base.myproject.client.tools.GreetingServiceAsync greetingService =
              GWT.create(com.base.myproject.client.tools.GreetingService.class);
          greetingService.SendCommandSync(
              list,
              new AsyncCallback<CommandSyncReturnObject>() {
                public void onFailure(Throwable caught) {
                  Window.alert("网络连接不稳定,请稍后重试!");
                }

                public void onSuccess(CommandSyncReturnObject cyro) {

                  System.out.println("成功:" + cyro.getMessage() + cyro.isB() + cyro.getRetrunstr());
                  if (cyro.isB()) {
                    Info.display("", "保存成功", "");
                    addfinace.setEnabled(true);
                    // close();
                  } else {
                    MessageBox.alert("错误", "保存错误!" + cyro.getMessage(), null);
                  }
                }
              });

          // store.trySave(0);
          d.getButtonById(Dialog.YES).setEnabled(false);
        } else MessageBox.alert("禁止", "请检查录入是否正确!", null);
      }

    } else if (be.getType().equals(Events.Change)) {
      if (be.getSource().equals(cardno_t)) {

        final com.base.myproject.client.tools.GreetingServiceAsync greetingService =
            GWT.create(com.base.myproject.client.tools.GreetingService.class);
        greetingService.getDataSet(
            "select count(*) as c from ccode where s_cardno='" + cardno_t.getValue() + "'",
            new AsyncCallback<DataSet>() {

              @Override
              public void onFailure(Throwable caught) {}

              @Override
              public void onSuccess(DataSet result) {

                if (Integer.parseInt(result.getValue(0, "c")) > 0) {
                  Validator v =
                      new Validator() {

                        @Override
                        public String validate(Field<?> field, String value) {

                          return "已经存在相同卡号的用户";
                        }
                      };

                  cardno_t.setValidator(v);

                } else {
                  cardno_t.setValidator(null);
                }
                cardno_t.validate();
              }
            });

      } else if (be.getSource().equals(cname_t)) {

        final com.base.myproject.client.tools.GreetingServiceAsync greetingService =
            GWT.create(com.base.myproject.client.tools.GreetingService.class);
        greetingService.getDataSet(
            "select count(*) as c from ccode where cname='" + cname_t.getValue() + "'",
            new AsyncCallback<DataSet>() {

              @Override
              public void onFailure(Throwable caught) {}

              @Override
              public void onSuccess(DataSet result) {

                if (Integer.parseInt(result.getValue(0, "c")) > 0) {
                  Validator v =
                      new Validator() {

                        @Override
                        public String validate(Field<?> field, String value) {

                          return "已经存在相同名字的用户";
                        }
                      };

                  cname_t.setValidator(v);
                } else {
                  cname_t.setValidator(null);
                }

                cname_t.validate();
              }
            });
      }
      //			else if (name.equals("s_cardno")) {
      //				ccode_t.setFireChangeEventOnSetValue(true);
      //				ccode_t.setValue(icode_t.getValue());
      //				ccode_t.setFireChangeEventOnSetValue(false);
      //			}
    }
  }
  @SuppressWarnings("unchecked")
  public static boolean handleFormException(FormPanel form, Throwable caught) {

    boolean isWarning = false;
    if (caught instanceof GwtKuraException) {

      List<Field<?>> fields = form.getFields();
      GwtKuraException gee = (GwtKuraException) caught;
      GwtKuraErrorCode code = gee.getCode();
      switch (code) {
        case DUPLICATE_NAME:
          boolean fieldFound = false;
          String duplicateFieldName = gee.getArguments()[0];
          for (Field<?> field : fields) {
            if (duplicateFieldName.equals(field.getName())) {
              TextField<String> textField = (TextField<String>) field;
              textField.markInvalid(MSGS.duplicateValue());
              fieldFound = true;
              break;
            }
          }
          if (!fieldFound) {
            Info.display(CMSGS.error(), caught.getLocalizedMessage());
          }
          break;

        case ILLEGAL_NULL_ARGUMENT:
          String invalidFieldName = gee.getArguments()[0];
          for (Field<?> field : fields) {
            if (invalidFieldName.equals(field.getName())) {
              TextField<String> textField = (TextField<String>) field;
              textField.markInvalid(MSGS.invalidNullValue());
              break;
            }
          }
          break;

        case ILLEGAL_ARGUMENT:
          String invalidFieldName1 = gee.getArguments()[0];
          for (Field<?> field : fields) {
            if (invalidFieldName1.equals(field.getName())) {
              TextField<String> textField = (TextField<String>) field;
              textField.markInvalid(gee.getCause().getMessage());
              break;
            }
          }
          break;

        case INVALID_RULE_QUERY:
          for (Field<?> field : fields) {
            if ("query".equals(field.getName())) {
              TextArea statement = (TextArea) field;
              statement.markInvalid(caught.getLocalizedMessage());
              break;
            }
          }
          break;

        case WARNING:
          isWarning = true;
          Info.display(CMSGS.warning(), caught.getLocalizedMessage());
          break;

        default:
          Info.display(CMSGS.error(), caught.getLocalizedMessage());
          caught.printStackTrace();
          break;
      }
    } else {

      Info.display(CMSGS.error(), caught.getLocalizedMessage());
      caught.printStackTrace();
    }

    return isWarning;
  }