Format Data on a Screen in a LightSwitch Application


Introduction

LightSwitch is a Microsoft application which is used for create business application. Using this article one can easily validate business application data.

Format Data on a screen in LightSwitch Application

Step 1. First of all we created a table in LightSwitch application.

image1.gif

Step 2. Run the application.

image2.gif

Step 3. Double click one customer and write an email without domain (which shows an error.) likes below image.

image3.gif

Step 4. Change the  length of state (no error)->cut->ok.

image4.gif

Step 5. Come back to the customer page like below image.

image5.gif

Step 6. Now go to phone properties->change maximum length(255 replace by 25)-> then go to email properties set default domain (gmail.com) ->then go to postal code properties change maximum length(255 replace by 10)-> then go to state properties change maximum length(255 replace by 2) and click custom validation (.cs page will be open) then write coding.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
   
public partial class Customer
    {
       
partial void State_Validate(EntityValidationResultsBuilder results)
        {
           
// results.AddPropertyError("<Error-Message>");
            if (!string.IsNullOrEmpty(this.State))
            {
               
this.State = this.State.ToUpper();
            }
        }
    }
}

Code Description: This code converts the lowercase letter in to uppercase letter of state name.

Step 7. Add a new property gender->then go to properties of gender ->then click choice list and add value and display name ->ok  likes below image.

image6.gif

Step 8. Go to computed property->add name (Full Name)->properties->click edit method then write code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class Customer
    {
            partial void FullName_Compute(ref string result)
        {
            // Set result to the desired field value
            result = this.LastName + " " + this.FirstName;
        }
    }
}

Code Description: This code print the full name of customer. 

Step 9. Save->go to customer property->choose summary property->full name looks likes below image.

image7.gif 

Step 10. Run the  application->open the first customer ->shows full name likes blow image.

image8.gif

Step 11. Click design screen and add Full Name like the below image.

image9.gif

Step 12. Go to Last Name properties->uncheck show as a link->Go to Full Name properties->check show as a link->save->open any customer->change status (maximum length will be 2) and postal code (maximum length will be 10)->design screen->yes (likes below image).

imqge10.gif

Step 13. Add gender in the customer->save likes below image.

image11.gif

Step 14. Now we can choose Male or Female from gender likes below image.

image12.gif

Step 15. Save. Now we can write an email without domain name then there will be no error.

If we write state name which length is more than 2, then there will be an error like in the below image.

image13.gif

If we write postal code which length is more  than 10, then there will be an error like below.

image14.gif

Summary

So this article is very useful for data format on a screen in LightSwitch application.


Similar Articles