1、单据设置某行或某字段不能修改
//i是行号,"cash"是字段名称
getBillCardPanelWrapper().getBillCardPanel().getBillModel().setCellEditable(i, "cash", false);
//取得单据表体所有项用以上语句做循环就能设置整行了
getBillCardPanelWrapper().getBillCardPanel().getBodyItems();
2、判断是否在卡片状态下
public boolean isCardPanel(){
boolean istrue = true;
ButtonObject[] buobj = super.getButtons();
for(int i = 0 ;i<buobj.length;i++){
String btnName = buobj[i].toString();
Object btnStatus = buobj[i].isEnabled();
//列表显示返回false
if("卡片显示".equals(btnName) && btnStatus.equals(true)){
istrue = false;
break;
}
}
return istrue;
}
3、JTree中得到当前选择节点的最末级子节点
1)、构造树的时候已经把数据按编码进行了排序,而且编码类似于这样:1401->140101 140102 .并将对象VO放到DefaultMutableTreeNode的userObject中.
2)、选择树时,可以通过这行代码得到选择的节点
DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent();
BudgetTargetVO vo = (BudgetTargetVO)node.getUserObject();
3)、得到选择节点node的最后一个子节点
DefaultMutableTreeNode nn = (DefaultMutableTreeNode)node.getLastChild();
nn即为当前选择节点的编码最大的子节点...
4、在UI画面上设置一个按钮的快捷键
调用ButtonObject的下面两个方法即可
1> setModifiers(int modifiers) 设置任意修饰符,可以调用NCKey类中的常量,如:NCKey.MODIFIERS_ALT
2> setHotKey(String keyStr) 设置任意快捷键,如:"G"。
假如我们创建了一个ButtonObject类型的对象按钮bnObj,通过下面的设置,就可以指定按钮的快捷键为:alt+G
bnObj.setModifiers(NCKey.MODIFIERS_ALT);
bnObj.setHotKey("G");
5、nc后台怎么得到当前的登录用户
String usercode = nc.bs.framework.common.InvocationInfoProxy.getInstance().getUserCode();
(nc.ui.pub.ClientEnvironment.getInstance().getUser()这个在前台用)
6、前台更新语句
nc.itf.uif.pub.IUifService srv=(nc.itf.uif.pub.IUifService)NCLocator.getInstance().lookup("nc.itf.uif.pub.IUifService");
------------------------------------------------------------------------------------
7、 在单据初始化的时候就把表体某些字段的默认颜色修改为红色
getBillListPanel().getBodyBillModel().setFont(new Font(null,Font.PLAIN,20));
------------------------------------------------------------------------------------
8、查询条件主子转换
public void onBoQuery() throws Exception{
StringBuffer strWhere = new StringBuffer();
if (askForQueryCondition(strWhere) == false)
return;// 用户放弃了查询
SuperVO[] queryVos = queryHeadVOs(convertSqlWhere(strWhere,"kyss_install_b",
new String[]{"kyss_install_b.vdebugid","kyss_install_b.vinstallid","kyss_install_b.dhd_spname"},
"pk_install"));
getBufferData().clear();
addDataToBuffer(queryVos);
updateBuffer();
}
/**
* 转换查询模板中的子表条件为主表条件,子表条件应与查询模板中一致
* @param strWhere
* @param tab_b 子表名
* @param fields 子表条件项
* @param refField 关联的主表pk
* @return
* @throws Exception
*/
public String convertSqlWhere(StringBuffer strWhere,String tab_b,String[] fields,String refField) throws Exception{
String str = "";
String newSql = strWhere.toString();
for (int i = 0; i < fields.length; i++) {
ConditionVO[] vo =
((HYQueryDLG) getQueryUI()).getConditionVOsByFieldCode(fields[i]);
if (!Toolkit.isEmpty(vo)) {
if (!Toolkit.isEmpty(vo[0].getValue())) {
str = vo[0].getValue();
}
if (!Toolkit.isEmpty(vo[0].getValue())) {
newSql = Toolkit.replaceAll(newSql, fields[i], "'1'");
newSql = Toolkit.replaceAll(newSql, str, "1");
newSql = newSql + " and "+refField+" in (";
newSql = newSql + " select pk_install from "+tab_b;
newSql = newSql + " where "+fields[i]+" = '" + str + "' and nvl(dr, 0) = 0)";
}
}
}
return newSql;
}
getBillCardPanel().getBillModel("costs").setValueAt(oVer,arow,"pver");
//修改行状态
bm.setRowState(arow, BillModel.MODIFICATION);
------------------------------------------------------------------------------------
9、判断表体列不重复
public int uniqueCheck(BillModel bm,String[] code){
int res= -1;
HashMap hm=new HashMap();
for(int i=0;i<bm.getRowCount();i++){
String key="key";
for(int j=0;j<code.length;j++){
key+=bm.getValueAt(i,code[j])==null?"":bm.getValueAt(i,code[j]).toString();
}
if(hm.containsKey(key)){
return i+1;
}
hm.put(key, i+"");
}
return res;
}
public int uniqueCheck(CircularlyAccessibleValueObject[] cvos,String[] code){
int res= -1;
HashMap hm=new HashMap();
for(int i=0;i<cvos.length;i++){
String key="key";
for(int j=0;j<code.length;j++){
key += cvos[i].getAttributeValue(code[j]) == null? "" : cvos[i].getAttributeValue(code[j]).toString();
}
if(hm.containsKey(key)){
return i+1;
}
hm.put(key, i+"");
}
return res;
}
------------------------------------------------------------------------------------
10、单据模板不允许点击表头排序
//移除HEAD表头排序监听
getBillListPanel().getHeadTable().removeSortListener();
//移除BODY表头排序监听
getBillListPanel().getBodyTable().removeSortListener();
------------------------------------------------------------------------------------
11、表单界面数据编辑状态控制
调用代码
BillModel bm = ainpanel.getBillListPanel().getHeadBillModel();
BillModelCellEditableController bmc=new BillModelCellEditableController();
bmc.setRows(new int[]{1,3,5});
bm.setCellEditableController();
界面控制类
public class EditableControllerImpl implements BillModelCellEditableController{
private int rows[]=null;
public boolean isCellEditable(boolean value, int row, String itemkey) {
boolean tag=true;
for(int i=0;i<rows.length;i++){
if(row==rows[i]){
tag=false;
}
}
return tag;
}
public void setRows(int rows[]){
this.rows=rows;
}
}
------------------------------------------------------------------------------------
12、会计科目参照
BillItem items[] = new BillItem[sBodyItemKeys.length];
items[i].setDataType(5);//items[i].setDataType(BillItem.UFREF);
items[i].setRefType("会计科目");//如果是参照收支项目:items[i].setRefType("收支项目");
items[i].setLoadFormula(new String[]{"jksubjname->getColValue(bd_accsubj,subjname,pk_accsubj,jksubjpk)",});
items[i].setIDColName("jksubjpk");
items[i].setEditFormula(new String[]{"jksubjname->getColValue(bd_accsubj,subjname,pk_accsubj,jksubjpk)",});
------------------------------------------------------------------------------------
13、附件
public void doFile(){
int irow = getMainPanel().getBillTable().getSelectedRow();
if(irow < 0) return;
String pk_ssinfo = getMainPanel().getBodyValueAt(irow, "pk_ssinfo")==null
?"":getMainPanel().getBodyValueAt(irow, "pk_ssinfo").toString();
if(pk_ssinfo == null || "".equals(pk_ssinfo)) return;
// FileManageUI.showInDlg(this,"附件",pk_ssinfo);
FileManageTreeTableUI.showInDlg(this,"附件",pk_ssinfo);
}
------------------------------------------------------------------------------------
14、前台调用接口
接口名 iquery = (接口名) NCLocator.getInstance().lookup(接口名.class.getName());
------------------------------------------------------------------------------------
15、返回选择的文件路径
public String getUserFilePath(){
//弹出客户端对话框
UIFileChooser m_filechooser = new UIFileChooser();
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("xls");
filter.setDescription("EXCEL文件");
m_filechooser.setFileFilter(filter);
m_filechooser.setDialogType(JFileChooser.FILES_ONLY);//m_filechooser.setDialogType(JFileChooser.SAVE_DIALOG);
int result = m_filechooser.showOpenDialog(null);//m_filechooser.showSaveDialog(null);
if(result != 0) return null;
//取得用户保存的路径和文件名
final String filepath= m_filechooser.getSelectedFile().getParent();
final String filename = m_filechooser.getSelectedFile().getName();
final String ExcelFile_Path = filepath+"\\"+filename;
return ExcelFile_Path;
}
------------------------------------------------------------------------------------
16、设置多表头
//设置多表头
public void setMultiHead(){
BillTable table = getBodyPanel().getTable();
GroupableTableHeader header = (GroupableTableHeader) table.getTableHeader();
TableColumnModel cm = table.getColumnModel();
ColumnGroup subjname = new ColumnGroup("科目名称");
//合并哪些列
subjname.add(cm.getColumn(0));
subjname.add(cm.getColumn(1));
header.addColumnGroup(subjname);
ColumnGroup rlpropn = new ColumnGroup("人力提取计划(元)");
rlpropn.add(cm.getColumn(2));
rlpropn.add(cm.getColumn(3));
rlpropn.add(cm.getColumn(4));
rlpropn.add(cm.getColumn(5));
header.addColumnGroup(rlpropn);
ColumnGroup cwpropn = new ColumnGroup("财务成本列支(元)");
cwpropn.add(cm.getColumn(6));
cwpropn.add(cm.getColumn(7));
cwpropn.add(cm.getColumn(8));
cwpropn.add(cm.getColumn(9));
header.addColumnGroup(cwpropn);
// ColumnGroup fipay = new ColumnGroup("实际支出(元)");
// fipay.add(cm.getColumn(10));
// header.addColumnGroup(fipay);
}
------------------------------------------------------------------------------------
17、增行时表体联动
/*-------------------增行时表体联动表头选择的标准类型 START--------------------------------*/
//得到表头选择标准类型
Grade_BZTypeVO btVO = (Grade_BZTypeVO)this.getMainCardPanel().getHeadItem("bztype").getValueObject();
//设置表体新增行的pk_bztype字段值setBodyValueAt(值,行号,字段)
this.getMainCardPanel().setBodyValueAt(btVO.getPk_bztype(), this.getMainCardPanel().getRowCount()-1, "pk_bztype");
//执行表体加载公式(如果没有设置公式可以不用)
this.getMainCardPanel().getBillModel().execLoadFormula();
/*-------------------增行时表体联动表头选择的标准类型 END---------------------------------*/
------------------------------------------------------------------------------------
18、得到参照中PK字段的值
UIRefPane ref = (UIRefPane)this.getHeadItem("pk_bz").getComponent();
return ref.getRefPKs();
19、得到参照中非PK的其他字段的值
/**
* 得到选择的评价标准类型主键
* @return String[] 评价标准类型主键
*/
public String[] getPKBZTypes()
{
ArrayList<String> list = null;
/*得到参照中选择的评价标准类型主键*/
UIRefPane ref = (UIRefPane)this.getHeadItem("pk_bz").getComponent();
Object obj[] = (Object[])ref.getRefValues("b.pk_bztype");
if(obj!=null)
{
list = new ArrayList<String>();
for (int i=0;i<obj.length;i++) {
//去重复
if(!list.contains(obj))
{
list.add((String)obj[i]);
}
}
}
if(list==null)
{
return null;
}
return list.toArray(new String[0]);
}
------------------------------------------------------------------------------------
20、取得表体选择行的VO
/**
* 取得页面选择的VO
* @return Grade_CorpWeightVO[]
*/
public Grade_CorpWeightVO[] getBillSelectVOs(){
int row_count = getRowCount();
if (row_count <= 0)
return null;
int[] rows = getBillTable().getSelectedRows();
if(rows==null||rows.length==0){
return null;
}
for (int i = 0; i < row_count; i++) {
getBillModel().setRowState(i, BillModel.NORMAL);
}
for (int xxx = 0; xxx < rows.length; xxx++) {
getBillModel().setRowState(rows[xxx], BillModel.SELECTED);
}
Grade_BZVO[] vos = (Grade_BZVO[]) getBillModel()
.getBodySelectedVOs(Grade_BZVO.class.getName());
return vos;
}
------------------------------------------------------------------------------------
21、设置表体只能单选
this.getBillTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
22、表体菜单事件监听
实现:
implements BillBodyMenuListener
添加监听:
addBodyMenuListener(this);
方法:如
public void onMenuItemClick(ActionEvent arg0) {
if("删行".equals(arg0.getActionCommand())){
if(this.getRowCount()!=1){
super.delLine();
}
}else if("增行".equals(arg0.getActionCommand())){
super.addLine();
}
}
23、查询数据源是否存在
/**
* 判断数据源是否存在
* @param dsName 数据源名称
* @return true:存在,false:不存在
*/
public boolean checkDataSource(String dsName){
boolean exist = false;
String[] ds;
try {
ds = XMLTableStruDataBO_Client.readDataSources();
for(int xx=0;xx<ds.length;xx++){
if(dsName.equals(ds[xx])){
exist = true;
}
}
if(!exist){
MessageDialog.showErrorDlg(this, "错误", "数据源不存在,操作失败!");
}
} catch (Exception e1) {
e1.printStackTrace();
MessageDialog.showErrorDlg(this, "错误", "判断数据源时发生错误");
}
return exist;
}
24、后台得到日期
public static UFDate getBSDate(){
InvocationInfoProxy invocationInfoProxy = InvocationInfoProxy.getInstance();
UFDate bsDate = null;
if (null != invocationInfoProxy && null != invocationInfoProxy.getDate() && !"null".equals(invocationInfoProxy.getDate()))
bsDate = new UFDate(Long.parseLong(invocationInfoProxy.getDate()));
return bsDate;
}
25、状态栏显示文字
ToftPanel中 this.showHintMessage("提示内容");
26、数字类型加千分位分割符
BillItemNumberFormat format = new BillItemNumberFormat();
format.setShowThMark(true);
items[i].setNumberFormat(format);