Topic: How to restrict creation of sub entry ?

Hello Guys,

I was trying to create small cereal app to learn MVD more. Here is my issue Original grams of cereal is 1000 in main "cereal" table for perticular brand when I try to divide it or create sub entry in form3 it doesn't understand that first entry was 100 grams and next entry can't be 1000 grams. or there is no subtract function in it I think so, how can I achieve this problem's solution.

Basically what i want is if main entry is 1000 gram than total of sub entry for particular brand must not exceed original grams.

Post's attachments

Attachment icon cereal.zip 338.35 kb, 28 downloads since 2017-04-29 

2 (edited by derek 2017-04-29 16:52:03)

Re: How to restrict creation of sub entry ?

Hi Kim,
Not sure if I understand your exact problems, but I'll have a go.
One of the issues in your app seemed to be that the two grids weren't 'talking' to each other - have a look at the attachment as a possible way to do this (it uses a 'search' function to take a specific row in tablegrid1 as a criteria to display related records in tablegrid2).  Apologies if it sounds more complicated than it actually is - once you've done a couple, it becomes very straightforward.
Another issue seemed to be some sort of calculation between the cereal weight and the summed weight of sub-entries so have a look at using a calculated field in the table structure (see attachment) to warn of this (but it's just one of many ways you could do it).
As an observation, in your app, you are using the same form to add / edit records.  It's okay to do it that way but can cause problems with duplicate records (try saving a record in your app and then press 'enter' a few times to watch the duplicates increase!).  In my opinion (for what it's worth LOL!), using a discrete form to add/edit records is a much safer option, particularly if you are new to MVD.
Hope this takes you forward a bit and please come back to the Forum if there's anything that's not clear.
Derek.

Post's attachments

Attachment icon cereal suggestion.zip 340.43 kb, 29 downloads since 2017-04-29 

Re: How to restrict creation of sub entry ?

Hello Derek

I think you misunderstood what I was trying to say but thanks for the nice example. learned few more things.

My application was not about mixing cereals. I attached Image so you can understand more thanks for the help.

Post's attachments

Attachment icon cerealpng.png 14.27 kb, 9 downloads since 2017-04-30 

Re: How to restrict creation of sub entry ?

Hello Kim,
Not a problem - I didn' think I'd really understood your app.  But some of the things I did in my previous attachment should help you no matter what the app is - the principles are always going to be the same.
When I first came across MVD, I found the best way to understand it was to search through the forum and download various apps that people had posted as part of some problem.
Good Luck,
Derek.

Re: How to restrict creation of sub entry ?

Hello Derek Good morning

I tried your way searching through forum but I was not able to find the solution.

I have attached project can you please look at it

so far what i have tried is going through calculated field but it only shows results not stopping me to enter more grams then Main.

tried SQLExecute pulling out the data from table and compare them it does comparison but not the way I want. I went through lots of example but couldn't find the thing I want. Please Help. sad

My problem is when I add entry in sub form more than what is in main it does not work 

Example : Main entry is 1000 grams sub entry is 100 grams and 200 grams for "type" so sub total is 300 grams I would like to halt the process if i add sub entry more that 700 grams, so if i enter sub entry for 800 grams it should stop me to enter the data.

Post's attachments

Attachment icon releted_tgrid.zip 339.27 kb, 47 downloads since 2017-05-01 

Re: How to restrict creation of sub entry ?

Hi Kim,
There are a number of ways of doing it - the attachment is just a suggestion.
I use a 'false save' button which checks the total weights for a commodity;  only if the total is less than or equal to the permitted, does it 'click' the 'real save' button.  If the total weights are more than permitted, it displays an error.
I've added a 'current running total' so that when the user enters form3, he sees what it is.
Also, note that the combobox on form3 now shows not only the commodity, but also it's permitted weight - it just gives the user a bit more info'.
Sorry it's not very 'polished' but I'm pushed for time at the moment.
Hope this helps.
Derek.

Post's attachments

Attachment icon releted_tgrid2.zip 340.38 kb, 29 downloads since 2017-05-01 

Re: How to restrict creation of sub entry ?

Thank you so much @derek

Here's how I did it. with one small issue " "" is not a valid integer value" when empty the textbox i mean backspace to clear textbox lol. smile

Post's attachments

Attachment icon releted_tgrid.zip 340.69 kb, 18 downloads since 2017-05-01 

