using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Common; using IntelligentControlForsx.Service; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; namespace IntelligentControlForsx.MyControls { public partial class MatrixDevice4 : UserControl { public MatrixDevice4() { SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.   SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲   InitializeComponent(); toolTip1.SetToolTip(this.btnTip, " "); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.   SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲   } protected override void WndProc(ref Message m) { if (m.Msg == 0x0014) // 禁掉清除背景消息 return; base.WndProc(ref m); } string deviceId; string deviceModel; string stationId; double windSpeed; double power; double status; bool isLock; long ts; [Browsable(true), Category("Data")] public string DeviceId { get { return deviceId; } set { deviceId = value; lblDeviceId.Text = value; } } [Browsable(true), Category("Data")] public double WindSpeed { get { return windSpeed; } set { windSpeed = value; lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00") + "m/s"; } } [Browsable(true), Category("Data")] public double Power { get { return power; } set { power = value; lblPower.Text = Convert.ToDouble(value).ToString("0.00") + "kw"; } } [Browsable(true), Category("Data")] public double Status { get { return status; } set { status = value; this.BackColor = getBackColor(value); this.pTop.BackColor = getBackColor(value); } } public bool IsLock { set { if (value) this.pBack.BackColor = Color.Yellow; else this.pBack.BackColor = pTop.BackColor; isLock = value; } get { return isLock; } } private double lokcValue; public double LockValue { get { return lokcValue; } set { lokcValue = value; } } public string DeviceModel { get { return deviceModel; } set { deviceModel = value; } } public string StationId { get { return stationId; } set { stationId = value; } } public long Ts { get { return ts; } set { ts = value; } } private Color getBackColor(double status) { int st = Convert.ToInt32(status); switch (st) { //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS case 0: //停机状态 return Color.FromArgb(176, 151, 63); case 1: //上电状态 return Color.FromArgb(177, 14, 126); case 2: //待机状态 return Color.FromArgb(15, 141, 106); case 3: //启动状态 return Color.FromArgb(14, 72, 91); case 4: //并网状态 return Color.FromArgb(15, 135, 170); case 5: //故障状态 return Color.FromArgb(170, 15, 59); case 6: //维护状态 return Color.FromArgb(204, 83, 51); case 7: //离线状态 return Color.FromArgb(134, 150, 165); default: return Color.Black; //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3 //case 5: //case 1: // return Color.FromArgb(0, 153, 204); //case 0: // return Color.FromArgb(51, 153, 51); //case 4: // return Color.FromArgb(255, 102, 0); //case 2: // return Color.FromArgb(204, 51, 51); //case 3: // return Color.FromArgb(153, 153, 153); //default: // return Color.FromArgb(153, 153, 153); } } public bool testShow(double status1, bool autoFilter, double minSpeed = 0, double maxSpeed = 0, double minPower = 0, double maxPower = 0) { bool result = true; if (status1 == 9) { if (autoFilter) { if (minSpeed != 0 || maxSpeed != 0) { if (minPower == 0 && maxPower == 0) { if (windSpeed >= minSpeed && windSpeed <= maxSpeed) result = true; else result = false; } else { if (windSpeed >= minSpeed && windSpeed <= maxSpeed && power >= minPower && power <= maxPower) result = true; else result = false; } } else { if (power >= minPower && power <= maxPower) result = true; else result = false; } } } else if (status1 == status) { if (autoFilter) { if (windSpeed >= minSpeed && windSpeed <= maxSpeed && power >= minPower && power <= maxPower) result = true; else result = false; } } else { result = false; } return result; } private Rectangle dragBoxFromMouseDown; private void lblDeviceId_MouseDown(object sender, MouseEventArgs e) { //记录鼠标按下位置,DragSize获取以鼠标按钮的按下点为中心的矩形的宽度和高度,在该矩形内不会开始拖动操作。 Size dragSize = SystemInformation.DragSize; //创建一个矩形区域(正方形)。以鼠标按下电为中心,以DragSize为高和宽的矩形。 dragBoxFromMouseDown = new Rectangle(new System.Drawing.Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize); } private void lblDeviceId_MouseMove(object sender, MouseEventArgs e) { //如果鼠标位置在拖动矩形之外(就可以开始拖动了) if (dragBoxFromMouseDown != Rectangle.Empty && !dragBoxFromMouseDown.Contains(e.X, e.Y)) { //传递ListBox选中项并触发DoDragDrop事件(这里可以是ListDragSoure触发,也可以是ListDragTarget) //DoDragDrop 方法确定当前光标位置下的控件。然后它将检查该控件是否是有效的放置目标。 DragDropEffects dropEffect = this.DoDragDrop(this.deviceId, DragDropEffects.All | DragDropEffects.Link); //if (dropEffect == DragDropEffects.Move) //{ //} } } private void toolTip1_Popup(object sender, PopupEventArgs e) { System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); //messageBoxCS.Append(this.deviceId); //messageBoxCS.AppendLine(); //messageBoxCS.AppendFormat("当前状态:{0}", getStatusName(this.status)); //messageBoxCS.AppendLine(); //messageBoxCS.AppendFormat("开始时间:{0}, 时长 {1}分钟。", getBeginTime(this.ts)); //messageBoxCS.AppendLine(); //messageBoxCS.AppendFormat("\r\n持续时长:{0}分钟", getTimeSpan(this.ts)); //messageBoxCS.AppendLine(); //MessageBox.Show(messageBoxCS.ToString()); string hungString = ""; if (this.lokcValue != 0.0) { hungString = "挂牌原因:"; HungType type = (HungType)Convert.ToInt32(this.lokcValue); switch (type) { case HungType.CheckLock: hungString = hungString + "检修"; break; case HungType.FaultLock: hungString = hungString + "故障维修"; break; case HungType.StationCheckLock: hungString = hungString + "场内受累检修"; break; case HungType.StationFaulLockt: hungString = hungString + "场内受累故障"; break; case HungType.StationPowerLineLock: hungString = hungString + "场外受累电网"; break; case HungType.StationWeatherLock: hungString = hungString + "场外受累天气"; break; } } StringBuilder sb = new StringBuilder(); string toolString1 = String.Format("开始时间:{0}, 时长 {1}分钟\r\n", getBeginTime(this.ts), getTimeSpan(this.ts)); this.toolTip1.ToolTipTitle = toolString1 + Environment.NewLine + "\r\n " + hungString; } private string getStatusName(double status) { int st = Convert.ToInt32(status); switch (st) { //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS case 0: //停机状态 return "停机"; case 1: //上电状态 return "上电"; case 2: //待机状态 return "待机"; case 3: //启动状态 return "启动"; case 4: //并网状态 return "并网"; case 5: //故障状态 return "故障"; case 6: //维护状态 return "维护"; case 7: //离线状态 return "离线"; default: return "未知"; } } private string getBeginTime(long ts) { if (ts < 10000) return ""; DateTime dt = CommonMethod.ConvertIntDateTime(ts); return dt.ToString("yyyy-MM-dd hh:mm:ss"); } private string getTimeSpan(long ts) { if (ts < 10000) return ""; DateTime dt = CommonMethod.ConvertIntDateTime(ts); TimeSpan tts = DateTime.Now - dt; return (long)tts.TotalMinutes + ""; } private void MatrixDevice3_MouseDoubleClick(object sender, MouseEventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; MessageBox.Show("双击事件" + windturbineId + "||" + powerStationId); } private void lblDeviceId_MouseDoubleClick(object sender, MouseEventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId); } private void lblWindSpeed_MouseDoubleClick(object sender, MouseEventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId); } private void lblPower_MouseDoubleClick(object sender, MouseEventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId); } private void pTop_MouseDoubleClick(object sender, MouseEventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId); } } }