26

(9 replies, posted in Script)

Hi,
Is there anyway to change a grid cell text using Script?
Cannot find any property sad

Many thanks

Yep It worked,
Many Many thanks

Hi everyone,
I have a question.
I have a field in my database called date which is stored date string from date time picker.
I just want to calculate days between that date and today in database calculated fields.
how should I write my query?

many many thanks

Hi,
I just need to have calculated field values inside my a query in my script!

I just tried to use the exact same query in my script but got sql syntax Error which is works fine in calculated fields!!!!!

here is the code:

Main.Panel1.Caption := SQLExecute('CASE WHEN (SELECT b.is_active FROM bookings b WHERE b.is_active=1 AND b.id_boxes=1) != 0 THEN "Nein" ELSE "Ja" END');

I just got this error: Near CASE syntax error! and here is the returned query:

CASE WHEN (SELECT b.is_active FROM bookings b WHERE b.is_active=1 AND b.id_boxes=1) != 0 THEN "Nein" ELSE "Ja" END

how can I fix my query?

Many thanks

30

(2 replies, posted in Script)

brian.zaballa wrote:

try running the dbupdate after your filter

Payment.ComboBox1.dbFilter := 'id_customers = 4';
Payment.ComboBox1.dbUpdate;

Payment.TableGrid1.dbFilter := 'id_customers = 4';
Payment.TableGrid1.dbUpdate;

Perfect, it works
many Thanks

31

(2 replies, posted in Script)

Hi everyone,
I just have a problem with dbFilter in both Grid and combobox!!!

