using DevExpress.Utils.About; using DevExpress.XtraEditors; using Eventech.Common; using IStation.Unit; using IStation.Untity; using IStation.WinFrmUI.Basic.basic; using System; using System.ComponentModel; using System.Linq; namespace IStation.WinFrmUI.Basic { /// /// /// public partial class MonitorPointGridMgrCtrl : XtraUserControl { public MonitorPointGridMgrCtrl() { InitializeComponent(); this.gridView1.SetNormalView(); this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; this.gridView1.OptionsView.AllowCellMerge = true; this.gridView1.ActiveFilterEnabled = false; this.layoutControl1.SetupLayoutControl(); } public class CurrentViewModel : Model.MonitorPointExSignalExSignalType { public CurrentViewModel() { } public CurrentViewModel(Model.MonitorPointExSignalExSignalType rhs, string belongName) : base(rhs) { if (int.TryParse(this.UnitValue, out int value)) { var dict = UnitHelper.GetEnUnitDict(this.UnitType); if (dict != null) this.Unit = dict[value]; } else { this.Unit = this.UnitValue; } this.BelongName = belongName; this.FlagsList = FlagsHelper.ToString(rhs.Flags); } public string Unit { get; set; } public string BelongName { get; set; } public string FlagsList { get; set; } } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; private BindingList _allBindingList = null;//所有绑定列表 /// /// 绑定数据 /// public void Clear() { _allBindingList = new BindingList(); this.currentViewModelBindingSource.DataSource = _allBindingList; this.FocusedChangedEvent?.Invoke(null); } /// /// 绑定数据 /// public void SetBindingData() { WaitFrmHelper.ShowWaitForm("正在加载数据..."); _allBindingList = new BindingList(); var bll = new BLL.MonitorPoint(); var stations = new BLL.Station().GetAll(); if (stations != null && stations.Any()) { foreach (var station in stations) { var stationMappings = bll.GetExSignalExSignalTypeByMappingTypeAndMappingID(IStation.ObjectType.Station, station.ID); if (stationMappings != null && stationMappings.Any()) { foreach (var mapping in stationMappings) { var vm = new CurrentViewModel(mapping, station.Name); _allBindingList.Add(vm); } } var pumps = new BLL.Product().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID); if (pumps != null || pumps.Any()) { foreach (var pump in pumps) { var enginePumpId = pump.ParentIds.FirstOrDefault(); var pumpMappings = bll.GetExSignalExSignalTypeByMappingTypeAndMappingID(IStation.ObjectType.Product, enginePumpId); if (pumpMappings != null && pumpMappings.Any()) { foreach (var mapping in pumpMappings) { var vm = new CurrentViewModel(mapping, pump.Name); _allBindingList.Add(vm); } } } } } } this.currentViewModelBindingSource.DataSource = _allBindingList; this.gridView1.BestFitColumns(); WaitFrmHelper.HideWaitForm(); } /// /// 绑定数据 /// public void SetBindingData(string mappingName, string mappingType, long mappingId) { WaitFrmHelper.ShowWaitForm("正在加载数据..."); _allBindingList = new BindingList(); var monitorPointExSignalExSignalTypes = new BLL.MonitorPoint().GetExSignalExSignalTypeByMappingTypeAndMappingID(mappingType, mappingId); if (monitorPointExSignalExSignalTypes != null && monitorPointExSignalExSignalTypes.Any()) { foreach (var item in monitorPointExSignalExSignalTypes) { var vm = new CurrentViewModel(item, mappingName); _allBindingList.Add(vm); } } this.currentViewModelBindingSource.DataSource = _allBindingList; this.gridView1.BestFitColumns(); WaitFrmHelper.HideWaitForm(); } //聚焦改变 private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { var vm = this.gridView1.GetCurrentViewModel(_allBindingList); if (vm == null) return; this.FocusedChangedEvent?.Invoke(vm); } //private Model.MonitorPoint monitorPoint= null; //private Model.Signal Signal= null; //编辑监测信息 public void EditMonitor() { var row = gridView1.GetCurrentViewModel(_allBindingList); if (row == null) return; var dlg = new EditMonitorDlg(); dlg.SetBindingData(row,row.Name); dlg.ReloadDataEvent += (Info) => { var monitor=Info.GetMonitorPoint(); var bll = new BLL.MonitorPoint(); var isok = bll.Update(monitor); if (isok) { this.currentViewModelBindingSource.ResetBindings(false); this.SetBindingData(); } var bl = new BLL.Signal(); var signal = Info.GetSignal(); var isokk = bl.Update(signal); if (isokk) { this.currentViewModelBindingSource.ResetBindings(false); this.SetBindingData(); return true; } return false; }; dlg.ShowDialog(); } } }