using DevExpress.XtraEditors;
using System.Windows.Forms;
namespace IStation.WinFrmUI.Schedule
{
public partial class ScheduleAnalyPage : DocumentPage
{
public ScheduleAnalyPage()
{
InitializeComponent();
PageTitle.Caption = "优化调度2";
gridView1.SetNormalView();
gridView1.RegistCustomDrawRowIndicator(40);
gridView1.OptionsView.ShowDetailButtons = true;
gridView1.OptionsDetail.ShowDetailTabs = false;
gridView2.SetNormalView();
stationListCtrl1.FocusedChangedEvent += StationListCtrl1_FocusedChangedEvent;
}
public class CurrentViewModel
{
///
///
///
public int ID { get; set; }
///
///
///
public double TotalWrkQ { get; set; }
///
///
///
public double TotalWrkH { get; set; }
///
///
///
public double TotalWrkE { get; set; }
///
///
///
public double TotalWrkP { get; set; }
///
/// 千吨水能耗
///
public double UWP { get; set; }
///
/// 能耗
///
public double WP { get; set; }
///
/// 开泵数量
///
public int RunNumber
{
get
{
if (Items == null)
return 0;
return Items.Count();
}
set => value = RunNumber;
}
///
///
///
public List Items { get; set; }
public string Captain { get; set; }
}
private Model.Station _station = null;
private List _dispatchPumps = null;
private List _allPumpCurves = null;
private List _allBindingList = null;
private double _targetQ, _targetH;
private Service.AnalysisParameter _serviceAnalysisParameter = new Service.AnalysisParameter();
///
/// 初始化数据
///
public override void InitialDataSource()
{
_station = null;
_dispatchPumps = new List();
_allPumpCurves = new BLL.PumpCurve().GetAll();
_allPumpCurves = new BLL.PumpCurve().GetAll();
stationListCtrl1.SetBindingData();
}
//泵站列表变换
private void StationListCtrl1_FocusedChangedEvent(Model.Station obj)
{
_station = obj;
_dispatchPumps = new List();
if (_station != null)
{
var pumps = new BLL.Equipment().GetPumpModelListByBelongTypeAndBelongID(IStation.ObjectType.Station, _station.ID);
if (pumps != null && pumps.Any())
{
var bll = new BLL.PumpCurveMapping();
foreach (var pump in pumps)
{
Model.PumpModel dispatchPump = null;
var mapping = bll.GetWorkCurveByPumpID(pump.ID);
if (mapping != null)
{
var pumpCurve = _allPumpCurves?.Find(x => x.ID == mapping?.CurveID);
if (pumpCurve==null)
{
TipFormHelper.ShowError($"{pump.Name}:没有曲线!");
}
dispatchPump = new Model.PumpModel(pump, pumpCurve);
}
else
{
dispatchPump = new Model.PumpModel(pump, null);
}
_dispatchPumps.Add(dispatchPump);
}
}
}
}
//泵运行配置
private void barBtnSetPumpRunConfig_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (_station == null)
return;
var dlg = new SetPumpRunStatusDlg();
dlg.SetBindingData(_dispatchPumps);
if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
}
//调度分析
private void barBtnDispatchAnaly_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
_allBindingList = new List();
currentViewModelBindingSource.DataSource = _allBindingList;
try
{
ScheduleAnaly();
WaitFrmHelper.HideWaitForm();
}
catch (Exception ex)
{
throw ex;
}
finally
{
WaitFrmHelper.HideWaitForm();
}
}
///
/// 调度分析
///
private void ScheduleAnaly()
{
_allBindingList = new List();
currentViewModelBindingSource.DataSource = _allBindingList;
if (_station == null) return;
if (_dispatchPumps == null || !_dispatchPumps.Any()) return;
WaitFrmHelper.ShowWaitForm("计算中...");
if (File.Exists(ConfigHelper.AnalysisDbFilePath))
{
File.Delete(ConfigHelper.AnalysisDbFilePath);
}
var all_pump_list = _dispatchPumps;
var flags = all_pump_list.Select(x => x.Flag);
if (flags.Distinct().Count() != flags.Count())
{
TipFormHelper.ShowError("请确定机组的排序码是唯一的");
return;
}
IStation.Service.AnalysisParameter.RemoveDictCache();
var helperAnalysis = new IStation.Service.AnalysisHelper();
helperAnalysis.AnalysisPump(all_pump_list);
helperAnalysis.AnalysisParameter(all_pump_list);
_targetQ = Convert.ToDouble(barBtnTargetQ.EditValue);
_targetH = Convert.ToDouble(barBtnTargetH.EditValue);
var config = new Model.ScheduleConfig();
config.MinOpenCount = 1;
config.MaxOpenCount = all_pump_list.Count;
config.MustCloseFlagList = all_pump_list.Where(x => x.MachineRunStatus == Model.PumpModel.eMachineRunStatus.Close)
.Select(x => x.Flag).ToList();
var helper = new Service.ScheduleHelper();
helper.Initial(null, config);
var ana_combine_list = helper.GetAnaCombineList(all_pump_list, _targetQ, _targetH);
if (ana_combine_list == null || ana_combine_list.Count() == 0)
{
TipFormHelper.ShowError("无计算方案");
return;
}
var dict = _dispatchPumps.ToDictionary(x => x.Flag, y => y);
var bllPump = new BLL.Equipment();
foreach (var rhs in ana_combine_list)
{
var vm = new CurrentViewModel();
vm.TotalWrkQ = Math.Round(rhs.TotalFlow, 1);
vm.TotalWrkH = Math.Round(rhs.TotalHead, 1);
vm.TotalWrkE = Math.Round(rhs.TotalEfficiency, 1);
vm.TotalWrkP = Math.Round(rhs.TotalPower, 1);
vm.UWP = Math.Round(rhs.UWP, 1);
vm.WP = Math.Round(rhs.WP, 1);
vm.RunNumber = rhs.AnaFrePumps.Count;
vm.Items = new List();
foreach (var item in rhs.AnaFrePumps)
{
var pump = dict[item.Flag];
var qh = pump.CurveQH;
var qp = pump.CurveQP;
var qe = pump.CurveQE;
var sItem = new AnaSchemeItem();
sItem.PumpCurveID = pump.Flag;
sItem.WorkPointQ = Math.Round(item.Flow, 1);
sItem.WorkPointH = Math.Round(item.Head, 1);
sItem.WorkPointE = Math.Round(item.Eff, 1);
sItem.WorkPointP = Math.Round(item.Power, 1);
sItem.Frequence = item.Frequency;
sItem.Speed = Math.Round(item.Speed, 1);
sItem.MachineName = dict[item.Flag].Name;
sItem.CurveInfoQH = Model.CurveCalcuHelper.CalculateSimilarQH(qh, 50, item.Frequency);
sItem.CurveInfoQP = Model.CurveCalcuHelper.CalculateSimilarQP(qp, 50, item.Frequency);
var similarQe = Model.CurveCalcuHelper.CalculateSimilarQP(qe, 50, item.Frequency);
var eff = similarQe.GetFitPointY(item.Flow);
vm.Items.Add(sItem);
}
var names = vm.Items.Select(x => x.MachineName);
vm.Captain = string.Join(",", names);
_allBindingList.Add(vm);
}
this.currentViewModelBindingSource.ResetBindings(false);
}
//单元格点击事件
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
if (_allPumpCurves == null || !_allPumpCurves.Any())
return;
if (e.Column == colParallelCurve)
{
var row = gridView1.GetCurrentViewModel(_allBindingList);
if (row == null)
return;
var dlg = new ParallelCurveViewDlg();
dlg.SetBindingData(row.TotalWrkQ, row.Items);
dlg.ShowDialog();
}
}
}
}