| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.Utils.Design; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraTreeList; |
| | | using HStation.Vmo; |
| | | using System.ComponentModel; |
| | | using Yw; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | |
| | | InitializeComponent(); |
| | | this.treeList1.InitialDefaultSettings(); |
| | | this.layoutControl1.SetupLayoutControl(); |
| | | this.barBtnAdd.ItemClick += BarBtnAdd_ItemClick; |
| | | this.barBtnEdit.ItemClick += BarBtnEdit_ItemClick; |
| | | this.barBtnDelete.ItemClick += BarBtnDelete_ItemClick; |
| | | this.barBtnInfo.ItemClick += BarBtnInfo_ItemClick; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 聚焦改变事件 |
| | | /// </summary> |
| | | public event Action<SimpleTreeViewModel> FocusedChangedEvent; |
| | | public event Action<AssetsCoolingSeriesVmo> FocusedChangedEvent; |
| | | |
| | | /// <summary> |
| | | /// 所有绑定列表 |
| | | /// </summary> |
| | | private List<SimpleTreeViewModel> _allBindingList = null; |
| | | private List<AssetsCoolingSeriesMgrViewModel> _allBindingList = null; |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// 初始化数据 |
| | | /// </summary> |
| | | public void SetBindingData(List<SimpleTreeViewModel> allList) |
| | | public async void InitialData() |
| | | { |
| | | _allBindingList = new List<SimpleTreeViewModel>(); |
| | | var overlay = this.ShowOverlay(); |
| | | var allList = await BLLFactory<HStation.BLL.AssetsCoolingSeries>.Instance.GetAll(); |
| | | _allBindingList = new List<AssetsCoolingSeriesMgrViewModel>(); |
| | | allList?.ForEach(x => |
| | | { |
| | | _allBindingList.Add(x); |
| | | var vm = new AssetsCoolingSeriesMgrViewModel(x); |
| | | _allBindingList.Add(vm); |
| | | }); |
| | | this.treeList1.DataSource = _allBindingList; |
| | | this.treeList1.ForceInitialize(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 全部展开 |
| | | /// </summary> |
| | | public void ExpandAll() |
| | | { |
| | | this.treeList1.ExpandAll(); |
| | | overlay.Close(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 全部折叠 |
| | | /// </summary> |
| | | public void CollapseAll() |
| | | { |
| | | this.treeList1.CollapseAll(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示树线 |
| | | /// </summary> |
| | | public bool ShowTreeLines |
| | | { |
| | | get { return this.barCkTreeLine.Checked; } |
| | | set { this.barCkTreeLine.Checked = value; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示搜索框 |
| | | /// </summary> |
| | | public void ShowSearchControl() |
| | | { |
| | | this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭搜索框 |
| | | /// </summary> |
| | | public void CloseSearchControl() |
| | | { |
| | | this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 选择图片列表 |
| | | /// </summary> |
| | | [DefaultValue(null)] |
| | | [TypeConverter(typeof(ImageCollectionImagesConverter))] |
| | | public object SelectImageList |
| | | { |
| | | get |
| | | { |
| | | return this.treeList1.SelectImageList; |
| | | } |
| | | set |
| | | { |
| | | this.treeList1.SelectImageList = value; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 工具条可见性 |
| | | /// </summary> |
| | | public bool ToolBarVisible |
| | | { |
| | | get { return this.bar1.Visible; } |
| | | set { this.bar1.Visible = value; } |
| | | } |
| | | |
| | | |
| | | //全部展开 |
| | | private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | |
| | | //聚焦节点改变 |
| | | private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetDataRecordByNode(e.Node) as SimpleTreeViewModel; |
| | | this.FocusedChangedEvent?.Invoke(vm); |
| | | var vm = this.treeList1.GetDataRecordByNode(e.Node) as AssetsCoolingSeriesMgrViewModel; |
| | | this.FocusedChangedEvent?.Invoke(vm.Vmo); |
| | | } |
| | | |
| | | //拖拽排序 |
| | | private void barCkDrag_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | //刷新 |
| | | private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | InitialData(); |
| | | } |
| | | |
| | | //右键菜单 |
| | | private void treeList1_MouseClick(object sender, MouseEventArgs e) |
| | | { |
| | | if (e.Button != MouseButtons.Right) |
| | | { |
| | | return; |
| | | } |
| | | _calcHitInfo = this.treeList1.CalcHitInfo(e.Location); |
| | | this.popupMenu1.ShowPopup(MousePosition); |
| | | } |
| | | private TreeListHitInfo _calcHitInfo = null; |
| | | |
| | | //右键菜单弹出前验证 |
| | | private void popupMenu1_BeforePopup(object sender, CancelEventArgs e) |
| | | { |
| | | if (_calcHitInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | if (_calcHitInfo.InRow) |
| | | { |
| | | this.barBtnAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; |
| | | this.barBtnEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; |
| | | this.barBtnDelete.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; |
| | | this.barBtnInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; |
| | | } |
| | | else |
| | | { |
| | | this.barBtnAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; |
| | | this.barBtnEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; |
| | | this.barBtnDelete.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; |
| | | this.barBtnInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; |
| | | } |
| | | } |
| | | |
| | | //获取当前 |
| | | private AssetsCoolingSeriesMgrViewModel GetCurrentViewModel() |
| | | { |
| | | if (_allBindingList == null) |
| | | { |
| | | TipFormHelper.ShowError("数据初始化错误!"); |
| | | return null; |
| | | } |
| | | if (_allBindingList.Count < 1) |
| | | { |
| | | TipFormHelper.ShowInfo("无数据!"); |
| | | return null; |
| | | } |
| | | var vm = this.treeList1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | { |
| | | TipFormHelper.ShowWarn("请选择数据行!"); |
| | | return null; |
| | | } |
| | | return vm; |
| | | } |
| | | |
| | | //添加 |
| | | private void Add() |
| | | { |
| | | if (_allBindingList == null) |
| | | { |
| | | TipFormHelper.ShowError("数据初始化失败!"); |
| | | return; |
| | | } |
| | | if (_calcHitInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | long parentId = 0; |
| | | if (_calcHitInfo.InRow) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_allBindingList); |
| | | if (vm != null) |
| | | { |
| | | parentId = vm.ID; |
| | | } |
| | | } |
| | | var dlg = new AddAssetsCoolingSeriesDlg(); |
| | | dlg.ReloadDataEvent += (rhs) => |
| | | { |
| | | var vm = new AssetsCoolingSeriesMgrViewModel(rhs); |
| | | _allBindingList.Add(vm); |
| | | this.treeList1.RefreshDataSource(); |
| | | TipFormHelper.ShowSucceed("添加成功!"); |
| | | }; |
| | | dlg.SetBindingData(parentId); |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //编辑 |
| | | private void Edit() |
| | | { |
| | | var vm = GetCurrentViewModel(); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var dlg = new EditAssetsCoolingSeriesDlg(); |
| | | dlg.ReloadDataEvent += (rhs) => |
| | | { |
| | | vm.Reset(rhs); |
| | | this.treeList1.RefreshNode(this.treeList1.FocusedNode); |
| | | TipFormHelper.ShowSucceed("更新成功"); |
| | | }; |
| | | dlg.SetBindingData(vm.Vmo); |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //删除 |
| | | private async void Delete() |
| | | { |
| | | var vm = GetCurrentViewModel(); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var result = XtraMessageBox.Show("请问确认删除当前数据吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes; |
| | | if (!result) |
| | | { |
| | | return; |
| | | } |
| | | var bol = await BLLFactory<HStation.BLL.AssetsCoolingSeries>.Instance.DeleteByID(vm.ID); |
| | | if (!bol) |
| | | { |
| | | TipFormHelper.ShowError("删除失败!"); |
| | | return; |
| | | } |
| | | _allBindingList.Remove(vm); |
| | | this.treeList1.RefreshDataSource(); |
| | | TipFormHelper.ShowSucceed("删除成功!"); |
| | | } |
| | | |
| | | //查看 |
| | | private void View() |
| | | { |
| | | var vm = GetCurrentViewModel(); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var dlg = new ViewAssetsCoolingSeriesDlg(); |
| | | dlg.SetBindingData(vm.Vmo); |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //添加 |
| | | private void BarBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | Add(); |
| | | } |
| | | |
| | | //编辑 |
| | | private void BarBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | Edit(); |
| | | } |
| | | |
| | | //详细信息 |
| | | private void BarBtnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | View(); |
| | | } |
| | | |
| | | //删除 |
| | | private void BarBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | Delete(); |
| | | } |
| | | |
| | | |
| | | } |