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 { /// /// 工作日枚举 /// 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++; } } } }