using DevExpress.Utils.DragDrop;
|
using DevExpress.XtraEditors;
|
using Yw;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class AssetsCoolingFactorMgrPage : DocumentPage
|
{
|
public AssetsCoolingFactorMgrPage()
|
{
|
InitializeComponent();
|
this.gridView1.SetLimitView(30);
|
this.PageTitle.Caption = "冷却塔系数";
|
this.PageTitle.HeaderSvgImage = this.svgImg32[0];
|
this.PageTitle.SvgImageSize = new Size(24, 24);
|
}
|
|
//数据绑定列表
|
private List<AssetsCoolingFactorMgrViewModel> _allBindingList = null;
|
|
/// <summary>
|
/// 初始化数据源
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
base.InitialDataSource();
|
InitialData();
|
}
|
|
//初始化数据
|
private async void InitialData()
|
{
|
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();
|
SetDragEnable(this.barCkDrag.Checked);
|
}
|
|
/// <summary>
|
/// 刷新数据
|
/// </summary>
|
public override void RefreshData()
|
{
|
base.RefreshData();
|
InitialData();
|
}
|
|
//添加
|
private void Add()
|
{
|
if (_allBindingList == null)
|
{
|
TipFormHelper.ShowError("数据初始化失败!");
|
return;
|
}
|
var dlg = new AddAssetsCoolingFactorDlg();
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new AssetsCoolingFactorMgrViewModel(rhs);
|
_allBindingList.Add(vm);
|
this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
|
TipFormHelper.ShowSucceed("添加成功!");
|
};
|
dlg.SetBindingData();
|
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();
|
}
|
|
//删除
|
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("删除成功!");
|
}
|
|
//查看
|
private void View()
|
{
|
var vm = GetCurrentViewModel();
|
if (vm == null)
|
{
|
return;
|
}
|
var dlg = new ViewAssetsCoolingFactorDlg();
|
dlg.SetBindingData(vm.Vmo);
|
dlg.ShowDialog();
|
}
|
|
//上移
|
private async void Up()
|
{
|
var vm = GetCurrentViewModel();
|
if (vm == null)
|
{
|
return;
|
}
|
var rowHandle = this.gridView1.FocusedRowHandle;
|
if (rowHandle == 0)
|
{
|
TipFormHelper.ShowWarn("上移失败!");
|
return;
|
}
|
var current = this.gridView1.GetRow(rowHandle) as AssetsCoolingFactorMgrViewModel;
|
if (current == null)
|
{
|
return;
|
}
|
var prevHandle = rowHandle - 1;
|
var prev = this.gridView1.GetRow(prevHandle) as AssetsCoolingFactorMgrViewModel;
|
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 BLLFactory<HStation.BLL.AssetsCoolingFactor>.Instance.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.assetsCoolingFactorMgrViewModelBindingSource.DataSource = _allBindingList;
|
this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
|
this.gridView1.FocusedRowHandle = prevHandle;
|
}
|
|
//下移
|
private async void Down()
|
{
|
var vm = GetCurrentViewModel();
|
if (vm == null)
|
{
|
return;
|
}
|
var rowHandle = this.gridView1.FocusedRowHandle;
|
if (rowHandle == _allBindingList.Count - 1)
|
{
|
TipFormHelper.ShowWarn("下移失败!");
|
return;
|
}
|
var current = this.gridView1.GetRow(rowHandle) as AssetsCoolingFactorMgrViewModel;
|
if (current == null)
|
{
|
return;
|
}
|
var nextHandle = rowHandle + 1;
|
var next = this.gridView1.GetRow(nextHandle) as AssetsCoolingFactorMgrViewModel;
|
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 BLLFactory<HStation.BLL.AssetsCoolingFactor>.Instance.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.assetsCoolingFactorMgrViewModelBindingSource.DataSource = _allBindingList;
|
this.assetsCoolingFactorMgrViewModelBindingSource.ResetBindings(false);
|
this.gridView1.FocusedRowHandle = nextHandle;
|
}
|
|
|
#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;
|
}
|
|
#endregion
|
|
#region Ribbon
|
|
//添加
|
private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Add();
|
}
|
|
//编辑
|
private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Edit();
|
}
|
|
//删除
|
private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Delete();
|
}
|
|
//详细信息
|
private void barBtnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
View();
|
}
|
|
//上移
|
private void barBtnUp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Up();
|
}
|
|
//下移
|
private void barBtnDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Down();
|
}
|
|
//查询
|
private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.gridView1.OptionsFind.AlwaysVisible = !this.gridView1.OptionsFind.AlwaysVisible;
|
}
|
|
//刷新
|
private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.RefreshData();
|
}
|
|
#endregion
|
|
#region GridView
|
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (e.Column == this.colDetail)
|
{
|
View();
|
}
|
}
|
#endregion
|
|
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 AssetsCoolingFactorMgrViewModel;
|
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 AssetsCoolingFactorMgrViewModel;
|
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 bll = BLLFactory<HStation.BLL.AssetsCoolingFactor>.Instance;
|
var bol = await bll.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 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;
|
}
|
|
}
|
}
|