bad coding practice (FA Team)
ComboBox 패턴
[ bad coding ]
public partial class ComboBoxEx : ComboBox
{
public ComboBoxEx()
{
DisplayMember = "DisplayEx";
ValueMember = "ValueEx";
this.ForeColor = Color.Black;
}
public ComboBoxEx(ComboBoxExItems items)
{
this.DisplayMember = "DisplayEx";
this.ValueMember = "ValueEx";
this.DataSource = items.getItems();
}
public void setDataSource(ComboBoxExItems items)
{
this.DataSource = items.getItems();
}
public void findSelectKey(string _key)
{
foreach (ComboBoxExItem cbitem in this.Items)
{
if (cbitem.DisplayEx.Contains(_key))
{
this.SelectedItem = cbitem;
break;
}
}
}
public bool findSelectValue(string _value)
{
foreach (ComboBoxExItem cbitem in this.Items)
{
if (cbitem.ValueEx == _value)
{
this.SelectedItem = cbitem;
return true;
}
}
return false;
}
public string GetKey()
{
if (this.SelectedItem != null)
return ((ComboBoxExItem)this.SelectedItem).DisplayEx;
return null;
}
public string GetValue()
{
if (this.SelectedItem != null)
return ((ComboBoxExItem)this.SelectedItem).ValueEx;
return null;
}
}
public class ComboBoxExItems
{
List<ComboBoxExItem> items = new List<ComboBoxExItem>();
public void Add(ComboBoxExItem item)
{
items.Add(item);
}
public void Clear()
{
items.Clear();
}
public List<ComboBoxExItem> getItems()
{
return items;
}
}
public class ComboBoxExItem
{
public string DisplayEx { get; set; }
public string ValueEx { get; set; }
}[ good coding ]
#A01 - ComboBox의 Item으로 사용할 자료형 정의
#A02 - Items 초기화
#A03 - ComboBox에서 Item 찾기
#A04 - ComboBox에서 선택된 Item을 캐스팅하여 특정 멤버 참조
#B01 - Form.ShowDialog / 팝업을 통한 값 세팅
[ bad coding ]
[ good coding ]
#C01 - Timer
[ bad coding ]
#D01 - 프로그램이 실행중인지 판단하여 중복 실행 제어
etc.
Last updated