Topic: Button to save records with strange behavior

Hello everyone, as always, thank you for your interest in my problem.
I'm doing a new project and right away I have a couple of problems that I can't answer.
The first concerns the opening of the 'frmAvviso' form which starts at the top left instead of in the centre.
The second is a fact that I consider inexplicable and I don't understand how to solve it: in the 'frmImpostazioni' form, going to the third and last tab (Prodotti) I inserted a button to add products. It doesn't open the input form and on the contrary it always gives me the popup that indicates that the field is mandatory within the TableGrid and it doesn't form that it should.
Thanks everyone for the help.

Post's attachments

Attachment icon Ricevuta.zip 1.05 mb, 95 downloads since 2023-06-25 

2 (edited by domebil 2023-06-25 15:01:01)

Re: Button to save records with strange behavior

Ciao Fabio purtroppo non puoi salvare dallo stesso form su un solo database, salverà sia azienda sia cliente che prodotto.
Avendo come campo obbligatorio il cliente se non inserisci prima il cliente non ti farà inserire il prodotto

Post's attachments

Attachment icon Ricevuta 2.rar 1.22 mb, 87 downloads since 2023-06-25 

Domebil

Re: Button to save records with strange behavior

Caio Fabio, Domebil,
1.  Have a look at the attachment for a solution to the 'frmavviso' problem (see screenshot1 in the attachment).
2.  The second problem you have is not with tabsheet 'prodotti' but with tabsheet 'clienti'.   
With tabsheet 'clienti' there is not active tablegrid to display 'clienti' records therefore, by default, MVD puts you into 'add' mode and because you are in 'add' mode, it wants you to fill in any mandatory fields before you can then call 'frmprodotti'.   
You can fix the problem by using a tablegrid on 'clienti' tabsheet' to then call a new form ('frmclienti')..
I would also do the same thing for 'azienda' tabsheet to make it consistent for the user (and at the moment although there are no mandatory fields on table 'azienda' you could encounter the same problem as you currently have with the 'clienti' tabsheet.
Derek.

Post's attachments

Attachment icon Ricevuta1.zip 1.07 mb, 91 downloads since 2023-06-25 

Re: Button to save records with strange behavior

Ciao Domenico, grazie per la risposta. Questa cosa di più pulsanti di salvataggio nello stgesso form non l'avevo proprio immaginata. Cercavo di farlo più minimale possibile ma dovrò per forza aggiungere qualche form. Mi sembrava una buona idea quella di avere tutti gli inserimenti in una sola finestra ma dovrò adattarmi.
Già che ci sono vorrei chiedere un'altra cosa: siccome nella tabella 'Azienda' ci andrà solo un unico record sono i dati relativi alla propria azienda, quale potrebbe essere il miglior modo per, diciamo, "bloccare" la tabella ad un unico record? Cioè una volta inseriti i dati dell'azienda si possa solo modificare i dati e non che venga creato un altro record.
----------------------------------------------------------------------------------------------------------------
Hi Derek,
I hadn't thought that even though I put a TableSheet things are not divided but the form remains the same. It seemed like a good idea to have all entries in one window but I'll have to adapt. Thanks for the explanations and the possible alternative.
While I'm at it, I'd like to ask something else: since only a single record will go in the 'Company' table, it's the data relating to your company, what could be the best way to, let's say, "lock" the table to a single record ? That is, once the company data has been entered, it is only possible to modify the data and not create another record.

Re: Button to save records with strange behavior

Hi,
I think the easiest way (and so the best way smile !) is to disable the 'add' button when the 'azienda' table has 1 row (see attached) but there are other ways as well.
Derek.

Post's attachments

Attachment icon Ricevuta2.zip 1.13 mb, 76 downloads since 2023-06-25 

Re: Button to save records with strange behavior

Hi Derek, Fabio


Unexpected, but it seems to work. wink At least for a new record.

Post's attachments

Attachment icon Ricevuta3.rar 1.02 mb, 86 downloads since 2023-06-25 

Re: Button to save records with strange behavior

Hi derek and sparrow,
first of all thank you as always, then I am always amazed by what you manage to invent. Getting around that obstacle with that button system is amazing and I also liked the ShowModal property instead of Show to show the form.

Re: Button to save records with strange behavior

Now if you also tell me how to save the 0s in front of a number in an integer (I tried real too) field because I tried everything but I couldn't. If I write 00123 he saves 123.
I am very grateful to you.

Re: Button to save records with strange behavior

The first is the display format and not how to write.

Re: Button to save records with strange behavior

Sorry sparrow, i didn't understand.

Re: Button to save records with strange behavior

Hi Fabio, Hi Sparrow,
I think what Sparrow is saying is that the way the data is displayed to you on a Form is not how the data is stored in SQLITE (or any other database). 
This is best illustrated with an example  (I will use a 'datetimepicker' field because it is visually the most obvious (but it is true of other data types as well)). 
Look at 'screenshot1' in the attachment - it shows how the date is displayed to you when you run your application but also shows how the date is stored in the database - it's quite different.
So, returning to your question, you could try to format an integer field to display as 00123 on the Form, but it will always be saved in the database as 123.
The big question is why are you trying to format an 'integer' field like that?  My guess would be that you are referring to the fields 'telefono' in the tables 'clienti' and 'azienda' - but these are incorrectly defined as 'integer' (see screenshot2). 
Ask yourself "....do I want to perform mathematical calculations on the field 'telefon'?"  And the answer is, of course, no you don't - in which case it should be defined as 'text' (even though it will contain only numbers - you can still force 'numbers only' on a 'text' field).
One final thing - if you are using the same form (or same tabsheet) for adding and editing your clienti, you need to be careful because doing it that way, it is very easy to create duplicate records.
Hope this helps,
Derek.

Post's attachments

Attachment icon fabio.zip 97.74 kb, 69 downloads since 2023-06-26 

12 (edited by reteinformatica 2023-06-26 08:45:25)

Re: Button to save records with strange behavior

Hello all, thanks derek for the clarifications, I understood very well the question of the type of field and when to use them and I changed the text as you suggested.
In the meantime, I went a little further in the structure of the program that I am attaching.
As you can see, I added a 'frmRicevuta' form in which I put the 'bNuovo' button with "New Record" action but the button doesn't open the 'frmProdotti' form as it should.
Maybe for the same opening speech that you can't put two "Save" controls on the same form?
In this case I set the "NewRecord" property to the 'lbCliente' Label via script when it is clicked.

Post's attachments

Attachment icon Ricevuta.zip 1.06 mb, 69 downloads since 2023-06-26 

Re: Button to save records with strange behavior

Hi Fabio,
'BNuovo' doesn't open 'frmprodotti' because that's not what you've set it to do - you've set it to open 'frmreicevuta' (see screenshot1).  It's trying to open itself!
But before you go further, I think you need to examine your data schema;  two things look immediately wrong
1.  The relationship between 'prodotto' and 'fatture' is incorrect (see screenshot2) - shouldn't it be the other way round (table 'fatture' should have a relationship ('id_prodotto') back to 'prodotto')?
2.  With your current data schema, it does not allow for you to have multiple products on an invoice.  If this is what you intend, then it's okay but I would have thought you would want to have more than one product per invoice.  If you do then I suggest you change 'fatture' to hold just a record_count and a date and then create a new table (something like 'dettagli') to hold details of each invoice line (obviously with a relationship between 'fatture' and 'dettagli').
As a general comment (and it's just my opinion), I think the 'flow' of your application is a bit confusing and could be streamlined quite a bit (but then, I always like to keep things simple!  smile).
Derek.

Post's attachments

Attachment icon fabio.zip 99.68 kb, 65 downloads since 2023-06-26 

14 (edited by reteinformatica 2023-06-26 14:30:57)

Re: Button to save records with strange behavior

Hi Derek,
I've been studying this project night and day for 3 days, I've completely lost my mind, I've even managed to create a button that opens the same form.
Obviously, as you always guessed the purpose, he had to open the form 'frmNuovoProdotto' and not himself and you got it right: I would like to insert more products in the invoice.
To make this project I first studied the example project "Invoice" which is downloaded from the site of which I tried to follow in its footsteps.
As you suggested, I moved the relation field from the 'Fatture' table to 'Prodotti', which was also the system used in the example I followed. I had tried to do a little by myself without just copying.
In the example, Dimitri has put the "Date" field in the Customers table, so I did too even if it seems a little logical to me since this field relates to the invoice. But if it has to be done this way to work well, then it's done this way.
So I went a little further: I set up a calculated field (Totale) in the 'Ricevuta' table to do the calculation of the item for the quantity. And here I would say that it works: he inserts the item in the invoice and makes the correct calculations.
Now the problem that arises is in saving the invoice (frmRicevuta) and more precisely in the save button 'bSalva', I get an error.
I support your idea of making things as easy as possible, so if you have any other suggestions to improve this project, please let me know.
Thanks for everything derek

Post's attachments

Attachment icon Ricevuta.zip 1.06 mb, 69 downloads since 2023-06-26 

15 (edited by domebil 2023-06-26 16:10:52)

Re: Button to save records with strange behavior

ora funziona

Post's attachments

Attachment icon Ricevuta 2.rar 1.23 mb, 97 downloads since 2023-06-26 

Domebil

16 (edited by reteinformatica 2023-06-26 16:31:32)

Re: Button to save records with strange behavior

Ciao Domenico,
ho visto le correzioni e più o meno ho capito. Quello che però non mi spiego è perchè non funziona come l'ho impostato io che l'ho fatto sulla falsa riga dell'esempio scaricabile dal sito.
Hai cliccato sul tasto OK all'avvio del programma?

17 (edited by domebil 2023-06-26 18:15:43)

Re: Button to save records with strange behavior

Perchè mancava un database " Lista" , non puoi salvare entrambe fattura e elenco sullo stesso database

Domebil

Re: Button to save records with strange behavior

Eppure è quasi uguale, almeno in struttura, all'esempio "Invoice" e che funziona. Ero curioso di capire perchè non funzioni.

Re: Button to save records with strange behavior

Hi Fabio,
I had a bit of free time so had a look at your project and tried to simplify things a bit (probably the main change is that everything is accessed through a 'page control' ('tab sheets') so the interface is consistent.
Anyway, just my initial thoughts and feel free to use or ignore as suits your project smile.
If anything's not clear, then shout out.
Derek.

Post's attachments

Attachment icon Ricevuta4.zip 1.25 mb, 93 downloads since 2023-06-28 

20 (edited by Без_имени 2023-06-27 18:43:25)

Re: Button to save records with strange behavior

derek wrote:

Hi Fabio,
I had a bit of free time so had a look at your project and tried to simplify things a bit (probably the main change is that everything is accessed through a 'page control' ('tab sheets') so the interface is consistent.
Anyway, just my initial thoughts and feel free to use or ignore as suits your project smile.
If anything's not clear, then shout out.
Derek.

Привет Derek
Подскажи пожалуйста, как сделать сохранение тестовых полей (переменных) в отдельный файл, а при загрузке что бы они уже были введены в свои поля, минуя таблицу баз данных.
Заранее благодарю за ответ
http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=9643&download=0

Post's attachments

Attachment icon Снимок экрана 2023-06-27 233840.png 36.27 kb, 23 downloads since 2023-06-27 

Re: Button to save records with strange behavior

For questions not on this topic, create a new topic.
Feel free to read and use the forum search. It's free.


Для вопросов не по этой теме создавайте новую тему.
Не стесняйтесь читать и пользоваться поиском по форуму. Это бесплатно.

Post's attachments

Attachment icon ini.zip 325.82 kb, 82 downloads since 2023-06-27 

Re: Button to save records with strange behavior

Hi Derek, hi everyone,
thanks for the suggestions always welcome. Your project is very nice and corresponds to what I wanted.
The thing is, when I don't understand something, I stubbornly stick with it until I understand it.
Sometimes, then, it seems to me that in some projects something doesn't work for me that worked for me in others and then I get stubborn even more. Certainly it is a feeling, if they are the same they must both work.
For example in this case I tried to make the project along the lines of the "Invoice" example downloadable from the site. That works, mine has this problem. The only difference is that in the example there are two textboxes for the customer's name and surname, while I had placed a combobox.

Re: Button to save records with strange behavior

Hi Fabio,
Replacing a couple of text boxes with a combobox shouldn't make any difference.
Perhaps you can upload your project and give an example with the exact details of what is not working in comparison to the 'invoicing' example that you downloaded.  Then maybe someone can spot where there is a difference.
Derek.

Re: Button to save records with strange behavior

Hi Derek,
when using the program, when you click either on the "Salva" button (frmRicevuta.bSalva) or on the "Aggiungi prodotto" button (frmRicevuta.bNuovo) it gives me the error of the screen shot that I insert in the attachment).If at the "Salva" (frmReceipt.bSalva) I remove the property to save the record then the "Aggiungi prodotto" button (frmReceipt.bNew) works.

Post's attachments

Attachment icon Ricevuta.zip 1.07 mb, 65 downloads since 2023-06-29 

Re: Button to save records with strange behavior

Hi Fabio,
The 'aggiungi prodotto' button doesn't work because of the error with the 'salva' button.  The error with the 'salva' button is because you have attached fields from both the 'clienti' and the 'fatture' tables to the 'salva' button which is defined to save to the 'clienti' table only.
Attached is a fixed version of your program.
But with respect, I think that using the MVD 'invoices' project as the basis for what you are trying to do is adding a lot of confusion and probably not how you want your project to work anyway.
Fundamentally, the MVD 'invoices' project does not hold a discrete table for clients (even though there is a table confusingly called 'clients'!). 
But this table is being used as an 'invoice header' and then the 'bills' table is being used as an 'invoice details' table.  This is why you:
1.   need to enter details even for the same client every time you create a new invoice because the client details are not held in a relationship.
2.  why is there a 'date' field on the 'clients' table? - because it is actually an 'invoice header date'.
3.  why you can't use a combobox to select client details - because client details are not stored in a related table (although there is a way to get around this).
4.  why I have removed the 'nuovo clienti' button from your main screen - because you don't create new clients, you just create new invoices.
4.  likewise, the 'clienti' tabsheet has been removed.
If this is the way that you want your project to work then fine - the attachment in this post will work for you. 
But I suspect what you actually need is a proper 'clienti' table related to an invoice header table which is in turn related to an invoice details table (which is how my previous attachment on this subject is structured).
Derek.

Post's attachments

Attachment icon Ricevuta fixed sort of.zip 1.09 mb, 108 downloads since 2023-06-30