Topic: Conditional coloring of label and panel

I was trying to color label and panel depending on combobox content on same form with the following but couldn't get the script constructed correctly:

procedure Form1_OnShow (Sender: string; Action: string);  // for combo def index 0 which is Sale. However, combo doesn't show it somehow?
begin
  begin
   if Form1.cbSaleInvDBCR.text = 'Sale' then
      begin
      Form1.Label1.Caption := 'Sales Invoice'.color := clWhite;                            
      Form1.Panel1.color :=  clBlue;
      end
end;

procedure Form1_cbSaleInvDBCR_OnChange (Sender: string);
begin
   if Form1.cbSaleInvDBCR.text = 'Sale' then
      begin
      Form1.Label1.Caption := 'Sales Invoice'.color := clWhite;
      Form1.Panel1.color :=  clBlue;
      end else
      begin
      Form1.Label1.Caption := 'Sales Credit Note'.color := clWhite
      Form1.Panel.color :=  clRed;
      end;
end;

Combo has two items in total.
Sale
Refund.
First empty item set to false
Default index set to zero


If needed please see the sample project attached:

Post's attachments

Attachment icon Label and Panel.zip 4.15 kb, 379 downloads since 2017-05-05 

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

Re: Conditional coloring of label and panel

Adam, First your DbCr table was empty (No sale and No Refund). I added them manually. Second, you tried to set the label caption and the color all in one statement. You can't really do that, so I separated them out for you.  See the attached for the fix.


Also, I'm assuming you realize that in this particular project, that your Save button will always add a new SaleInv record.

Post's attachments

Attachment icon Label and Panel_Fixed.zip 581.41 kb, 410 downloads since 2017-05-05 

Re: Conditional coloring of label and panel

Hi EHW,


Thank you very much for the fix......... truly appreciated........

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

Re: Conditional coloring of label and panel

I'm still playing with Derek's approach on refunds. It was all fine until I start testing inv report/print. I realized that it's not practical to have sale and return items on same invoice when printing; as sale and refunds usually happens at different times. If already sale invoice issued/sent later on adding refund items to same invoice and issuing it again would be incorrect. Granted, one can issue sale and refund inv headers and items separately but this would require extra attention on user part so that user doesn't add refund items to sale inv header etc.


In order to avoid all those inconveniences, I thought moving sale or refund (DbCr) combo to sale invoice header and referencing combo value on sale inv items so that user can only add sale inv items to sale inv header and vice versa. With additional coloring (Thanks to EHW) to highlight it's whether sale or refund + hiding refund reason combo and it's label if it's a sale on sale inv items form.


In attached sample project I have tried to apply coloring and getting sale/ refund (DbCr) value on sale inv item form in order to apply same coloring + show / hide refund reason combo and it's label but failed again?


EHW, I used onAfterClick for coloring on form1 add and edit buttons beside combo on change events. Thinking it'd be used with add and edit actions beside combo change on inv header. When existing record displayed with edit action it'd keep the original status (coloring) whether it's a sale or refund.

Post's attachments

Attachment icon Label and Panel 2.zip 18.76 kb, 380 downloads since 2017-05-06 

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

Re: Conditional coloring of label and panel

Project fixed. Since sales items belong to sales invoices and credit items belong to credit invoices, you no longer need the dbcr field in the sales items table. I removed it. I think you were getting confused with the timing of the "onAfterClick" event. From a parent form you were trying to manipulate properties on a subsequent form after the subsequent form was completed. Changing properties are typically (not always) done during the onShow event and OnChange events for an open form. Anyway, see if the attached project takes care of what you were trying to do.

Post's attachments

Attachment icon Label and Panel 2 Fixed.zip 596.92 kb, 564 downloads since 2017-05-06 

Re: Conditional coloring of label and panel

Hi EHW,


Thank you very much for the fix and the info......................
There are some great stuff for me to learn and use in future projects... truly appreciated............


Your fixed sample project runs perfectly. No problem on there.
However, my work project not when I remove dbcr field from the sales items table I get an error.
https://s30.postimg.org/3vmi30f35/zzzzz_Temp29.png
I checked tgMainCustomersTrans grid, even taken out additional columns to make it same as the test project but no luck. When I put back dbcr field to sales items table it works without error but causes invoice items table refresh failure on browsing customers.

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

Re: Conditional coloring of label and panel

In the fixed project I had to change your calculated fields in the SaleInv table. Change the cfSales calculated field to

select sum(saleinvitem.totalamt) 
from   saleinvitem 
where  saleinvitem.id_saleinv = saleinv.id
and    saleinv.id_dbcr = '1'

