搜档网
当前位置:搜档网 › NC_API

NC_API

NC_API
NC_API

NC开发帮助

作者:jieely

? A

Accsubjdoc

// 通过系统提供的会计科目接口查询所有会计科目

Accsubjdoc itf =

(Accsubjdoc) NCLocator.getInstance().lookup(Accsubjdoc.class.getName());

nc.vo.bd.b02.AccsubjVO[] targetSubjV os = itf.queryAccsubjVOs(pk_glorgbook, null, false); AccperiodVO

//查询会计期间

AccperiodVO[] accperiodVOs =

(AccperiodVO[]) HYPubBO_Client.queryByCondition(AccperiodVO.class, " nvl(dr,0)=0 "); addBetch

a.无参批量更新

String sql = "update bd_deptdoc set dept_code =…aaa? where dept_code=…bbb?"; session.addBatch(sql); //添加需要执行的同构SQL

int rows = session.executeBatch(); //执行

b.有参批量更新

String sql = "update bd_deptdoc set dept_code =…aaa? where dept_code=?”; SQLParameter param = new SQLParameter(); //构造参数对象

param.addParam(“bbb”); //添加参数

session.addBatch(sql, param); //添加需要执行的同构SQL

int rows = session.executeBatch(); //执行

afterEdit

@Override//表的编辑后赋默认值方法(UI类重写方法)*先执行afterEdit,后执行公式* public void afterEdit(BillEditEvent event)

{

super.afterEdit(event);

if(event.getKey().equals("zd"))

{

t his.getBillCardPanel().execHeadEditFormulas();

}

else if (event.getTableCode().equals("st_xx_jyzy") &&

event.getKey().equals("code"))

{

t his.getBillCardPanel().setBodyValueAt(new UFBoolean('N'), event.getRow(), "jyzt");

t his.getBillCardPanel().setBodyValueAt(new UFBoolean('Y'), event.getRow(), "zyzt");

}

}

ALTER

//增加字段

ALTER TABLE tablea ADD newcol char(20)

//更改字段名

ALTER TABLE tablea CHANGE newcol newrow char(50)

//更改字段类型

ALTER TABLE tablea MODIFY newrow char(30)

//删除字段

ALTER TABLE tablea DROP newrow

ArrayList

ArrayList list = new ArrayList();

…..

list.add();

SettleVO[] vos = new SettleVO[list.size()];

vos = list.toArray(vos);//List与VO数组转换

? B

BillCode

//得到单据号

BillcodeGenerater billNoGen = new BillcodeGenerater();

billno = billNoGen.getBillCode("TI55", "0001", null, null);

BillData

BillData bd = getBillCardPanel().getBillData();

