351

(4 replies, posted in General)

Humblelion, 

I think for your purposes a lookup field is what you need, I'm not the best with databases as yet, so I could be wrong.

After you have calculated the daily sales, do you need to write that to the database or just calculate it everytime you access the database?

Thanks Derek,

I don't know why I keep making things so difficult for myself!

I'm trying to make a table grid cell not editable once it has a value in it.

The below code works for checking if a cell is empty and allows in this case a date to be entered. It also allows the date to be changed again just by clicking on column 5, which what I don't want to happen. Note this is not using the datetimepicker  as a visible component.

if Acol = col then //check if column 5 has been clicked
    begin
     //If column 5 has no tick in the checkbox 
        if frmMain.grdOrders.Cell[col,ARow].Empty = false then
        begin

        // update the grid with the date in column 4
            frmMain.grdOrders.Cell[(col-1),ARow].asDateTime := dt;  {dbdate function does not work here}
      
 // update database
            sqlexecute('UPDATE requests SET rec_date = "' + DBDateStr(dt,1)+'" WHERE id =' +
           (frmMain.grdOrders.sqlValue));
        end;
   end;

However if I write this, the complete grid table no longer allows the date to be entered on the empty date column 4.

if (Acol = col) AND (frmMain.grdOrders.Cell[4,Arow].AsString = Null) then 
  
    begin
        if frmMain.grdOrders.Cell[col,ARow].Empty = false then
        begin
            frmMain.grdOrders.Cell[(col-1),ARow].asDateTime := dt; 
            sqlexecute('UPDATE requests SET rec_date = "' + DBDateStr(dt,1)+'" WHERE id =' +
           (frmMain.grdOrders.sqlValue));
        end;
   end;
 end;

I've tried using frmMain.grdOrders.Cell[4,Arow].AsString = '', I've tried removing this part of the code from AND and using an If statement instead and I've tried changing  frmMain.grdOrders.Cell[4,Arow].Empty = True.
None seem to do what I'm hoping for.

Thanks Derek, that solved my problem.

The reason why I'm going for a checkbox to enter a date is because:

1. I want a user to definitely select a 'date received' rather than perhaps accidently clicking on the grid and entering a date, as this is a one time entry. No reversal allowed, or mistakes for that matter smile

2. I intend to have a double click on a specific cell, similar to your example and open up another form.

I have a TableGrid it has  5 columns.  Column 5 has a checkbox enabled by selecting checkbox under 'settings'.

My intention is to click in cell 5 on a specific row and cause the current date to be entered into cell 4. I then want to change the font color of the row.

I have the code below  which partly works, the checkbox appears and the date does get entered into the correct cell.

However, I can click anywhere on the row to get this to happen, what I want is to have just column 5 cell to perform the date function when clicked.

I can't get the row font colour to change at all, though I would be just as happy to have a row grayed out.

procedure frmMain_grdOrders_OnCellClick (Sender: TObject; ACol, ARow: Integer);
 var
     YY,MM,DD:Word;

begin
    DecodeDate(frmMain.DateTimePicker1.DateTime,YY,MM,DD); //get only the date portion of datetime

    if frmMain.grdOrders.Cell[5,ARow].Empty = false then    //checkbox is unticked
    begin
        frmMain.grdOrders.Cell[4,ARow].AsDateTime := EncodeDate(YY,MM,DD); 
        frmMain.grdOrders.font.color:= clGreen;

    end;  
 

       
end;

Any ideas greatfully received.

356

(6 replies, posted in General)

Thank you both for your suggestions.

I was so busy trying to puzzle out why this had happened it hadn't occurred to me to go the simple route of just starting over again.

357

(4 replies, posted in General)

humblelion,

Are you having a problem trying to calculate the sales value or the quantity sold?

Are you using a calculated column to work out your sales?

358

(6 replies, posted in General)

Hi Derek, thanks for looking at the project.

It is still a work-in-progress. Just a warning, if you click the 'Add Order' button, your email client will open.

359

(6 replies, posted in General)

I have hit a strange problem which only has become apparent after I installed v6.2 .

I have a form on which is placed a  Page Control. This control has three tabs.

On tab 2, along with some edit boxes and labels I have placed a Date Time Picker. The picker is appearing on all three tab layouts instead of just the layout of tab 2.

I don't recall this happening with the earlier builds of MVD.

I'm assuming that to solve this problem I'll have to instantiate the date time picker in code rather than from design time or delve into the Forms.xml file and physically move the control into the Tab 2 group.

Any thoughts?

I wonder if you should have

with FORM_NAME.imgList16 do //Eg: frmMain.imgList16
begin
  Masked    :=false;
  ColorDepth:=cd32bit;
  ...
end;

Thank you very much Dmitry, that worked a treat.

Hello,

I am having a problem  working out how to delete an item in a database from an entry in a combobox.

What I'm trying to do is to select an item from a combobox and then click on a button to delete the entry out of both the database and the combobox itself.

The code I currently have is:

procedure frmMain_btnDeleteSupplier_OnClick (Sender: TObject; var Cancel: boolean);
var
    item: integer;
    idx:string;

begin
  
  idx := frmMain.ComboBox2.text;  //get the entry selected from the combobox

{  frmMain.ComboBox2.dbDeleteRecord(16);}  // I feel I should be able to use this somehow
  
  showmessage('Item ' + idx); // shows a message box just for debugging purposes. At this point the correct item shows in the message

  
 frmMain.ComboBox2.dbSQLExecute('DELETE FROM supplier WHERE sup_name =' + idx); //Delete the selected item from the database

 frmMain.ComboBox2.dbUpdate; //Update the database and possibly the combobox
end;

One of my problems is, the above SQL produces and error message 'no such column: item text that I've selected

If someone could point me in the right direction I'd be very grateful.

Do I need to somehow read in the row ID from the DB and then use 'dbDeleteRecord(rowID)'? If so I'm not sure how to do that in MVD.

I am using the trial version 6.1.