DEP腳本


新方式添加表格監聽,解決擴展腳本添加的監聽無法移除的問題
新方式添加表格監聽,解決擴展腳本添加的監聽無法移除的問題,目的是跳過methodName參數 最近和部門大神在調試的時候,發現一個神奇的現象。使用腳本給一個表格增加了監聽,腳本如下: pluginCtx.getKDTable("kdtEntrys").addKDTEditListener(function(event,methodName){ if(methodName == "editStopped") { com.kingdee.eas.util.client.MsgBox.showInfo("$$$$$EditStopped"); } }); 然后業務代碼中在提交后有移除表格監聽的動作。居然報錯了, var obj = { editStarting : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editStarting"); } , editStarted : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editStarted"); } , editValueChanged : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editValueChanged"); } , editStopping : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editStopping"); } , editStopped : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editStopped"); } , editCanceled : function (e) { com.kingdee.eas.util.client.MsgBox.showInfo("editCanceled"); } } ; kdtable.addKDTEditListener( new com.kingdee.bos.ctrl.kdf.table.event.KDTEditListener(obj));

  使用DEP給采購入庫單的分錄物料編碼F7增加值改變監聽時,使用Dep提供的表格表格編輯監聽事件方式進行業務邏輯處理,通過F7物料編碼值改變,查詢並攜帶給物料新增F7的值填充到采購入庫單分錄的字符串字段中。

  注意:因為使用表格值改變事件(table.addKDTPropertyChangeListener(function(event,methodName)),保存單據時,出現了點擊保存按鈕無任何反應,但客戶端日志中會提示 去掉表格監聽事件出錯。此問題未解決,因此,采用上面的事件方式進行監聽。

 

var easImporter = JavaImporter();
easImporter.importPackage(Packages.com.kingdee.bos.dao.query);
easImporter.importPackage(Packages.com.kingdee.eas.util.client);
easImporter.importPackage(Packages.com.kingdee.eas.basedata.master.material);

with(easImporter){
    var table = pluginCtx.getKDTable("detailTable");
    var obj = { 
          editStopped : function (e) 
         { 
              com.kingdee.eas.util.client.MsgBox.showInfo("editStopped");
              var row = e.getRowIndex();
               var col = e.getColIndex();

               if(col==2){
                // 獲取物料編碼F7的MaterialInfo
                var material =  table.getRow(row).getCell("materialNum").getValue();
                var sql = "select material.fname_l2 as mName,cp.fname_l2 as cpName, bizType.fname_l2 as btName, levy.fname_l2 as leName from T_BD_Material material left join CT_CUS_Levy levy on levy.fid = material.cflevyid left join CT_CUS_CarPrice cp on cp.fid = material.cfcarpriceid left join CT_CUS_BizType bizType  on bizType.fid = material.cfbiztypeid where material.fid = '"+ material.getId()+"'";
                var se = new SQLExecutor(sql);
                var rs = se.executeSQL();
                var leName = "",cpName = "",btName = "";
                while(rs.next()){
                    // 稅款
                    if(rs.getString("leName") != null){
                        leName = rs.getString("leName").toString();
                    }
                    
                    // 車款
                    if(rs.getString("cpName") != null){
                        cpName = rs.getString("cpName").toString();
                    }
                    
                    // 業務類型 
                    if(rs.getString("btName") != null){
                        btName = rs.getString("btName").toString();
                    }
                

                }    
               //給kdtable 測試單元格賦值
               table.getRow(row).getCell("levy").setValue(leName);
               table.getRow(row).getCell("carPrice").setValue(cpName);
               table.getRow(row).getCell("bizType").setValue(btName);

            }

         }
       };

       table.addKDTEditListener( new com.kingdee.bos.ctrl.kdf.table.event.KDTEditListener(obj));
}

 

 批量更新序時簿中選中行數據的字段值

var easImporter = JavaImporter();
easImporter.importPackage(Packages.com.kingdee.bos.dao.query);
easImporter.importPackage(Packages.com.kingdee.eas.util.client);
easImporter.importPackage(Packages.com.kingdee.eas.fm.common);

with(easImporter){

    //批量修改物料的監管狀態-監管中
    var tblMain = pluginCtx.getKDTable("tblMain");
    var size = tblMain.getSelectManager().size();

    for(var i = 0; i < size; i++){
        var block = tblMain.getSelectManager().get(i); 
            for (var j = block.getTop(); j <= block.getBottom(); j++) {
                    var cellstr = tblMain.getRow(j).getCell("id");
                    // 選中行的id
                    var materialId =  cellstr.getValue();

                    //獲取監管基礎資料中 監管中  fid
                    //此處不再進行查詢FID,直接寫死FID
                    var sid = 'dUEz3FjuG0OZ/0CDJXh0zGPRCMw=';
    
                    //修改該物料的監管狀態   
                    var sql = "UPDATE T_BD_Material SET cfcontrolstatusid  = '" + sid + "'   WHERE  FID = '" + materialId + "'";
                   FMIsqlFacadeFactory.getRemoteInstance().executeSql(sql);

                }
        }

}

 

 F7字段添加過濾

var easImporter = JavaImporter();
easImporter.importPackage(Packages.com.kingdee.bos.ctrl.extendcontrols);
easImporter.importPackage(Packages.com.kingdee.bos.metadata.entity);
easImporter.importPackage(Packages.com.kingdee.bos.metadata.query.util);
easImporter.importPackage(Packages.com.kingdee.bos.util);

with(easImporter){
    
    var prmtSQBM = pluginCtx.getKDBizPromptBox("prmtSQBM");
    var filterInfo = new FilterInfo();
    var entityViewInfo = new EntityViewInfo();
    var company = pluginCtx.getUIContext().get("sysContext").getCurrentFIUnit();
    filterInfo.getFilterItems().add(new FilterItemInfo("CU.id",company.get("Id"),CompareType.EQUALS));
    entityViewInfo.setFilter(filterInfo);
    
    prmtSQBM.setEntityViewInfo(entityViewInfo);
}

 

  彈出界面並傳輸選中行信息給界面類處理邏輯

dep:

var easImporter = JavaImporter();
easImporter.importPackage(Packages.com.kingdee.bos.dao.query);
easImporter.importPackage(Packages.com.kingdee.eas.util.client);
easImporter.importPackage(Packages.com.kingdee.eas.fm.common);

with(easImporter){
    var tblMain = pluginCtx.getKDTable("tblMain");
    //彈出界面
    var uiContext =new  com.kingdee.eas.common.client.UIContext(pluginCtx.getUI());
  //選中行信息 uiContext.put(
"idMains",tblMain.getSelectManager()); uiContext.put("tblMain",tblMain); var uiName = "com.kingdee.eas.custom.material.client.BantchUpdateFieldsUI"; var uiWindow = com.kingdee.bos.ui.face.UIFactory.createUIFactory (com.kingdee.eas.common.client.UIFactoryName.MODEL).create(uiName, uiContext); //"com.kingdee.eas.base.uiframe.client.UIModelDialogFactory" //com.kingdee.eas.common.client.UIFactoryName.MODEL uiWindow.show(); }

 界面:BantchUpdateFieldsUICTEx.java

  1 package com.kingdee.eas.custom.material.client;
  2 
  3 import java.awt.event.ActionEvent;
  4 import java.sql.SQLException;
  5 import java.util.ArrayList;
  6 
  7 import org.apache.commons.lang.StringUtils;
  8 import org.apache.log4j.Logger;
  9 import org.mozilla.javascript.edu.emory.mathcs.backport.java.util.Arrays;
 10 
 11 import com.kingdee.bos.BOSException;
 12 import com.kingdee.bos.ctrl.kdf.table.KDTSelectBlock;
 13 import com.kingdee.bos.ctrl.kdf.table.KDTSelectManager;
 14 import com.kingdee.bos.ctrl.kdf.table.KDTable;
 15 import com.kingdee.bos.dao.query.SQLExecutor;
 16 import com.kingdee.bos.ui.face.CoreUIObject;
 17 import com.kingdee.eas.common.EASBizException;
 18 import com.kingdee.eas.fm.common.FMIsqlFacadeFactory;
 19 import com.kingdee.eas.util.SysUtil;
 20 import com.kingdee.eas.util.client.MsgBox;
 21 import com.kingdee.jdbc.rowset.IRowSet;
 22 import com.kingdee.portal.biz.common.exception.BizException;
 23 
 24 /**
 25  * 批量更新字段(車款 稅款 經營方式)
 26  * @desc 批量更新界面
 27  * @author yacong_liu
 28  * 
 29  */
 30 public class BantchUpdateFieldsUICTEx extends BantchUpdateFieldsUI {
 31     private static final Logger logger = CoreUIObject
 32             .getLogger(BantchUpdateFieldsUICTEx.class);
 33     private static final ArrayList<String> materialIds = new ArrayList<String>(
 34             8);
 35     // 需要更新的字段F7類型
 36     private static final String[] types = { "車款", "稅款", "經營方式" };
 37     private String carPriceId = "";
 38     private String levyId = "";
 39     private String bizTypeId = "";
 40 
 41     public BantchUpdateFieldsUICTEx() throws Exception {
 42         super();
 43     }
 44 
 45     /**
 46      * 取消按鈕-關閉當前窗口
 47      */
 48     @Override
 49     public void actionBtnCancel_actionPerformed(ActionEvent e) throws Exception {
 50         super.actionBtnCancel_actionPerformed(e);
 51         // 關閉當前窗口
 52         getUIWindow().close();
 53     }
 54 
 55     /**
 56      * 確定按鈕-更新數據
 57      */
 58     @Override
 59     public void actionBtnSubmit_actionPerformed(ActionEvent e) throws Exception {
 60         super.actionBtnSubmit_actionPerformed(e);
 61         getValues();
 62 
 63         if(updateFields()){
 64             MsgBox.showInfo("更新數據已完成!");
 65             Thread.sleep(2000);
 66             getUIWindow().close();
 67         }
 68         
 69     }
 70 
 71     /**
 72      * 獲取值
 73      */
 74     private void getValues() {
 75         // 車款
 76         String carPrice;
 77         // 稅款
 78         String levy;
 79         // 經營方式
 80         String bizType;
 81         if (null != this.carPrice.getSelectedItem()
 82                 && !"無".equals(this.carPrice.getSelectedItem().toString())) {
 83             carPrice = this.carPrice.getSelectedItem().toString();
 84             carPriceId = getUpdateFieldsIdByItemName(carPrice, "車款");
 85         }
 86         if (null != this.levy.getSelectedItem()
 87                 && !"無".equals(this.levy.getSelectedItem().toString())) {
 88             levy = this.levy.getSelectedItem().toString();
 89             levyId = getUpdateFieldsIdByItemName(levy, "稅款");
 90         }
 91         if (null != this.bizTypes.getSelectedItem()
 92                 && !"無".equals(this.bizTypes.getSelectedItem().toString())) {
 93             bizType = this.bizTypes.getSelectedItem().toString();
 94             bizTypeId = getUpdateFieldsIdByItemName(bizType, "經營方式");
 95         }
 96     }
 97 
 98     @Override
 99     public void onLoad() throws Exception {
100         materialIds.clear();
101         this.btn_cancel.setEnabled(true);
102         KDTSelectManager sManager = (KDTSelectManager) getUIContext().get(
103                 "idMains"); //dep傳來的選中行信息
104         KDTable tblMain = (KDTable) getUIContext().get("tblMain");
105         for (int i = 0; i < sManager.size(); i++) {
106             KDTSelectBlock block = sManager.get(i);
107             for (int j = block.getTop(); j <= block.getBottom(); j++) {
108                 // 選中行的id
109 
110                 if (null != tblMain.getRow(j).getCell("id")) {
111                     String id = (String) tblMain.getRow(j).getCell("id")
112                             .getValue();
113                     materialIds.add(id);
114                     
115                 }
116 
117             }
118 
119         }
120         logger.info("本次批量更新的物料內碼:"+materialIds.toString());
121         super.onLoad();
122     }
123 
124     /**
125      * 更新 車款 稅款 經營方式
126      * 
127      * @throws BizException
128      * 
129      * @throws EASBizException
130      * @throws BOSException
131      */
132     private boolean updateFields() {
133         if (materialIds.size() <= 0) {
134             return false;
135         }
136         
137         if(StringUtils.isEmpty(carPriceId)&&StringUtils.isEmpty(levyId)&&StringUtils.isEmpty(bizTypeId)){
138             // 沒有選擇任何字段
139             MsgBox.showWarning("您尚未選擇更新的字段內容!");
140             return false;
141         }
142 
143         try {
144             String setSql = setFieldsSql();
145             for (String materialId : materialIds) {
146                 String updateSql = "update t_bd_material set " + setSql
147                         + " where fid = '" + materialId + "'";
148                 logger.info("***************更新SQL: " + updateSql);
149                 FMIsqlFacadeFactory.getRemoteInstance().executeSql(updateSql);
150             }
151             return true;
152         } catch (EASBizException e) {
153             logger.error(" 更新選中字段數據出錯,請聯系管理員!" + e);
154             MsgBox.showError("更新選中字段數據出錯,請聯系管理員");
155             SysUtil.abort(e);
156         } catch (BOSException e) {
157             logger.error(" 更新選中字段數據出錯,請聯系管理員!" + e);
158             MsgBox.showError("更新選中字段數據出錯,請聯系管理員");
159             SysUtil.abort(e);
160         }
161         return false;
162 
163     }
164 
165     /**
166      * 需要更新的字段
167      * 
168      * @return
169      */
170     private String setFieldsSql() {
171         ArrayList<String> ids = new ArrayList<String>(3);
172         ids.clear();
173         if (StringUtils.isNotEmpty(bizTypeId)) {
174             ids.add(bizTypeId);
175         }
176         if (StringUtils.isNotEmpty(carPriceId)) {
177             ids.add(carPriceId);
178         }
179         if (StringUtils.isNotEmpty(levyId)) {
180             ids.add(levyId);
181         }
182         
183 
184         StringBuilder sb = new StringBuilder();
185         sb.setLength(0);
186         if(StringUtils.isNotEmpty(carPriceId) && ids.size() == 1){
187             //只選擇了車款
188             sb.append(" cfcarpriceid = '" + carPriceId + "'");
189         }else if(StringUtils.isNotEmpty(carPriceId) && ids.size() > 1){
190             // 除了車款 還有別的字段
191             sb.append(" cfcarpriceid = '" + carPriceId + "',");
192         }
193         
194         if(StringUtils.isNotEmpty(levyId) && ids.size() == 1){
195             //只選了稅款
196             sb.append(" cflevyid = '" + levyId + "'");
197         }else if(StringUtils.isNotEmpty(levyId) && StringUtils.isNotEmpty(bizTypeId)){
198             //選了稅款 和 經營方式
199             sb.append(" cflevyid = '" + levyId + "',");
200         }else if(StringUtils.isNotEmpty(levyId) && StringUtils.isEmpty(bizTypeId)){
201             //選了稅款 沒有 經營方式
202             sb.append(" cflevyid = '" + levyId + "'");
203         }
204         
205         if(StringUtils.isNotEmpty(bizTypeId)){
206             //選了 經營方式
207             sb.append(" cfbiztypeid = '" + bizTypeId + "'");
208         }
209 
210         return sb.toString();
211 
212     }
213 
214     /**
215      * 根據下拉框選中的項目名稱獲取其對應的fid
216      * 
217      * @param name
218      *            下拉框選中項名稱
219      * @return FID
220      */
221     private String getUpdateFieldsIdByItemName(String name, String type) {
222         if (StringUtils.isEmpty(name) || StringUtils.isEmpty(type)) {
223             return null;
224         }
225 
226         String sql = "select c.fid from " + getTableName(type)
227                 + " c where c.fname_l2 = '" + name + "'";
228         try {
229             SQLExecutor sqe = new SQLExecutor(sql);
230             IRowSet rowSet = sqe.executeSQL();
231             while (rowSet.next()) {
232                 return rowSet.getString("fid");
233             }
234         } catch (BOSException e) {
235             logger.error("獲取" + type + " Fid 失敗!SQL執行器獲取失敗!" + e);
236             MsgBox.showError("獲取" + type + " 內碼FID失敗!SQL執行器獲取失敗!請聯系管理員" + e);
237         } catch (SQLException e) {
238             logger.error("獲取" + type + " Fid 失敗!執行SQL失敗!" + e);
239             MsgBox.showError("獲取" + type + " 內碼FID失敗!執行SQL失敗!請聯系管理員" + e);
240         }
241 
242         return null;
243 
244     }
245 
246     /**
247      * 獲取表名
248      * 
249      * @param F7Type
250      * @return
251      */
252     private String getTableName(String F7Type) {
253         if (!Arrays.asList(types).contains(F7Type)) {
254             logger.warn("不存在該F7類型!" + F7Type);
255             return null;
256         }
257 
258         if (types[0].equals(F7Type)) {
259             // 車款
260             return "ct_su_carprice";
261         }
262         if (types[1].equals(F7Type)) {
263             // 稅款
264             return "ct_su_levy";
265 
266         }
267         if (types[2].equals(F7Type)) {
268             // 經營方式
269             return "ct_su_biztype";
270         }
271 
272         return null;
273 
274     }
275 
276     /**
277      * 根據車款枚舉名稱獲取車款id (重構 不在使用 請使用 getUpdateFieldsIdByItemName(String name,
278      * String type))
279      * 
280      * @param name
281      * @return
282      */
283     @Deprecated
284     private String getCarPriceIdByName(String name) {
285         if (StringUtils.isEmpty(name)) {
286             return null;
287         }
288 
289         String sql = "select c.fid from ct_su_carprice c where c.fname_l2 = '"
290                 + name + "'";
291         try {
292             SQLExecutor sqe = new SQLExecutor(sql);
293             IRowSet rowSet = sqe.executeSQL();
294             while (rowSet.next()) {
295                 return rowSet.getString("fid");
296             }
297         } catch (BOSException e) {
298             logger.error("獲取車款id 失敗!SQL執行器獲取失敗!" + e);
299             MsgBox.showError("獲取車款內碼FID失敗!SQL執行器獲取失敗!請聯系管理員" + e);
300         } catch (SQLException e) {
301             logger.error("獲取車款id 失敗!執行SQL失敗!" + e);
302             MsgBox.showError("獲取車款內碼FID失敗!執行SQL失敗!請聯系管理員" + e);
303         }
304 
305         return null;
306 
307     }
308 
309     /**
310      * 根據稅款枚舉名稱獲取稅款id (重構 不再使用 請使用 getUpdateFieldsIdByItemName(String name,
311      * String type))
312      * 
313      * @param name
314      * @return
315      */
316     @Deprecated
317     private String getLevyIdByName(String name) {
318         if (StringUtils.isEmpty(name)) {
319             return null;
320         }
321 
322         String sql = "select c.fid from ct_su_levy c where c.fname_l2 = '"
323                 + name + "'";
324         try {
325             SQLExecutor sqe = new SQLExecutor(sql);
326             IRowSet rowSet = sqe.executeSQL();
327             while (rowSet.next()) {
328                 return rowSet.getString("fid");
329             }
330         } catch (BOSException e) {
331             e.printStackTrace();
332             logger.error("獲取稅款id 失敗!" + e);
333         } catch (SQLException e) {
334             e.printStackTrace();
335             logger.error("獲取稅款id 失敗!" + e);
336         }
337 
338         return null;
339 
340     }
341 
342     /**
343      * 根據經營方式枚舉名稱獲取經營方式id (重構 不再使用 請使用 getUpdateFieldsIdByItemName(String name,
344      * String type))
345      * 
346      * @param name
347      * @return
348      */
349     @Deprecated
350     private String getBizTypeIdByName(String name) {
351         if (StringUtils.isEmpty(name)) {
352             return null;
353         }
354 
355         String sql = "select c.fid from ct_su_biztype c where c.fname_l2 = '"
356                 + name + "'";
357         try {
358             SQLExecutor sqe = new SQLExecutor(sql);
359             IRowSet rowSet = sqe.executeSQL();
360             while (rowSet.next()) {
361                 return rowSet.getString("fid");
362             }
363         } catch (BOSException e) {
364             e.printStackTrace();
365             logger.error("獲取經營方式id 失敗!" + e);
366         } catch (SQLException e) {
367             e.printStackTrace();
368             logger.error("獲取經營方式id 失敗!" + e);
369         }
370 
371         return null;
372 
373     }
374 
375 }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM