| | |
| | | using Yw.WinFrmUI; |
| | | using DevExpress.Utils.DragDrop; |
| | | using DevExpress.XtraEditors; |
| | | using Yw; |
| | | using Yw.WinFrmUI; |
| | | |
| | | namespace HStation.WinFrmUI.PBS |
| | | namespace PBS.WinFrmUI |
| | | { |
| | | public partial class PlaceMgrPage : DocumentPage |
| | | { |
| | | public PlaceMgrPage() |
| | | { |
| | | InitializeComponent(); |
| | | this.gridView1.SetNormalView(30); |
| | | } |
| | | |
| | | private List<PlaceViewModel> _allBindingList; |
| | | |
| | | private BLL.Place _placeBll = new(); |
| | | |
| | | public override void InitialDataSource() |
| | | { |
| | | SetBindingData(); |
| | | } |
| | | |
| | | private async void SetBindingData() |
| | | { |
| | | _allBindingList = new List<PlaceViewModel>(); |
| | | var allList = await _placeBll.GetAll(); |
| | | if (allList != null) |
| | | { |
| | | foreach (var item in allList) |
| | | { |
| | | _allBindingList.Add(new PlaceViewModel(item)); |
| | | } |
| | | } |
| | | this.placeViewModelBindingSource.DataSource = _allBindingList; |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | } |
| | | |
| | | //新增小区 |
| | | private void btnAddBuilding_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var dlg = new AddPlaceDlg(); |
| | | dlg.SetBindingData(HStation.PBS.ePlaceType.Build); |
| | | dlg.ReloadDataEvent += async (Vmo) => |
| | | { |
| | | var id = await _placeBll.Insert(Vmo); |
| | | if (id > 0) |
| | | { |
| | | Vmo.ID = id; |
| | | _allBindingList.Add(new PlaceViewModel(Vmo)); |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | return true; |
| | | } |
| | | return false; |
| | | }; |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //新增学校 |
| | | private void btnAddschool_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var dlg = new AddPlaceDlg(); |
| | | dlg.SetBindingData(HStation.PBS.ePlaceType.School); |
| | | dlg.ReloadDataEvent += async (Vmo) => |
| | | { |
| | | var id = await _placeBll.Insert(Vmo); |
| | | if (id > 0) |
| | | { |
| | | Vmo.ID = id; |
| | | _allBindingList.Add(new PlaceViewModel(Vmo)); |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | return true; |
| | | } |
| | | return false; |
| | | }; |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //新增医院 |
| | | private void btnAddHospital_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var dlg = new AddPlaceDlg(); |
| | | dlg.SetBindingData(HStation.PBS.ePlaceType.Hospital); |
| | | dlg.ReloadDataEvent += async (Vmo) => |
| | | { |
| | | var id = await _placeBll.Insert(Vmo); |
| | | if (id > 0) |
| | | { |
| | | Vmo.ID = id; |
| | | _allBindingList.Add(new PlaceViewModel(Vmo)); |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | return true; |
| | | } |
| | | return false; |
| | | }; |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //新增商铺 |
| | | private void btnAddShop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var dlg = new AddPlaceDlg(); |
| | | dlg.SetBindingData(HStation.PBS.ePlaceType.Shop); |
| | | dlg.ReloadDataEvent += async (Vmo) => |
| | | { |
| | | var id = await _placeBll.Insert(Vmo); |
| | | if (id > 0) |
| | | { |
| | | Vmo.ID = id; |
| | | _allBindingList.Add(new PlaceViewModel(Vmo)); |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | return true; |
| | | } |
| | | return false; |
| | | }; |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //删除 |
| | | private async void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var vm = this.gridView1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var result = XtraMessageBox.Show("请问确认删除当前数据吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes; |
| | | if (!result) |
| | | { |
| | | return; |
| | | } |
| | | var bol = await _placeBll.DeleteByID(vm.ID); |
| | | if (!bol) |
| | | { |
| | | TipFormHelper.ShowError("删除失败!"); |
| | | return; |
| | | } |
| | | _allBindingList.Remove(vm); |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | TipFormHelper.ShowSucceed("删除成功!"); |
| | | } |
| | | |
| | | //刷新 |
| | | private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | SetBindingData(); |
| | | } |
| | | |
| | | //查询 |
| | | private void barCekSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | this.gridView1.OptionsFind.AlwaysVisible = !this.gridView1.OptionsFind.AlwaysVisible; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | private async void dragDropEvents1_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e) |
| | | { |
| | | var indexs = e.Data as int[]; |
| | | if (indexs == null || indexs.Length < 1) |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | var sourceIndex = indexs[0]; |
| | | var sourceObj = this.gridView1.GetRow(sourceIndex) as PlaceViewModel; |
| | | if (sourceObj == null) |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | |
| | | var destIndex = this.gridView1.GetRowHandleByCP(e.Location); |
| | | if (destIndex < 0) |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | |
| | | var destObj = this.gridView1.GetRow(destIndex) as PlaceViewModel; |
| | | if (destObj == null) |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | |
| | | var sorters = new List<Yw.Vmo.Sorter>(); |
| | | |
| | | if (e.InsertType == InsertType.Before) |
| | | { |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = sourceObj.ID, SortCode = destObj.SortCode }); |
| | | _allBindingList.ForEach(x => |
| | | { |
| | | if (x.SortCode >= destObj.SortCode) |
| | | { |
| | | if (x != sourceObj) |
| | | { |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = x.ID, SortCode = x.SortCode + 1 }); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | else if (e.InsertType == InsertType.After) |
| | | { |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = sourceObj.ID, SortCode = destObj.SortCode + 1 }); |
| | | _allBindingList.ForEach(x => |
| | | { |
| | | if (x.SortCode > destObj.SortCode) |
| | | { |
| | | if (x != sourceObj) |
| | | { |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = x.ID, SortCode = x.SortCode + 1 }); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | |
| | | var bol = await _placeBll.UpdateSorter(sorters); |
| | | if (!bol) |
| | | { |
| | | e.Handled = true; |
| | | return; |
| | | } |
| | | |
| | | _allBindingList.ForEach(x => |
| | | { |
| | | var sorter = sorters.Find(t => t.ID == x.ID); |
| | | if (sorter != null) |
| | | { |
| | | x.SortCode = sorter.SortCode; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | Up(); |
| | | } |
| | | |
| | | //上移 |
| | | private async void Up() |
| | | { |
| | | var vm = this.gridView1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var rowHandle = this.gridView1.FocusedRowHandle; |
| | | if (rowHandle == 0) |
| | | { |
| | | TipFormHelper.ShowWarn("上移失败!"); |
| | | return; |
| | | } |
| | | var current = this.gridView1.GetRow(rowHandle) as PlaceViewModel; |
| | | if (current == null) |
| | | { |
| | | return; |
| | | } |
| | | var prevHandle = rowHandle - 1; |
| | | var prev = this.gridView1.GetRow(prevHandle) as PlaceViewModel; |
| | | if (prev == null) |
| | | { |
| | | return; |
| | | } |
| | | var sorters = new List<Yw.Vmo.Sorter>(); |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = current.ID, SortCode = prev.SortCode }); |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = prev.ID, SortCode = current.SortCode }); |
| | | var bol = await _placeBll.UpdateSorter(sorters); |
| | | if (!bol) |
| | | { |
| | | TipFormHelper.ShowError("上移失败!"); |
| | | return; |
| | | } |
| | | var sortCode = current.SortCode; |
| | | current.SortCode = prev.SortCode; |
| | | prev.SortCode = sortCode; |
| | | _allBindingList = _allBindingList.OrderBy(x => x.SortCode).ToList(); |
| | | this.placeViewModelBindingSource.DataSource = _allBindingList; |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | this.gridView1.FocusedRowHandle = prevHandle; |
| | | } |
| | | |
| | | private void barBtnDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | Down(); |
| | | } |
| | | |
| | | //下移 |
| | | private async void Down() |
| | | { |
| | | var vm = this.gridView1.GetCurrentViewModel(_allBindingList); |
| | | if (vm == null) |
| | | { |
| | | return; |
| | | } |
| | | var rowHandle = this.gridView1.FocusedRowHandle; |
| | | if (rowHandle == _allBindingList.Count - 1) |
| | | { |
| | | TipFormHelper.ShowWarn("下移失败!"); |
| | | return; |
| | | } |
| | | var current = this.gridView1.GetRow(rowHandle) as PlaceViewModel; |
| | | if (current == null) |
| | | { |
| | | return; |
| | | } |
| | | var nextHandle = rowHandle + 1; |
| | | var next = this.gridView1.GetRow(nextHandle) as PlaceViewModel; |
| | | if (next == null) |
| | | { |
| | | return; |
| | | } |
| | | var sorters = new List<Yw.Vmo.Sorter>(); |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = current.ID, SortCode = next.SortCode }); |
| | | sorters.Add(new Yw.Vmo.Sorter() { ID = next.ID, SortCode = current.SortCode }); |
| | | var bol = await _placeBll.UpdateSorter(sorters); |
| | | if (!bol) |
| | | { |
| | | TipFormHelper.ShowError("下移失败!"); |
| | | return; |
| | | } |
| | | var sortCode = current.SortCode; |
| | | current.SortCode = next.SortCode; |
| | | next.SortCode = sortCode; |
| | | _allBindingList = _allBindingList.OrderBy(x => x.SortCode).ToList(); |
| | | this.placeViewModelBindingSource.DataSource = _allBindingList; |
| | | this.placeViewModelBindingSource.ResetBindings(false); |
| | | this.gridView1.FocusedRowHandle = nextHandle; |
| | | } |
| | | } |
| | | } |
| | | } |