金蝶云苍穹开发实用整理
1. afterBindData:页面每次打开进入的方法
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
IFormView view = this.getView();
IDataModel bill = this.getModel();
//设置字段可见性;锁定行:隐藏等
DynamicObject packstyle = (DynamicObject) this.getModel().getValue("tp_packstyle");
if (null !=packstyle) {
packCom(packstyle);
}
}
/**
* @param packstyle
*/
private void packCom(DynamicObject packstyle) {
packstyle=BusinessDataServiceHelper.loadSingle(packstyle.getPkValue(), "tp_bd_packingstyle","number,name,tp_enname");
String name = packstyle.getString("name");
if (StringUtils.isNotEmpty(name)) {
if ("散装".equals(name)) {
this.getView().setVisible(false, "freebox");
this.getView().setEnable(false, "");
}else {
this.getView().setVisible(true, "freebox");//可见性
this.getView().setEnable(true, "");//锁定性
}
}
}
2. 监听事件
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
//文本
TextEdit creditbill = this.getView().getControl("creditbill");
creditbill.addButtonClickListener(this);
//基础资料
BasedataEdit material = this.getView().getControl("material");
material.addBeforeF7SelectListener(this);
}
3.用户点击按钮、菜单,执行完绑定的操作后,不论成功与否,均会触发此事件
@Override
public void afterDoOperation(AfterDoOperationEventArgs e) {
super.afterDoOperation(e);
boolean isSuccess = false;
if (e.getOperationResult() != null) {
isSuccess = e.getOperationResult().isSuccess();
}
String operateKey = e.getOperateKey();
if (StringUtils.isNotEmpty(operateKey)) {
IFormView view = this.getView();
IDataModel model = this.getModel();
FormShowParameter bsp = new FormShowParameter();
bsp.setStatus(OperationStatus.ADDNEW);
bsp.getOpenStyle().setShowType(ShowType.Modal);
if ("save".equals(operateKey) && isSuccess) {
this.getView().invokeOperation("refresh");
}else if ("submit".equals(operateKey) && isSuccess) {
this.getView().invokeOperation("refresh");
} else if ("audit".equals(operateKey) && isSuccess) {
this.getView().invokeOperation("refresh");
} else if ("unaudit".equals(operateKey) && isSuccess) {
this.getView().invokeOperation("refresh");
}else if ("arrivalinfoau".equals(operateKey)) {// 到港信息动态回填
Map<String, Object> arrivalInfo = this.getArrivalInfo();
bsp.setFormId(KEY_TP_ARRIVAL_INFO);
bsp.setCustomParams(arrivalInfo);
CloseCallBack callBack = new CloseCallBack(this, KEY_ARRIVALINFO);
bsp.setCloseCallBack(callBack);
view.showForm(bsp);
}
}
}
4.值改变事件
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
IFormView view = this.getView();
IDataModel bill = this.getModel();
ChangeData[] changeData = e.getChangeSet();
Object newValue = changeData[0].getNewValue();
int rowIndex = changeData[0].getRowIndex();
String key = e.getProperty().getName();
switch (key) {
case "material":
this.sethscode((DynamicObject) newValue, changeData[0].getRowIndex());
propertyNames = initCelVisibleMap();
BuscalentityUtil.setCelVisible(view, bill, propertyNames);
break;
case "tp_packstyle":
DynamicObject packstyle = (DynamicObject) newValue;
if (packstyle != null) {
packCom(packstyle);
}
break;
default:
break;
}
}
5.单据体分录监听事件(删除行触发此事件)
@Override
public void afterDeleteRow(AfterDeleteRowEventArgs e) {
super.afterDeleteRow(e);
EntryProp entryProp = e.getEntryProp();
if (StringUtils.equals("goodsentry", entryProp.getName())) {
DynamicObjectCollection entrys = this.getModel().getEntryEntity("goodsentry");
BigDecimal amount = BigDecimal.ZERO;
BigDecimal connumsum = BigDecimal.ZERO;
BigDecimal pieceqty = BigDecimal.ZERO;
BigDecimal grossweightsum = BigDecimal.ZERO;
BigDecimal netweightsum = BigDecimal.ZERO;
BigDecimal piece = BigDecimal.ZERO;
for (DynamicObject entry : entrys) {
amount = BigDecimalUtils.add(amount, BigDecimalUtils.toBigDecimal(entry.getBigDecimal("amount")), 4);
connumsum = BigDecimalUtils.add(connumsum,
BigDecimalUtils.toBigDecimal(entry.getBigDecimal("tp_connum")), 4);
pieceqty = BigDecimalUtils.add(pieceqty, BigDecimalUtils.toBigDecimal(entry.getBigDecimal("piece")), 4);
grossweightsum = grossweightsum.add(entry.getBigDecimal("grossweightsum"));
netweightsum = netweightsum.add(entry.getBigDecimal("netweightsum"));
piece = piece.add(entry.getBigDecimal("vol"));
}
this.getModel().setValue("tp_decgweisum", grossweightsum);// 总毛重
this.getModel().setValue("tp_decnweisum", netweightsum);// 总净重
this.getModel().setValue("tp_totalvolume", piece);// 总体积
}
}
6.单据体分录监听事件( 新增 插入 复制触发此事件)
@Override
public void afterAddRow(AfterAddRowEventArgs e) {
super.afterAddRow(e);
EntryProp entryProp = e.getEntryProp();
if (StringUtils.equals("goodsentry", entryProp.getName())) {
DynamicObjectCollection entrys = this.getModel().getEntryEntity("goodsentry");
BigDecimal amount = BigDecimal.ZERO;
BigDecimal connumsum = BigDecimal.ZERO;
BigDecimal pieceqty = BigDecimal.ZERO;
BigDecimal grossweightsum = BigDecimal.ZERO;
BigDecimal netweightsum = BigDecimal.ZERO;
BigDecimal piece = BigDecimal.ZERO;
for (DynamicObject entry : entrys) {
amount = BigDecimalUtils.add(amount, BigDecimalUtils.toBigDecimal(entry.getBigDecimal("amount")), 4);
connumsum = BigDecimalUtils.add(connumsum,
BigDecimalUtils.toBigDecimal(entry.getBigDecimal("tp_connum")), 4);
pieceqty = BigDecimalUtils.add(pieceqty, BigDecimalUtils.toBigDecimal(entry.getBigDecimal("piece")), 4);
grossweightsum = grossweightsum.add(entry.getBigDecimal("grossweightsum"));
netweightsum = netweightsum.add(entry.getBigDecimal("netweightsum"));
piece = piece.add(entry.getBigDecimal("vol"));
}
this.getModel().setValue("totalamount", amount);
this.getModel().setValue("tp_consum", connumsum);// 集装箱数
this.getModel().setValue("tp_pieceqty", pieceqty);// 件数
this.getModel().setValue("tp_decgweisum", grossweightsum);// 总毛重
this.getModel().setValue("tp_decnweisum", netweightsum);// 总净重
this.getModel().setValue("tp_totalvolume", piece);// 总体积
}
}
7.beforeF7Select事件(实现implements BeforeF7SelectListener 并监听hscode.addBeforeF7SelectListener(this))
if ("hscode".equals(name)){//字段标识
List ids = new ArrayList();
int rowCount = model.getEntryRowCount("goodsentry");//分录标识
for(int j =0;j<rowCount;j++) {
DynamicObject material = (DynamicObject)model.getValue("material", j);
if(material!=null) {
material = BusinessDataServiceHelper.loadSingle(material.getPkValue(), material.getDynamicObjectType().getName(),"number,name,tp_mulhscode");
DynamicObjectCollection mulhscodeColl = material.getDynamicObjectCollection("tp_mulhscode");
if (null !=mulhscodeColl && mulhscodeColl.size()>0) {
for (int i = 0; i < mulhscodeColl.size(); i++) {
DynamicObject mulhscode = mulhscodeColl.get(i);
mulhscode = mulhscode.getDynamicObject("fbasedataid");
ids.add(mulhscode.getPkValue());
}
}
//过滤弹出框
QFilter qFilter = new QFilter("id", QCP.in, ids);
ListShowParameter showParameter = (ListShowParameter)e.getFormShowParameter();
showParameter.getListFilterParameter().setFilter(qFilter);
}else {
model.setValue("hscode", null, j);
}
}
}
8.单据体金额汇总方法
/**
* 总毛重
* @param view
* @param bill
*/
private void grossweightsum(IFormView view, IDataModel bill) {
DynamicObjectCollection entrys = bill.getEntryEntity("goodsentry");//分录标识
BigDecimal piece = BigDecimal.ZERO;
for (DynamicObject entry : entrys) {
piece = piece.add(entry.getBigDecimal("grossweightsum"));
}
this.getModel().setValue("tp_decgweisum", piece);
}
9:beforeItemClick 事件(用户点击单据列表主菜单工具栏上的按钮时,触发此事件)
public String getItemKey():按钮标识
public String getOperationKey():按钮绑定的操作
public void setCancel(boolean cancel):取消操作
@Override
public void beforeItemClick(BeforeItemClickEvent evt) {
super.beforeItemClick(evt);
String itemKey = evt.getItemKey();
IFormView view = this.getView();
String tips = "";
if (KEY_CLEARSHIPINFO.equals(itemKey)) {
tips = "确认清空船运信息吗?";
view.showConfirm(tips, MessageBoxOptions.OKCancel, new ConfirmCallBackListener(KEY_CLEARSHIPINFO, this));
evt.setCancel(true);
}
}
}
未完待续 持续更新