Update the Quantity

Guys I have small doubt I had a form1 if I am pressing ctrl+N it opens form2 for create in that new form I had 3 fields ProjId,ItemId,Qty if I am entering data in form2 , so data goes to insert form1
In form1 also 3 fields ProjId,ItemId,Qty
I am enter data in form2 ProjId,ItemId,Qty ; if ProjId,ItemId already exists in form1 then qty is to add there respective previous qty ;
Ex:
Form1
ProjId ItemId Qty
1 2 20
2 3 17
Then form2 entering data
ProjId: 1
ItemId: 2
Qty: 33
In form1 data will change like
ProjId ItemId Qty
1 2 53
2 3 17
this.qty = this.qty+form2.qty
Can any one help me

Override the insert method(table) of the data source of your second form. Write your logic in such a manner if the record in the table (used by the first form) is found then update the founded record else insert a new record into the table.

i wote code in Classes like below

Public void InsertUpdate()

{

Table1 _table1;

;

_table1 = this.CreateSurplus();

// ttsBegin;

if(_table1)

{

_table1.ProjId = _projid;

_table1.ItemId = _ItemId;

_table1.SurplusQty = _table1.Qty +_Qty;

_table1.update();

}

else

{

_table1.ProjId = _projid;

_table1.ItemId = _ItemId;

_table1.SurplusQty = _Qty;

_table1.insert();

}

// ttsCommit;

}

_table1 = this.createsurplus()

means that

createsurplus is boolean method this method return ture /false

Never do that, as the method will return the boolean and not the table buffer.

Take one boolean variable and assign the output of the method to that.(based on that do an insert or update)

Hello Ven,

  1. Create a static exist method on your Table1 which is used in the form1 as datasource table as shown below:

public static boolean exist(ProjId _projId, ItemId _itemId)

{

;

return _projId && _itemId &&(select firstonly RecId from Table1

where Table1.ProjId == _projId

&& Table1.ItemId == _itemId).RecId != 0;

}

  1. Instead of creating a new form form2 use a dialog form for form2 and add three fields in the dialog form i.e. ProjId, ItemId and Qty.

  2. While creating a new record in form1 by pressing Ctrl+N open the dialog form, let the user enter the values for ProjId, ItemId and Qty fields.

  3. Capture the values entered by the user in the ProjId, ItemId and Qty fields in the dialog form.

  4. Create a method as shown below:

public void insertOrUpdateTable( ProjId _projId, ItemId _itemId, Qty _qty)

{

Table1 table1;

;

if (Table1::exist(_projId, _itemId))

{

ttsbegin;

select forupdate table1

where table1.ProjId == _projId

&& table1.ItemId == _itemId;

table1.Qty += _qty;

table1.update();

ttscommit;

}

else

{

ttsbegin;

table1.ProjId == _projId;

table1.ItemId == _itemId;

table1.Qty == _qty;

table1.insert();

ttscommit;

}

}

  1. Use the values captured from the dialog form and call this method at appropriate place .