net7/trunk/Net7Tools/CommonTools/Database/CodeValue.cs
2014-05-11 16:54:16 -04:00

78 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// TODO: Have ItemEditor's CodeValue.cs reuse this code
namespace CommonTools.Database
{
/// <summary>
/// <para>Store a code/id and a value/description such that the code/id
/// is easily retrievable and the value/description is displayed
/// in a control such as a combobox</para>
/// </summary>
public class CodeValue
{
public Int32 code;
public String value;
public CodeValue()
{
code = 0;
value = "";
}
public CodeValue(Int32 code)
{
this.code = code;
this.value = "";
}
public CodeValue(Int32 code, String value)
{
this.code = code;
this.value = value;
}
public static CodeValue Formatted(int code, String value)
{
String formattedValue = value
+ " ("
+ code.ToString()
+ ")";
return new CodeValue(code, formattedValue);
}
public static CodeValue FormattedLeft(int code, String value)
{
String formattedValue = "("
+ code.ToString()
+ ") "
+ value;
return new CodeValue(code, formattedValue);
}
/// <summary>
/// <para>Text displayed within controls such as comboboxes</para>
/// </summary>
public override string ToString()
{
return value;
}
/// <summary>
/// <para>Equality is based only on the value/id rather than the entire class</para>
/// </summary>
public override bool Equals(object obj)
{
if (obj.GetType() != typeof(CodeValue))
return false;
return code.Equals(((CodeValue)obj).code);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}