TTRMW
asked on
Decrement a value in a database.. via string grid... on an onclick.. in delphi!
Hi there
For a bit of background, my project is a sort of EPOS/Stock management system.
Everything is now all good, except I haven't been able to figure out how to decrement the stock values as they go through the transaction process.
There are two tables in the database - Product and Takings.. All the stock is stored in Product, obviously. I need to decrement the quantityinstock field when items are sold, of course.
It works by displaying all stock in a dbgrid. There is a query component which allows the user to find an item of stock. The user selects the record in question, then an onclick adds it to a strgrid, which keeps track of items in the current transaction. The code for this onclick is:
procedure TFrmEPOS.BtnEPOSAddClick(S ender: TObject);
begin
BtnEPOSAdd.Enabled := false;
{ Write current record fieldvalues to string grid }
StrGridTransaction.Cells[0 ,Strrow]:= EPOSQuery. FieldValue s['Product Name'];
StrGridTransaction.Cells[1 ,Strrow]:= EPOSQuery. FieldValue s['Product Cost'];
{ Strrow points to next row to modify - is incremented as additions made }
Strrow := Strrow + 1;
{ If statement disables user's ability to add to grid if full - delete button
is re-enabled. }
if Strrow = 17 then
begin
BtnEPOSAdd.Enabled := false;
end;
BtnEPOSdelete.Enabled := true;
end;
When all items desired are added to the strgrid, the user clicks another button to total the cost, then a final button to register cash tender and calculate change. This final onclick also posts the transaction date and takings to the takings table. The code for that is here:
procedure TFrmEPOS.BtnTenderClick(Se nder: TObject);
var
tender, change : real;
count: integer;
begin
tender := StrToFloat(inputbox('Tende r','Please enter cash tendered.', ''));
if tender >= total then
{ allows user to enter cash tendered and calculates change }
begin
change := Tender - total;
LblEPOSChange.Caption := '£'+FloatToStr(change);
{ appending takings table }
FrmTakings.TakingsQuery.Cl ose;
FrmTakings.ADOTakings.Appe nd;
FrmTakings.ADOTakings.Fiel dvalues['T ransaction Date']:=da te;
FrmTakings.ADOTakings.Fiel dValues['T ransaction Takings']: =total;
FrmTakings.ADOTakings.Post ;
FrmTakings.TakingsQuery.Op en;
{ Clears the string grid of all values }
Strrow := Strrow +1;
for count := 0 to Strrow do
begin
StrGridTransaction.Cells[1 ,Count]:=' ';
StrGridTransaction.Cells[0 ,Count]:=' ';
end;
{ re enables transaction controls for new transaction }
MmoTransactionTotal.Text:= '';
BtnEposAdd.Enabled := true;
BtnEposDelete.Enabled := true;
BtnEposQuantity.Enabled := true;
BtnEposTotal.Enabled := true;
Strrow := 0;
end
else
begin
ShowMessage('Tender cannot be less than transaction cost!');
end;
end;
At this point don't mind if the solution is quite clunky, just that it works!
Cheers in advance!!
For a bit of background, my project is a sort of EPOS/Stock management system.
Everything is now all good, except I haven't been able to figure out how to decrement the stock values as they go through the transaction process.
There are two tables in the database - Product and Takings.. All the stock is stored in Product, obviously. I need to decrement the quantityinstock field when items are sold, of course.
It works by displaying all stock in a dbgrid. There is a query component which allows the user to find an item of stock. The user selects the record in question, then an onclick adds it to a strgrid, which keeps track of items in the current transaction. The code for this onclick is:
procedure TFrmEPOS.BtnEPOSAddClick(S
begin
BtnEPOSAdd.Enabled := false;
{ Write current record fieldvalues to string grid }
StrGridTransaction.Cells[0
StrGridTransaction.Cells[1
{ Strrow points to next row to modify - is incremented as additions made }
Strrow := Strrow + 1;
{ If statement disables user's ability to add to grid if full - delete button
is re-enabled. }
if Strrow = 17 then
begin
BtnEPOSAdd.Enabled := false;
end;
BtnEPOSdelete.Enabled := true;
end;
When all items desired are added to the strgrid, the user clicks another button to total the cost, then a final button to register cash tender and calculate change. This final onclick also posts the transaction date and takings to the takings table. The code for that is here:
procedure TFrmEPOS.BtnTenderClick(Se
var
tender, change : real;
count: integer;
begin
tender := StrToFloat(inputbox('Tende
if tender >= total then
{ allows user to enter cash tendered and calculates change }
begin
change := Tender - total;
LblEPOSChange.Caption := '£'+FloatToStr(change);
{ appending takings table }
FrmTakings.TakingsQuery.Cl
FrmTakings.ADOTakings.Appe
FrmTakings.ADOTakings.Fiel
FrmTakings.ADOTakings.Fiel
FrmTakings.ADOTakings.Post
FrmTakings.TakingsQuery.Op
{ Clears the string grid of all values }
Strrow := Strrow +1;
for count := 0 to Strrow do
begin
StrGridTransaction.Cells[1
StrGridTransaction.Cells[0
end;
{ re enables transaction controls for new transaction }
MmoTransactionTotal.Text:=
BtnEposAdd.Enabled := true;
BtnEposDelete.Enabled := true;
BtnEposQuantity.Enabled := true;
BtnEposTotal.Enabled := true;
Strrow := 0;
end
else
begin
ShowMessage('Tender cannot be less than transaction cost!');
end;
end;
At this point don't mind if the solution is quite clunky, just that it works!
Cheers in advance!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
helpful, cheers!
It sounds like you are maintaining aQOH in the Product table. As you are posting the individual inserts of the Product lines in vovled in the Taking, you need to use that same information to post a change to the Product table (sort of likeUPDATE PRODUCT SET QOH = QOH - AmtTaken; ).
If you are using a DBMS that allows triggers, you can do that with an INSERT or UPDATE trigger on the Takings table.