Click here to Skip to main content
15,071,729 members
Articles / Programming Languages / C#
Posted 7 Dec 2011


38 bookmarked

The Health and Safety Management System - Created with LightSwitch

Rate me:
Please Sign up or sign in to vote.
4.87/5 (19 votes)
20 Dec 2011CPOL7 min read
A LightSwitch created Health and Safety Management System

Hello all! As part of the ever growing number of LightSwitch Star contest participants, here is my submission of an example of what is possible with LightSwitch. Hope you find some useful information here, or at least get inspired to give LightSwitch a try yourself.


Health & Safety Management System

A solution created with Microsoft Visual Studio LightSwitch.

Sample Image - maximum width is 600 pixels


What does your application/extension do? What business problem does it solve?

The Health and Safety Management System is an application that is used to help organizations better manage and mitigate health and safety statistics and KPIs. The solution is designed to empower users with a tool that can be used to capture and report on finely grained health and safety performance metrics.

Workplace safety is serving an ever increasing role with many organizations. Companies are now being held accountable to, not just their own internal stakeholders such as employees and shareholders, but also other external stakeholders such as customers, vendors, and suppliers. Whether it is for internal corporate health and safety concerns, or performance metrics such as KPIs, organizations are putting more and more visibility into health and safety concerns.

Companies are now asking for health and safety accountability from their partners, often before engaging in a relationship. For example, large energy industry companies make it a prerequisite that their vendors have a health and safety program in place with proper record keeping and reporting. Often these relationships include contractual obligations which require the vendor to provide regular health and safety reporting; especially when performing work on a customer work-site.

The Health and Safety Management System has been designed to provide an organization with the means to capture and report on key health and safety metrics. The key value propositions for the Health and Safety Management System include:

  • Granular health and safety information gathering, such as:
    • Observations - capturing data that identifies health and safety threats and opportunities,
    • Near Miss Incidents - incidents that occur and do not result in an injury or time loss, and
    • Injury and Time Loss Incidents - managing details about injuries and time loss.
  • Flexible and intuitive user configurable reporting, including:
    • Several "canned" and built-in reports that can be optionally printed or exported to various formats such as Excel or PDF.
    • Powerful OLAP analytics that are highly customizable.
    • Flexible user defined querying that can optionally be saved, reloaded, printed, or exported.
  • Highly configurable, and is easily customizable for each customer.
  • Can be quickly integrated with existing organization systems; such as legacy customer or human resources ERP systems.
  • Can be deployed to either the desktop, web, or the cloud.

How many screens and entities does this application have?

Currently, the Health and Safety Management System has:

  • 19 screens that provide standard data entry interfaces as well as for various administration tasks such as lookup or reference tables, reporting and analytics, and security, and
  • 23 entities (tables)

Did LightSwitch save your business money? How?

LightSwitch provided the means to build the solution very quickly. The quality of the solution matches that of an enterprise class solution that would have taken a great deal of more time and effort to create using other, more common, technologies.

Getting to market quickly is key, as is the quality of the offering. With LightSwitch, a solution can be created using technologies and proven software development best practices. The quality of the solution is something that is automatically applied when using LightSwitch. Enabling the scenarios and requirements was easy using the template based tasks.

Would this application still be built if you didn’t have LightSwitch? If yes, with what?

The solution concept was already on-the-table well before any consideration was being made regarding the technology to use for it. Consideration was made for using one or more technologies, including; ASP.Net MVC, HTML5/JSON, SQL Server, and WCF.

Again, as mentioned earlier, LightSwitch makes for a much faster turnaround in delivery time. Using relatively traditional development technologies would result in much more time before delivering on requirements.

How many users does this application support?

As many as required. There are no known constraints to suggest that the solution could not be deployed in a large enterprise.

How long did this application take to actually build using LightSwitch?

As of the time of this writing, the solution took only a few days to build. It is estimated that the actual total hours of effort would be 18.

Does this application use any LightSwitch extensions? If so, which ones? Did you write any of these extensions yourself? If so, is it available to the public? Where?

The Health and Safety Management System uses a number of extensions and custom controls. These include:

A key success factor of the development of this solution is to utilize existing extensions and tools whenever possible. The goal was to deliver on requirements as quickly as possible. Using existing tools offered the opportunity to enable scenarios without having to "reinvent the wheel".