Re: How to restrict creation of sub entry ?

Another example for you.

Post's attachments

Attachment icon Grams.zip 5.8 kb, 39 downloads since 2017-05-01 

Dmitry.

Re: How to restrict creation of sub entry ?

@Dmitry thanks for new example

Re: How to restrict creation of sub entry ?

Hello @derek thanks for help I was testing your given example with some twist just added one extra button to "edit" and save the record but what happened was the condition restrict me from saving it was not new record i was just editing old record value was not higher even with same value it stopped me to edit an save record help please 

derek wrote:

Hi Kim,
There are a number of ways of doing it - the attachment is just a suggestion.
I use a 'false save' button which checks the total weights for a commodity;  only if the total is less than or equal to the permitted, does it 'click' the 'real save' button.  If the total weights are more than permitted, it displays an error.
I've added a 'current running total' so that when the user enters form3, he sees what it is.
Also, note that the combobox on form3 now shows not only the commodity, but also it's permitted weight - it just gives the user a bit more info'.
Sorry it's not very 'polished' but I'm pushed for time at the moment.
Hope this helps.
Derek.

Re: How to restrict creation of sub entry ?

Hello @Dmitry I was testing derek's example and yours too both have similar issue when I edit record and try to save with similar or slight new value it stops me from saving, even i think that condition was just for new record and it was not for edit button .
thanks for help.

DriveSoft wrote:

Another example for you.

12 (edited by derek 2017-05-17 23:14:32)

Re: How to restrict creation of sub entry ?

Hello Kim,
If I understand correctly and your condition is only valid for a new record, then you could try the following test in your script:
procedure xxxxxxxx
begin
   if action = 'NewRecord' then
      begin..........
         etc etc
     end;
end;
However, the test for 'newrecord' is usually associated with the formxxxx on_show procedure so if you are using the same form for new records and for editing records, you might need to amend this.
Derek.

Re: How to restrict creation of sub entry ?

kim143 wrote:

Hello @Dmitry I was testing derek's example and yours too both have similar issue when I edit record and try to save with similar or slight new value it stops me from saving, even i think that condition was just for new record and it was not for edit button .
thanks for help.

DriveSoft wrote:

Another example for you.


Yes, you are right, there is a bug, check it out:

procedure Form3_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    Grams: integer;
    id: integer;
begin
    id := Form3.Button1.dbGeneralTableId;
    if id=-1 then Grams := SQLExecute('SELECT TOTAL(gram) FROM subrecords WHERE id_cereal='+IntToStr(Form2.bSaveRecord.dbGeneralTableId))
    else Grams := SQLExecute('SELECT TOTAL(gram) FROM subrecords WHERE id_cereal='+IntToStr(Form2.bSaveRecord.dbGeneralTableId) +' AND id<>'+IntToStr(id));

    if (Grams+Form3.edGram.Value) > Form2.edGrams.Value then
    begin
        ShowMessage('Underweight.'+#13#13+'Allowed: '+Form2.edGrams.Text + #13+'In the moment: ' + IntToStr(Grams));
        Cancel := True;
    end;
end;
Dmitry.

Re: How to restrict creation of sub entry ?

DriveSoft wrote:
kim143 wrote:

Hello @Dmitry I was testing derek's example and yours too both have similar issue when I edit record and try to save with similar or slight new value it stops me from saving, even i think that condition was just for new record and it was not for edit button .
thanks for help.

DriveSoft wrote:

Another example for you.


Yes, you are right, there is a bug, check it out:

procedure Form3_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    Grams: integer;
    id: integer;
begin
    id := Form3.Button1.dbGeneralTableId;
    if id=-1 then Grams := SQLExecute('SELECT TOTAL(gram) FROM subrecords WHERE id_cereal='+IntToStr(Form2.bSaveRecord.dbGeneralTableId))
    else Grams := SQLExecute('SELECT TOTAL(gram) FROM subrecords WHERE id_cereal='+IntToStr(Form2.bSaveRecord.dbGeneralTableId) +' AND id<>'+IntToStr(id));

    if (Grams+Form3.edGram.Value) > Form2.edGrams.Value then
    begin
        ShowMessage('Underweight.'+#13#13+'Allowed: '+Form2.edGrams.Text + #13+'In the moment: ' + IntToStr(Grams));
        Cancel := True;
    end;
end;

thank you  @Dmitry