daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package commonPanels.StrategyDao;
  2.  
  3. import solution.common.query.Query;
  4. import solution.common.query.QueryData;
  5. import solution.commondb.Global;
  6. import solution.commondb.ambdoctor.db.dao.AbstractDao;
  7. import solution.commondb.dao.exception.ProcErrorException;
  8. import solution.commondb.select.SelectDlg;
  9. import solution.commondb.tables.SOLUTION_FORM.FILTER_ITEM;
  10.  
  11. import javax.swing.*;
  12.  
  13. public class FilterReferenceWithParam extends AbstractDao implements IReferenceWithParams {
  14.  
  15.     private FILTER_ITEM item = null;
  16.  
  17.     /* SQLs*/
  18.     public static final String SQL_SELECT_REFERENCE_PARAMS  = "SELECT_REF_PARAMS";
  19.     public static final String SQL_SELECT_FILTER_ITEMS      = "SELECT_FILTER_ITEM_EXT";
  20.     public static final String SQL_SELECT_FILTER_LIST       = "SELECT_FILTER_LISTS";
  21.     public static final String SQL_INSERT_PARAM             = "INSERT_PASS_ITEM";
  22.     public static final String SQL_UPDATE_PARAM             = "UPDATE_PASS_ITEM";
  23.     public static final String SQL_UPDATE_STATUS            = "UPDATE_CHECK_STATUS";
  24.     public static final String SQL_DELETE_PARAM             = "DELETE_CONNECT_PARAMS";
  25.  
  26.     /*Fields*/
  27.     public static final String ID = "CONNECT_ID";
  28.     public static final String PARAM = "PARAM_ID";
  29.  
  30.     public FilterReferenceWithParam(FILTER_ITEM item) {
  31.         this.item = item;
  32.     }
  33.  
  34.     @Override
  35.     public Query getTableQuery() {
  36.         return getPreparedQuery(Global.getSQL(SQL_SELECT_REFERENCE_PARAMS), new QueryData().put("FILTER_ITEM_ID", item.getId()));
  37.     }
  38.  
  39.     @Override
  40.     public SelectDlg getParamSelectDlg() {
  41.         SelectDlg dlg = new SelectDlg(getConnection(), "addCurrentItem", ListSelectionModel.SINGLE_SELECTION);
  42.         dlg.addColumn("ID", "", false);
  43.         dlg.addColumn("STATUS", "", true);
  44.         dlg.setColumnFixed("STATUS", true, 20);
  45.         dlg.addColumn("CODE", "Код", true);
  46.         dlg.addColumn("TEXT", "Название", true);
  47.         dlg.setActiveCheckBoxVisible(true);
  48.         dlg.setTitle("Выбор параметра");
  49.         Query query = getPreparedQuery(Global.getSQL(SQL_SELECT_FILTER_ITEMS).replaceAll(":SELECT", Global.getSQL(SQL_SELECT_FILTER_LIST))
  50.                                        , new QueryData().put("FILTER_ID", item.getFilterId()));
  51.         dlg.setQuery(query);
  52.         dlg.enableFilter(true);
  53.         return dlg;
  54.     }
  55.  
  56.     @Override
  57.     public void saveParam(Object idConnect, Object idRefParamId, Object idParam) throws ProcErrorException {
  58.         if (isUpdateParam(idConnect)){
  59.             update(idConnect, idParam);
  60.         } else {
  61.             insert(idRefParamId, idParam);
  62.         }
  63.     }
  64.  
  65.     private void insert(Object idRefParam, Object idParam) throws ProcErrorException {
  66.         executeOneRowQuery(Global.getSQL(SQL_INSERT_PARAM), getInsertQueryData(idRefParam, idParam));
  67.     }
  68.  
  69.     private void update(Object idConnect, Object idParam){
  70.         executeUpdate(Global.getSQL(SQL_UPDATE_PARAM), getUpdateQueryData(idConnect, idParam));
  71.     }
  72.  
  73.     private boolean isUpdateParam(Object id){
  74.         return id != null;
  75.     }
  76.  
  77.     private QueryData getInsertQueryData(Object idRefParam, Object idParam) {
  78.         return new QueryData()
  79.             .put("CURR_ITEM_ID", item.getId())
  80.             .put("REF_ITEM_ID", idRefParam)
  81.             .put(PARAM, idParam);
  82.     }
  83.  
  84.     private QueryData getUpdateQueryData(Object idConnect, Object idParam) {
  85.         return new QueryData()
  86.             .put(ID, idConnect)
  87.             .put(PARAM, idParam);
  88.     }
  89.  
  90.     private QueryData getUpdateStatusQueryData(Object idConnect, int status) {
  91.         return new QueryData()
  92.             .put(ID, idConnect)
  93.             .put("CHECK_STATUS", status);
  94.     }
  95.  
  96.     @Override
  97.     public void saveStatusCheck(Object idConnect, int statusParam) {
  98.         executeUpdate(Global.getSQL(SQL_UPDATE_STATUS), getUpdateStatusQueryData(idConnect, statusParam));
  99.     }
  100.  
  101.     @Override
  102.     public void deleteParam(Object idConnect) throws ProcErrorException {
  103.         executeOneRowQuery(Global.getSQL(SQL_DELETE_PARAM), new QueryData().put(ID, idConnect));
  104.     }
  105.  
  106. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top