of_insertitem


pfcapsrv.pbl   >   pfc_n_cst_lvsrv_datasource   >   of_insertitem   

Full name pfc_n_cst_lvsrv_datasource.of_insertitem
Access public
Extend of integer
Return value integer
Prototype public function integer of_insertitem(ref n_ds,long,listviewitem,string,integer)

Name Datatype
No Data

Name Datatype
li_after integer
li_index integer
li_newindex integer
li_rc integer
li_totalitems integer
ll_rowcount long
ll_rowid long
llvi_temp ListViewItem
ls_key string
ls_syntax1 string
ls_syntax2 string

public function integer of_insertitem (ref n_ds ads_obj, long al_row, listviewitem alvi_new, string as_position, integer ai_item);//////////////////////////////////////////////////////////////////////////////
//	Public Function:	of_InsertItem
//	Arguments:		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 listview, or
//										another maintained by the user.  If the latter, the row will be added
//										to the listviews DataStore.  Passed by reference.
//						al_Row		The row in the DataStore pointing to the data.
//						alvi_item	The Item to be added to the listview
//						as_Position	The position under the parent where the new item will be inserted:
//										"First" - before the first item of the listview 
//										"Last" - after the last listview item (default)
//										"Before" - before the item with index ai_item
//										"After" - after the item with index ai_item
//						ai_Item		The index to the item which the new item will be inserted either after or before.
//										Ignored unless as_Position = "After" or "Before".
//	Returns:			Integer
//						Returns the index of the item if it was added successfully, 
//						-1 if an error occurrs.
//	Description:	Add a new item to the ListView using data from a DataStore.
//////////////////////////////////////////////////////////////////////////////
//	Rev. History:	Version
//						6.0   Initial version
// 					7.0   Performance Improvements:  Removed extraneous rowcounts, and ArrangeAll
//////////////////////////////////////////////////////////////////////////////
//	Copyright © 1996-1999 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_rc
integer				li_index, li_newindex, li_totalitems, li_after
long					ll_rowcount, ll_rowid
string				ls_key, ls_syntax1, ls_syntax2
ListViewItem		llvi_temp

// check reference variables
if IsNull(ilv_requestor) or not IsValid(ilv_requestor) then return -1

// Check Arguments
if IsNull(al_row) or IsNull(ai_item) or (al_row < 1) or (ai_item < 0) or IsNull(as_position) &
or (Trim(as_position) = "") or IsNull(ads_obj) or not IsValid(ads_obj) then return -1

choose case as_position
	case ilv_requestor.INSERT_FIRST, ilv_requestor.INSERT_LAST, &
		  ilv_requestor.INSERT_BEFORE, ilv_requestor.INSERT_AFTER
		// valid values
	case else
		return -1
end choose

// Check if the DataStore passed is the same as the one for the level
if ads_obj <> inv_Attrib.ids_Source then
	
	// Verify that the it is valid for the level
	if (ads_obj.DataObject = inv_Attrib.ids_Source.DataObject) then
		if ads_obj.DataObject = "" then
			ls_syntax1 = ads_obj.Object.Datawindow.Syntax
			ls_syntax2 = inv_Attrib.ids_Source.Object.Datawindow.Syntax
			if ls_syntax1 <> ls_syntax2 then return -1
		end if
	else
		return -1
	end if

	// Append the rows to the DataStore
	ll_rowcount = inv_Attrib.ids_Source.RowCount()
	li_rc = ads_obj.RowsCopy(al_Row, al_Row, Primary!, inv_Attrib.ids_Source, (ll_rowcount + 1), 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++
	choose case ads_obj.GetItemStatus(al_Row, 0, primary!)
		case New!
			// newmodified! and notmodified! = new!
			inv_Attrib.ids_Source.SetItemStatus(ll_rowcount, 0, primary!, notmodified!)
//		case DataModified!
//			// newmodified! and datamodified! = datamodified!
//			inv_Attrib.ids_Source.SetItemStatus(ll_rowcount, 0, primary!, datamodified!)
//		case NotModified!
//			// newmodified!  and datamodified! = datamodified!
//			// datamodified! and notmodified!  = notmodified!
//			inv_Attrib.ids_Source.SetItemStatus(ll_rowcount, 0, primary!, datamodified!)
//			inv_Attrib.ids_Source.SetItemStatus(ll_rowcount, 0, primary!, notmodified!)
	end choose
	al_row = ll_rowcount
end if

// set the data attribute so we can find this row again later
ls_key = of_EncodeKey(inv_Attrib.ids_Source, al_row)
if ls_key = "!" then return -1
alvi_new.Data = String(alvi_new.Data) + ls_key

// Insert the Item.  Based on position not index.  Change x, y of item to be added
//li_totalitems = ilv_requestor.TotalItems() + 1
choose case Lower(as_Position)
	case "first"
		li_index = ilv_requestor.FindItem(0, DirectionDown!, false, false, false, false)
		if ilv_requestor.GetItem(li_index, llvi_temp) <> 1 then return -1
		alvi_new.ItemX = llvi_temp.ItemX - 1
		alvi_new.ItemY = llvi_temp.ItemY - 1
		li_newindex = ilv_requestor.InsertItem(1, alvi_new)
	case "after"
		// get next item in the listview
		li_after = ai_item + 1
		if li_after > ilv_requestor.TotalItems() then
			// at end, after is adding to end
			li_newindex = ilv_requestor.AddItem(alvi_new)
		else	
			if ilv_requestor.GetItem(ai_item, llvi_temp) <> 1 then return -1
			alvi_new.ItemX = llvi_temp.ItemX + 1
			alvi_new.ItemY = llvi_temp.ItemY + 1
			li_newindex = ilv_requestor.InsertItem(li_after, alvi_new)
		end if
	case "before"
		if ilv_requestor.GetItem(ai_item, llvi_temp) <> 1 then return -1
		alvi_new.ItemX = llvi_temp.ItemX - 1
		alvi_new.ItemY = llvi_temp.ItemY - 1
		li_newindex = ilv_requestor.InsertItem(ai_item, alvi_new)
	case else	// "last"
		li_newindex = ilv_requestor.AddItem(alvi_new)
end choose

// Add for Undo capability
if ib_Undo then
	if li_newindex > 0 then
		il_UndoInsertHandle = li_newindex
		is_UndoType = UNDO_INSERT
	end if
end if

return li_newindex
end function

     
Name Owner
pfc_n_cst_lvsrv_datasource.pfc_insertitem pfc_n_cst_lvsrv_datasource

     
Name Owner
listview.additem listview
listview.finditem listview
listview.getitem listview
listview.insertitem listview
listview.totalitems listview
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
pfc_n_cst_lvsrv_datasource.of_EncodeKey pfc_n_cst_lvsrv_datasource

     
Full name
No Data

     
Name Scope
No Data