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 }