I want to filter results based on customer id. so Combo box or grid will show only records related to customer and not all of them.
I just want to do it in separate window (form) so I have to do that using scripts but its not working:(
if I write the filter manually in filter field of grid it will works but using script not working.

here is my script for both:

procedure Payment_OnShow (Sender: TObject; Action: string);
begin
   //Payment.ComboBox1.dbFilter := 'id_customers = ' + IntToStr(Payment.Save.dbParentTableId);
   Payment.ComboBox1.dbFilter := 'id_customers = 4';
end;
procedure Payment_OnShow (Sender: TObject; Action: string);
begin
    //Payment.TableGrid1.dbFilter := 'id_customers = ' + IntToStr(Payment.Save.dbParentTableId);
   Payment.TableGrid1.dbFilter :=  'id_customers = 4';
end;

how can I make it work?
I need one of them no matter which one.

There is a table called booking, I want to show all bookings related to customer in grid/combobox and select one of them in payment form to be able to add a payment for that certain booking.

Many many thanks

32

(7 replies, posted in Script)

Many Many thanks,
Properties of save button just helped.

33

(5 replies, posted in Script)

Many Thanks.

34

(7 replies, posted in Script)

Many thanks,
But I want to have it before save anything!

I want to use it in scripts to show something on the form, no matter if save button pressed or not.


is it still stored in save button properties even before click on save button?

Hi,
I have 3 fields in my Database:

Title
Firstname
Lastname

I want to merge them and have a single field like this: Title Firstname Lastname

How can I do that using calculated fields?
any query example?

Mnay Thanks

36

(10 replies, posted in Script)

sparrow wrote:

Barcode and QRcode are generated in the Report.
Now the "Print barcode" button opens the designer. You can switch directly to the preview.

Many thanks,
so there is no way to show qr code in the program itself? (only in reports?)

37

(7 replies, posted in Script)

Hi,
I just want to get parent Id of new record to run a query.

I want to have the name of parent record when creating new child record.

imagine i have a customer (john doe) and i want to add his telephone number using a new form. so I want in new form have a text box like this: add new number for: john doe

Many Thanks

38

(10 replies, posted in Script)

Wow,
Many thanks.
Is there any way to show them in program itself too?

39

(10 replies, posted in Script)

Hi
Is there any way/example to generate qr code/barcode programmatically? 
Also I need qr code/barcode in report (print) form.

Many Many thanks

40

(13 replies, posted in Script)

Many many Thanks,
That was what exactly I need.
I thought MYVDB not supporting nested query

41

(13 replies, posted in Script)

sparrow wrote:

I understand you correctly that all records from BOXES should be in the tablegrid and their status (yes / no)
should depend on the records in the BOOKINGS table.


If there are two records in the BOOKINGS table with the same ID from BOXES but with a different is_terminated value,
what should we do then? What to display (yes/no)?


Could you draw or fill in the table as you imagine it in the table? With what fields? I will try to help you.


Hi,
Sorry for late,
Yes its correct, It must show all boxes like what I had in my original project (of course filtered by level per grid)
and if there is at least one active booking box marked as not free. so it can simply show yes/no or true false.

a box can booked by two customer at the same time so to mark as unavailable (is_free = false) there must be at least one active booking for that box.

Many Many Thanks

42

(13 replies, posted in Script)

Many Many Thanks,
It works but there is a small problem.
query only shows 2 records! which is means it only shows bookings records.
the purpose of my grid views is to show all records (in boxes) and if there is a booking for a certain record mark it as not available.

I believe right join can do the job but its not supported sad

maybe i should do that using scripts and not query? in such a case i can have problem when users want to create a new record for already booked box.

and if I have to using scripts how can I have loop through all gridbox rows?

Many Many Thanks

43

(13 replies, posted in Script)

Hi
Actually no its not, its another problem but same project.
I want to mark a box as unavailable automatically if there is a active booking for it in another table.

I believe using a query is better option rather than delphi script. Its not about changing colors.

Many many Thanks

44

(13 replies, posted in Script)

here is the project files

45

(13 replies, posted in Script)

let me show you database schema. maybe it can help.

I have two tables, one boxes and another one is bookings.

I want to have a calculated field in my boxes table which is run a query to find a record with two conditions in bookings:

1- bookings.id_boxes = boxes.id
2- bookings.is_terminated = false (is_terminated is a boolean field)

if find any result then it should return true, yes, ja or similar.
if cannot find any reslut then it will be false, no, nein or similar.

so I can use that field for my future uses like to show if box is booked or cannot booked it again cause its not available.
I also attached project file maybe can help.
many many thanks

46

(13 replies, posted in Script)

hi everyone,
Can I use IIF in my query in mvdb?

I just tried them both but not working. maybe my query have problem!

here it is:

(SELECT id_boxes, is_terminated IIF(boxes.id = bookings.id_boxes AND bookings.is_terminated = False,'Booked','Free') FROM bookings)  

And this is CASE

(SELECT id_boxes,is_terminated CASE WHEN boxes.id = bookings.id_boxes AND bookings.is_terminated = False THEN 'Ja' ELSE 'Nein' END category FROM bookings)  

I just want to know if a box is booked or not. it better to return boolean but I don't know how to replace yes no with other words in grid!

Many Thanks

47

(10 replies, posted in Script)

derek wrote:

Hello Everyone,
Sonixax,
Perhaps you could attach your project (ideally with some data in it) which would be helpful to demonstrate your problem .  As K245 has suggested, there may be different ways to achieve what you want to do.  200 panels (and, if I follow the discussion correctly,  each panel linked to a record) seems excessive and does not appear, at least initially, to be taking a relational database approach.
Derek.

Sure,
Here it is,
Still working on it.
There is some rooms, every panel represent a room.
I have a form which is called AddBox, I just want on click on every single panel AddBox opens to show the room record. more details will add later currently just open the form to show it.
I just starting to replace buttons with panels cause cannot change buttons color.
if possible to draw panels with a loop to, it will be amazing cause maybe in future we are going to change the map so we have to re arrenge everything from source again. of course it will be easier to add, remove or position them within the final product.

many many thanks everyone

48

(10 replies, posted in Script)

k245 wrote:
sonixax wrote:

Many many Thanks,
Is it possible to have such a functionality for events too?
For example onclick?

Many many Thanks again.

The name of the event handler is in the db<event> property, for example onClick:

procedure frmForm_btnButton_OnClick (Sender: TObject; var Cancel: boolean);
var  
  i: integer;
begin
  for i := 0 to frmForm.ComponentCount-1 do
    if frmForm.components[i] is TdbPanel then 
      TdbPanel(frmForm.components[i]).caption := TdbPanel(frmForm.components[i]).dbOnClick;
end;

Many thanks for the answer,
But I need something else.
let me explain:

I have around 200 panels, and I want instead of 200 times code like this one:

procedure Main_Panel10_OnClick (Sender: TObject);
begin

end;

only have one loop.
every single panel (button) should linked to a record and open a form to show that record.

I can send the project if you need it.
many many thanks

49

(10 replies, posted in Script)

Many many Thanks,
Is it possible to have such a functionality for events too?
For example onclick?

Many many Thanks again.

50

(10 replies, posted in Script)

Hi,

is there any way to point components in a loop?
I just have about 50 panels and want to go through them one by one in a loop instead of writing of 50 similar line of codes! something like this:

   for i := 1 to 5 do
  begin
        Main.Panel(i).Caption := 'Panel number is: ' + IntToStr(i);

  end;

Many Thanks