Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Manage

Manage() provides data management functionality for your application and/or process.

Below is the code for Manage():

procedure TForm1.Manage;

var

iItems: integer;

iOrders: integer;

counter: integer;

savePoint : integer;

begin

iItems := 1;

iOrders := 1;

StringGrid1.Cells[0, 0] := 'Customer Num';

StringGrid1.Cells[1, 0] := 'Order Num';

StringGrid1.Cells[2, 0] := 'Item Num';

StringGrid1.Cells[3, 0] := 'Qty';

// populate the tables with data

Add_ItemMaster_Records;

Add_CustomerMaster_Records;

Delete_Records(TabOrderList);

Delete_Records(TabOrderItem);

// Add Transactions, FOR Each order

try

for counter := 1 to 3 do

begin

CtSession1.BeginTransaction;

// insert items associated with an order

TabOrderList.ActiveRecord.Clear;

// populate the record buffer

ShortDateFormat := 'mm/dd/yyyy';

TabOrderList.ActiveRecord.SetFieldAsDate(0, StrToDate(ol_data[iOrders, 1]));

TabOrderList.ActiveRecord.SetFieldAsDate(1, StrToDate(ol_data[iOrders, 2]));

TabOrderList.ActiveRecord.SetFieldAsString(2, ol_data[iOrders, 3]);

TabOrderList.ActiveRecord.SetFieldAsString(3, ol_data[iOrders, 4]);

// write the orderlist record

TabOrderList.ActiveRecord.Write;

savePoint := TabOrderItem.SetSavePoint;

// process each orderitem while the ordernum matches

while (CompareStr(oi_data[iItems,1],ol_data[iOrders,3])= 0) do

begin

TabOrderItem.ActiveRecord.Clear;

// populate the record buffer

TabOrderItem.ActiveRecord.SetFieldAsString(0, oi_data[iItems, 1]);

TabOrderItem.ActiveRecord.SetFieldAsSigned(1, StrToInt(oi_data[iItems, 2]));

TabOrderItem.ActiveRecord.SetFieldAsSigned(2, StrToInt(oi_data[iItems, 3]));

TabOrderItem.ActiveRecord.SetFieldAsString(3, oi_data[iItems, 4]);

// write the orderitem record

TabOrderItem.ActiveRecord.Write;

// find the itemnum in table itemmaster

TabItemMast.ActiveRecord.Clear;

TabItemMast.ActiveRecord.SetFieldAsString(2, oi_data[iItems, 4]);

if TabItemMast.ActiveRecord.Find(CTFIND_EQ) then

savePoint := TabOrderItem.SetSavePoint

else

TabOrderItem.RestoreSavePoint(savePoint);

iItems := iItems + 1;

// On the last order do not go beyond the end of the items

if (iItems > 6) then

break;

end;

TabCustMast.ActiveRecord.Clear;

TabCustMast.ActiveRecord.SetFieldAsString(0, ol_data[iOrders, 4]);

if TabCustMast.ActiveRecord.Find(CTFIND_EQ) then

CtSession1.CommitTransaction

else

CtSession1.AbortTransaction;

iOrders := iOrders + 1;

end;

except

on E : ECtError do Application.ShowException(E);

end;

Display_Records();

end;

procedure TForm1.Add_ItemMaster_Records();

var

counter : integer;

begin

try

Delete_Records(TabItemMast);

TabItemMast.ActiveRecord.BeginTransaction;

for counter := 1 to 4 do

begin

// clear the record buffer

TabItemMast.ActiveRecord.Clear;

// populate the record buffer

TabItemMast.ActiveRecord.SetFieldAsString(0, im_data[counter, 1]);

TabItemMast.ActiveRecord.SetFieldAsString(1, im_data[counter, 2]);

TabItemMast.ActiveRecord.SetFieldAsString(2, im_data[counter, 3]);

TabItemMast.ActiveRecord.SetFieldAsString(3, im_data[counter, 4]);

// write the record

TabItemMast.ActiveRecord.Write;

end;

TabItemMast.ActiveRecord.CommitTransaction;

except

on E : ECtError do Application.ShowException(E);

end;

end;

procedure TForm1.Add_CustomerMaster_Records();

var

counter : integer;

begin

try

Delete_Records(TabCustMast);

TabCustMast.ActiveRecord.BeginTransaction;

for counter := 1 to 4 do

begin

// clear the record buffer

TabCustMast.ActiveRecord.Clear;

// populate the record buffer

TabCustMast.ActiveRecord.SetFieldAsString(0, cm_data[counter, 1]);

TabCustMast.ActiveRecord.SetFieldAsString(1, cm_data[counter, 2]);

TabCustMast.ActiveRecord.SetFieldAsString(2, cm_data[counter, 3]);

TabCustMast.ActiveRecord.SetFieldAsString(3, cm_data[counter, 4]);

TabCustMast.ActiveRecord.SetFieldAsString(4, cm_data[counter, 5]);

TabCustMast.ActiveRecord.SetFieldAsString(5, cm_data[counter, 6]);

TabCustMast.ActiveRecord.SetFieldAsString(6, cm_data[counter, 7]);

// write the record

TabCustMast.ActiveRecord.Write;

end;

TabCustMast.ActiveRecord.CommitTransaction;

except

on E : ECtError do Application.ShowException(E);

end;

end;

procedure TForm1.Delete_Records(ATable : TCtTable);

begin

try

ATable.ActiveRecord.BeginTransaction;

while ATable.ActiveRecord.First do

begin

ATable.ActiveRecord.Delete;

end;

ATable.ActiveRecord.CommitTransaction;

except

on E : ECtError do Application.ShowException(E);

end;

end;

procedure TForm1.Display_Records();

var

itemnum : String;

custnum : String;

ordernum : String;

counter : integer;

quantity: integer;

bOrderList: boolean;

bOrderItem: boolean;

begin

counter := 1;

try

bOrderList := TabOrderList.ActiveRecord.First;

while (bOrderList) do

begin

TabOrderList.ActiveRecord.GetFieldAsString(3, custnum);

TabOrderList.ActiveRecord.GetFieldAsString(2, ordernum);

TabOrderItem.ActiveRecord.SetFieldAsString(0, ordernum);

TabOrderItem.ActiveRecord.RecordSetOn(7);

bOrderItem := TabOrderItem.ActiveRecord.First;

while (bOrderItem) do

begin

TabOrderItem.ActiveRecord.GetFieldAsString(3, itemnum);

quantity := TabOrderItem.ActiveRecord.GetFieldAsSigned(2);

StringGrid1.Cells[0, counter] := custnum;

StringGrid1.Cells[1, counter] := ordernum;

StringGrid1.Cells[2, counter] := itemnum;

StringGrid1.Cells[3, counter] := IntToStr(quantity);

StringGrid1.RowCount := StringGrid1.RowCount + 1;

counter := counter + 1;

bOrderItem := TabOrderItem.ActiveRecord.Next;

end;

bOrderList := TabOrderList.ActiveRecord.Next;

end;

except

on E : ECtError do Application.ShowException(E);

end;

end;

TOCIndex