using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using DevExpress.XtraBars.Docking2010; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; using IStation.CalcModel; using IStation.Model; using IStation.WinFrmUI.CalcErQu.Wizard; namespace IStation.WinFrmUI.CalcErQu { public partial class pageManuResult : XtraUserControl { private List _allCalcPumpInfos; private eAnaPrjType _anaPrjType = eAnaPrjType.Opt; private DateTime _anaDay = DateTime.Today; private List _elePriceMonthList = null; private IStation.CalcModel.AnaRequest _anaRequest; /// /// /// public pageManuResult() { InitializeComponent(); } /// /// /// /// internal void SetAnaType(eAnaPrjType anaPrjType) { this._anaPrjType = anaPrjType; RegistButtonClick(); } #region 底部按钮 /// /// /// private void RegistButtonClick() { this.winBtnBottom.QueryPeekFormContent += windowsUIButtonPanel1_QueryPeekFormContent; foreach (var btn in winBtnBottom.Buttons) { if (btn is DevExpress.XtraBars.Docking2010.WindowsUIButton) { var ui_btn = btn as DevExpress.XtraBars.Docking2010.WindowsUIButton; if (ui_btn == null) continue; if (ui_btn.Tag == null) continue; switch (ui_btn.Tag.ToString()) { case "导出": { // ExportRecursionCsv(); ui_btn.Click += (sender, e) => this.winBtnBottom.ShowPeekForm((DevExpress.XtraBars.Docking2010.WindowsUIButton)sender); break; } case "Save": ui_btn.Click += (sender, e) => { if (_anaPrjType == eAnaPrjType.Opt) { if (this._currentViewPrj == null) return; //if (HistoryAnaPrjFileHelper.SaveXml(this._anaDay, this._currentViewPrj)) //{ // MessageBox.Show("保存成功"); //} //else //{ // MessageBox.Show("保存失败"); //} } else { ui_btn.Visible = false; } }; break; case "分析设置": ui_btn.Click += (sender, e) => { AnaSettingMgrDlg frm = new AnaSettingMgrDlg(); if (frm.ShowDialog() != DialogResult.OK) return; }; break; case "电价信息": ui_btn.Click += (sender, e) => { ViewElecPriceByDay frm = new ViewElecPriceByDay(); frm.SetBindingData(this._anaDay); frm.Show(); }; break; case "上一步": ui_btn.Click += (sender, e) => { if (OnBeforePageEvent != null) { OnBeforePageEvent.Invoke(); } }; break; case "重新分配": ui_btn.Click += (sender, e) => { RefreshPrjRangeTime(); }; break; case "开始动画": ui_btn.Click += (sender, e) => { ShowChartTipWindow(true); }; break; case "暂停动画": ui_btn.Click += (sender, e) => { ShowChartTipWindow(false); }; break; default: break; } } } } /// /// /// /// /// private void windowsUIButtonPanel1_QueryPeekFormContent(object sender, QueryPeekFormContentEventArgs e) { if (e.Button is WindowsUIButton) { var tag = (e.Button as WindowsUIButton).Tag; if (tag == null) return; if (tag.ToString() == "导出") { #region 导出 var peekItems = new List(); peekItems.Add(new IStation.WinFrmUI.TilePeekItem { Caption = "导出运行时间", NormalImage = IStation.WinFrmUI.CalcErQu.Properties.Resources.Down32B, Click = () => { anaResultInfoDefaultCtrl.ExportSpanGrid(); this.winBtnBottom.HidePeekForm(); } }); //peekItems.Add(new IStation.WinFrmUI.TilePeekItem //{//加一个多余的, 保证下面不会被挡住 // Caption = "", // Click = () => // { // } //}); var ctrl = new LayoutPeekCtrl(); ctrl.Padding = new System.Windows.Forms.Padding(0, 0, 0, 20); //ctrl.Margin = new System.Windows.Forms.Padding(0, 0, 0, 40); ctrl.SetBindingData(peekItems); var peekCtrl = ctrl;// peekItems.CreatePeekCtrl(); e.Control = peekCtrl; #endregion 风格 } } } #endregion #region 初始化 /// /// /// private void InitalPumpInfo() { if (_allCalcPumpInfos == null) { var allCurveList = new BLL.PumpCurve().GetAll(); var allPumpMapList = new BLL.PumpCurveMapping().GetAll(); var allPumpList = new BLL.Product().GetAllPump(); _allCalcPumpInfos = new List(); foreach (var pump in allPumpList) { var curve_wrk_map = (from x in allPumpMapList where x.PumpID == pump.ID && x.IsWorking select x).FirstOrDefault(); if (curve_wrk_map == null) { MessageBox.Show(pump.Name + "未设置工作曲线"); return; } var curve = allCurveList.Find(x => x.ID == curve_wrk_map.CurveID); IStation.CalcModel.PumpInfo calcPumpInfo = new IStation.CalcModel.PumpInfo(); calcPumpInfo.Product = pump; calcPumpInfo.ID = pump.ID; calcPumpInfo.Name = pump.Name; calcPumpInfo.CurveInfo = curve.CurveInfo; calcPumpInfo.RatedParas = pump.RatedParas; _allCalcPumpInfos.Add(calcPumpInfo); } } } /// /// /// private void InitialElePrice() { if (_elePriceMonthList == null) { var bllElecPrice = new BLL.ElecPrice(); var allPrices = bllElecPrice.GetAll(); _elePriceMonthList = allPrices.First().Settings.MonthList; } } #endregion #region 动画 //bool _isDispAnimationTip = false; //AnimationTipInfoDlg _tipDlg = null; private void ShowChartTipWindow(bool isShow) { //var realTimeDataList = anaResultInfoDefaultCtrl.GetRealTimeDataList(); //if (_tipDlg != null) //{ // if (isShow) // { // if (_isDispAnimationTip) // return; // _isDispAnimationTip = true; // _tipDlg.SetBindingData(this._currentViewPrj); // _tipDlg.SetRealTimeDataList(realTimeDataList); // _tipDlg.Show(); // } // else // { // _isDispAnimationTip = false; // _tipDlg.StopAnimation(); // _tipDlg.Hide(); // } // return; //} //_tipDlg = new AnimationTipInfoDlg(); //_tipDlg.TopMost = true; //_tipDlg.Name = "AnimationTipInfoDlg"; //_tipDlg.WindowState = FormWindowState.Normal; //_tipDlg.SetPumpInfo(this._allCalcPumpInfos); //_tipDlg.OnStopAnimation += () => //{ // this.anaResultInfoDefaultCtrl.SetTipLineVisible(false); //}; //_tipDlg.OnStartAnimation += () => //{ // this.anaResultInfoDefaultCtrl.SetTipLineVisible(true); //}; //_tipDlg.OnRefreshAnimation += (t, d) => //{ // anaResultInfoDefaultCtrl.SetTipLineValue(t); //}; //_isDispAnimationTip = true; //anaResultInfoDefaultCtrl.SetTipLineValue(this._currentViewPrj.StartTime); //_tipDlg.OnHide = () => //{ // _isDispAnimationTip = false; // _tipDlg.Hide(); //}; //_tipDlg.SetRealTimeDataList(realTimeDataList); //_tipDlg.SetBindingData(this._currentViewPrj); //_tipDlg.Show(); } #endregion /// /// /// /// /// private void GetAnaRangeTime(out DateTime startTime, out DateTime endTime) { var anaSetting = IStation.AnaGlobalParas.Setting; var day = this._anaDay; var startHour = anaSetting.StartHourPerDay; if (startHour < 1) { startTime = day; endTime = startTime.AddDays(1); } else { startTime = new DateTime(day.Year, day.Month, day.Day, startHour, 0, 0); endTime = startTime.AddDays(1); } } /// /// 计算 手动 /// public void AnaManuResult(IStation.CalcModel.AnaRequest anaRequest, Action finish_cb) { this._anaRequest = anaRequest; if (anaRequest == null) return; this._anaDay = anaRequest.StartTime; if (anaRequest.WaterLevels长江 == null) { finish_cb.Invoke(false); MessageBox.Show("请输入长江水位信息"); return; } InitalPumpInfo(); InitialElePrice(); //bool isLimitLevel = false; //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.MaxLimitWaterBoxLevel != null) // isLimitLevel = true; //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false, isLimitLevel); //string error_info; //AnaPrj anaPrj = new AnaPrj(); //anaPrj.ID = Guid.NewGuid().ToString("N"); //anaPrj.Type = 1; //anaPrj.Name = "手动"; //anaPrj.CalcSpaceMinute = calcHelper.CalcSpaceMinute; //calcHelper.CalcManuPrj(ref anaPrj, anaRequest.ManuPrjTimeBlockList, out error_info); //if (!string.IsNullOrEmpty(error_info) || anaPrj == null) //{ // finish_cb.Invoke(false); // MessageBox.Show(error_info); // return; //} //this.ViewPrj(anaRequest, anaPrj,true); //finish_cb.Invoke(true); } /// /// 计算最优 /// public void AnaOptResult(IStation.CalcModel.AnaRequest anaRequest, Action finish_cb) { this._anaRequest = anaRequest; if (anaRequest == null) return; this._anaDay = anaRequest.StartTime; if (anaRequest.WaterLevels长江 == null) { finish_cb.Invoke(false); MessageBox.Show("请输入长江水位信息"); return; } InitalPumpInfo(); InitialElePrice(); //bool isLimitLevel = false; //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.MaxLimitWaterBoxLevel != null) // isLimitLevel = true; //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(true, isLimitLevel); //string error_info; //var anaPrjs = calcHelper.CalcOptPrjs(out error_info); //if (!string.IsNullOrEmpty(error_info) || anaPrjs == null || anaPrjs.Count() == 0) //{ // finish_cb.Invoke(false); // MessageBox.Show(error_info); // return; //} //anaPrjs.Sort(new AnaPrj.Comparer(anaRequest.CalcOptType)); //var defaultPrj = anaPrjs.First(); //defaultPrj.Name = anaRequest.Day.ToString(); //this.ViewPrj(anaRequest, defaultPrj, false); //finish_cb.Invoke(true); } // AnaPrj _currentViewPrj; private void ViewPrj(IStation.CalcModel.AnaRequest anaRequest, AnaPrj current_prj,bool isManuPrj) { if (string.IsNullOrEmpty(current_prj.ID)) current_prj.ID = Guid.NewGuid().ToString("N"); this._currentViewPrj = current_prj; this._anaRequest = anaRequest; current_prj.SumMoney = Math.Round(current_prj.SumMoney, 0); current_prj.SumFlow = Math.Round(current_prj.SumFlow, 0); current_prj.SumPower = Math.Round(current_prj.SumPower, 0); this.anaResultInfoDefaultCtrl.SetBindingData(current_prj ); listBoxControl1.Items.Clear(); listBoxControl1.Items.Add("----------目标参数---------"); listBoxControl1.Items.Add(string.Format("取水总量 {0} 万方", anaRequest.TotalFlow取水总量/10000)); listBoxControl1.Items.Add(string.Format("优化目标 {0} ", anaRequest.CalcOptType== eCalcOptType.功率?"用电量最优":"电费最优")); listBoxControl1.Items.Add("----------开机方案---------"); bool isFirstOpenPump = true; int last_open_num = 0; for (int i = 0; i < current_prj.BlockTimes.Count; i++) { var item = current_prj.BlockTimes[i]; if (isFirstOpenPump) { isFirstOpenPump = false; last_open_num = item.OpenPumpCount; listBoxControl1.Items.Add(string.Format("{0} 开机 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount, item.OpenPumpCount)); } else if (item.OpenPumpCount != last_open_num) { isFirstOpenPump = false; if (item.OpenPumpCount == 0) { listBoxControl1.Items.Add(string.Format("{0} 全部关机", item.StartTime.ToString("HH:mm"), item.OpenPumpCount)); } else { if (item.OpenPumpCount > last_open_num) { if (last_open_num == 0) listBoxControl1.Items.Add(string.Format("{0} 开启 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount - last_open_num, item.OpenPumpCount)); else listBoxControl1.Items.Add(string.Format("{0} 多开 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount - last_open_num, item.OpenPumpCount)); } else { listBoxControl1.Items.Add(string.Format("{0} 关掉 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), last_open_num - item.OpenPumpCount, item.OpenPumpCount)); } } last_open_num = item.OpenPumpCount; } } //current_prj.Name = string.Format("当前水位:{0} ,最低水位:{1},最高水位:{2} ({3})", // anaRequest.CurrentWaterBoxLevel, // anaRequest.MinLimitWaterBoxLevel, // anaRequest.MaxLimitWaterBoxLevel, // anaRequest.CalcOptType); listBoxControl1.Items.Add("-----------水位参数--------"); DateTime max_wt_dt = current_prj.PointTimes.First().Time; DateTime min_wt_dt = current_prj.PointTimes.First().Time; double max_wt = double.MinValue; double min_wt = double.MaxValue; foreach (var pt in current_prj.PointTimes) { if (max_wt < pt.WaterLevelH) { max_wt_dt = pt.Time; max_wt = pt.WaterLevelH; } if (min_wt > pt.WaterLevelH) { min_wt_dt = pt.Time; min_wt = pt.WaterLevelH; } } var wt_list = from x in current_prj.PointTimes select x.WaterLevelH; var avr_wt = wt_list.Average(); listBoxControl1.Items.Add(string.Format("最初水位: {0:N2} m (0时)", anaRequest.CurrentWaterBoxLevel)); listBoxControl1.Items.Add(string.Format("最高水位: {1:N2} m ({0})", max_wt_dt.ToString("HH:mm"), Math.Round(max_wt, 2))); listBoxControl1.Items.Add(string.Format("最低水位: {1:N2} m ({0})", min_wt_dt.ToString("HH:mm"), Math.Round(min_wt, 2))); listBoxControl1.Items.Add(string.Format("平均水位: {0:N2} m", Math.Round(avr_wt, 2))); current_prj.WaterLevelInfo = string.Format("{0},{1},{2},{3},{4},{5}", anaRequest.CurrentWaterBoxLevel, max_wt_dt.ToString("HH:mm"), Math.Round(max_wt, 2), min_wt_dt.ToString("HH:mm"), Math.Round(min_wt, 2), Math.Round(avr_wt, 2)); } /// /// /// /// /// private void RereshPrjTimeSpan(IStation.CalcModel.AnaPrj anaPrj, List ranges) { //IStation.WinFrmUI.WaitFrmHelper.ShowWaitForm(this); //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false, false); //string error_info; //calcHelper.CalcManuPrj(ref anaPrj, ranges, out error_info); //IStation.WinFrmUI.WaitFrmHelper.HideWaitForm(this); //if (!string.IsNullOrEmpty(error_info) || anaPrj == null) //{ // MessageBox.Show(error_info); // return; //} //this.ViewPrj(this._anaRequest, anaPrj, true); } /// /// 构建计算辅助类 /// /// /// // private IStation.Calc.ErQuCalcBaseHelper GetCalcHelper(bool isIgnoreOpenLimitAble, bool isLimitLevel) // { // DateTime rangeStartTime, rangeEndTime; // GetAnaRangeTime(out rangeStartTime, out rangeEndTime); // var anaSetting = IStation.AnaGlobalParas.Setting; // if (anaSetting == null) // return null; // IStation.Calc.ErQuCalcBaseHelper calcHelper = IStation.Calc.ErQuCalcBaseHelper.Build(); // calcHelper.MinOpenPumpMinute = anaSetting.MinOpenTimeMinute; // calcHelper.MinSwitchPumpMinute = anaSetting.MinSwitchTimeMinute; // if (isLimitLevel) // { // calcHelper.CalcSpaceMinute = anaSetting.CalcSpaceMinuteL; // calcHelper.MaxPumpSwitchCount = anaSetting.MaxPumpSwitchCountL; // } // else // { // calcHelper.CalcSpaceMinute = anaSetting.CalcSpaceMinuteQ; // calcHelper.MaxPumpSwitchCount = anaSetting.MaxPumpSwitchCountQ; // } // calcHelper.SetPumpInfo(_allCalcPumpInfos); // calcHelper.SetCalcTimeRange(rangeStartTime, rangeEndTime); // calcHelper.StartOpenCount = this._anaRequest.StartOpenCount;// Convert.ToInt32(imageComboCurrentOpenCount.EditValue); // calcHelper.ElecPrice = _elePriceMonthList; // calcHelper.IsDispDebug = true; // calcHelper.OnShowDebugInfo += (info) => // { // //if (tabPageDebug.PageVisible) // // this.listBoxDebug.Items.Add(info); // }; // //不许切泵时间 // if (IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes != null && IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes.Count > 0) // { // List limit_times = new List(); // foreach (var t in IStation.AnaGlobalParas.Setting.SwitchPumpIgnoreTimes) // { // if (t.IsUse == false) // continue; // int ed_h = t.EndHour; // int st_h = t.StartHour; // IStation.CalcModel.TimeRange v = new IStation.CalcModel.TimeRange(); // if (ed_h <= rangeStartTime.Hour) // { // var nextDay = rangeStartTime.AddDays(1); // v.Start = new DateTime(nextDay.Year, nextDay.Month, //nextDay.Day, st_h, t.StartMinute, 0); // } // else // { // v.Start = new DateTime(rangeStartTime.Year, rangeStartTime.Month, //rangeStartTime.Day, st_h, t.StartMinute, 0); // } // bool isNext = ed_h > 23 ? true : false; // if (isNext) // { // var nextDay = v.Start.AddDays(1); // v.End = new DateTime(nextDay.Year, nextDay.Month, // nextDay.Day, ed_h - 24, t.EndMinute, 0); // } // else // { // v.End = new DateTime(v.Start.Year, v.Start.Month, // v.Start.Day, ed_h, t.EndMinute, 0); // } // if (v.End > v.Start) // { // limit_times.Add(v); // } // } // calcHelper.LimitSwitchPumpTimes = limit_times; // } // //不许开泵时间 // //if (isIgnoreOpenLimitAble == true && // // !string.IsNullOrEmpty(anaSetting.OpenPumpIgnoreTimes)) // //{ // //} // calcHelper.SetAnaRequest(_anaRequest); // return calcHelper; // } /// /// /// /// /// private void layoutControlGroup7_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { var btn = e.Button as DevExpress.XtraEditors.ButtonsPanelControl.GroupBoxButton; if (btn == null || btn.Tag == null) return; if (btn.Tag.ToString() == "Export") { } if (btn.Tag.ToString() == "Empty") { } } /// /// /// /// private void RefreshPrjRangeTime() { var anaPrj = anaResultInfoDefaultCtrl.GetAnaPrj(); if (anaPrj == null) return; //DateTime rangeStartTime, rangeEndTime; //GetAnaRangeTime(out rangeStartTime, out rangeEndTime); SetPrjItemSpanTimeInfoDlg frm = new SetPrjItemSpanTimeInfoDlg(); frm.SetBindingData(anaPrj); frm.OnRefreshData += (prj, ranges) => { anaPrj = prj; bindingSourcePrjList.ResetBindings(false); RereshPrjTimeSpan(anaPrj, ranges); }; if (frm.ShowDialog() == DialogResult.OK) { } } // public event MethodInvoker OnNextPageEvent;//下一步委托事件 public event MethodInvoker OnBeforePageEvent;//上一步委托事件 /// /// /// private void ExportRecursionCsv() { //if (string.IsNullOrEmpty(textEditTotalFlow水库放水量.Text)) //{ // return; //} //if (!Initial长江水位()) //{ // MessageBox.Show("请输入长江水位信息"); // return; //} //InitalPumpInfo(); //InitialElePrice(); //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false ); //SaveFileDialog saveFileDlg = new SaveFileDialog(); //saveFileDlg.Filter = "csv 文件(*.csv)|*.csv"; //if (saveFileDlg.ShowDialog() != DialogResult.OK) // return; //string error_info; //calcHelper.ExportTimeData(saveFileDlg.FileName, out error_info); //if (!string.IsNullOrEmpty(error_info)) // MessageBox.Show(error_info); } private void anaResultInfoDefaultCtrl_Load(object sender, EventArgs e) { } } }