0

grid can not be clear after second action

asked 2009-01-21 17:09:57 +0800

ibsolution gravatar image ibsolution
468 1 1 6

hai,

i create dynamic grid. i need to clear all component inside my grid.

i got a problem when i click a button "save and new". zk can not clear a grid when second entry

first entry this below code run well, after i click "save and new" button and try entry again and save and new again that code can not clear the grid.

		Grid mygrid = (Grid)getComponent(GRIDNAME);
		Rows gridRows = (Rows)getComponent("gridrows");
		mygrid.removeChild(gridRows);
		gridRows = new Rows();
		gridRows.setId("gridrows");
		gridRows.setParent(mygrid);
		mygrid.setId(GRIDNAME);

is there any solution ?

TIA,

Andy Susanto

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2009-01-21 18:28:03 +0800

YamilBracho gravatar image YamilBracho
1722 2

Try:

Grid mygrid = (Grid) getComponent(GRIDNAME);
mygrid.getRows().clear();

link publish delete flag offensive edit

answered 2009-01-22 00:16:30 +0800

ibsolution gravatar image ibsolution
468 1 1 6

hai,

which version zk that have a clear method ?

i am using zk 3.5.2

Regards,

Andy Susanto

link publish delete flag offensive edit

answered 2009-01-22 00:49:00 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

It should be - mygrid.getRows().getChildren().clear();

The clear method existed in Java List API for a long time, please see its JavaDoc

link publish delete flag offensive edit

answered 2009-01-26 16:03:26 +0800

ibsolution gravatar image ibsolution
468 1 1 6

hai jumperchen

please create a grid that can added row dynamic. after that try to clear a row.

first click all row will deleted. but when you try second click all row can not be deleted.

dynamic grid with some component

TIA,

Andy Susanto

link publish delete flag offensive edit

answered 2009-02-02 04:16:47 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

Could you give me a sample?

Thanks in advance.

link publish delete flag offensive edit

answered 2009-02-03 14:16:16 +0800

ibsolution gravatar image ibsolution
468 1 1 6

hai,

i can give you my vm if you want to try

TIA

Andy Susanto

link publish delete flag offensive edit

answered 2009-02-04 04:35:00 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi Andy,

It is better to simplify to be a war file or some zul file.

Thanks,
Jumper

link publish delete flag offensive edit

answered 2009-02-07 07:18:22 +0800

ibsolution gravatar image ibsolution
468 1 1 6

hai,

zul file

<?init class="ibs.transaksi.sales.NewSalesInvoice" ?>

<window id="wndsalesinvoiceentry" title="New Sales Invoice"
	mode="overlapped" closable="true"
	use="ibs.transaksi.sales.NewSalesInvoice"
	onClose="wndsalesinvoiceentry.refreshList()">
	Customer :
	<combobox id="customer" autodrop="true" />
	<separator />
	Nomor :
	<textbox id="no" />
	Tanggal :
	<datebox id="tanggaltransaksi" format="dd/MM/yyyy" compact="true" />
	<vbox>
		keterangan
		<textbox id="keterangan" rows="5" cols="140" multiline="true" />
	</vbox>
	<separator />
	<grid id="salesinvoicedetil" height="130px">
		<columns>
			<column label="Item" />
			<column label="Deskripsi" />
			<column label="Quantity" />
			<column label="Unit Price" />
			<column label="Satuan" />
			<column label="Price" align="right" />
			<column label="" />
		</columns>
		<rows id="gridrows"></rows>
	</grid>
	<grid>
		<columns>
			<column />
			<column align="right" />
		</columns>
		<rows>
			<row>
				<label value="Sub Total" />
				<label id="subtotal" value="0" />
			</row>
			<row>
				<label value="Diskon" />
				<decimalbox id="diskoninvoice" format="#,##0.##"
					value="0" onBlur="wndsalesinvoiceentry.recalculateDiscount()" />
			</row>
			<row>
				<label value="Total Invoice" />
				<label id="totalinvoice" value="0" />
			</row>
		</rows>
	</grid>
	<groupbox>
		<button label="Save" id="save"
			onClick="wndsalesinvoiceentry.actionSave()" />
		<button label="Save New" id="savenew" visible="true"
			onClick="wndsalesinvoiceentry.onSaveAndNew()" />
		<button label="Print" id="print"
			onClick="wndsalesinvoiceentry.onPrint()" />
	</groupbox>