How did LightSwitch make your developer life better? Was it faster to build compared to other options you considered?

LightSwitch made a remarkable impact on the developer experience when using LightSwitch for this solution. The investment in effort and time was considerably less than what it would have taken using the other considered technologies.

Links, Screenshots, Videos



Home Page

The Health and Safety Management Home Page


New Observation entry

Injury and Time Loss

Injury and Time Loss


An example report


Some very flexible data mining features...


...with visualizations!

User Defined Queries

Intuitive user defined queries that can be saved and loaded for later use.


Scheduling capabilities, such as tailgate safety meetings.

As far as coding and techniques go, here are a few useful tips and tricks that you might find helpful for your own LightSwitch projects...

Images and Icons

Applying images and icons to the application added some UX appeal to the overall look and feel of the application. The process used to add images to headers of each of the screens in the application included;

  1. Create appropriately sized .png images for screen header images.
  2. Open the Solution Explorer File View.
  3. Add the images as an Embedded Resource in the Resources folder of the Client project.

    Screen Header Images

  4. Add the image control to the screen element tree. In this application, the element is a SilverLight Image control, so that the element would be borderless...

    Screen Header Images

  5. A class named MyImageHelper was created in the UserCode folder of the Client project (open Solution Explorer in File View). This was used to provide a small bit of infrastructure to use the embedded resource image files.
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.IO;
    using System.Reflection;
    using System.Windows.Media.Imaging;
    namespace LightSwitchApplication
        public class MyImageHelper
            public static byte[] GetImageByName(string fileName)
                Assembly currentAssembly = Assembly.GetExecutingAssembly();
                Stream stream = currentAssembly.GetManifestResourceStream
                ("LightSwitchApplication.Resources." + fileName);
                return GetStreamAsByteArray(stream);
            public static BitmapImage GetBitmapImageByName(string fileName)
                Assembly currentAssembly = Assembly.GetExecutingAssembly();
                Stream stream = currentAssembly.GetManifestResourceStream
                ("LightSwitchApplication.Resources." + fileName);
                return GetBitmapImage(GetStreamAsByteArray(stream));
            private static byte[] GetStreamAsByteArray(System.IO.Stream stream)
                if (stream != null)
                    int streamLength = Convert.ToInt32(stream.Length);
                    byte[] fileData = new byte[streamLength];
                    stream.Read(fileData, 0, streamLength);
                    return fileData;
                    return null;
            private static BitmapImage GetBitmapImage(byte[] bytes)
                // Create a BitmapImage from a byte[];
                using (MemoryStream ms = new MemoryStream(bytes))
                    var bi = new BitmapImage();
                    return bi;
  6. Then back in the home page screen, code was implemented to retrieve and use the image on the screen...
    partial void AllIncidents_InitializeDataWorkspace(List<idataservice> saveChangesTo)
           IContentItemProxy logo = this.FindControl("HomeHeaderLogo");
           logo.ControlAvailable += new EventHandler
    void HomeHeaderLogo_ControlAvailable(object sender, ControlAvailableEventArgs e)
           // Set image source to PNG logo.
           var img = e.Control as Image;
           if (img != null)
             img.Source = MyImageHelper.GetBitmapImageByName("HealthAndSafetyLogo.png");
       }</controlavailableeventargs> </idataservice>
  7. ...the image is applied when the application opens the screen...

    Screen Header Images

Other Techniques

A couple of other techniques applied to this solution include:

  • Intermediate, or "Dummy", screen - Observations, Near Misses, and Injury Incidents are actually each of a type of Incident entity. When clicking on the hyperlink for any of the incidents in the home page listing, logic was applied so that depending on the type of incident selected, the application would open the appropriate incident type screen.
  • One Detail Screen for Add or Edit - A single screen is used for both adding and editing entities. This is achieved by adding a parameter to the screen, usually an integer parameter representing the id of the entity. Logic on the screen would then interpret whether the application is opening the screen for a new or existing record. For example...
    partial void InjuryIncidentScreen_InitializeDataWorkspace
        (List<idataservice> saveChangesTo)
      Incident incident;
      if (!this.IncidentID.HasValue)
       incident = new Incident();
      IncidentType incidentType = (from it in DataWorkspace.ApplicationData.IncidentTypes
                                    where it.IncidentTypeName == "Injury"
                                    select it).FirstOrDefault();
       incident.IncidentType = incidentType;
       incident.HoursLost = 0;
       this.IncidentProperty = incident;
        int incidentId = (int)this.IncidentID;
        incident = (from i in DataWorkspace.ApplicationData.Incidents
                    where i.Id == incidentId
                    select i).FirstOrDefault();
                    this.IncidentProperty = incident;

