using DevExpress.XtraGrid.Views.Grid; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Text; namespace IStation.WinFrmUI.Basic { public partial class CompareCurveParasListCtrl : DevExpress.XtraEditors.XtraUserControl { // 单位 protected Eventech.Model.UnitQ _unitQ = Eventech.Model.UnitQ.M3H; protected Eventech.Model.UnitH _unitH = Eventech.Model.UnitH.M; protected Eventech.Model.UnitP _unitP = Eventech.Model.UnitP.KW; protected Eventech.Model.UnitH _unitNPSH = Eventech.Model.UnitH.M; #region 构造函数和加载函数 public CompareCurveParasListCtrl() { InitializeComponent(); _unitP = Eventech.Model.UnitP.KW; _unitQ = Eventech.Model.UnitQ.M3H; _unitH = Eventech.Model.UnitH.M; this.Load += new System.EventHandler(this.OnFrmLoad); this.gridView1.SetNormalEditView(); } private void OnFrmLoad(object sender, EventArgs e) { this.gridView1.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel this.gridView1.OptionsSelection.MultiSelect = false;//单选 this.gridView1.OptionsBehavior.Editable = true;// this.gridView1.BestFitColumns(); //this.gridView1.IndicatorWidth = 45; this.gridView1.OptionsView.EnableAppearanceEvenRow = true; this.gridView1.OptionsView.EnableAppearanceOddRow = true; this.gridView1.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridView_RowClick); this.gridView1.CustomDrawCell += GridView_CustomDrawCell; this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanged); this.gridView1.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanging); this.gridView1.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridView_RowCellClick); this.gridControl1.DataSource = _bindList; //this.gridView1.BestFitColumns(); } #endregion 构造函数和加载函数 // internal class CurrentViewModel { public long ItemID { get; set; } public Color DispColor { set { _dispColor = value; } get { return _dispColor; } } private Color _dispColor = Color.Black; public string PumpName { get; set; } public string ProjectCode { get; set; } public string ProjectName { get; set; } public string PartCode { get; set; } public string TestTime { get; set; } public string PartName { get; set; } public string QueryPtQ { get; set; } public string QueryPtH { get; set; } public string QueryPtE { get; set; } public string QueryPtP { get; set; } } private BindingList _bindList = new BindingList(); public Action< IStation.Model.PumpCurve, Color> OnAddTestItem = null; public Action OnDeleteTestItem = null; public Action OnChangeColor = null; /// /// /// /// public void AddTestItem( string stationName, Model.Product pump, IStation.Model.PumpCurve pumpCurve) { foreach (var it in _bindList) { if (it.ItemID == pumpCurve.ID) { return; } } if (pumpCurve.CurveInfo == null || pumpCurve.CurveInfo.CurveQH == null) return; var curveInfo = pumpCurve.CurveInfo; if (curveInfo.CurveQH == null) return; var color = GetCurveColor(); if (OnAddTestItem != null) { OnAddTestItem(pumpCurve, color); } CurrentViewModel v = new CurrentViewModel(); v.PumpName = pump.Name; v.ItemID = pumpCurve.ID; v.DispColor = color; v.ProjectCode = pumpCurve.CurveCode; v.ProjectName = stationName; v.TestTime = pumpCurve.CreateTime.ToString("yyyy-MM-dd HH:mm"); v.PartCode = pump.ModelType; v.PartName = pump.Name; _bindList.Add(v); } private Color GetCurveColor() { for (int index = 0; index < 20; index++) { Color color = index < ColorArray.Count ? ColorArray[index] : GetRandomColor(); CurrentViewModel fff = null; foreach (var it in _bindList) if (it.DispColor == color) { fff = it; break; } if (fff == null) return color; } return Color.Black; } public int GetListCout() { return _bindList.Count; } public void ClearList() { _bindList.Clear(); } #region 获取曲线的随机颜色 private List ColorArray = new List() { Color.Red, Color.Blue, Color.Green, Color.DodgerBlue,Color.Fuchsia,Color.MidnightBlue,Color.Maroon, Color.Aquamarine, Color.Bisque ,Color.BurlyWood }; public Color GetRandomColor() { Random RandomNum_First = new Random((int)DateTime.Now.Ticks); int int_Red = RandomNum_First.Next(256); Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks); int int_Green = RandomNum_Sencond.Next(256); int int_Blue = RandomNum_Sencond.Next(256); return Color.FromArgb(int_Red, int_Green, int_Blue); } #endregion 获取曲线的随机颜色 public void SetQueryInfo(long id, Eventech.Model.GroupPoint queryPt) { if (queryPt == null || queryPt.Q < 0.1) return; var m = _bindList.First(x => x.ItemID == id); if (m == null) return; StringBuilder builder = new StringBuilder(); m.QueryPtQ = string.Format("{0} {1}", IStation.Common.RoundHelper.GetDispValueFlow(Eventech.Common.UnitQHelper.fromM3H(_unitQ, queryPt.Q)), Eventech.Common.UnitQHelper.GetEnUnitName(this._unitQ)); builder.AppendFormat("Q:{0} {1} ", IStation.Common.RoundHelper.GetDispValueFlow(Eventech.Common.UnitQHelper.fromM3H(_unitQ, queryPt.Q)), Eventech.Common.UnitQHelper.GetEnUnitName(this._unitQ)); m.QueryPtH = string.Format("{0} {1}", IStation.Common.RoundHelper.GetDispValueHead(Eventech.Common.UnitHHelper.fromM(_unitH, queryPt.H)), Eventech.Common.UnitHHelper.GetEnUnitName(this._unitH)); builder.AppendFormat(" H:{0} {1} ", IStation.Common.RoundHelper.GetDispValueHead(Eventech.Common.UnitHHelper.fromM(_unitH, queryPt.H)), Eventech.Common.UnitHHelper.GetEnUnitName(this._unitH)); if (queryPt.E > 0) { m.QueryPtE = string.Format("{0:N1} %", queryPt.E); builder.AppendFormat(" E:{0:N1}%", queryPt.E); } if (queryPt.P > 0) { m.QueryPtP = string.Format("{0} {1} ", IStation.Common.RoundHelper.GetDispValuePower( Eventech.Common.UnitPHelper.fromKW(_unitP, queryPt.P)), Eventech.Common.UnitPHelper.GetEnUnitName(this._unitP)); builder.AppendFormat(" P:{0} {1} ", IStation.Common.RoundHelper.GetDispValuePower( Eventech.Common.UnitPHelper.fromKW(_unitP, queryPt.P)), Eventech.Common.UnitPHelper.GetEnUnitName(this._unitP)); } this.gridControl1.RefreshDataSource(); } private void MenuItem删除Speed_Click(object sender, EventArgs e) { var m = this._bindList[_clickIndex]; if (null == m) { return; } this._bindList.RemoveAt(_clickIndex); if (OnDeleteTestItem != null) { OnDeleteTestItem(m.ItemID); } _clickIndex = 0; } #region GridView private void GridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { // if (e.Column == colDelete) // { // // var m = this._bindList[e.RowHandle]; // // e.Appearance.ForeColor = m.DispColor; // // if (m.IsOverRatedSpeed) // // { // // e.Appearance.BackColor = Color.PaleVioletRed; // // } //} //SpeedListItem colorItem = e.Item as SpeedListItem; //if (colorItem == null) // return; //e.Appearance.ForeColor = colorItem.DispColor; } private void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { //if (e.Value == null) // return; } private void GridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.Column == colColor) { var index = e.RowHandle; if (index < 0) return; var item = _bindList[index]; item.DispColor = (Color)e.Value; if (OnChangeColor != null) OnChangeColor(item.ItemID, item.DispColor); } } private void GridView_RowCellClick(object sender, RowCellClickEventArgs e) { if (e.Column == colDelete) { var m = this._bindList[e.RowHandle]; if (null == m) { return; } this._bindList.RemoveAt(e.RowHandle); if (OnDeleteTestItem != null) { OnDeleteTestItem(m.ItemID); } } } private int _clickIndex = 0; private void GridView_RowClick(object sender, RowClickEventArgs e) { if (e.RowHandle < 0) return; //gridViewPumpID = (gridView1.GetRow(e.RowHandle) as System.Data.DataRowView).Row.Field("PumpID"); if (e.Button == System.Windows.Forms.MouseButtons.Right) { //_clickViewModel = gridViewPump.GetRow(e.RowHandle) as IStation.XingHao.Part; //if (e.RowHandle > 0)//最大不用删除 { _clickIndex = e.RowHandle; multiSpeedMenuStrip.Show(gridControl1, e.Location); } } else { //SetRibbonButtonDisp(IStation.WinFrmUI.SeriesTreeView.eNodeLevel.Pump); } } #endregion GridView } }