duheng
2025-03-28 b266e82b9a377fa35a766f7a3a2f5aa95f3c9125
WinFrmUI/PBS.WinFrmUI/01-place/PlaceMgrPage.cs
@@ -1,5 +1,7 @@
using DevExpress.Utils.DragDrop;
using DevExpress.DataProcessing.InMemoryDataProcessor;
using DevExpress.Utils.DragDrop;
using DevExpress.XtraEditors;
using HStation.WinFrmUI;
using Yw;
using Yw.WinFrmUI;
@@ -11,6 +13,7 @@
        {
            InitializeComponent();
            this.gridView1.SetNormalView(30);
            behaviorManager1.Detach<DragDropBehavior>(gridView1);
        }
        private List<PlaceViewModel> _allBindingList;
@@ -30,27 +33,35 @@
            {
                foreach (var item in allList)
                {
                    _allBindingList.Add(new PlaceViewModel(item));
                    var mapInfo = await BLLFactory<Yw.BLL.MapInfo>.Instance
                        .Get(PBS.DataType.PBSPlace, item.ID, Yw.Map.Kind.Gaodei, Yw.Map.Purpose.Location);
                    _allBindingList.Add(new PlaceViewModel(item, mapInfo));
                }
            }
            this.placeViewModelBindingSource.DataSource = _allBindingList;
            this.placeViewModelBindingSource.ResetBindings(false);
            var allRegion = await new Yw.BLL.Division().GetAll();
            this.repositoryItemTreeListLookUpEdit1.DataSource = allRegion;
        }
        //新增小区
        private void btnAddBuilding_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddPlaceDlg();
            dlg.SetBindingData(HStation.PBS.ePlaceType.Build);
            dlg.ReloadDataEvent += async (Vmo) =>
            dlg.SetBindingData(PBS.ePlaceType.Build);
            dlg.ReloadDataEvent += async (vmo, mapInfo) =>
            {
                var id = await _placeBll.Insert(Vmo);
                var id = await _placeBll.Insert(vmo);
                if (id > 0)
                {
                    Vmo.ID = id;
                    _allBindingList.Add(new PlaceViewModel(Vmo));
                    vmo.ID = id;
                    mapInfo.ObjectID = id;
                    var mapId= await new Yw.BLL.MapInfo().Insert(mapInfo);
                    mapInfo.ID = mapId;
                    _allBindingList.Add(new PlaceViewModel(vmo, mapInfo));
                    this.placeViewModelBindingSource.ResetBindings(false);
                    return true;
                     return true;
                }
                return false;
            };
@@ -61,15 +72,18 @@
        private void btnAddschool_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddPlaceDlg();
            dlg.SetBindingData(HStation.PBS.ePlaceType.School);
            dlg.ReloadDataEvent += async (Vmo) =>
            dlg.SetBindingData(PBS.ePlaceType.School);
            dlg.ReloadDataEvent += async (Vmo, mapInfo) =>
            {
                var id = await _placeBll.Insert(Vmo);
                if (id > 0)
                {
                    Vmo.ID = id;
                    _allBindingList.Add(new PlaceViewModel(Vmo));
                    _allBindingList.Add(new PlaceViewModel(Vmo, mapInfo));
                    this.placeViewModelBindingSource.ResetBindings(false);
                    mapInfo.ObjectID = id;
                    await new Yw.BLL.MapInfo().Insert(mapInfo);
                    return true;
                }
                return false;
@@ -81,15 +95,18 @@
        private void btnAddHospital_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddPlaceDlg();
            dlg.SetBindingData(HStation.PBS.ePlaceType.Hospital);
            dlg.ReloadDataEvent += async (Vmo) =>
            dlg.SetBindingData(PBS.ePlaceType.Hospital);
            dlg.ReloadDataEvent += async (Vmo, mapInfo) =>
            {
                var id = await _placeBll.Insert(Vmo);
                if (id > 0)
                {
                    Vmo.ID = id;
                    _allBindingList.Add(new PlaceViewModel(Vmo));
                    _allBindingList.Add(new PlaceViewModel(Vmo, mapInfo));
                    this.placeViewModelBindingSource.ResetBindings(false);
                    mapInfo.ObjectID = id;
                    await new Yw.BLL.MapInfo().Insert(mapInfo);
                    return true;
                }
                return false;
@@ -101,14 +118,49 @@
        private void btnAddShop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddPlaceDlg();
            dlg.SetBindingData(HStation.PBS.ePlaceType.Shop);
            dlg.ReloadDataEvent += async (Vmo) =>
            dlg.SetBindingData(PBS.ePlaceType.Shop);
            dlg.ReloadDataEvent += async (Vmo, mapInfo) =>
            {
                var id = await _placeBll.Insert(Vmo);
                if (id > 0)
                {
                    Vmo.ID = id;
                    _allBindingList.Add(new PlaceViewModel(Vmo));
                    _allBindingList.Add(new PlaceViewModel(Vmo, mapInfo));
                    this.placeViewModelBindingSource.ResetBindings(false);
                    mapInfo.ObjectID = id;
                    await new Yw.BLL.MapInfo().Insert(mapInfo);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
        //修改
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                TipFormHelper.ShowWarn("请选择数据行");
            }
            var dlg = new EditPlaceDlg();
            dlg.SetBindingData(vm.Vmo, vm.MapInfo);
            dlg.ReloadDataEvent += async (vmo, map) =>
            {
                var bol = await _placeBll.Update(vmo);
                if (bol)
                {
                    if (map.ID > 0)
                    {
                        await new Yw.BLL.MapInfo().Update(map);
                    }
                    else
                    {
                        await new Yw.BLL.MapInfo().Insert(map);
                    }
                    vm.Resert(vmo, map);
                    this.placeViewModelBindingSource.ResetBindings(false);
                    return true;
                }
@@ -129,6 +181,14 @@
            if (!result)
            {
                return;
            }
            if (vm.MapInfo != null)
            {
                if (!await BLLFactory<Yw.BLL.MapInfo>.Instance.DeleteByObjectTypeAndObjectID(PBS.DataType.PBSPlace, vm.ID))
                {
                    TipFormHelper.ShowError("项目地图位置删除失败,请重试!");
                    return;
                }
            }
            var bol = await _placeBll.DeleteByID(vm.ID);
            if (!bol)
@@ -155,14 +215,14 @@
        private void barCkDrag_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SetDragEnable(this.barCkDrag.Checked);
        }
        //设置拖拽可用性
        private void SetDragEnable(bool allowArag)
        {
            var be = this.behaviorManager1.GetBehavior<DevExpress.Utils.DragDrop.DragDropBehavior>(this.gridView1);
            be.Properties.AllowDrag = allowArag;
            if (barCkDrag.Checked)
            {
                behaviorManager1.Attach<DragDropBehavior>(this.gridView1);
            }
            else
            {
                behaviorManager1.Detach<DragDropBehavior>(gridView1);
            }
        }
        private async void dragDropEvents1_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e)
@@ -343,5 +403,28 @@
            this.placeViewModelBindingSource.ResetBindings(false);
            this.gridView1.FocusedRowHandle = nextHandle;
        }
        private void barBtnUpdateUseStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                return;
            }
            var dlg = new SetUseStatusDlg();
            dlg.SetBindingData((Yw.Model.eUseStatus)vm.UseStatus);
            dlg.ReloadDataEvent += async (status) =>
            {
                var bol = await BLLFactory<PBS.BLL.Place>.Instance.UpdateUseStatus(vm.ID, status);
                if (bol)
                {
                    vm.UseStatus = (Yw.Vmo.eUseStatus)(int)status;
                    this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
    }
}