Topic: Search plus display

Hi Guys,


I was trying something new for me. I wanted to display selected record + details on same window. I tried with edit action for the first record but I don't think that's the right way going about it.


Please see the attached sample project.

Post's attachments

Attachment icon Search and Details.zip 7.89 kb, 427 downloads since 2016-10-05 

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi Adam,
Attached is your project with an example of how you can do it by script (which is, to my knowledge, the only way);  it allows the user to scroll through the grid using both mouse and keyboard (only having one or the other would be confusing for users).
It is not possible with your current structure to display details from the 'classes' table in the same way because you don't have a relationship (join) between the 'people' and the 'classes' tables.
Regards,
Derek.

Post's attachments

Attachment icon Search and Details.zip 341.54 kb, 428 downloads since 2016-10-05 

3 (edited by AD1408 2016-10-06 09:12:48)

Re: Search plus display

Hi Derek,


Thanks a lot...... very nice, just  how I wanted .it to work.


I can link people to classes but after it needs script too. That's where I need help. You can change the structure as it needs to be.
Since a person can have more than 1 class, it would be better to display person's classes in table grid I think.


On a different matter, I'm using your method for lookups. I like your method as it saves me dealing with a lot of tables and forms. I had around 18 lookups, they were working fine. I added 2 more recently and it start giving error on run. "Exception TDBXError in module....no such column: lookup_key."
I checked many times to spot the error but cannot find anything missing. They seems to be set same as working ones. Only difference I can see filter names bit longer than others. Any pointers for possible causes?

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi Adam,
Glad it helped.  I'd agree about your 'one to many' between people and classes - much better (and easier as it's just vanilla MVD) to display them in a separate tablegrid
If you're having a problem with a new look up and all the others work okay, i'd have to suspect something in the way you've added the new ones or something else that has been added/changed at the same time.
Can you attach a copy and I might be able to spot something.
Derek.

Re: Search plus display

I have added foreign key to the table "People" and small script

Post's attachments

Attachment icon Search and Details_fixed.zip 9.48 kb, 454 downloads since 2016-10-06 

Dmitry.

6 (edited by AD1408 2016-10-06 11:45:28)

Re: Search plus display

Thanks a lot Dmitry............ appreciated very much


------------------------------------------


Thanks a lot Derek...

I have tried to recreate but still same crash error. please see the attached file.

Post's attachments

Attachment icon Lookup Issue.zip 12.73 kb, 414 downloads since 2016-10-06 

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi,
You have called the fields in the 'lookups' table 'key' and 'value'. 
However, in your calculated fields you reference it as 'lookups_value';  it should be 'value'. 
In the combobox  'filter' object property, you reference it as lookups_key;  it should be 'key'. 
Two of your calculated fields have a leading space in their name (not a problem now but maybe later??). 
See the screen capture in the attachment along with the project with the calculated fields and the object properties for the comboboxes changed as per above.
Derek.

Post's attachments

Attachment icon Lookup Issue.zip 600.48 kb, 454 downloads since 2016-10-06 

Re: Search plus display

Hi Derek,


Thanks a million... I learn a new stuff that in calculated fields for lookups need to match lookups table field names plus on filters.  Am I correct in saying, I can use "lookup_value" instead of "value" as named on lookups table for calculated field names and vice versa, but in expression editor it must match.


It's never enough however much I thank you.

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi Derek,


Sorry for bothering you again.


    Form1.cbCust_Title.Text := SQLExecute('SELECT customers.lookup_value FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

    Form1.EdCust_Name.Text := SQLExecute('SELECT name FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

Second line of the script works ok but first line returns error, which is combobox with lookup keys and values. What would it be the correct way of handling fields with lookup keys and values in context of the script above please?

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi,
The first line errors because you are using SQL to retrieve a calculated field (customers.lookup_value);  calculated fields don't actual 'exist' in terms of being stored in a table, they are simply used as temporary containers to hold data whilst the program is running.   
The field you actually need is customers.id_lookups. 
So, you should replace:
Form1.cbCust_Title.Text := SQLExecute('SELECT customers.lookup_value FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);
WITH:
Form1.cbCust_Title.Text := SQLExecute('SELECT customers.id_lookups FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);
But without seeing the script 'in situ' with the application, I can't be 100% sure.
Derek.

11 (edited by AD1408 2016-10-07 21:16:27)

Re: Search plus display

Thanks a lot Derek............


Looks like fun is starting. Now I get error "Could not convert variant type (UnicodeStrings) into type (Double)"


Also I'm missing something for pulling date fields. Following didn't do anything:
Form1.dtpCustomer_StartDate.Date := SQLExecute('SELECT start_date FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);


____________________________
Edit:


It seems SQL script requires different field names for different field types.


Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);


Lets assume form field names are same. How would you write the above code for field types:

//Integer
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Real
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Currency
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Boolean
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

Date/Time
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Date
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Time
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Image
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Calculated field
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);

//Relationship
Form1.EdCust_City.Text := SQLExecute('SELECT city FROM Customers WHERE id='+Form1.TGrid_Form1Search_Customers.sqlValue);
Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

Hi Guys,


As mentioned above having problems using different types of database fields with SQL script etc. I have commented out SQL script lines that didn't work.


Also failed on 1 to many display using SQL . Please see attached sample project.


Please help.......

Post's attachments

Attachment icon Search and details with sql.zip 17.83 kb, 413 downloads since 2016-10-09 

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

AD1408 wrote:

Hi Guys,


As mentioned above having problems using different types of database fields with SQL script etc. I have commented out SQL script lines that didn't work.


Also failed on 1 to many display using SQL . Please see attached sample project.


Please help.......



Hi Dmitry,


Would you be so kind to do 1 to many part script for the above sample project please....

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

AD1408
Done.

Post's attachments

Attachment icon Search and details with sql_fixed.zip 18.77 kb, 432 downloads since 2016-10-13 

Dmitry.

15 (edited by AD1408 2016-10-14 09:28:29)

Re: Search plus display

Hi Dmitry,


Thank you VERY much..... Now, I can pull in different fields type.


I have tried to do 1 to many part (getting selected customer's invoice/s displayed on invoice tgrid on same form) but couldn't. Could you please do at least one field so that I can go at it to do the rest.

Post's attachments

Attachment icon Search and details with sql_fixed_2.zip 19.14 kb, 423 downloads since 2016-10-14 

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

AD1408 wrote:

Hi Dmitry,


Thank you VERY much..... Now, I can pull in different fields type.


I have tried to do 1 to many part (getting selected customer's invoice/s displayed on invoice tgrid on same form) but couldn't. Could you please do at least one field so that I can go at it to do the rest.


Done.
I have added foreign key id_Customers to the table "Invoices", thus you should select a customer from ComboBox when create a new invoice using form frmInvoice

Post's attachments

Attachment icon Search and details with sql_fixed_3.zip 19.66 kb, 461 downloads since 2016-10-17 

Dmitry.

Re: Search plus display

Hi Dmitry,


Thank you very much for the latest fix....


However, there seems to be an issue with image field display. It doesn't update/refresh image field when record has no image. Please see caps below:



https://s16.postimg.org/a19sprdgl/img_refresh.png

Adam
God... please help me become the person my dog thinks I am.

Re: Search plus display

You should add line for clear image

Form1.dbimg_Image.Clear;

As result:

    Form1.dbimg_Image.Clear;
    Form1.dbimg_Image.LoadFromDatabase('Customers', 'image', Form1.tgCustomersSearch.dbItemID);
Dmitry.

Re: Search plus display

Thank you very much Dmitry............


That fixed the issue.

Adam
God... please help me become the person my dog thinks I am.