Link to home
Start Free TrialLog in
Avatar of TroyCrowe
TroyCroweFlag for United States of America

asked on

Better Solutions

Hey everyone,

I am looking for a better way of accomplishing my task.  My thought process today is a little out of wack and I am getting frustrated so I am searching for answers.  I have created a custom error class.  When applying an error message, for example account not created, I am passing an int value through the query string.  The problem I am dealing with is how to keep the retrieving of the message value to display in a label's text without having to use a cumbersome switch statement.  I tried assigning the values to an enum, which I do not know enough about, but I have found that not to be a good way to handle it; at least it does not seem to be.  The code below is a smaller version of what I have going on.
public class Messages
{
    public static string ItemConfigNotFound = "Items configuration section could not be found";
    public static string ItemProviderInstantiationError = "Items default provider could not be instantiated";
    public static string CategoryIdUndefined = "Category 'Id' is not defined";
    public static string CategoryTitleUndefined = "Category 'Title' is not defined";
    public static string ItemIdUndefined = "Item 'id' not defined";
 
    public static string ItemTitleUndefined = "Item 'title' not defined";
    public static string ItemTitleIsNull = "Title must be a non null, non-empty string";
    public static string ItemRequiredAttributesMissing = "Some of the required attributes of Item are NULL in the Items table";
    public static string CategoryRequiredAttributesMissing = "Some of the required attributes of Category are NULL in the Category table";
    public static string NewsConfigSectionNotFound = "News configuration section could not be found";
}
 
//Error page receives a query string with an interger value named errMsg
 
if (Request.QueryString["Message"] != "")
            {
                errMsg = Request.QueryString["Message"];
            }
 
            switch (errMsg)
            {
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    break;
}
 
//this is the problem: I have 24 error messages.  I would like to have more efficient code.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Reddgum
Reddgum

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TroyCrowe

ASKER

That sounds good.  I will check it out.  I am only a little familiar with the dictionary so implementing one will be something I will need to check out.  However, I do think you are correct.  I was trying to avoid changing something already implemented for I am appending to an existing application.
Solution is a good solution.  Thanks