Hope you all find this helpful and useful. Cheers!

Post a link to this contest entry on our Facebook wall and let people know they should rate this submission! And don’t forget to follow us on Twitter for contest updates! Good luck!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

Comments and Discussions

QuestionSource code Pin
Quaid J. Surti10-Sep-21 9:54
MemberQuaid J. Surti10-Sep-21 9:54 
QuestionWant to purchase this application Pin
Member 1492665530-Aug-20 19:26
MemberMember 1492665530-Aug-20 19:26 
AnswerRe: Want to purchase this application Pin
OriginalGriff30-Aug-20 19:39
mveOriginalGriff30-Aug-20 19:39 
GeneralMy vote of 3 Pin
rajn_mca19-Nov-12 23:23
Memberrajn_mca19-Nov-12 23:23 
QuestionCan add a video to a lightswitch screen Pin
emeka Bianue22-Aug-12 22:48
Memberemeka Bianue22-Aug-12 22:48 
GeneralMy vote of 5 Pin
ConstantineNightroad30-May-12 3:34
MemberConstantineNightroad30-May-12 3:34 
QuestionMy vote of 5 Pin
Delordson Kallon20-Dec-11 8:20
MemberDelordson Kallon20-Dec-11 8:20 
Would I be allowed to withdraw my entry for this month? This is just so good.
AnswerRe: My vote of 5 Pin
PaulSPatterson20-Dec-11 8:42
MemberPaulSPatterson20-Dec-11 8:42 
SuggestionGood article! Pin
Wonde Tadesse18-Dec-11 12:43
professionalWonde Tadesse18-Dec-11 12:43 
GeneralRe: Good article! Pin
PaulSPatterson18-Dec-11 12:49
MemberPaulSPatterson18-Dec-11 12:49 
Questionany sample code ? Pin
kiquenet.com14-Dec-11 20:19
professionalkiquenet.com14-Dec-11 20:19 
AnswerRe: any sample code ? Pin
robalexclark15-Dec-11 1:03
Memberrobalexclark15-Dec-11 1:03 
GeneralRe: any sample code ? Pin
PaulSPatterson17-Dec-11 6:36
MemberPaulSPatterson17-Dec-11 6:36 
GeneralRe: any sample code ? Pin
kiquenet.com26-Dec-11 20:25
professionalkiquenet.com26-Dec-11 20:25 
GeneralRe: any sample code ? Pin
PaulSPatterson30-Dec-11 5:54
MemberPaulSPatterson30-Dec-11 5:54 
AnswerRe: any sample code ? Pin
PaulSPatterson17-Dec-11 6:35
MemberPaulSPatterson17-Dec-11 6:35 
Questionmi voto 5 Pin
fedison7312-Dec-11 6:52
Memberfedison7312-Dec-11 6:52 
AnswerRe: mi voto 5 Pin
PaulSPatterson17-Dec-11 6:38
MemberPaulSPatterson17-Dec-11 6:38 
GeneralMy vote of 5 Pin
Doron Goldberg11-Dec-11 1:56
MemberDoron Goldberg11-Dec-11 1:56 
GeneralRe: My vote of 5 Pin
PaulSPatterson17-Dec-11 6:39
MemberPaulSPatterson17-Dec-11 6:39 
QuestionGood Job! Pin
defwebserver8-Dec-11 4:38
Memberdefwebserver8-Dec-11 4:38 
AnswerRe: Good Job! Pin
PaulSPatterson17-Dec-11 6:41
MemberPaulSPatterson17-Dec-11 6:41 
GeneralMy vote of 5 Pin
DaveAuld8-Dec-11 3:16
professionalDaveAuld8-Dec-11 3:16 
GeneralRe: My vote of 5 Pin
PaulSPatterson8-Dec-11 3:34
MemberPaulSPatterson8-Dec-11 3:34 
GeneralRe: My vote of 5 Pin
DaveAuld8-Dec-11 3:42
professionalDaveAuld8-Dec-11 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.