using DevExpress.Utils.Extensions; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid.ViewInfo; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace IStation.WinFrmUI.Monitor { public partial class SchedulingAnalysisMgrPage : DocumentPage { public SchedulingAnalysisMgrPage() { InitializeComponent(); this.PageTitle.Caption = "数据整合"; this.gridView1.SetNormalView(); // this.gridView1.OptionsView.AllowCellMerge = true; this.stationListCtrl1.FocusedChangedEvent += StationListCtrl1_FocusedChangedEvent; this.monitorDataSourcesTreeList1.FocusedChangedEvent += MonitorDataSourcesListCtrl1_FocusedChangedEvent; this.barEditDate.EditValue = DateTime.Now.AddYears(-1); } public class CurrentViewModel { public DateTime Time { get; set; } public double TotalFlow { get; set; } public double TotalHead { get; set; } public int RunCount { get; set; } public string RunFlags { get; set; } } private BLL.StationStatisticalRecordPacket _bll = new BLL.StationStatisticalRecordPacket(); private Model.Station _station = null; private Model.MonitorDataSources _monitorDataSources = null; private List _allBindingList = null; /// /// 清空数据 /// public void Clear() { _allBindingList = new List(); this.currentViewModelBindingSource.DataSource = _allBindingList; } /// /// 初始化数据 /// public override void InitialDataSource() { this.stationListCtrl1.SetBindingData(); this.monitorDataSourcesTreeList1.SetBindingData(); } //泵站变换 private void StationListCtrl1_FocusedChangedEvent(Model.Station obj) { _station = obj; } //来源变换 private void MonitorDataSourcesListCtrl1_FocusedChangedEvent(Model.MonitorDataSources obj) { _monitorDataSources = obj; } /// /// 绑定数据 /// public void SetBindingData(DateTime date, Model.StationStatisticalRecordPacket packet) { WaitFrmHelper.ShowWaitForm(); _allBindingList = new List(); if (packet != null) { var enginePumps = new BLL.Equipment().GetEnginePumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, _station.ID); packet.StationStatisticalRecords?.ForEach(record => { var vm = new CurrentViewModel(); vm.Time = record.Time; vm.TotalFlow = record.TotalFlow; vm.TotalHead = record.TotalHead; vm.RunCount = record.PumpRunCount; vm.RunFlags = record.PumpRunFlags; _allBindingList.Add(vm); }); } this.currentViewModelBindingSource.DataSource = _allBindingList; this.gridView1.ExpandAllGroups(); this.gridView1.BestFitColumns(); WaitFrmHelper.HideWaitForm(); } #region GridView ////自定义组名 //private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) //{ // var vm = this.gridView1.GetRow(e.RowHandle) as CurrentViewModel; // var grid = e.Info as GridGroupRowInfo; // grid.GroupText = vm.GroupName; //} #endregion #region 菜单 //全部展开 private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.gridView1.ExpandAllGroups(); } //全部折叠 private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.gridView1.CollapseAllGroups(); } //检索 private void barCekSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.barCekSearch.Checked) this.gridView1.ShowFindPanel(); else this.gridView1.HideFindPanel(); } // 刷新数据 private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialDataSource(); } #endregion //整合 private void barBtnIntegration_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_monitorDataSources == null || _station == null) return; var packets = _bll.Get(_monitorDataSources.ID, _station.ID); if (packets != null && packets.Any()) { if (XtraMessageBox.Show($"已存在整合数据,是否重新整合,?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK) return; } var dlg = new SetTimeStepDlg(); dlg.ReloadDataEvent += (timeStep) => { packets = _bll.AnalysisAndSave(_monitorDataSources.ID, _station.ID, timeStep); }; dlg.ShowDialog(); } //加载 private void barBtnLoad_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.barEditDate.EditValue == null) { XtraMessageBox.Show("请选择时间!"); return; } if (_monitorDataSources == null || _station == null) return; var date = (DateTime)this.barEditDate.EditValue; var packet = _bll.Get(_monitorDataSources.ID, _station.ID, date.Year, date.Month); SetBindingData(date, packet); } } }