using DevExpress.XtraEditors;
|
|
namespace Yw.WinFrmUI
|
{
|
public partial class HydroWorkingMgrDlg : DevExpress.XtraBars.Ribbon.RibbonForm
|
{
|
public HydroWorkingMgrDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.gridView1.SetNormalEditView();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
this.repositoryItemButtonEdit1.ButtonClick += RepositoryItemButtonEdit1_ButtonClick;
|
}
|
|
/// <summary>
|
/// 重载数据事件
|
/// </summary>
|
public event Action<Dictionary<HydroWorkingVmo, bool>> ReloadDataEvent;
|
|
/// <summary>
|
/// 更新数据事件
|
/// </summary>
|
public event Action<HydroWorkingVmo> UpdateDataEvent;
|
|
/// <summary>
|
/// 应用数据事件
|
/// </summary>
|
public event Action<HydroWorkingVmo> ApplyDataEvent;
|
|
/// <summary>
|
/// 删除数据事件
|
/// </summary>
|
public event Action<HydroWorkingVmo> DeleteDataEvent;
|
|
private BindingList<HydroWorkingMgrViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定列表
|
/// </summary>
|
public void SetBindingData(Dictionary<HydroWorkingVmo, bool> dict)
|
{
|
_allBindingList = new BindingList<HydroWorkingMgrViewModel>();
|
if (dict != null && dict.Count > 0)
|
{
|
foreach (var item in dict)
|
{
|
var vm = new HydroWorkingMgrViewModel(item.Key, item.Value);
|
_allBindingList.Add(vm);
|
}
|
}
|
this.hydroWorkingMgrViewModelBindingSource.DataSource = _allBindingList;
|
this.hydroWorkingMgrViewModelBindingSource.ResetBindings(false);
|
}
|
|
//获取当前视图
|
private HydroWorkingMgrViewModel 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 void Edit()
|
{
|
var vm = GetCurrentViewModel();
|
if (vm == null)
|
{
|
return;
|
}
|
var dlg = new EditHydroWorkingDlg();
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
vm.Reset(rhs);
|
this.UpdateDataEvent?.Invoke(vm.Vmo);
|
this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle);
|
TipFormHelper.ShowSucceed("更新成功");
|
};
|
dlg.SetBindingData(vm.Vmo);
|
dlg.ShowDialog();
|
}
|
|
//应用
|
private void Apply()
|
{
|
var vm = GetCurrentViewModel();
|
if (vm == null)
|
{
|
return;
|
}
|
this.ApplyDataEvent?.Invoke(vm.Vmo);
|
TipFormHelper.ShowSucceed("应用成功");
|
}
|
|
//删除
|
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<Yw.BLL.HydroWorking>.Instance.DeleteByID(vm.ID);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("删除失败!");
|
return;
|
}
|
_allBindingList.Remove(vm);
|
this.DeleteDataEvent?.Invoke(vm.Vmo);
|
this.hydroWorkingMgrViewModelBindingSource.ResetBindings(false);
|
TipFormHelper.ShowSucceed("删除成功!");
|
}
|
|
//确定
|
private void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (_allBindingList == null)
|
{
|
TipFormHelper.ShowError("数据初始化失败!");
|
return;
|
}
|
var dict = new Dictionary<HydroWorkingVmo, bool>();
|
foreach (var item in _allBindingList)
|
{
|
dict.Add(item.Vmo, item.HasChecked);
|
}
|
this.ReloadDataEvent?.Invoke(dict);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
//操作点击
|
private void RepositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
{
|
var tag = e.Button.Tag?.ToString();
|
switch (tag)
|
{
|
case "edit": Edit(); break;
|
case "apply": Apply(); break;
|
case "delete": Delete(); break;
|
default: break;
|
}
|
}
|
|
|
}
|
}
|