| | |
| | | using DevExpress.XtraEditors.Controls; |
| | | using DevExpress.CodeParser; |
| | | using DevExpress.DataAccess.Wizard.Model; |
| | | using DevExpress.XtraEditors; |
| | | using System; |
| | | using Yw.Dto; |
| | | |
| | | namespace HStation.WinFrmUI.Basic |
| | | { |
| | | public partial class SetSysPropForCatalogDlg : Form |
| | | public partial class SetSysPropForCatalogDlg : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | public SetSysPropForCatalogDlg() |
| | | { |
| | | InitializeComponent(); |
| | | repositoryItemCheckedComboBoxEdit1.DisplayMember = "Name"; |
| | | repositoryItemCheckedComboBoxEdit1.ValueMember = "Name"; |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | } |
| | | |
| | | public class CurrentViewModel |
| | | { |
| | | public CurrentViewModel(SysPropHaveLogicalTreeDto rhs) |
| | | { |
| | | if (rhs.LogicalType == "sys-prop") |
| | | { |
| | | Name = rhs.LogicalName; |
| | | ID = rhs.LogicalID; |
| | | IsHave = rhs.Have; |
| | | } |
| | | else |
| | | { |
| | | Name = rhs.LogicalName; |
| | | ID = rhs.LogicalID; |
| | | IsHave = rhs.Have; |
| | | } |
| | | } |
| | | |
| | | public string Name { get; set; } |
| | | public long ID { get; set; } |
| | | public long ParentID { get; set; } |
| | | public bool IsHave { get; set; } |
| | | } |
| | | |
| | | private List<CurrentViewModel> _allBindingList = new List<CurrentViewModel>(); |
| | | private List<SysPropMappingViewModel> _allBindingList = new List<SysPropMappingViewModel>(); |
| | | |
| | | private Yw.BLL.SysPropMapping _bll = null; |
| | | |
| | |
| | | { |
| | | _CatlogID = ID; |
| | | _bll = new Yw.BLL.SysPropMapping(); |
| | | var PropTreeList = await _bll.GetHaveLogicalTreeList(ID); |
| | | var PropTreeList = await _bll.GetHaveListByCatalogID(ID); |
| | | foreach (var item in PropTreeList) |
| | | { |
| | | if (item.Children.Count > 0) |
| | | repositoryItemCheckedComboBoxEdit1.Items.Clear(); |
| | | var parent = new SysPropMappingViewModel(); |
| | | parent.ID = item.ID; |
| | | parent.IsGroup = true; |
| | | parent.Name = item.Name; |
| | | _allBindingList.Add(parent); |
| | | if (item.PropList.Count > 0) |
| | | { |
| | | foreach (var child in item.Children) |
| | | foreach (var child in item.PropList) |
| | | { |
| | | CheckedListBoxItem childitem = new CheckedListBoxItem(); |
| | | childitem.Value = child.LogicalID; |
| | | childitem.Description = child.LogicalName; |
| | | checkedListBoxControl1.Items.Add(childitem); |
| | | if (child.Have) |
| | | { |
| | | childitem.CheckState = CheckState.Checked; |
| | | } |
| | | var model = new SysPropMappingViewModel(); |
| | | model.GroupName = item.Name; |
| | | model.ID = child.ID; |
| | | model.ParentID = item.ID; |
| | | model.Name = child.Name; |
| | | model.IsHave = child.Have; |
| | | model.IsNull = child.IsNull; |
| | | model.DefaultValue = child.DefaultValue; |
| | | model.UnitName = child.UnitName; |
| | | model.Inherit = child.Inherit; |
| | | model.ChoiceList = child.ChoiceList; |
| | | model.ChoiceIds = child.ChoiceList.Where(x => x.Have).Select(x => x.ID).ToList(); |
| | | var stringList = child.ChoiceList.Where(x => x.Have == true).ToList().Select(x => x.Name.ToString()).ToList(); |
| | | string result = string.Join(", ", stringList); |
| | | model.DisplayChoice = result; |
| | | _allBindingList.Add(model); |
| | | } |
| | | } |
| | | } |
| | | this.sysCatalogPropViewModelBindingSource.DataSource = _allBindingList; |
| | | this.treeList1.ExpandAll(); |
| | | } |
| | | |
| | | // 完成 |
| | | private async void BtnOk_Click(object sender, EventArgs e) |
| | | { |
| | | List<long> IdList = new List<long>(); |
| | | foreach (var item in checkedListBoxControl1.CheckedItems) |
| | | var list = new List<Yw.Vmo.SysPropMappingSetterVmo>(); |
| | | foreach (var item in _allBindingList) |
| | | { |
| | | if (item is CheckedListBoxItem checkedListBoxItem) |
| | | if (item.IsHave) |
| | | { |
| | | var model = item as CheckedListBoxItem; |
| | | if (model != null) |
| | | list.Add(new Yw.Vmo.SysPropMappingSetterVmo |
| | | { |
| | | var value = model.Value; |
| | | IdList.Add(Convert.ToInt64(model.Value)); |
| | | } |
| | | PropID = item.ID, |
| | | UnitName = item.UnitName, |
| | | IsNull = item.IsNull, |
| | | DefaultValue = item.DefaultValue, |
| | | ChoiceIds = item.ChoiceIds, |
| | | }); |
| | | } |
| | | } |
| | | if (await _bll.Set(_CatlogID, IdList)) |
| | | if (await _bll.SetByCatalogID(_CatlogID, list)) |
| | | { |
| | | MessageBoxHelper.ShowSuccess("修改成功!"); |
| | | } |
| | |
| | | } |
| | | this.Close(); |
| | | } |
| | | |
| | | private void repositoryItemCheckedComboBoxEdit1_EditValueChanged(object sender, EventArgs e) |
| | | { |
| | | try |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | return; |
| | | var allselectList = repositoryItemCheckedComboBoxEdit1.GetCheckedItems(); |
| | | var strList = Convert.ToString(allselectList); |
| | | if (strList != null && strList != string.Empty) |
| | | { |
| | | if (strList.Contains(',')) |
| | | { |
| | | string[] parts = strList.Split(','); |
| | | List<long> longs = parts.Select(part => long.Parse(part.Trim())).ToList(); |
| | | |
| | | vm.ChoiceIds = longs; |
| | | } |
| | | else |
| | | { |
| | | if (long.TryParse(strList, out long Id)) |
| | | { |
| | | List<long> choiceId = new List<long>(); |
| | | choiceId.Add(Id); |
| | | vm.ChoiceIds = choiceId; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | vm.ChoiceIds = new List<long>(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | } |
| | | |
| | | private void treeList1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | if (vm.Inherit) |
| | | { |
| | | e.Cancel = true; |
| | | } |
| | | if (vm.IsGroup) |
| | | { |
| | | e.Cancel = true; |
| | | } |
| | | if (treeList1.FocusedColumn.Name == "colPropChoice") |
| | | { |
| | | repositoryItemCheckedComboBoxEdit1.Items.Clear(); |
| | | repositoryItemCheckedComboBoxEdit1.DataSource = vm.ChoiceList; |
| | | } |
| | | } |
| | | |
| | | private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e) |
| | | { |
| | | if (e.Node != null) |
| | | { |
| | | string Inherit = e.Node.GetValue("Inherit").ToString(); |
| | | string isGroup = e.Node.GetValue("IsGroup").ToString(); |
| | | if (Inherit == "True") |
| | | { |
| | | e.Appearance.BackColor = Color.DarkGray; |
| | | } |
| | | if (isGroup == "True") |
| | | { |
| | | e.Appearance.BackColor = Color.Gainsboro; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e) |
| | | { |
| | | string Inherit = e.Node.GetValue("Inherit").ToString(); |
| | | if (Inherit == "True") |
| | | { |
| | | e.State = CheckState.Checked; |
| | | } |
| | | else |
| | | { |
| | | if (e.PrevState == CheckState.Checked) |
| | | { |
| | | e.State = CheckState.Unchecked; |
| | | } |
| | | else |
| | | { |
| | | e.State = CheckState.Checked; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e) |
| | | { |
| | | SetCheckedChildNodes(e.Node, e.Node.CheckState, e); |
| | | } |
| | | |
| | | #region 设置子节点状态 |
| | | |
| | | private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check, DevExpress.XtraTreeList.NodeEventArgs e) |
| | | { |
| | | for (int i = 0; i < node.Nodes.Count; i++) |
| | | { |
| | | string Inherit = node.Nodes[i].GetValue("Inherit").ToString(); |
| | | if (Inherit == "False") |
| | | { |
| | | node.Nodes[i].CheckState = check; |
| | | SetCheckedChildNodes(node.Nodes[i], check, e); |
| | | } |
| | | else if (Inherit == "True") |
| | | { |
| | | node.Nodes[i].CheckState = CheckState.Checked; |
| | | SetCheckedChildNodes(node.Nodes[i], check, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion 设置子节点状态 |
| | | } |
| | | } |