lixiaojun
2024-12-13 c4049242a1cc73da8210f381db72d1a807bd08d4
WinFrmUI/HStation.WinFrmUI.Assets.Core/22-cooling/02-main/AssetsCoolingMainMgrPage.cs
@@ -32,6 +32,7 @@
                return;
            }
            _series = series;
            InitialData();
        }
        /// <summary>
@@ -46,24 +47,24 @@
        //初始化数据
        private async void InitialData()
        {
            //if (_series == null)
            //{
            //    return;
            //}
            //var overlay = this.ShowOverlay();
            //var allBindingList = await BLLFactory<HStation.BLL.AssetsCoolingFactor>.Instance.GetAll();
            //_allBindingList = new List<AssetsCoolingFactorMgrViewModel>();
            //if (allBindingList != null && allBindingList.Count > 0)
            //{
            //    foreach (var item in allBindingList)
            //    {
            //        var vm = new AssetsCoolingFactorMgrViewModel(item);
            //        _allBindingList.Add(vm);
            //    }
            //}
            //this.assetsCoolingFactorMgrViewModelBindingSource.DataSource = _allBindingList;
            //this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
            //overlay.Close();
            if (_series == null)
            {
                return;
            }
            var overlay = this.ShowOverlay();
            var allBindingList = await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.GetBySeriesID(_series.ID);
            _allBindingList = new List<AssetsCoolingMainMgrViewModel>();
            if (allBindingList != null && allBindingList.Count > 0)
            {
                foreach (var item in allBindingList)
                {
                    var vm = new AssetsCoolingMainMgrViewModel(item);
                    _allBindingList.Add(vm);
                }
            }
            this.assetsCoolingMainMgrViewModelBindingSource.DataSource = _allBindingList;
            this.assetsCoolingMainMgrViewModelBindingSource.ResetBindings(false);
            overlay.Close();
        }
        /// <summary>
@@ -78,77 +79,81 @@
        //添加
        private void Add()
        {
            //if (_allBindingList == null)
            //{
            //    TipFormHelper.ShowError("数据初始化失败!");
            //    return;
            //}
            //var dlg = new AddAssetsCoolingMainDlg();
            //dlg.ReloadDataEvent += (rhs) =>
            //{
            //    var vm = new AssetsCoolingMainMgrViewModel(rhs);
            //    _allBindingList.Add(vm);
            //    this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
            //    TipFormHelper.ShowSucceed("添加成功!");
            //};
            //dlg.SetBindingData();
            //dlg.ShowDialog();
            if (_series == null)
            {
                return;
            }
            if (_allBindingList == null)
            {
                TipFormHelper.ShowError("数据初始化失败!");
                return;
            }
            var dlg = new AddAssetsCoolingMainDlg();
            dlg.ReloadDataEvent += (rhs) =>
            {
                var vm = new AssetsCoolingMainMgrViewModel(rhs);
                _allBindingList.Add(vm);
                this.assetsCoolingMainMgrViewModelBindingSource.ResetBindings(false);
                TipFormHelper.ShowSucceed("添加成功!");
            };
            dlg.SetBindingData(_series);
            dlg.ShowDialog();
        }
        //编辑
        private void Edit()
        {
            //var vm = GetCurrentViewModel();
            //if (vm == null)
            //{
            //    return;
            //}
            //var dlg = new EditAssetsCoolingFactorDlg();
            //dlg.ReloadDataEvent += (rhs) =>
            //{
            //    vm.Reset(rhs);
            //    this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle);
            //    TipFormHelper.ShowSucceed("更新成功");
            //};
            //dlg.SetBindingData(vm.Vmo);
            //dlg.ShowDialog();
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var dlg = new EditAssetsCoolingMainDlg();
            dlg.ReloadDataEvent += (rhs) =>
            {
                vm.Reset(rhs);
                this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle);
                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.AssetsCoolingFactor>.Instance.DeleteByID(vm.ID);
            //if (!bol)
            //{
            //    TipFormHelper.ShowError("删除失败!");
            //    return;
            //}
            //_allBindingList.Remove(vm);
            //this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
            //TipFormHelper.ShowSucceed("删除成功!");
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var result = XtraMessageBox.Show("请问确认删除当前数据吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes;
            if (!result)
            {
                return;
            }
            var bol = await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.DeleteByID(vm.ID);
            if (!bol)
            {
                TipFormHelper.ShowError("删除失败!");
                return;
            }
            _allBindingList.Remove(vm);
            this.assetsCoolingMainMgrViewModelBindingSource.ResetBindings(false);
            TipFormHelper.ShowSucceed("删除成功!");
        }
        //查看
        private void View()
        {
            //var vm = GetCurrentViewModel();
            //if (vm == null)
            //{
            //    return;
            //}
            //var dlg = new ViewAssetsCoolingFactorDlg();
            //dlg.SetBindingData(vm.Vmo);
            //dlg.ShowDialog();
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var dlg = new ViewAssetsCoolingMainDlg();
            dlg.SetBindingData(vm.Vmo);
            dlg.ShowDialog();
        }
        //上移
@@ -167,27 +172,27 @@
        #region 当前
        ////获取当前
        //private AssetsCoolingFactorMgrViewModel GetCurrentViewModel()
        //{
        //    if (_allBindingList == null)
        //    {
        //        TipFormHelper.ShowError("数据初始化错误!");
        //        return null;
        //    }
        //    if (_allBindingList.Count < 1)
        //    {
        //        TipFormHelper.ShowInfo("无数据!");
        //        return null;
        //    }
        //    var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
        //    if (vm == null)
        //    {
        //        TipFormHelper.ShowWarn("请选择数据行!");
        //        return null;
        //    }
        //    return vm;
        //}
        //获取当前
        private AssetsCoolingMainMgrViewModel GetCurrentViewModel()
        {
            if (_allBindingList == null)
            {
                TipFormHelper.ShowError("数据初始化错误!");
                return null;
            }
            if (_allBindingList.Count < 1)
            {
                TipFormHelper.ShowInfo("无数据!");
                return null;
            }
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                TipFormHelper.ShowWarn("请选择数据行!");
                return null;
            }
            return vm;
        }
        #endregion
@@ -262,5 +267,8 @@
                }
            }
        }
    }
}