using System; using System.Collections.Generic; using System.Linq; using System.Text; // TODO: Have ItemEditor's CodeValue.cs reuse this code namespace CommonTools.Database { /// /// 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 /// 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); } /// /// Text displayed within controls such as comboboxes /// public override string ToString() { return value; } /// /// Equality is based only on the value/id rather than the entire class /// 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(); } } }