package nc.ui.xhfx.pub;
import java.awt.Component;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.KeyboardFocusManager;
import javax.swing.JComponent;
import nc.ui.pub.beans.UIComboBox;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillData;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.UITextAreaScrollPane;
import nc.vo.pub.NullFieldException;
import nc.vo.pub.ValidationException;
import nc.vo.pub.bill.BillTabVO;
/**
* 校验必输项,并光标定位到第一个必输项
*
* @author baidx
*
*/
public class DataNotNullValidate {
BillCardPanel cardPanel = null;
BillData bd = null;
public DataNotNullValidate(BillCardPanel cardpanel) {
cardPanel = cardpanel;
bd = cardPanel.getBillData();
}
/**
* 校验必输项,并光标定位
*
* @param bd
* @throws ValidationException
*/
public void validate() throws ValidationException {
StringBuffer message = null;
BillItem[] headtailitems = bd.getHeadTailItems();
BillItem firstNullItem = null;
if (headtailitems != null) {
for (int i = 0; i < headtailitems.length; i++) {
if (headtailitems[i].isNull())
if (headtailitems[i].isEnabled() // 可编辑
&& headtailitems[i].isBaseTableCodeShow() // 卡片显示
&& isNULL(headtailitems[i].getValueObject())) {
if (firstNullItem == null) {
firstNullItem = headtailitems[i];
}
// setShowWarn(headtailitems[i], true);// 是否显示图标
if (message == null)
message = new StringBuffer();
message.append("[");
message.append(headtailitems[i].getName());
message.append("]");
message.append(",");
} else {
// setShowWarn(headtailitems[i], false);
}
}
}
if (message != null) {
message.deleteCharAt(message.length() - 1);
// 光标定位
String tableCode = firstNullItem.getTableCode();
BillTabVO tabvo = new BillTabVO();
tabvo.setPos(BillData.HEAD);
tabvo.setTabcode(tableCode);
int index = cardPanel.getHeadTabbedPane().getIndexofTableCode(tabvo);
cardPanel.getHeadTabbedPane().setSelectedIndex(index);
// 5.5 UIDialog加入show和hide两个邪恶的方法后修改.不知道以后还会出什么问题.09.6.25 baidx
Component com = null;
if (firstNullItem.getDataType() == BillItem.TEXTAREA) {
com = ((UITextAreaScrollPane) firstNullItem.getComponent()).getUITextArea();
} else {
com = firstNullItem.getComponent();
}
MyManager a = new MyManager();
MyManager.setCurrentKeyboardFocusManager(KeyboardFocusManager.getCurrentKeyboardFocusManager());
a.setFocusOwner(com);
KeyboardFocusManager.setCurrentKeyboardFocusManager(a);
// end------------
cardPanel.paint(cardPanel.getGraphics());
throw new NullFieldException(message.toString());
}
// 增加多子表的循环
String[] tableCodes = bd.getTableCodes(BillData.BODY);
int row = -1;
if (tableCodes != null) {
for (int t = 0; t < tableCodes.length; t++) {
String tablecode = tableCodes[t];
for (int i = 0; i < bd.getBillModel(tablecode).getRowCount(); i++) {
StringBuffer rowmessage = new StringBuffer();
rowmessage.append(" ");
if (tableCodes.length > 1) {
rowmessage.append(bd.getTableName(BillData.BODY, tablecode));
rowmessage.append("(");
// "页签"
rowmessage.append(nc.ui.ml.NCLangRes.getInstance().getStrByID("_Bill", "UPP_Bill-000003"));
rowmessage.append(") ");
}
rowmessage.append(i + 1);
rowmessage.append("(");
// "行"
rowmessage.append(nc.ui.ml.NCLangRes.getInstance().getStrByID("_Bill", "UPP_Bill-000002"));
rowmessage.append(") ");
StringBuffer errormessage = null;
BillItem[] items = bd.getBodyItemsForTable(tablecode);
for (int j = 0; j < items.length; j++) {
BillItem item = items[j];
if (item.isNull()) {
Object aValue = bd.getBillModel(tablecode).getValueAt(i, item.getKey());
// 090720 add by baidx 判断表体cell编辑属性,不可编辑则不判空
boolean bis = cardPanel.getBillModel(tablecode).isCellEditable(i,
cardPanel.getBillModel(tablecode).getBodyColByKey(item.getKey()));
if (item.isEnabled() && bis && item.isBaseTableCodeShow() && isNULL(aValue)) {
if (firstNullItem == null) {
firstNullItem = item;
row = i;
}
errormessage = new StringBuffer();
errormessage.append("[");
errormessage.append(item.getName());
errormessage.append("]");
errormessage.append(",");
}
}
}
if (errormessage != null) {
errormessage.deleteCharAt(errormessage.length() - 1);
rowmessage.append(errormessage);
if (message == null)
message = new StringBuffer(rowmessage);
else
message.append(rowmessage);
break;
}
}
if (message != null)
break;
}
}
if (message != null) {
// 光标定位
String tableCode = firstNullItem.getTableCode();
int col = cardPanel.getBillTable(tableCode).convertColumnIndexToView(
cardPanel.getBillModel(tableCode).getBodyColByKey(firstNullItem.getKey()));
BillTabVO tabvo = new BillTabVO();
tabvo.setPos(BillData.BODY);
tabvo.setTabcode(tableCode);
int index = cardPanel.getBodyTabbedPane().getIndexofTableCode(tabvo);
cardPanel.getBodyTabbedPane().setSelectedIndex(index);
cardPanel.getBillTable(tableCode).setRowSelectionInterval(row, row);
cardPanel.getBillTable(tableCode).setColumnSelectionInterval(col, col);
throw new NullFieldException(message.toString());
}
}
class MyManager extends DefaultKeyboardFocusManager {
void setFocusOwner(Component c) {
setGlobalFocusOwner(c);
}
}
private boolean isNULL(Object o) {
if (o == null || o.toString().trim().equals(""))
return true;
return false;
}
// public static void setShowWarn(BillItem item, boolean isshow) {
// String str = item.getName() + "必需录入";
// JComponent com = item.getComponent();
// if (com instanceof UIRefPane) {
// ((UIRefPane) com).getUITextField().setShowWarning(isshow);
// ((UIRefPane) com).getUITextField().setStrWarn(isshow ? str : null);
// } else if (com instanceof UIComboBox) {
// ((UIComboBox) com).setShowWarning(isshow);
// ((UIComboBox) com).setStrWarn(isshow ? str : null);
// }
//
// }
}
NC57 单据必输项校验类
最新推荐文章于 2023-03-24 15:59:51 发布