|
using System;
using System.Drawing;
using System.ComponentModel;
namespace EditableListboxApp.Infrastructure
{
public enum WeebitType
{
Standard = 1,
Custom = 2
}
public class WeebitData : IDataErrorInfo
{
enum ValidationProperties
{
Name,
Description,
Length,
Width,
Height
}
#region properties
public string Name
{
set;
get;
}
public string Description
{
set;
get;
}
public string Length
{
set;
get;
}
public string Width
{
set;
get;
}
public string Height
{
set;
get;
}
public Color WeebitColor
{
get;
set;
}
public WeebitType WeebitType
{
set;
get;
}
#endregion
public bool IsValid()
{
bool returnVal = true;
foreach (string property in Enum.GetNames(typeof(ValidationProperties)))
if (GetValidationError(property) != null)
{
returnVal = false;
break;
}
return returnVal;
}
#region IDataErrorInfo
string IDataErrorInfo.Error { get { return null; } }
string IDataErrorInfo.this[string propertyName]
{
get { return this.GetValidationError(propertyName); }
}
#endregion
#region validations
string GetValidationError(string propertyName)
{
string error = null;
switch (propertyName)
{
case "Name":
error = this.ValidateName();
break;
case "Description":
error = this.ValidateDescription();
break;
case "Length":
error = this.ValidateFloat(this.Length,"Length");
break;
case "Width":
error = this.ValidateFloat(this.Width,"Width");
break;
case "Height":
error = this.ValidateFloat(this.Height,"Height");
break;
}
return error;
}
string ValidateName()
{
if (String.IsNullOrEmpty(this.Name))
{
return "Enter Name";
}
return null;
}
string ValidateDescription()
{
if (String.IsNullOrEmpty(this.Description))
{
return "Enter Description";
}
return null;
}
string ValidateFloat(string value, string item)
{
if (String.IsNullOrEmpty(value))
{
return "Enter "+item;
}
try
{
float temp = float.Parse(value);
return null;
}
catch
{
return "Invalid entry.";
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.