BillItem item = bd.getBodyItem(https://www.sodocs.net/doc/2c15729074.html,_TABLECODE1, "ialloctype");

BillField

@Override//修改单据状态时需重写此方法

protected IBillField createBillField()

{

return BillField.getInstance();

}

Button

//自定义按钮

public ButtonVO getFujian_btn()

{

ButtonVO btnVO = new ButtonVO();

btnVO.setBtnNo( IprivateButton.Fujian_btn );

btnVO.setBtnName( "附件管理" );

btnVO.setHintStr( "附件管理" );

btnVO.setOperateStatus( new int[]{IBillOperate.OP_NOTEDIT} ); // 在非新增和非编辑状态下可用

return btnVO;

}

//在UI中设置按钮状态

getButtonManager().getButton(nc.ui.trade.button.IBillButton.Add).setEnabled(false);

Byte[]

public static final byte[] m_ENTER = {0x0d, 0x0a};//换行符 ASCII码: 0x0d 0x0a ? C

CaseWhen

ORACLE: Case…..When 语句

SELECT

(CASE dr WHEN0THEN'有效'

WHEN1THEN'无效'

END) AS显示

FROM bd_corp

try{

}

catch(DbException e){

//如果是语法错误

if(e.isBadSQLGrammar()){

Logger.error("语法错误:"+e.getMessage(),e);

}

//如果是数据一致性错误

if(e.isDataIntegrityViolation()){

Logger.error("数据一致性错误:"+e.getMessage(),e);

}

}

CheckRule

<前台校验类> XXX UICheckRule

//校验数据是否重复

public IUniqueRule[] getItemUniqueRules(String tablecode) { if( "cl_gg_ytzwlb".equals( tablecode ) )

{

IUniqueRule[] unique = null;

unique = new IUniqueRule[]{

new UniqueRule("座类编码不能重复",new

String[]{("zlbm")})

};

return unique;

}

return null;

}

//校验是否为空

public ICheckRule[] getItemCheckRules(String tablecode) { CheckRule[] rules = new CheckRule[] {

new CheckRule("【NC结算方式编码】", "ncsettlecode", false, null, null)

};

return rules;

}

checkPrerequisite

//对于控制集团不能打开节点,只有公司可以打开节点的处理

//在ClientUI中覆写Toftpanel的方法:

public String checkPrerequisite()

{

String pk_corp = _getCorp().getPk_corp();

if (pk_corp.equals("0001")) {

return "当前处于集团,此功能点无法进入";

}

return null;

}

ClientEnvironment

Column

//单据模板获得jtable可通过getBillCardPanel().getBillTable()

//获取列表模型 TableColumnModel tcm=table.getColumnMode();

//第n列设置为隐藏

TableColumn hideColumn = table.getColumn("第n列");

//隐藏第n列设置

tcm.removeColumn(hideColumn);

//显示第n列设置

tcm.addColumn(hideColumn);

//把i列移动到第j列

tcm.moveColumn(i, j);

getBillCardPanel().getBodyPanel().hideTableCol(strKey);//隐藏

getBillCardPanel().getBodyPanel().showTableCol(strKey);//显示

ComboBox

UIComboBox typeCom = (UIComboBox) this.getBillCardPanel().getBodyItem("x").getComponent();

typeCom.addItems(Object[] obj);

Connection

PersistenceManager sessionManager = PersistenceManager.getInstance(); JdbcSession session = sessionManager.getJdbcSession();

Connection con = session.getConnection();

PreparedStatement stmt = null;

stmt = con.prepareStatement(con, sql);

finally{

stmt.close();

con.close();

sessionManager.release();}

ConnectException

//启动NC时抛异常

https://www.sodocs.net/doc/2c15729074.html,.ConnectException: Connection refused: connect

原因:80端口被占用

ConditionVO

//取查询对话框VO值

ConditionVO[] conVOs = getQueryDLG().getConditionVO();

for (int i = 0; i < conVOs.length; i++)

{

if ("billdate".equals(conVOs[i].getFieldCode()))

{

billdate = conVOs[i].getValue();

}

else if()

{

……

}

}

Coperatorid

//操作员所对应业务员

cworkpsnid->getColValue(bd_psndoc,pk_psndoc,pk_psnbasdoc,getColValue( sm_userandclerk,pk_psndoc,userid,coperatorid))

createQueryDLG()

/**

*重写父类方法,取得查询对话框,如有动态显示下拉框和默认值需重写此方法

*/

protected QueryDLG createQueryDLG() {

FundReportDLG dlg = new FundReportDLG();

dlg.setTempletID(

getUIControl()._getPk_corp(),

this.getModuleCode(),

getUIControl()._getOperator(),

null);

//设置默认日期

QueryConditionVO[] qryvos = dlg.getConditionDatas();

for(int i=0;i

if(qryvos[i].getFieldCode().equals("billdate")){ qryvos[i].setValue(getClientEnvironment().getDate().toString());

break;

}

}

return dlg;

}

CARDPANEL

if(clientUI.isListPanelSelected())//如果是选取的列表界面

clientUI.setCurrentPanel(BillTemplateWrapper.CARDPANEL);

Control

control userpasswords2 //运行【用户帐户】

Custflag

说明:0客户

1供应商

2既是客户又是供应商

3既是供应商又是客户

? D

DapCall

nc.ui.pf.pub.DapCall

getPkcorp()//取公司

getOperator()//取操作员

dataNotNullValidate

// 验证不能为空的字段

getBillCardPanelWrapper().getBillCardPanel().dataNotNullValidate();

dataSource

String dataSource = DataSourceCenter.getInstance().getSourceName();//取当前数据源

Date

UFDate date = ClientEnvironment.getInstance().getDate();//得到登陆日期

select to_char(last_day(to_date('20100625','yyyymmdd')),'dd') from dual;//得到每月多少天 DateFormat

public class DateTest {

public static void main(String[] args) {

String dates = "2007-8-14";//日期时间

DateFormat df = new SimpleDateFormat("yy-MM-dd");//日期格式化辅助类

Date d;

try {

d = df.parse(dates);//格式化日期

if (d.getDay() == 0 || d.getDay() == 6)//判断是不是双休日

System.out.println("日期:[" + dates + "] 是双休日");

else

System.out.println("日期:[" + dates + "] 不是双休日");

} catch (ParseException e) {

e.printStackTrace();

}

}

}

dataNotNullValidate

public void onBoSave() throws Exception {

getBillCardPanelWrapper().getBillCardPanel().getBillData().dataNotNullValidate ();//UAP模板设置必输项

boolean flag = true;

try

{

super.onBoSave();

}

catch (IllegalArgumentException e)

{

https://www.sodocs.net/doc/2c15729074.html,(e);

flag = false;

}

catch (Exception e)

{

if(flag)

this.getSelfUI().showErrorMessage("【资产名称】已存在,请检查");

return ;

}

super.onBoRefresh();

}

Decode

DECODE的语法:DECODE(value,if1,then1,if2,then2,if3,then3,...,else)

表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else。通过一些函数或计算替代value,是可以使DECODE函数具备大于、小于或等于功能。

Delete

删除废数据的方法如下:

有个表有3个字段ID, PID, NAME; 用父子结构来保存树的信息。

其中ID代表节点编号,PID是父节点编号;

由于删除的时候只删除了ID = id的记录, 没有把所有PID指向id的数据删除,导致大量无用的数据滞留

DELETE FROM TEST1

WHERE ID IN (SELECT ID

FROM TEST1

MINUS

SELECT ID

FROM TEST1

START WITH PID IS NULL

CONNECT BY PRIOR ID = PID);

//删除表中重复记录:

DELETE FROM a a1

WHERE ROWID IN (SELECT rd

FROM (SELECT ROWID rd,

ROW_NUMBER() OVER(P ARTITION BY bm,mc ORDER BY ROWID) rn

FROM a)

WHERE rn <> 1);

delLine

//表体增删行的操作,注意加上这一句代码

if ( event.getKey().equals("vdef2") )

{

f or( int i = 0 ; i < delnum ;i++)

{

this.getBillCardPanel().getBodyPanel().getTable().selectAll();

this.getBillCardPanel().delLine();

}

f or( int j = 0 ; addnum.intValue() > 0 && j < addnum.intValue() ;j++ )

{

this.getBillCardPanel().addLine();

this.getBillCardPanel().setBodyValueAt( "" + (j+1) , j, "code");

}

}

DesktopPanel

//nc.ui.sm.desktop.DesktopPanel

private void initialize(){

//============TODO modify by jtxr_jieely 【环保部项目专用】登陆后自动隐藏左侧树状条S tring pk_corp =

nc.ui.pub.ClientEnvironment.getInstance().getCorporation().getPrimaryKey();

i f("1002".equals(pk_corp))//只针对144001公司,主键为1002

{

setLayout(new BorderLayout());

setBackground(new Color(0xC1CCDB));

centerPanel = new JPanel(new BorderLayout());

centerPanel.setOpaque(false);

centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 3, 3, 5));

centerPanel.add(getTabbedPane(), BorderLayout.CENTER);

add(centerPanel, BorderLayout.CENTER);

add(getSysFuncBtnPanel(), BorderLayout.NORTH);

return;

}

