of_insertitem


pfcapsrv.pbl   >   pfc_n_cst_tvsrv_levelsource   >   of_insertitem   

Full name pfc_n_cst_tvsrv_levelsource.of_insertitem
Access public
Extend of long
Return value long
Prototype public function long of_insertitem(long,n_ds,long,treeviewitem,string,long)

Name Datatype
No Data

Name Datatype
li_Index Integer
li_NewLevel Integer
li_rc Integer
ll_newhandle long
ll_rowcount long
ls_key String
ltvi_Parent TreeViewItem

public function long of_insertitem (long al_parent, n_ds ads_obj, long al_row, treeviewitem atvi_item, string as_position, long al_after);//////////////////////////////////////////////////////////////////////////////
//
//	Function:	of_InsertItem
//
//	Access:		public
//
//	Arguments:
//	al_Parent	The handle of the parent TreeView item that the new item will
//						be inserted under - new item is now parent's child.
//	ads_obj		The DataStore containing the data to be used for the new item.
//						This can be the same DataStore that was created for the level, or
//						another maintained by the user.  If the latter, the row will be added
//						to the level's DataStore. 
//	al_Row		The row in the DataStore pointing to the data.
//	atvi_item	The Item to be added to the treeview
//	as_Position	The position under the parent where the new item will be inserted:
//						"First" - before the first child of the parent (Default)
//						"Last" - after the last child
//						"Sort" - in the sorted position based on the item's label
//						"After" - after the item with handle al_After
//	al_After		The handle to the item after which the new item will be inserted.
//						Ignored unless as_Position = "After".
//
//	Returns:		Long
//					Returns the handle of the item if it was added successfully, 
//					-1 if an error occurrs.
//
//	Description:	Add a new item to the TreeView using data from a DataStore.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	6.0   Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
Integer				li_NewLevel, li_Index, li_rc
long					ll_rowcount, ll_newhandle
String				ls_key
TreeViewItem		ltvi_Parent

// check reference variables
If IsNull(itv_requestor) or Not IsValid(itv_requestor) Then Return -1

// Check Arguments
If IsNull(al_parent) or IsNull(al_row) or IsNull(al_after) or &
	(al_parent < 0) or (al_row < 1) or (al_after < 0) or &
	IsNull(as_position) or (Trim(as_position) = "") or &
	IsNull(ads_obj) or Not IsValid(ads_obj) Then
	Return -1
End If

Choose Case lower(as_position)
	Case itv_requestor.INSERT_FIRST, itv_requestor.INSERT_LAST, &
			itv_requestor.INSERT_SORT, itv_requestor.INSERT_AFTER
		// valid insert type
	Case Else
		Return -1
End Choose

// Determine the level to place data in correct datastore
If al_Parent <> 0 Then
	If itv_requestor.GetItem(al_Parent, ltvi_Parent) = -1 Then Return -1
	li_NewLevel = ltvi_Parent.Level + 1
Else
	li_NewLevel = 1
End If

// Get index into the data source array
li_Index = UpperBound(inv_attrib)
If li_NewLevel <= li_Index Then
	li_Index = li_NewLevel
Else
	// If new item is being added to a level > li_Index then
	// inv_attrib[li_Index] must be recursive
	If Not inv_attrib[li_Index].ib_Recursive Then Return -1
End If

// Check if the DataStore passed is the same as the one for the level
If ads_obj <> inv_attrib[li_Index].ids_obj Then
	// Verify that the it is valid for the level
	If ads_obj.DataObject <> inv_attrib[li_Index].ids_obj.DataObject Then Return -1

	// Append the rows to the level's DataStore
	ll_rowcount = inv_attrib[li_Index].ids_obj.rowcount()
	li_rc = ads_obj.RowsCopy(al_Row, al_Row, Primary!, inv_attrib[li_Index].ids_obj, (ll_rowcount + 999999), Primary!)
	If li_rc < 1 Then Return -1
	
	// Set status flag of new row to what it was in the original datastore
	// The new row is copied as NewModified! 
	ll_rowcount = inv_attrib[li_Index].ids_obj.rowcount()
	choose case ads_obj.GetItemStatus(al_Row, 0, primary!)
		case New!
			// newmodified! and notmodified! = new!
			inv_attrib[li_Index].ids_obj.SetItemStatus(ll_rowcount, 0, primary!, notmodified!)
		case DataModified!
			// newmodified! and datamodified! = datamodified!
			inv_attrib[li_Index].ids_obj.SetItemStatus(ll_rowcount, 0, primary!, datamodified!)
		case NotModified!
			// newmodified!  and datamodified! = datamodified!
			// datamodified! and notmodified!  = notmodified!
			inv_attrib[li_Index].ids_obj.SetItemStatus(ll_rowcount, 0, primary!, datamodified!)
			inv_attrib[li_Index].ids_obj.SetItemStatus(ll_rowcount, 0, primary!, notmodified!)
	end choose
	al_row = inv_attrib[li_Index].ids_obj.RowCount()
End If

// Set Data to the unique key
ls_key = this.of_encodekey(inv_attrib[li_Index].ids_obj, al_row)
If ls_key = "!" then return -1
atvi_Item.Data = string(atvi_item.data) + ls_key

//  Add the Item
Choose Case Lower(as_Position)
	Case itv_requestor.INSERT_LAST
		ll_newhandle = itv_requestor.InsertItemLast(al_Parent, atvi_Item)
	Case itv_requestor.INSERT_SORT
		ll_newhandle = itv_requestor.InsertItemSort(al_Parent, atvi_Item)
	Case itv_requestor.INSERT_AFTER
		ll_newhandle = itv_requestor.InsertItem(al_Parent, al_After, atvi_Item)
	Case itv_requestor.INSERT_FIRST
		ll_newhandle = itv_requestor.InsertItemFirst(al_Parent, atvi_Item)
End Choose

// Remember for Undo capability
If ib_undo Then
	If ll_newhandle > 0 then
		il_undoinserthandle = ll_newhandle
		is_UndoType = UNDO_INSERT
	End If
End If

Return ll_newhandle

end function

     
Name Owner
pfc_n_cst_tvsrv_levelsource.pfc_insertitem pfc_n_cst_tvsrv_levelsource

     
Name Owner
treeview.getitem treeview
treeview.insertitem treeview
treeview.insertitemfirst treeview
treeview.insertitemlast treeview
treeview.insertitemsort treeview
datastore.getitemstatus datastore
datastore.rowcount datastore
datastore.rowscopy datastore
datastore.setitemstatus datastore
systemfunctions.isnull systemfunctions
systemfunctions.isvalid systemfunctions
systemfunctions.lower systemfunctions
systemfunctions.string systemfunctions
systemfunctions.trim systemfunctions
systemfunctions.upperbound systemfunctions
pfc_n_cst_tvsrv_levelsource.of_encodekey pfc_n_cst_tvsrv_levelsource

     
Full name
No Data

     
Name Scope
No Data