1 (edited by AD1408 2017-06-11 22:27:51)

Topic: Changing Combobox Value

Using one form and table with grid filters and combo value moving record from one grid to another.
Kind of converting purchase inv to sale inv.


Please see the image below for reference:
https://s15.postimg.org/usl1kmt63/zzzzz_Temp38.png


Used "Convert Selected Item to Sale Inv" button with showRecord action as I need the purchase inv data on frmInvoice.
Used Inv Type combobox on frmInvoice as tGrid filters uses combobox values for displaying the record on relevant tGrid on form1. Inv Type combobox is disabled so that user cannot choose a wrong value.


I need Inv Type combobox displays Sale text instead of Purchase if button "Convert Selected Item to Sale Inv" clicked, in order to move the item to sale invs tGrid on save.
I tried in code various things I could think of but unfortunately couldn't get it working.


Please see the attached sample project below:

Post's attachments

Attachment icon Changing Combobox Value.zip 7.35 kb, 398 downloads since 2017-06-12 

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

Re: Changing Combobox Value

You were very close Adam. Since the convert button does a ShowRecord action, then your script for the frmInvoice OnShow should check for "ShowRecord" instead of "NewRecord". I commented your line and put in the fixed line. Technically, the "ShowRecord" check does not need to be in the "If" statement because the Form1button for "Add Sale" already implies a ShowRecord, but it does not hurt to have it there.

Post's attachments

Attachment icon Changing Combobox Value Fixed.zip 584.02 kb, 418 downloads since 2017-06-12 

3 (edited by AD1408 2017-06-12 11:07:11)

Re: Changing Combobox Value

Hi EHW,


Thank you very much............... Truly appreciated........................


I have tried showRecord but getting on click of "Edit" button on purch inv tGrid to combobox displaying Purchase and on click of  "Convert Selected Item to Sale Inv" displayed Sale was the issue. Same issue exist.
Issue is visible after clicking on "Convert Selected Item to Sale Inv" then clicking on "Edit" button which combobox shows Sale instead of Purchase.


I'm thinking that the code below should work but end else bit is not working. I cannot see what I have missed or done incorrectly?

procedure frmInvoice_OnShow (Sender: string; Action: string);
begin
if frmInvoice.edInvProduct.Text = '' then
   begin
   frmInvoice.btnInvSave.Enabled := False;
   end else
   frmInvoice.btnInvSave.Enabled := True;
end;
Adam
God... please help me become the person my dog thinks I am.

Re: Changing Combobox Value

The Form1Button variable needs to be cleared before leaving frmInvoice.


procedure frmInvoice_OnClose (Sender: string; Action: string);
begin
    Form1Button := '';
end;

Re: Changing Combobox Value

Thank very much EHW.............................

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

Re: Changing Combobox Value

I realized that populating combobox via DB is not a good idea. When DB is deleted combo items will be deleted too.


I decided to populate combo (Inv Type) within script. However, I couldn't get combo values displayed on tGrid and as a result tGrid filters stop working too ?


Please see the attached sample project below:

Post's attachments

Attachment icon Changing Combobox Value 2.zip 8.68 kb, 379 downloads since 2017-06-15 

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

Re: Changing Combobox Value

The fix is attached. You were off on the itemindex by 1. It starts with 0. However, in your case you do not need to check itemindex. Also, when changing the value in the combobox, the text value needs to be loaded into the edDBCR text field in order to save the field value in the record. One observation, I would recommend removing the "[Select an Invoice Type]' item in the combobox list. You pretty much control what goes into the combobox when adding a new record. If a user selects that first value and saves the record, the record will disappear from the tablegrids because of the filters.

Post's attachments

Attachment icon Changing Combobox Value 2 Fixed.zip 585.18 kb, 407 downloads since 2017-06-15 

Re: Changing Combobox Value

Hi EHW,


Thank you very much..............
Truly appreciated....................

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

Re: Changing Combobox Value

Hi EHW,


I'm about to loosing  face for asking you this many questions. I hope I'm not testing your patience.
I have added your working refunds code with appropriate changes (as I could think of) to this sample project but I'm embraced to say that I couldn't make it work.


Please see attached sample project:

Post's attachments

Attachment icon Changing Combobox Value 3.zip 12.69 kb, 369 downloads since 2017-06-17 

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

Re: Changing Combobox Value

Sorry Adam. I was unavailable last week and did not have an opportunity to check the forum. Don't ever think you are bothering me. I don't mind at all helping people. I'm not always available, but if I can. I will help. I think I fixed your project. One thing to note on this particular project. You really do not need the "type" combobox since you are populating the exact value through script and disabling it on the form. And since it is not a user selected combobox field, you could just display the text field (which is hidden right now). I would remove the combobox and unhide, but disable, the text box for "type" and move it into it's place on the form.