// ============END 2010-08-25

setLayout(new BorderLayout());

setBackground(new Color(0xC1CCDB));

centerPanel = new JPanel(new BorderLayout());

centerPanel.setOpaque(false);

centerPanel.setBorder(BorderFactory.createEmptyBorder(0,3, 2,3));

centerPanel.add(getSingleSidZoomPane(), BorderLayout.WEST);

centerPanel.add(getTabbedPane(), BorderLayout.CENTER);

add(centerPanel, BorderLayout.CENTER);

add(getSysFuncBtnPanel(), BorderLayout.NORTH);

}

DetailReportBaseEx

//报表UI类中的反注册按钮方法

protected void setPrivateButtons() {

this.unRegisterButton(ButtonAssets.m_boRefresh);

this.unRegisterButton(ButtonAssets.m_boGroup);

this.unRegisterButton(ButtonAssets.m_boFilter);

this.unRegisterButton(ButtonAssets.m_boCross);

this.unRegisterButton(ButtonAssets.m_boSort);

}

dialog

/**

*启用系统运行提示框避免造成假死现象

*/

private void onButton_import()

{

// 该操作是耗时操作,所以启用系统运行提示框

Runnable runImpDoc = new Runnable()

{

public void run()

{

BannerDialog dialog = new BannerDialog(getCurrUI());

dialog.start();

try

{

importData();

}

catch (Exception e)

{

dialog.end();

e.printStackTrace();

return;

}

dialog.end();// 销毁系统运行提示框

}

};

new Thread(runImpDoc).start();

}

/**

*系统运行提示框

*/