</window>

java file

package ibs.transaksi.sales;

import ibs.object.control.invoice.EntryInvoiceSalesForm;
import ibs.object.generic.Form;
import ibs.object.generic.ItemObject;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.transaction.xa.Xid;

import org.joda.time.DateTime;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Decimalbox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Groupbox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.Window;

import com.mysql.jdbc.jdbc2.optional.MysqlXid;

public class NewSalesInvoice extends EntryInvoiceSalesForm{

	/**
	 * 
	 */
	private static final long serialVersionUID = 5382107385315920460L;

	private int DETAILARRAY=8;
	protected static final String TABLETYPE ="SI";
	private String GRIDNAME="salesinvoicedetil";
	private String WINDOWNAME= "wndsalesinvoiceentry";


	public NewSalesInvoice() {
		super();
	}

	NewSalesInvoice(int id,String name){
		super(id,name);
	}

	@Override
	public void doAfterCompose(Page arg0) throws Exception {
		super.doAfterCompose(arg0);
		setDisplayGrid();
		NewSalesInvoice frmObj = (NewSalesInvoice)(Sessions.getCurrent()).getAttribute("form");
		if (frmObj != null){
			_updateState = Boolean.TRUE;
			ItemObject itmObj = (ItemObject)frmObj.getItemObject();

			Connection con = null;
			PreparedStatement pstmt = null;
			ResultSet rs = null;
			try{
				con = doOpenConnection();
				StringBuffer sbSQLStatement = new StringBuffer();
				getMasterData(Integer.parseInt(itmObj.getItemId()),sbSQLStatement,rs,pstmt,con);
				getDetailData(Integer.parseInt(itmObj.getItemId()),sbSQLStatement,rs,pstmt,con);
			}catch(SQLException e1){log.error(e1.getMessage());}
			finally{
				rs = (ResultSet)doClose(rs);
				pstmt = (PreparedStatement)doClose(pstmt);
				con = (Connection)doClose(con);
			}
		}
	}

	private void getDetailData(int siId,StringBuffer sbSQLStatement,
			ResultSet rs, PreparedStatement pstmt,Connection con)
	throws SQLException{
		sbSQLStatement = new StringBuffer("SELECT COUNT(SIDETAIL_ID) AS REC ")
		.append("FROM SIDETAIL ")
		.append("WHERE SIDETAIL_ID=?");
		pstmt = con.prepareStatement(sbSQLStatement.toString());
		pstmt.setInt(1, siId);
		rs = pstmt.executeQuery();
		int rowData = 0;
		while (rs != null & rs.next()){
			rowData = rs.getInt("REC");
		}
		sbSQLStatement = new StringBuffer("SELECT A.SIDETAIL_ITEMID,A.SIDETAIL_ITEMDESC,")
		.append("A.SIDETAIL_QTY,A.SIDETAIL_PRICE,A.SIDETAIL_UNITDESC,B.ITEM_NO ")
		.append("FROM SIDETAIL A ")
		.append("INNER JOIN ITEM B ON B.ITEM_ID = A.SIDETAIL_ITEMID ")
		.append("WHERE SIDETAIL_ID=?");
		pstmt = con.prepareStatement(sbSQLStatement.toString());
		pstmt.setInt(1, siId);
		rs = pstmt.executeQuery();

		int lastIdx=0;

		String[][] rowgrid = new String[rowData+1];
		rowgrid[0][0]= "";
		rowgrid[0][1]= "NewItemTransaksi";
		rowgrid[0][2]= "";
		rowgrid[0][3]= "1";
		rowgrid[0][4]= "0";
		rowgrid[0][5]= "";
		rowgrid[0][6]= "0";
		rowgrid[0][7]= "AddItemTransaksi";
		ListModel strset = null;
		Grid mygrid = (Grid)getComponent(GRIDNAME);
		lstGrid = new ArrayList<String[]>();
		String[] detail = new String;
		while (rs != null & rs.next()){
			rowgrid[++lastIdx][0] = rs.getString("SIDETAIL_ITEMID");
			rowgrid[1] = rs.getString("ITEM_NO");;
			rowgrid[2] = rs.getString("SIDETAIL_ITEMDESC");
			rowgrid[3]= String.valueOf(rs.getInt("SIDETAIL_QTY"));
			rowgrid[4]= rs.getString("SIDETAIL_PRICE");
			rowgrid[5]= rs.getString("SIDETAIL_UNITDESC");
			rowgrid[6]= String.valueOf(rs.getBigDecimal("SIDETAIL_PRICE").multiply(rs.getBigDecimal("SIDETAIL_QTY")).setScale(BigDecimal.ROUND_UP,4));
			rowgrid[7]= "DeleteItemTransaksi";		
			detail[0] = rowgrid[0];
			detail[1] = rowgrid[1];
			detail[2] = rowgrid[2];
			detail[3] = rowgrid[3];
			detail[4] = rowgrid[4];
			detail[5] = rowgrid[5];
			detail[6] = rowgrid[6];
			lstGrid.add(detail);
			strset = new SimpleListModel(rowgrid);
			try{
				mygrid.setModel(strset);
				mygrid.setRowRenderer(new rowRendererDynamicGrid());
			}catch(Exception e1){log.debug(e1.getMessage());}
		}
		(Sessions.getCurrent()).setAttribute("itemDetail", lstGrid);
		InvoiceFooter();
	}