Post's attachments

Attachment icon Changing Combobox Value 3 Fixed.zip 590.27 kb, 395 downloads since 2017-06-26 

Re: Changing Combobox Value

Hi EHW,


I'm truly grateful for your kind help and understanding.....................................
Thank you very much.................................

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

Re: Changing Combobox Value

You really do not need the "type" combobox since you are populating the exact value through script and disabling it on the form. And since it is not a user selected combobox field, you could just display the text field (which is hidden right now). I would remove the combobox and unhide, but disable, the text box for "type" and move it into it's place on the form.

Good point. Thanks. I think it's done.


I have tried to apply counters by script (thanks to Dmitry) in order to have multiple counters on same table with unique numbers that keeps their own count without a jump in count.


However, I couldn't resolve two issues:
1. After converting a purchase inv to sale inv, purch inv counter doesn't set the purch counter's last used count number. For instance, when a purch inv with number PI-1 to converted to sale inv, adding next purchase inv produces PI-3 number instead of PI-2. Additionally, product field becomes disabled. On re-run of of the app prod field becomes enabled as it should. I couldn't find a way to release of sale conditions after converting purch inv to sale inv.


2. I couldn't adopt the refund script to new counters.


Please see the attached sample project below:

Post's attachments

Attachment icon Changing Combobox Value 4 New Counters.zip 14.81 kb, 375 downloads since 2017-06-27 

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

Re: Changing Combobox Value

Adam, I think I have your issues resolved in the attached. The reason your Purchase Invoice counter looked like it skipped a number was because in converting it to a Sale Invoice the purchase Invoice counter still existed.  So the Max() function retrieved the Sale record with the existing Purchase counter. It actually worked as it is suppose to, but not what you intended. It needs to be cleared and that is what I put in the script. I wasn't sure if you intended to insert a new record for a sale or just change the type in the record. Your Refund insert did not work because not all fields values were defined in the statement. Since your counters can be null depending on the type, I also had to modify your Select Max() statement or it would always create an Invoice number of 1 because of the null values embedded in the table for other records types.


I'm not sure I agree with your approach with this particular project. There is a lot of redundant data in the database, especially with all the prefixes stored in every record. It is a very inefficient use of database storage. You would be better served either hard coding them in the script or creating another table with the definitions. Having said that, I do realize you are testing a lot of different scenarios with your overall project, so I won't question the design in this particular project.

Post's attachments

Attachment icon Changing Combobox Value 4 New Counters Fixed.zip 592.25 kb, 377 downloads since 2017-06-27 

14 (edited by AD1408 2017-06-28 08:44:39)

Re: Changing Combobox Value

Hi EHW,


Thank you very much....................
Truly appreciated..........................
and extra thanks for the explanations.............


I wasn't sure if you intended to insert a new record for a sale or just change the type in the record.

In this part of the project intention was changing type to sale with it's own sale inv prefix and number. I think this part is working as intended thanks to your help.


I'm not sure I agree with your approach with this particular project. There is a lot of redundant data in the database, especially with all the prefixes stored in every record.

Which fields are redundant other than prefix fields?
I have tried hard coding them in script but failed.
I have tried adding new table "InvPrefix" with text fields "SI, Cr, PI, Db" and linked Invoice table to InvPrefix table but failed on this approach too.

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

Re: Changing Combobox Value

I updated the project and removed the hard-coded prefixes in the table. I updated the calc fields to prefix the counters for the grids. Actually there is no need to enter prefix in the script. In the invoice form I simply put in the prefix as a label. I'm not sure what the advantage is in having a prefix at all since you identify the transaction with the "Type" field anyway. I assume it's the visual effect knowing what the transaction is when looking at the grid entries.


As far as other redundant data, the purchase info and product info is redundant. You could separate them out into separate tables, much like you have done in your other projects. However, I do recognize that maybe in this particular project it may not be appropriate since once you make the sale then the purchase invoice essentially goes away so actually the data is really not redundant. Just wasn't sure how this project fits in with your overall bigger project.

Post's attachments

Attachment icon Changing Combobox Value 4 New Counters Revised.zip 592.07 kb, 494 downloads since 2017-06-28 

Re: Changing Combobox Value

Hi EHW,


Agreed, using labels instead of fields in this case is definitely a better approach.
Thank you very much.................
Truly appreciated....................


I'm not sure what the advantage is in having a prefix at all since you identify the transaction with the "Type" field anyway. I assume it's the visual effect knowing what the transaction is when looking at the grid entries.

Indeed.

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