private Container getCurrUI()

{

return this.getSelfUI();

}

? E

Excel

//获取sheet中的HSSFRow对象,如果没有就创建一个

private HSSFRow getRow(HSSFSheet sheet, int rowNum)

{

HSSFRow row = sheet.getRow(rowNum);

return row == null ? sheet.createRow(rowNum) : row;

}

//获取sheet中的HSSFCell对象,如果没有就创建一个

private HSSFCell getCell(HSSFRow row, short cellNum)

{

HSSFCell cell = row.getCell(cellNum);

return cell == null ? row.createCell(cellNum) : cell;

}

//单元格赋值

public static void setCellValue(HSSFCell cell ,String cellValue) {

cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);//这一句是解决中文乱码问题cell.setCellValue(cellValue);//单元格赋值

}

//设置单元格背景颜色(为红色)

public static void setCellColorRed(HSSFCellStyle style, HSSFCell cell)

{

style.setFillForegroundColor(HSSFColor.RED.index);

style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

cell.setCellStyle(style);;

}//说明:HSSFColor里有好多颜色,可根据要求改为其他

//获取单元格背景颜色

public static void getCellColor(HSSFCell cell ) {

HSSFCellStyle style = cell.getCellStyle();

short colorIndex = style.getFillForegroundColor();

}

Exe

1.0 用java调用windows系统的exe文件,比如notepad,calc之类:

public class Demo{

public static void main(String args[]){

Runtime rn=Runtime.getRuntime();

Process p=null;

try{

p=rn.exec(notepad);

}catch(Exception e){

System.out.println("Error exec notepad");

}

}

}

2.0调用其他的可执行文件,例如:自己制作的exe,或是下载安装的软件public class Demo{

public static void main(String args[]){

Runtime rn=Runtime.getRuntime();

Process p=null;

try{

p=rn.exec(""D:/AnyQ/AnyQ.exe"");

}catch(Exception e){

System.out.println("Error exec AnyQ");

}

}

}

EXP/IMP

exp nc50/nc50@MINE file=e:\0328.dmp OWNER = nc50//导出

imp nc50/nc50@mine file=e:\0227.dmp fromuser=nc50test touser=nc50//导入 ExportExcel

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import javax.swing.JFileChooser;

import nc.bs.logging.Logger;

import https://www.sodocs.net/doc/2c15729074.html,ermodel.HSSFCell;

import https://www.sodocs.net/doc/2c15729074.html,ermodel.HSSFRow;

import https://www.sodocs.net/doc/2c15729074.html,ermodel.HSSFSheet;

import https://www.sodocs.net/doc/2c15729074.html,ermodel.HSSFWorkbook;

public class ExportExcel

{

private ClientUI clientUI = null;

public ExportExcel(ClientUI clientUI)

{

this.clientUI = clientUI;

}

/**

* 生成Excel文件

*/

public String makeExcel(Object[] cellVOs)

{

String[] keys1 = (String[]) cellVOs[0];

String[] keys2 = (String[]) cellVOs[1];

InputStream inputstream = null;

OutputStream outputstream = null;

String filePath = getFilePath();

if (filePath == null)

return filePath;

this.CreateExcel(filePath);

try

{

inputstream = new FileInputStream(filePath);

HSSFWorkbook book = new HSSFWorkbook(inputstream);

HSSFSheet sheet1 = book.getSheetAt(0);

for (int i = 0; i < keys1.length; i++)

{

int rowNum = i;

short cellNum1 = 1;

String goalPK1 = keys1[i];

HSSFRow row1 = getRow(sheet1, rowNum);

setCellValue(getCell(row1, cellNum1), goalPK1);

}

for (int i = 0; i < keys2.length; i++)

{

int rowNum = i;

short cellNum2 = 2;

String goalPK2 = keys2[i];

HSSFRow row2 = getRow(sheet1, rowNum);

setCellValue(getCell(row2, cellNum2), goalPK2);

}

File excel = new File(filePath);

outputstream = new FileOutputStream(excel);

book.write(outputstream);

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

}

finally

{

if (inputstream != null)

{

try

{

inputstream.close();

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

}

}

if (outputstream != null)

{

try

{

outputstream.close();

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

}

}

}

return filePath;

}

/**

* 获取sheet中的HSSFRow对象,如果没有就创建一个

*

* @param sheet

* @param rowNum

* 所在的行,索引从0开始

* @return

*/

private HSSFRow getRow(HSSFSheet sheet, int rowNum)

{

HSSFRow row = sheet.getRow(rowNum);

return row == null ? sheet.createRow(rowNum) : row;

}

/**

* 获取sheet中的HSSFCell对象,如果没有就创建一个

*

* @param row

* HSSFCell对象所在的行

* @param cellNum

* 所在的列,索引从0开始

* @return

*/

private HSSFCell getCell(HSSFRow row, short cellNum)

{

HSSFCell cell = row.getCell(cellNum);

return cell == null ? row.createCell(cellNum) : cell;

}

/**

* 设置单元格值

*

* @param cell

* @param value

*/

@SuppressWarnings("deprecation")

private void setCellValue(HSSFCell cell, String cellValue)

{

cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);

cell.setCellValue(cellValue);// 单元格赋值

}

