检验某个字段是否重复(以检验编码是否重复为例)

来源:互联网 发布:网络上赌博被骗怎么办 编辑:程序博客网 时间:2024/05/01 10:38

前台:

    public void actionSubmit_actionPerformed(ActionEvent e) throws Exception {
            try {
                super.actionSubmit_actionPerformed(e);
            } catch (Exception e1) {
                MsgBox.showDetailAndOK(null,"保存单据时出现异常点击详细信息查看详情",e1.getMessage(),1);
            }
    }

同时客户端需要先校验要检验的字段是否为空,为空的不允许提交或者保存等。

 

后台:

    /**
     * 提交事件
     */
    protected IObjectPK _submit(Context ctx, IObjectValue model)
            throws BOSException, EASBizException {
        logger.info("提交事件");
        synchronized (this) {
            // 检测单据号是否重复
            OverTimeApplyInfo ovetTimeApplyInfo = (OverTimeApplyInfo) model;
            sql.delete(0, sql.length());
            sql.append("select fid from T_ATT_OverTimeApply where 1=1 ");
            if (ovetTimeApplyInfo.getId() != null) {
                sql.append(" and fid!='");
                sql.append(ovetTimeApplyInfo.getId());
                sql.append("' ");
            }
            sql.append(" and FNumber='");
            sql.append(ovetTimeApplyInfo.getNumber());
            sql.append("'");
            IRowSet irs = DbUtil.executeQuery(ctx, sql.toString());
            if (irs != null && irs.size() > 0) {
                throw new BOSException("单据号重复./n");
            }
            return super._submit(ctx, model);
        }
    }