	private void getMasterData(int siId,StringBuffer sbSQLStatement,
			ResultSet rs, PreparedStatement pstmt,Connection con)
	throws SQLException{
		//			Component Master
		Combobox cboCustomer = (Combobox)getComponent("customer");
		Textbox txtSalesInvoiceNumber = (Textbox)getComponent("no");
		Datebox dbTanggal = (Datebox)getComponent("tanggaltransaksi");
		Textbox multiKeterangan = (Textbox)getComponent("keterangan");
		//			End Component Master

		sbSQLStatement = new StringBuffer("SELECT SIMASTER_CUSTOMERID,SIMASTER_NO,")
		.append("SIMASTER_DATE,SIMASTER_DESC ")
		.append("FROM SIMASTER ")
		.append("WHERE SIMASTER_ID=?");
		pstmt = con.prepareStatement(sbSQLStatement.toString());
		pstmt.setInt(1, siId);
		rs = pstmt.executeQuery();
		String[][] customer = (String[][])(Sessions.getCurrent()).getAttribute("arrCustomer");
		int i=0;
		while (rs != null & rs.next()){
			for ( ;i< customer.length;i++){
				if ((customer<i >[0]).equals(rs.getString("SIMASTER_CUSTOMERID")))
					break;
			}
			cboCustomer.setValue(customer<i >[1]);
			txtSalesInvoiceNumber.setValue(rs.getString("SIMASTER_NO"));
			multiKeterangan.setValue(rs.getString("SIMASTER_DESC"));
			dbTanggal.setValue(new DateTime(rs.getDate("SIMASTER_DATE").toString()).toDate());
		}
	}

	private void setDisplayGrid(){
		ListModel strset = null;
		int lastIdx = 0;
		Grid mygrid = (Grid)getComponent(GRIDNAME);
		if (lstGrid == null){
			lstGrid = new ArrayList<String[]>();
		}
		String[][] rowgrid = new String[lstGrid.size()+1];
		rowgrid[0][0]= "";
		rowgrid[0][1]= "NewItemTransaksi";
		rowgrid[0][2]= "";
		rowgrid[0][3]= "1";
		rowgrid[0][4]= "0";
		rowgrid[0][5]= "";
		rowgrid[0][6]= "0";
		rowgrid[0][7]= "AddItemTransaksi";

		//		munculkan yang lain;
		for (int i=lstGrid.size()-1;i>=0;i--){
			String[] temp = (String[])lstGrid.get(i);
			rowgrid[++lastIdx][0] = temp[0];
			rowgrid[1] = temp[1];
			rowgrid[2] = temp[2];
			rowgrid[3]= temp[3];
			rowgrid[4]= temp[4];
			rowgrid[5]= temp[5];
			rowgrid[6]= temp[6];
			rowgrid[7]= "DeleteItemTransaksi";			
		}
		strset = new SimpleListModel(rowgrid);
		try{
			mygrid.setModel(strset);
			mygrid.setRowRenderer(new rowRendererDynamicGrid());
		}catch(Exception e1){log.debug(e1.getMessage());}
	}

