using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraPrinting;
using Yw.Model;
namespace Yw.WinFrmUI
{
public partial class HydroFlowmeterListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroVisualList
{
public HydroFlowmeterListCtrl()
{
InitializeComponent();
this.layoutControl1.SetupLayoutControl();
this.gridView1.SetNormalView(30);
this.gridView1.RegistCustomDrawRowIndicator(40);
this.generalSearchAndSetCtrl1.SearchEvent += Search;
this.generalSearchAndSetCtrl1.ClearEvent += Reset;
this.generalSearchAndSetCtrl1.SetEvent += Set;
}
///
/// 水力点击事件
///
public event Action HydroClickInfoEvent;
///
/// 水力点击视图事件
///
public event Action HydroClickViewEvent;
///
/// 水力改变事件
///
public event Action> HydroChangedInfoEvent;
///
/// 水力改变视图事件
///
public event Action> HydroChangedViewEvent;
///
/// 是否拥有水力列表
///
public bool HasHydroList
{
get { return _allList != null && _allList.Count > 0; }
}
private List _allList = null;//所有列表
private List _allBindingList = null;//所有绑定列表
private HydroChangeHelper _changeHelper = null;//改变辅助类
private HydroPropStatusHelper _propStatusHelper = null;//属性状态辅助类
///
/// 绑定数据
///
public void SetBindingData
(
Yw.Model.HydroModelInfo hydroInfo,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
SetBindingData(hydroInfo, allCalcuResultVisualDict: null, changeHelper, propStatusHelper);
}
///
/// 绑定数据
///
public void SetBindingData
(
Yw.Model.HydroModelInfo hydroInfo,
List allCalcuResultList,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
var allCalcuResultVisualDict = allCalcuResultList?.ToDictionary(x => x.Code);
SetBindingData(hydroInfo, allCalcuResultVisualDict, changeHelper, propStatusHelper);
}
///
/// 绑定数据
///
public void SetBindingData
(
HydroModelInfo hydroInfo,
Dictionary allCalcuResultVisualDict,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
_allList = new List();
_changeHelper = changeHelper;
_propStatusHelper = propStatusHelper;
if (hydroInfo != null && hydroInfo.Flowmeters != null && hydroInfo.Flowmeters.Count > 0)
{
foreach (var visual in hydroInfo.Flowmeters)
{
var vm = new HydroFlowmeterViewModel(visual, hydroInfo);
var calcuResult = allCalcuResultVisualDict?.GetValue(visual.Code);
if (calcuResult != null)
{
vm.UpdateCalcuProperty(calcuResult);
}
_allList.Add(vm);
}
}
Search();
}
///
/// 绑定数据
///
public void SetBindingData
(
List allVisualViewModelList,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
_allList = new List();
_changeHelper = changeHelper;
_propStatusHelper = propStatusHelper;
allVisualViewModelList?.ForEach(x =>
{
if (x.Vmo.Catalog == Yw.Hydro.ParterCatalog.Flowmeter)
{
_allList.Add(x as HydroFlowmeterViewModel);
}
});
Search();
}
///
/// 更新绑定
///
public void UpdateBindingData()
{
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
///
/// 更新属性
///
public void UpdateProperty()
{
if (_allList == null || _allList.Count < 1)
{
return;
}
_allList.ForEach(x => x.UpdateProperty());
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
///
/// 更新属性
///
public void UpdateProperty(Yw.Model.HydroVisualInfo visual)
{
if (_allList == null || _allList.Count < 1)
{
return;
}
if (visual == null)
{
return;
}
var vm = _allList.Find(x => x.Code == visual.Code);
if (vm == null)
{
return;
}
vm.UpdateProperty();
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
///
/// 更新属性
///
public void UpdateProperty(List visualList)
{
if (_allList == null || _allList.Count < 1)
{
return;
}
if (visualList == null || visualList.Count < 1)
{
return;
}
visualList.ForEach(x =>
{
var vm = _allList.Find(t => x.Code == x.Code);
if (vm != null)
{
vm.UpdateProperty();
}
});
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
///
/// 更新计算属性
///
public void UpdateCalcuProperty(List allCalcuResultList)
{
var allCalcuResultVisualDict = allCalcuResultList?.ToDictionary(x => x.Code);
UpdateCalcuProperty(allCalcuResultVisualDict);
}
///
/// 更新计算属性
///
public void UpdateCalcuProperty(Dictionary allCalcuResultVisualDict)
{
if (allCalcuResultVisualDict != null && allCalcuResultVisualDict.Count > 0)
{
if (_allList != null && _allList.Count > 0)
{
foreach (var visual in _allList)
{
var calcuResult = allCalcuResultVisualDict.GetValue(visual.Code);
if (calcuResult != null)
{
visual.UpdateCalcuProperty(calcuResult);
}
}
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
}
}
//查询
private void Search()
{
if (_allList == null || _allList.Count < 1)
{
return;
}
var name = this.txtName.Text.Trim();
var code = this.txtCode.Text.Trim();
var modelType = this.txtModelType.Text.Trim();
_allBindingList = _allList;
if (!string.IsNullOrEmpty(name))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
}
if (!string.IsNullOrEmpty(code))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
}
if (!string.IsNullOrEmpty(modelType))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
}
this.hydroFlowmeterViewModelBindingSource.DataSource = _allBindingList;
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
}
//重置
private void Reset()
{
this.txtName.EditValue = null;
this.txtCode.EditValue = null;
this.txtModelType.EditValue = null;
Search();
}
//设置
private void Set()
{
Search();
if (_allBindingList == null || _allBindingList.Count < 1)
{
TipFormHelper.ShowWarn("无数据!");
return;
}
var dlg = new SetHydroFlowmeterDlg();
dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList(), _changeHelper, _propStatusHelper);
dlg.ReloadDataEvent += (list) =>
{
if (list == null || list.Count < 1)
{
return;
}
_allBindingList.ForEach(x => x.UpdateProperty());
this.hydroFlowmeterViewModelBindingSource.ResetBindings(false);
var allVisualViewModelList = _allBindingList.Select(x => x as HydroVisualViewModel).ToList();
this.HydroChangedViewEvent?.Invoke(allVisualViewModelList);
var allVisualInfoList = allVisualViewModelList.Select(x => x.Vmo).ToList();
this.HydroChangedInfoEvent?.Invoke(allVisualInfoList);
};
dlg.ShowDialog();
}
//行单元点击事件
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
var row = this.gridView1.GetRow(e.RowHandle) as HydroFlowmeterViewModel;
if (row == null)
{
return;
}
if (e.Column == this.colSet)
{
var dlg = new SetHydroFlowmeterDlg();
dlg.SetBindingData(row.Vmo, _changeHelper, _propStatusHelper);
dlg.ReloadDataEvent += (list) =>
{
if (list == null || list.Count < 1)
{
return;
}
row.UpdateProperty();
this.gridView1.RefreshRow(e.RowHandle);
this.HydroChangedViewEvent?.Invoke(new List() { row });
this.HydroChangedInfoEvent?.Invoke(new List() { row.Vmo });
};
dlg.ShowDialog();
}
else
{
this.HydroClickViewEvent?.Invoke(row);
this.HydroClickInfoEvent?.Invoke(row.Vmo);
}
}
///
/// 设置简单显示模式
///
public void SetSimpleView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = false;
this.colName.Visible = true;
this.colCode.Visible = true;
this.colModelType.Visible = true;
this.colElev.Visible = false;
this.colMinorLoss.Visible = false;
this.colCalcuQ.Visible = false;
this.colHasDb.Visible = false;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = false;
}
///
/// 设置正常显示模式
///
public void SetNormalView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colName.Visible = true;
this.colCode.Visible = true;
this.colModelType.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuQ.Visible = false;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
///
/// 设置计算显示模式
///
public void SetCalcuView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colName.Visible = true;
this.colCode.Visible = true;
this.colModelType.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuQ.Visible = true;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
///
/// 设置批量设置模式
///
public void SetBulkView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
this.colDbLocked.Visible = true;
this.colName.Visible = true;
this.colCode.Visible = true;
this.colModelType.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuQ.Visible = false;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
///
/// 设置结果模式
///
public void SetResultView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colName.Visible = true;
this.colCode.Visible = true;
this.colModelType.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colCalcuQ.Visible = true;
this.colSet.Visible = false;
}
///
///
///
public GridView GetGridView()
{
return this.gridView1;
}
///
///
///
public void ExportToXlsx()
{
var filePath = FileDialogHelper.SaveFile("导出Excel文件", "Excel文件|*.xlsx");
if (string.IsNullOrEmpty(filePath))
{
return;
}
var options = new XlsxExportOptions
{
ExportMode = XlsxExportMode.SingleFile, // 导出模式
ShowGridLines = true, // 显示网格线
TextExportMode = TextExportMode.Value, // 导出文本模式
SheetName = "流量计" // 工作表名称
};
this.gridView1.ExportToXlsx(filePath, options);
}
}
}