/*
 * Created on Mar 1, 2004
 *
 */
package LumiSoft.Data;

/**
 * 
 */
public class DataRowView 
{
	private DataView m_pView = null;
	private DataRow  m_pRow  = null;
	private boolean  m_IsNew = false;
	
	protected DataRowView(DataView view,DataRow row)
	{
		this(view,row,false);
	}
	
	protected DataRowView(DataView view,DataRow row,boolean newRow)
	{
		m_pView = view;
		m_pRow  = row;
		m_IsNew = newRow;
	}
	
	
	/**
	 * Returns a DataView for the child DataTable with the specified DataRelation name.
	 * @param relationName A string containing the DataRelation name. 
	 * @return a DataView for the child DataTable.
	 */
	public DataView CreateChildView(String relationName)
	{
		return new DataView(m_pRow.getTable(),relationName,this);
	}
	
	/**
	 * Ends an edit procedure.
	 *
	 */
	public void EndEdit()
	{
		if(m_IsNew){
			m_pRow.getTable().getRows().Add(m_pRow);
			m_IsNew = false;
		}
	}
	
	/**
	 * Deletes a row.
	 *
	 */
	public void Delete()
	{
		m_pView.Delete(this);
	}
	
	
	/**
	 * Gets the DataRow being viewed.
	 * @return
	 */
	public DataRow getRow()
	{
		return m_pRow;
	}
	
	/**
	 * Gets a value in a specified column.
	 * @param index
	 * @return
	 */
	public Object get(int index)
	{
		return m_pRow.get(index);
	}
	/**
	 * Gets a value in a specified column.
	 * @param columnName
	 * @return
	 */
	public Object get(String columnName)
	{
		return m_pRow.get(columnName);
	}
/*	public void set(int index,Object value)
	{
		
	}*/
	public void set(String columnName,Object value)
	{
		m_pRow.set(columnName,value);
	}
	
	/**
	 * Indicates whether a DataRowView is new.
	 * @return
	 */
	public boolean getIsNew()
	{		
		return m_IsNew;
	}
}
