How to display panel onclick data into dbgrid and how to save the dbgrid data into a table in Canteen billing software

1.2k views Asked by At

I am developing kiosk canteen billing software which enables the billing of items at the canteen.

I have two tables in the database, one with menu and other with users.
The items are displayed on panels which are created dynamically according to the record count. When the user clicks a panel the item needs to be added to the dbgrid.

Finally, the bill has to be saved according to the 'userid' into a table.

In brief; I wanted the item with its price to be displayed on the dbgrid when user clicks the panel. Also I want the bill to be saved into a table using a save button in the design.

The following tables I have;

1.) dbo.Menu with columns Menu_index,Item_Name,Item_Price.

2.) dbo.Users with columns UserId,UserName,UsrPwd,Status.

3.) dbo.Tran_details with columns Menu_index,Menu_id,Item_price.

4.) dbo.Tran_header with columns Menu_index,Date,UserID.

The coding I did is something like this (below) but I am stuck at this point. Any methodology or an example coding would be appreciated.

Thanks in advance.

procedure TfrmMenu.FormCreate(Sender: TObject);    
  begin
    with DMCanteen do
   begin
    QryMenu.Close;
    QryMenu.SQL.Clear;
    QryMenu.SQL.Add('select Menu_Index,Item_Name,Item_Price from MENU');
    QryMenu.Open;
      SetLength(arrmenu, QryMenu.recordCount);
      SetLength(arrmenuid, QryMenu.recordCount);
      SetLength(arritemprice, QryMenu.recordCount);
    i := 0;
    QryMenu.First;
     while not QryMenu.Eof do
   begin
     arrmenu[i] := QryMenu.FieldByName('Item_Name').AsString;
     arrmenuid[i] := QryMenu.FieldByName('Menu_Index').AsInteger;
     arritemprice[i] := QryMenu.FieldByName('Item_Price').AsString;
     QryMenu.Next;
     inc(i);
   end;
     showmessage(Inttostr(QryMenu.recordcount));
     CreateButtons(QryMenu.recordcount, 5, Panel1);
  end;
end;
1

There are 1 answers

4
AlexSC On

It seems to me that you need two different datasets (I strongly suggest you to use TClientDataset): one that has all the products and other that has the ordered products.

When a given panel is clicked, the corresponding record must be accessed in order to give you the product details to add a new record in the order dataset. It seems to me that your DBGrid will be linked to the order dataset, so anytime you add a record to that dataset, the DBGrid will be automatically updated to show it.

A tip here: when working with dataware components in Delphi, do not think about grids or edits, but about datasets. The visual components exist only to let the GUI to work on the data. The data are stored in the datasets. When the dataset is updated, the visual component will show it!

So, it´s my suggestion that you design your solution to work with two datasets, one as product catalog and other as product order. When a product is selected in the catalog dataset, a corresponding record will be inserted in the order dataset. With dataware components correctly linked to the proper datasets, the GUI will show what you want.