/**

* 得到生成文件的全路径

*

* @return

*/

private String getFilePath()

{

String filePath = null;

JFileChooser chooser = new JFileChooser();

chooser.setMultiSelectionEnabled(false);

chooser.setFileFilter(new javax.swing.filechooser.FileFilter()

{

public boolean accept(File file)

{

return file.getName().toLowerCase().endsWith(".xls");

}

public String getDescription()

{

return "Excel工作薄(*.xls)";

}

});

int returnVal = chooser.showOpenDialog(clientUI);

if (returnVal == JFileChooser.CANCEL_OPTION)

{

clientUI.showHintMessage("未生成Excel文件");

}

else

{

try

{

File file = chooser.getSelectedFile();

filePath = file.getCanonicalPath().endsWith(".xls") ? file.getCanonicalPath() : file.getCanonicalPath() + ".xls";

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

e.printStackTrace();

}

}

return filePath;

}

/**

* 在指定路径下创建Excel文件

*/

private void CreateExcel(String filePath)

{

FileOutputStream fOut = null;

try

{

HSSFWorkbook workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet("Sheet1");

HSSFRow row = sheet.createRow((short) 0);

row.createCell((short) 0);

fOut = new FileOutputStream(filePath);

workbook.write(fOut);

}

catch (FileNotFoundException e)

{

Logger.error("FileNotFoundException错误:" + e.getMessage(), e);

e.printStackTrace();

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

e.printStackTrace();

}

finally

{

try

{

fOut.flush();

fOut.close();

}

catch (IOException e)

{

Logger.error("IO错误:" + e.getMessage(), e);

e.printStackTrace();

}

}

}

}

? F

File

//处理单据上的图片类型

//首先在模版上设置此字段数据类型为: 图片类型

//在节点上新增单据时,双击此字段可以选择图片(和参照类似),选择后界面会自动显示//单据保存时:

//得到路径

String path = getBillCardPanel().getHeadItem("userphoto").getImagePath();

//取到文件名然后上传到服务器(默认路径是nchome\webapps\nc_web\ncupload )

File file = new File(path);

FileManagerUtil.saveFileToServer("USERIMAGE/",file.getAbsolutePath());

//然后可以把服务器存取此图片的路径和文件名赋值到VO保存到数据库.

//以后查询的时候转载图片:

//首先取到此单据VO 中的: 图片路径和文件名

File file = new File(vo.getUserPhoto);

//用下边方法把图片下载到本地(默认是在和缓存同级的NCCODE/ 下) FileManagerUtil.saveFileToLocal("USERIMAGE/", file.getName());

//构造URL

URL url = FileManagerUtil.getFileURLLocal("USERIMAGE/", file.getName());

//为图片字段赋值

ImageIcon = new ImageIcon(url);

((UILabel)getBillCardPanel().getHeadItem("userphoto").getComponent()).setIcon(new ImageIcon(url));

FileCreate

//在用户目录\jieely\下创建文件test.txt

public static void main(String[] args)

{

String userhome = System.getProperty("user.home");

String path = "\\jieely\\";

String absPath = userhome+path;

RandomAccessFile mm = null;

try

{

File folder = new File(absPath);

if (!folder.exists()) // 如果不存在则建该文件夹

folder.mkdir();

mm = new RandomAccessFile(absPath+"test.txt", "rw");

mm.writeBytes("AAAAAAA");

}

catch (FileNotFoundException e)

{

Logger.error(e);

}

catch (IOException e)

{

Logger.error(e);

e.printStackTrace();

}

}

FileFilter

A: 设置读取指定类型的文件

p ublic class PhotoFileFilter extends FileFilter

{

public boolean accept(File f)

{

if(f.isDirectory() || f.getName().endsWith(".jpg") || f.getName().endsWith(".gif") || f.getName().endsWith(".jpeg"))

{

相关主题