Friday, September 6, 2013

Message Grid Component


Another component that cannot miss on your toolbox is a Form where to append all messages.
When I talk about messages, I mean debug messages, user messages, error messages. This form is used, typically, on automation program or calculation and analysis application but also in many other contexts.
By the way, it is really a useful component. What it makes, it is simply said: first of all defines some methods to append a message on a list and visualize it, then allows to save all rows on a text file, a log file.



Message Class

A Message class has four main properties:
• The Type that can be an enumerative value Error, Warning or Infos
• A Code. Often is useful assign a code to each message.
• A Text: the description.
• A Count: For example if an error appears systematically, it can be useful update a counter and a date, insted to append it again. While on file the message is always saved.

MessagesCollection Class

The MessagesCollection class, manage a list of Message objects with the possibility to limit a number of these. It save every new message on a log text file.
This is a constructor declaration:

public MessagesCollection(string asFileName, int aiMaxElements)


It defines a simple method to add a message:
public void Add(EnumMessageType aoType, string asCode, string asMessage, bool abAddOnlyIfNew = true)

or to clear a list of these:
public void Clear()

public void Clear(string asCode)


MessagesGrid Control

At the end, we have a grid for a front end visualization. For the developer it is possible to access the MessagesCollection object by the property Messages, it can use the Add method as well. All other user activity can be done from the Form.


download sample

No comments :

Post a Comment