old_flsystem/应用/AutoAnswer/Controls/CategoryControl.cs

69 lines
1.9 KiB
C#

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UI.Framework.Entitys;
using static AutoAnswer.Controls.Enums;
namespace AutoAnswer.Controls
{
public class Enums
{
/// <summary>
/// 工作日枚举
/// </summary>
public enum WorkdayType
{
= 1,
= 2,
= 3,
= 4,
= 5,
= 6,
= 0,
}
}
class CategoryControl : PropertyGridEditStyle
{
public CategoryControl()
{
var listBox = new CheckedListBoxControl();
foreach (WorkdayType item in Enum.GetValues(typeof(WorkdayType)))
{
listBox.Items.Add(new CheckedListBoxItem(null, item.ToString()));
}
Control = listBox;
}
public override string GetValue()
{
var listBox = Control as CheckedListBoxControl;
string[] strs = new string[listBox.CheckedItems.Count];
int i = 0;
foreach (var item in listBox.CheckedItems)
{
strs[i] = item.ToString();
i++;
}
return string.Join(",", strs);
}
public override void SetValue(object value)
{
var listBox = Control as CheckedListBoxControl;
var strs = value.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
int i = 0;
foreach (var item in listBox.Items)
{
listBox.SetItemChecked(i, !string.IsNullOrEmpty(strs.FirstOrDefault(f => f == item.ToString())));
i++;
}
}
}
}