And change the cfRefunds to

select sum(saleinvitem.totalamt) 
from   saleinvitem 
where  saleinvitem.id_saleinv = saleinv.id
and    saleinv.id_dbcr = '2'

Re: Conditional coloring of label and panel

Thanks a lot for the quick info EHW..........


I noticed an issue on adding inv item. It would come up with not null error since id_customer was marked as required.  I checked off nut null. However, this time saved invoice item is not displayed tgMainCustomersTransItems tGrid.


Also, I'm not clear how to get customer details (address) on sale inv form as combo changed to label. I couldn't see onChange event for labels.


Once again I'm grateful for your kind help.........

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

Re: Conditional coloring of label and panel

Sorry Adam. Rushed through the solution I guess. Try attached.

Post's attachments

Attachment icon Label and Panel 3.zip 597.49 kb, 399 downloads since 2017-05-07 

10 (edited by AD1408 2017-05-07 11:10:04)

Re: Conditional coloring of label and panel

Great Stuff EHW.......................
Thank you very much.......................


What was the issue with adding and showing records on inv items? Your sample project works perfectly but with my work project I couldn't solve showing records correctly on inv items tGrid.


edit:
I think I sorted it out. I forgot to include combobox1 on inv items save.

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

11 (edited by AD1408 2017-05-08 13:51:41)

Re: Conditional coloring of label and panel

I tried to hide refund reason column [0] on tgMainCustomersTransItems, when column [1] cell value is 'Sale' on tgMainCustomersTrans with the script below but couldn't get it right:


procedure Form1_tgMainCustomersTrans_OnChange (Sender: string);
begin
if Form1.tgMainCustomersTrans.Cells[1,Form1.tgMainCustomersTrans.SelectedRow] = 'Sale' then
   begin
     Form1.tgMainCustomersTransItems.Columns[0].Visible := False;
   end;
end;

Another issue I have no idea how to solve. tGrid tax column contains + and - values. How can I pick only minus values from the tGrid tax column cells and show the total on edit field? Kind of creating virtual tGrid tax footer column without changing the current structure of the tGrid.

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

Re: Conditional coloring of label and panel

See attached for hiding column. I'm not sure I understand your tax issue though.

Post's attachments

Attachment icon Label and Panel 3_HideCol.zip 598.31 kb, 395 downloads since 2017-05-08 

Re: Conditional coloring of label and panel

Hi EHW,


Great Stuff!!!
Thank you very much................................


...I'm not sure I understand your tax issue though.

I was trying to display inv tax amounts on inv tGrid on a different form with some calcs. On inv tGrid credit (refund) tax amounts displayed with minus (-125) and sale ones normal (125). I wanted to display them in inv  register form to have a clearer picture about sales and refund with some calcs as there are discounts and deliv charges. Then I noticed that I need to add, sub etc some minus values from plus ones ((150 + (-125)) etc. and realized that I was making things difficult for myself. So I decided to take out all those minus items to simplify things in such a way that I could perhaps make something out of it.. Working on it currently.........

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

14 (edited by AD1408 2017-05-09 14:42:51)

Re: Conditional coloring of label and panel

I wanted to color all rows text to red on tgMainCustomersTransItems,  if  tgMainCustomersTrans column[1] contained 'Refund' as follow:

procedure tgCustInvItemChange2; // ********* Coloring refund Inv Items rows
var
   iRow1 ,c2: integer;
   q1, iCol1: integer;
begin
     c2 := Form1.tgMainCustomersTransItems.RowCount - 1;
     q1 := Form1.tgMainCustomersTransItems.Columns.Count-1;
     for iRow1 := 0 to c2 do
        if Form1.tgMainCustomersTrans.Cells[1,iRow1] = 'Refund' then
            for iCol1 := 0 to q1 do Form1.tgMainCustomersTransItems.Cell[iCol1,iRow1].textColor := clRed;
end;

but it didn't work? Tried to add Form1.btnCustTransItemSearch.click; to above which caused app crash on run.


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


Also tried to get tGrid focused on newly added record row with the following but didn't work too:

procedure frmSalesInv_Button1_OnAfterClick (Sender: string);
begin
      Form1.tgMainCustomersTrans.dbItemID:= Last_Insert_id;
      Form1_tgMainCustomersTrans_OnCellClick('',0,0);
end;
Adam
God... please help me become the person my dog thinks I am.

Re: Conditional coloring of label and panel

Here you go Adam.

Post's attachments

Attachment icon Label and Panel Grid_ColorRefunds.zip 600.18 kb, 455 downloads since 2017-05-09 

Re: Conditional coloring of label and panel

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

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