using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 pageCalcResult : XtraUserControl { private eAnaPrjType _anaPrjType = eAnaPrjType.Opt; private IStation.CalcModel.AnaRequest _anaRequest; /// /// /// public pageCalcResult() { 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; IStation.BLL.AnaPrj.SavePrj( this._anaRequest, IStation.AnaGlobalParas.Setting, _currentViewPrj, false); MessageBox.Show("保存成功"); } else { ui_btn.Visible = false; } }; break; case "Submit": ui_btn.Click += (sender, e) => { if (_anaPrjType != eAnaPrjType.Opt) { return; } if (this._currentViewPrj == null) return; AlertTool.ShowInfo(this.ParentForm, "提示", "开始链接服务器"); IStation.BLL.AnaPrj.SavePrj( this._anaRequest, IStation.AnaGlobalParas.Setting, _currentViewPrj,true ); }; break; case "分析设置": ui_btn.Click += (sender, e) => { AnaSettingMgrDlg frm = new AnaSettingMgrDlg(); if (frm.ShowDialog() != DialogResult.OK) return; }; break; case "电价信息": ui_btn.Click += (sender, e) => { if (this._currentViewPrj == null) return; ViewElecPriceByDay frm = new ViewElecPriceByDay(); frm.SetBindingData(this._currentViewPrj.StartTime); 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 动画 //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 /// /// 计算 手动 /// public void AnaManuResult(IStation.CalcModel.AnaRequest anaRequest, Action finish_cb) { this._anaRequest = anaRequest; if (anaRequest == null) return; if (anaRequest.WaterLevels长江 == null) { finish_cb.Invoke(false); MessageBox.Show("请输入长江水位信息"); return; } //InitalPumpInfo(); //InitialElePrice(); //bool isLimitLevel = false; //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.ReservoirMinLimitHours != 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; if (anaRequest.WaterLevels长江 == null) { finish_cb.Invoke(false); MessageBox.Show("请输入长江水位信息"); return; } //InitalPumpInfo(); //InitialElePrice(); //bool isLimitLevel = false; //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.ReservoirMinLimitHours != null) // isLimitLevel = true; //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(true, isLimitLevel); var calcHelper = new IStation.CalcPrjHelper(); AnaPrj defaultPrj = null; string error_info = calcHelper.Calc(anaRequest, out defaultPrj); if (!string.IsNullOrEmpty(error_info) || defaultPrj == null ) { finish_cb.Invoke(false); MessageBox.Show(error_info); return; } // defaultPrj.Name = defaultPrj.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.SetRiverWaterLevels(this._anaRequest.WaterLevels长江); //anaPrj.SumMoney = Math.Round(anaPrj.SumMoney, 0); //anaPrj.SumFlow = Math.Round(anaPrj.SumFlow, 0); //anaPrj.SumPower = Math.Round(anaPrj.SumPower, 0); var yester1_day_anaPrj = IStation.BLL.AnaPrj.GetPrj(current_prj.StartTime.AddDays(-1)); //var yester2_day_anaPrj = HistoryAnaPrjFileHelper.GetAnaPrj(current_prj.StartTime.AddDays(-2)); this.anaResultInfoDefaultCtrl.SetBindingData(current_prj, yester1_day_anaPrj); listBoxControl1.Items.Clear(); listBoxControl1.Items.Add("----------目标参数---------"); listBoxControl1.Items.Add(string.Format("取水总量 {0} 万方", anaRequest.TotalFlowIn / 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("-----------水位参数--------"); var allTime = current_prj.GetAllPointTimeList(); DateTime max_wt_dt = allTime.First().Time; DateTime min_wt_dt = allTime.First().Time; double max_wt = double.MinValue; double min_wt = double.MaxValue; foreach (var pt in allTime) { 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 allTime select x.WaterLevelH; var avr_wt = wt_list.Average(); listBoxControl1.Items.Add(string.Format("最初水位: {0:N2} m (0时)", anaRequest.StartReservoirLevel)); 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.StartReservoirLevel, 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 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) { } private void groupControl1_CustomButtonClick(object sender, BaseButtonEventArgs e) { StringBuilder sb = new StringBuilder(); foreach(var item in listBoxControl1.Items) { sb.Append(item.ToString());sb.AppendLine(); } Clipboard.SetDataObject(sb.ToString()); MessageBox.Show("已把文字内容复制到黏贴板中"); } } }