comboitem.cs

来自「工作流引擎」· CS 代码 · 共 93 行

CS
93
字号
using System;
using System.Collections;
using System.Windows.Forms;

namespace WorkFlow.util
{
	/// <summary>
	/// ComboItem 的摘要说明。
	/// </summary>
	public class ComboItem
	{
		private string name;
		private int ivalue;
		private string strvalue = null;

		public ComboItem(string name, int ivalue)
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
			this.name=name;
			this.ivalue=ivalue;
		}
		public ComboItem(String name,string strvalue)
		{
			this.name = name;
			this.strvalue = strvalue;
		}

		public string Name
		{
			get{ return name; }
		}

		public int Value
		{
			get { return ivalue; }
		}
		public string StrValue
		{
			get { return strvalue; }
		}
		public override string ToString()
		{
			return this.name;
		}

		public static ComboItem[] HashToComboItem(Hashtable hash)
		{
			try
			{
				ComboItem[] comboItems = new ComboItem[hash.Count];
				string[] keys = new string[hash.Count];

				IEnumerator ie = hash.Keys.GetEnumerator();
				int index = 0;
				while (ie.MoveNext())
				{
					keys[index] = ie.Current.ToString();
					index++;
				}

				for (int i=0;i<keys.Length;i++)
				{
					for (int j=i+1;j<keys.Length;j++)
					{
						if (keys[i].CompareTo(keys[j]) > 0)
						{
							string tmp = keys[i];
							keys[i] = keys[j];
							keys[j] = tmp;
						}
					}
				}

				for (int i=0;i<keys.Length;i++)
				{
					int ivalue = int.Parse(keys[i]);
					string name = hash[keys[i]].ToString();
					comboItems[i] = new ComboItem(name,ivalue);
				}

				return comboItems;
			}
			catch (Exception)
			{
				return null;
			}
		}

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?