	class rowRendererDynamicGrid implements RowRenderer{
		private int idx; 

		public rowRendererDynamicGrid(){
			idx = -1;
		}

		public void render(Row row, java.lang.Object data) throws Exception {
			String[] _data = (String[])data;
			Groupbox grpBtn = new Groupbox();
			itemId(new Label(_data[0]),grpBtn);
			itemCode(new Toolbarbutton(_data[1]),grpBtn);
			grpBtn.setParent(row);


			itemName(new Textbox(_data[2]),row);
			itemQty(new Intbox(Integer.parseInt(_data[3])),row);
			itemUnitPrice(new Decimalbox(new BigDecimal(_data[4])),row);
			itemSatuan(new Combobox(_data[5]),row);
			itemPrice(new Decimalbox(new BigDecimal(_data[6])),row);
			itemAction(new Toolbarbutton(_data[7]),row);

		}

		private void itemId(Label obj,Groupbox row){		
			obj.setId("itemid".concat(String.valueOf(++idx)));
			obj.setVisible(Boolean.FALSE);
			obj.setParent(row);
		}

		private void itemCode(Toolbarbutton obj,Groupbox row){		
			obj.setId("itemcode".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.addEventListener("onClick", new EventListener() {
				public void onEvent(Event event)
				{
					itemToSell(event.getTarget().getId().substring(8));
				}
			});
		}

		private void itemName(Textbox obj,Row row){		
			obj.setId("name".concat(String.valueOf(idx)));
			obj.setParent(row);
		}

		private void itemQty(Intbox obj,Row row){
			obj.setId("qty".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.addEventListener("onBlur", new EventListener(){
				public void onEvent(Event event)
				{
					String idComponent = event.getTarget().getId().substring(3);
					Intbox intQty = (Intbox)getComponent("qty".concat(String.valueOf(idComponent)));
					Decimalbox dbUnitPrice = (Decimalbox)getComponent("unitprice".concat(String.valueOf(idComponent)));
					Decimalbox price = (Decimalbox)getComponent("price".concat(String.valueOf(idComponent)));
					price.setValue(new BigDecimal(calculatePrice(intQty.getValue(), dbUnitPrice.getValue())));
					setToArray(idComponent);
				}
			});
		}

		private void itemUnitPrice(Decimalbox obj,Row row){		
			obj.setId("unitprice".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.addEventListener("onBlur", new EventListener(){
				public void onEvent(Event event)
				{
					String idComponent = event.getTarget().getId().substring(9);
					Intbox intQty = (Intbox)getComponent("qty".concat(String.valueOf(idComponent)));
					Decimalbox dbUnitPrice = (Decimalbox)getComponent("unitprice".concat(String.valueOf(idComponent)));
					Decimalbox price = (Decimalbox)getComponent("price".concat(String.valueOf(idComponent)));
					price.setValue(new BigDecimal(calculatePrice(intQty.getValue(), dbUnitPrice.getValue())));
					setToArray(idComponent);
				}
			});			
		}

		private void itemSatuan(Combobox obj,Row row){		
			obj.setId("satuan".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.addEventListener("onBlur", new EventListener(){
				public void onEvent(Event event)
				{
					String idComponent = event.getTarget().getId().substring(6);
					Intbox intQty = (Intbox)getComponent("qty".concat(String.valueOf(idComponent)));
					Decimalbox dbUnitPrice = (Decimalbox)getComponent("unitprice".concat(String.valueOf(idComponent)));
					Decimalbox price = (Decimalbox)getComponent("price".concat(String.valueOf(idComponent)));
					price.setValue(new BigDecimal(calculatePrice(intQty.getValue(), dbUnitPrice.getValue())));
					setToArray(idComponent);
				}
			});			
		}

		private void itemPrice(Decimalbox obj,Row row){		
			obj.setId("price".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.setReadonly(Boolean.FALSE);
		}

		private void itemAction(Toolbarbutton obj,Row row){		
			obj.setId("action".concat(String.valueOf(idx)));
			obj.setParent(row);
			obj.addEventListener("onClick", new EventListener() {
				public void onEvent(Event event)
				{
					if (((Toolbarbutton)event.getTarget()).getLabel().equals("AddItemTransaksi")){
						setToArray(event.getTarget().getId().substring(6),"Ins");
					} else {
						setToArray(event.getTarget().getId().substring(6),"Del");
					}
				}
			});
		}

		private void setToArray(String idx) {
			setToArray(idx, "Edt");
		}

		private void setToArray(String idx,String state) {
			String[] detail = new String;
			if (lstGrid != null){
				Label itemId = (Label)getComponent("itemid".concat(idx));
				Toolbarbutton itemCode = (Toolbarbutton)getComponent("itemcode".concat(idx));
				Textbox itemName = (Textbox)getComponent("name".concat(idx));
				Decimalbox itemPrice = (Decimalbox)getComponent("unitprice".concat(idx));
				Intbox itemQty = (Intbox)getComponent("qty".concat(idx));
				Combobox itemSatuan = (Combobox)getComponent("satuan".concat(idx));

				String satuan = itemSatuan.getValue();
				if ( satuan.equals("")){
					satuan ="1"; 
				}

				detail[0] = itemId.getValue();
				detail[1] = itemCode.getLabel();
				detail[2] = itemName.getValue();
				detail[3] = String.valueOf(itemQty.getValue());
				detail[4] = itemPrice.getValue().setScale(4,BigDecimal.ROUND_UP).toString(); 
				detail[5] = satuan;
				detail[6] = calculatePrice(itemQty.getValue(),itemPrice.getValue());

				if (state.equalsIgnoreCase("ins") && Integer.parseInt(idx) == 0){ // When Insert Item
					idx = "1";
					lstGrid.add(detail);
				} 
				if (state.equalsIgnoreCase("edt") && Integer.parseInt(idx) !=  0){ // When Edit Item
					lstGrid.set(lstGrid.size()-Integer.parseInt(idx),detail);
				}
				if (state.equalsIgnoreCase("del") && Integer.parseInt(idx) != 0){ // When Delete Item
					lstGrid.remove(lstGrid.size()-Integer.parseInt(idx));
				}

				if ((lstGrid.size() > 0 && Integer.parseInt(idx) != 0) || state.equalsIgnoreCase("del")) {
					(Sessions.getCurrent()).setAttribute("itemDetail", lstGrid);
					InvoiceFooter();
					setDisplayGrid();
				}
			}              
		}		
	}

	private void itemToSell(String idx) {
		(Sessions.getCurrent()).setAttribute("idxitem", idx);
		onModalWindow("../transaksi/item.zul");
	}

	@Override
	public void actionSave(){
		super.actionSave();
		Form frmObj = (Form)(Sessions.getCurrent()).getAttribute("form");
		if (frmObj == null){
			onSave();
		} else {
			onUpdate();
		}
	}

	@Override
	public void onSave() {
		Connection con = null;
		PreparedStatement pstmt = null;
		String[][] customer = (String[][])(Sessions.getCurrent()).getAttribute("arrCustomer");
		Xid xid = new MysqlXid(new byte[]{0x02}, new byte[]{0x01}, 100);
		int ret;

		//Component Master
		Combobox cboCustomer = (Combobox)getComponent("customer");
		Textbox txtSalesInvoiceNumber = (Textbox)getComponent("no");
		Datebox dbTanggal = (Datebox)getComponent("tanggaltransaksi");
		Textbox multiKeterangan = (Textbox)getComponent("keterangan");
		//End Component Master

		try{
			con = doOpenConnection();

			int transaksiId = getLastId(TABLETYPE);
			StringBuffer sbSQLStatement = new StringBuffer("INSERT INTO SIMASTER ")
			.append("(SIMASTER_ID,SIMASTER_NO,SIMASTER_DATE,SIMASTER_CUSTOMERID,SIMASTER_DESC) VALUES")
			.append("(?,?,?,?,?)");
			pstmt = con.prepareStatement(sbSQLStatement.toString());
			pstmt.setInt(1, transaksiId);
			pstmt.setString(2, txtSalesInvoiceNumber.getValue());
			pstmt.setString(3, sdDate.format(dbTanggal.getValue()));
			pstmt.setString(4, customer[cboCustomer.getSelectedIndex()][0]);
			pstmt.setString(5, multiKeterangan.getValue());
			pstmt.execute();

			sbSQLStatement = new StringBuffer("INSERT INTO SIDETAIL ")
			.append("(SIDETAIL_ID,SIDETAIL_SEQ,SIDETAIL_ITEMID,SIDETAIL_ITEMDESC,")
			.append("SIDETAIL_QTY,SIDETAIL_PRICE,SIDETAIL_UNITRATIO,SIDETAIL_UNITDESC,SIDETAIL_RECVITEM) VALUES")
			.append("(?,?,?,?,?,?,?,?,?)");
			pstmt = con.prepareStatement(sbSQLStatement.toString());

			Label itemId = null;
			Textbox itemName = null;
			Decimalbox itemPrice = null;
			Intbox itemQty = null;
			Combobox itemSatuan = null;

			List<String[]> item = (List<String[]>)(Sessions.getCurrent()).getAttribute("itemDetail");
			for (int idx =0;idx< item.size();){
				itemId = (Label)getComponent("itemid".concat(String.valueOf(++idx)));
				itemName = (Textbox)getComponent("name".concat(String.valueOf(idx)));
				itemPrice = (Decimalbox)getComponent("unitprice".concat(String.valueOf(idx)));
				itemQty = (Intbox)getComponent("qty".concat(String.valueOf(idx)));
				itemSatuan = (Combobox)getComponent("satuan".concat(String.valueOf(idx)));

				pstmt.setInt(1, transaksiId);
				pstmt.setInt(2, idx);
				pstmt.setString(3, itemId.getValue());
				pstmt.setString(4, itemName.getValue());
				pstmt.setInt(5, itemQty.getValue());
				pstmt.setBigDecimal(6, itemPrice.getValue());
				pstmt.setInt(7, 1);
				pstmt.setString(8, itemSatuan.getValue());		
				pstmt.setString(9, TABLETYPE);
				pstmt.addBatch();
			}

			pstmt.executeBatch();
			_successSave =Boolean.TRUE;
			if (!SAVEANDNEW){
				NewSalesInvoice frmObject  = new NewSalesInvoice(transaksiId,TABLETYPE);
				(Sessions.getCurrent()).setAttribute("form", frmObject);
			}			
		}catch(SQLException e1){
			_successSave =Boolean.FALSE;
			log.error(e1.getMessage());
		}
		finally{
			pstmt =(PreparedStatement)doClose(pstmt);
			con =(Connection)doClose(con);
			super.onSave();
		}
	}

	@Override
	public void onUpdate() {
		NewSalesInvoice frmObj = (NewSalesInvoice)(Sessions.getCurrent()).getAttribute("form");
		ItemObject formObj = frmObj.getItemObject();
		int transaksiId = Integer.parseInt(formObj.getItemId());
		_successUpdate = Boolean.FALSE;

		Connection con = null;
		PreparedStatement pstmt = null;
		String[][] customer = (String[][])(Sessions.getCurrent()).getAttribute("arrCustomer");

		//Component Master
		Combobox cboCustomer = (Combobox)getComponent("customer");
		Textbox txtSalesInvoiceNumber = (Textbox)getComponent("no");
		Datebox dbTanggal = (Datebox)getComponent("tanggaltransaksi");
		Textbox multiKeterangan = (Textbox)getComponent("keterangan");
		//End Component Master

		try{
			con = doOpenConnection();
			StringBuffer sbSQLStatement = new StringBuffer();
			//Delete Detail First
			sbSQLStatement = new StringBuffer("DELETE FROM SIDETAIL WHERE SIDETAIL_ID=?");
			pstmt = con.prepareStatement(sbSQLStatement.toString());
			pstmt.setInt(1, transaksiId);
			pstmt.execute();

			//Delete Master
			sbSQLStatement = new StringBuffer("DELETE FROM SIMASTER WHERE SIMASTER_ID=?");
			pstmt = con.prepareStatement(sbSQLStatement.toString());
			pstmt.setInt(1, transaksiId);
			pstmt.execute();			

			sbSQLStatement = new StringBuffer("INSERT INTO SIMASTER ")
			.append("(SIMASTER_ID,SIMASTER_NO,SIMASTER_DATE,SIMASTER_CUSTOMERID,SIMASTER_DESC) VALUES")
			.append("(?,?,?,?,?)");
			pstmt = con.prepareStatement(sbSQLStatement.toString());
			pstmt.setInt(1, transaksiId);
			pstmt.setString(2, txtSalesInvoiceNumber.getValue());
			pstmt.setString(3, sdDate.format(dbTanggal.getValue()));
			pstmt.setString(4, customer[cboCustomer.getSelectedIndex()][0]);
			pstmt.setString(5, multiKeterangan.getValue());
			pstmt.execute();

			sbSQLStatement = new StringBuffer("INSERT INTO SIDETAIL ")
			.append("(SIDETAIL_ID,SIDETAIL_SEQ,SIDETAIL_ITEMID,SIDETAIL_ITEMDESC,")
			.append("SIDETAIL_QTY,SIDETAIL_PRICE,SIDETAIL_UNITRATIO,SIDETAIL_UNITDESC,SIDETAIL_RECVITEM) VALUES")
			.append("(?,?,?,?,?,?,?,?,?)");
			pstmt = con.prepareStatement(sbSQLStatement.toString());

			Label itemId = null;
			Textbox itemName = null;
			Decimalbox itemPrice = null;
			Intbox itemQty = null;
			Combobox itemSatuan = null;

			List<String[]> item = (List<String[]>)(Sessions.getCurrent()).getAttribute("itemDetail");
			for (int idx =0;idx< item.size();){
				itemId = (Label)getComponent("itemid".concat(String.valueOf(++idx)));
				itemName = (Textbox)getComponent("name".concat(String.valueOf(idx)));
				itemPrice = (Decimalbox)getComponent("unitprice".concat(String.valueOf(idx)));
				itemQty = (Intbox)getComponent("qty".concat(String.valueOf(idx)));
				itemSatuan = (Combobox)getComponent("satuan".concat(String.valueOf(idx)));

				pstmt.setInt(1, transaksiId);
				pstmt.setInt(2, idx);
				pstmt.setString(3, itemId.getValue());
				pstmt.setString(4, itemName.getValue());
				pstmt.setInt(5, itemQty.getValue());
				pstmt.setBigDecimal(6, itemPrice.getValue());
				pstmt.setInt(7, 1);
				pstmt.setString(8, itemSatuan.getValue());
				pstmt.setString(9, TABLETYPE);
				pstmt.addBatch();
			}
			pstmt.executeBatch();
			_successUpdate =Boolean.TRUE;
		}catch(SQLException e1){
			_successUpdate =Boolean.FALSE;
			log.error(e1.getMessage());
		}
		finally{
			pstmt =(PreparedStatement)doClose(pstmt);
			con =(Connection)doClose(con);
			super.onUpdate();
		}

	}

	@Override
	public void onSaveAndNew() {
		super.onSaveAndNew();
		Button btn = (Button)getComponent("savenew");	
		if (btn.getLabel().equals("Save New")){
			onSave();
			clearComponent();
		} else {
			onCloseWindow(WINDOWNAME);
		}
	}

	@Override
	public void clearComponent() {
		super.clearComponent();
		clearTextBox((Textbox)getComponent("no"));
		clearTextBox((Textbox)getComponent("keterangan"));

		Combobox cboCustomer = (Combobox)getComponent("customer");
		Datebox dbTanggal = (Datebox)getComponent("tanggaltransaksi");

		cboCustomer.setValue("");
		dbTanggal.setValue(new DateTime().toDate());

		Grid mygrid = (Grid)getComponent(GRIDNAME);
		mygrid.getRows().getChildren().clear();

		setDisplayGrid();
	}

	public void onPrint(){
		if (_successSave){

		}
	}

	@Override
	public void refreshList(){
		super.refreshList();
		onRefresh((Window)getComponent("wndsalesinvoiceentry"), ListSalesInvoice.LISTSALESINVOICE);
	}	
}

this my code please see my code

TIA,

Andy Susanto

link publish delete flag offensive edit

answered 2009-02-09 04:52:57 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi Andy,

To tell the truth, the sample is not run from our environment.
Why not to simplify the issue by yourself to provide a SIMPLE SAMPLE?
It is good for everybody who want to help you.

Thanks,
Jumper

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-01-21 17:09:57 +0800

Seen: 338 times

Last updated: Feb 09 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More