locked
if field value is equal to then execute code, else do nothing RRS feed

  • Question

  • Hi!

    I am a novice in using Lightswitch and i have a problem wit writing a simple querry... If i would have to do it in php it would be simple, but here i dont know how to get field value and compare it...

    I am making simple invoicing system and i found this piece of code which does exactly what i need:

    partial void Invoices_Inserting(Invoice entity)
            {
    
                    {
                        // Get highest invoice number from invoices pending insertion.
                        Invoice highestInvoice = this.DataWorkspace.ApplicationData.Details.GetChanges().AddedEntities
                            .OfType<Invoice>()
                            .Where(invoice => null != invoice.Number)
                            .OrderByDescending(invoice => invoice.Number)
                            .FirstOrDefault();
    
                        // If one pending insertion has not gotten an invoice number yet, get the highest invoice number from the data source.
                        if (null == highestInvoice)
                        {
                            highestInvoice = this.DataWorkspace.ApplicationData.Invoices
                                .OrderByDescending(invoice => invoice.Number)
                                .FirstOrDefault();
                        }
    
                        // Now set the next invoice number for the invoice
                        if (null == highestInvoice)
                        {
                            entity.Number = 1; // First invoice
                        }
                        else
                        {
                            entity.Number = highestInvoice.Number.Value + 1;
                        }
                    }
            }

    Now, I have three options for saving the item. It can be saved as Quotation, Proforma and Invoice. If item is saved as quotation or proforma it shouldnt set the invoice number. So i know that i have to write statement something like if(InvoiceType == "2") ("2" is value from dropdown representing Invoice) than run the code that generates invoice number else do nothing.

    Thank you all for your help!

    Dario

    Monday, October 21, 2013 6:23 PM

Answers

  • Wrap your entire code in:

    if (entity.InvoiceType == "2")
    {
        // Insert your ID generation code here
    }


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by DarioOs81 Tuesday, October 22, 2013 7:33 AM
    Tuesday, October 22, 2013 3:56 AM
    Moderator

All replies

  • Wrap your entire code in:

    if (entity.InvoiceType == "2")
    {
        // Insert your ID generation code here
    }


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by DarioOs81 Tuesday, October 22, 2013 7:33 AM
    Tuesday, October 22, 2013 3:56 AM
    Moderator
  • Thanks a million! I knew it was easy as that, just didnt see the woods because of the tree :)) Thanks!
    Tuesday, October 22, 2013 7:34 AM