0

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;
  • It is not very clear with which bit of the problem you want help. Is it the insertion into the grid? – Hugh Jones Sep 12 '13 at 09:02
  • We need some more info. Table structures would be nice. Do you want to keep all ordered items in the database or only the total bill amount? Please edit your question. – Jan Doggen Sep 12 '13 at 09:45
  • BTW You never add data 'to a dbgrid', you insert data into the underlying database. Maybe that's part of your confusion. – Jan Doggen Sep 12 '13 at 09:45
  • I need to keep all the ordered items in the bill. The thing I needed is this ; (1). I need to display the items selected with the price on the grid. and (2). I need to save the bill into a table I have already created as dbo.Tran_details – Sreenath Krishnakumar Sep 12 '13 at 09:47

1 Answers1

0

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.

AlexSC
  • 1,823
  • 3
  • 28
  • 54
  • Thank for the idea boss ! Can you provide me an example with code for linking the dbgrid with order dataset , if you have time ? that would help me a lot. – Sreenath Krishnakumar Sep 15 '13 at 07:50
  • @SreenathKrishnakumar: code is not needed for that, you just assign the DataSource property of the TDBGrid to a TDataSource component that is linked (by Dataset property) to your order dataset. In code it's just the same, if you prefer, just assign those same properties. – AlexSC Sep 15 '13 at 15:33
  • What I have done is; I have created two datasets and are linked to a datasource.The form also have an adoquery & two adotables.But when I run the program all the values in the table is showing.I want the same item name to be displayed on the dbgrid which is same as in the item tag. The code is; procedure TfrmMenu.itemClick(Sender: TObject); begin With DMCanteen do begin with ADOQuery1 do begin SQL.Add('Select Menu_Index,Item_Name,Item_Price from Menu'); Open;end; end; end; – Sreenath Krishnakumar Sep 18 '13 at 11:11
  • @SreenathKrishnakumar: I´m not sure I realy follow you, however, what I would do it to have a `TDBGrid` linked to a `TDataSource` linked to the orders dataset. Everytime someone picks an item, we have to locate that item details in the products dataset (**not orders Dataset**). Now that the product dataSet is positioned at the item record, a new record in **orders dataset** should be added, containing a copy of the item details. When this new record is posted to the order dataSet, the grid will show it. – AlexSC Sep 18 '13 at 11:44