You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Controls/Mesnac.Controls.Feeding/Mixer2.cs

687 lines
20 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Mesnac.Controls.Base;
using System.Collections.Generic;
namespace Mesnac.Controls.Feeding
{
/// <summary>
/// 密炼机
/// </summary>
[ToolboxBitmap( typeof( Mixer2 ) , "ICONS.mixer.bmp" )]//新添加的代码
public partial class Mixer2 : FeedingControl
{
#region 事件定义
/// <summary>
/// 报警事件
/// </summary>
public event EventHandler OnAlarm;
#endregion
#region 事件属性
private List<DesignAction> _alarmActionList = new List<DesignAction>();
public List<DesignAction> AlarmActionList
{
get { return _alarmActionList; }
set { _alarmActionList = value; }
}
#endregion
#region 报警
private string _sdsAlarmValue;
private string _sdsAlarmValue_;
private string _jlmAlarmValue;
private string _jlmAlarmValue_;
private string _xlmAlarmValue;
private string _xlmAlarmValue_;
/// <summary>
/// 上顶栓报警信息属性
/// </summary>
public string SdsAlarmValue
{
get { return _sdsAlarmValue; }
set { _sdsAlarmValue = value; }
}
/// <summary>
/// 上顶栓报警信息
/// </summary>
[Alarm]
public string SdsAlarmValue_
{
get { return _sdsAlarmValue_; }
set { _sdsAlarmValue_ = value; }
}
/// <summary>
/// 加料门报警信息属性
/// </summary>
public string JlmAlarmValue
{
get { return _jlmAlarmValue; }
set { _jlmAlarmValue = value; }
}
/// <summary>
/// 加料门报警信息
/// </summary>
[Alarm]
public string JlmAlarmValue_
{
get { return _jlmAlarmValue_; }
set { _jlmAlarmValue_ = value; }
}
/// <summary>
/// 卸料门报警信息属性
/// </summary>
public string XlmAlarmValue
{
get { return _xlmAlarmValue; }
set { _xlmAlarmValue = value; }
}
/// <summary>
/// 卸料门报警信息
/// </summary>
[Alarm]
public string XlmAlarmValue_
{
get { return _xlmAlarmValue_; }
set { _xlmAlarmValue_ = value; }
}
#endregion
#region 枚举
/// <summary>
/// 上顶栓设备状态
/// </summary>
public enum SdsDeviceStatuses
{
Off = 0,
On = 1
}
/// <summary>
/// 上顶栓图画状态
/// </summary>
public enum sdsStatuses
{
sdsUp = 0, sdsMid = 1, sdsDown = 2, sdsAlarm = 3
//sdsUp = 0, sdsMid = 1, sdsDown = 2
}
public enum jlmStatuses
{
jlmClose = 0, jlmOpen = 1, jlmAlarm = 3
}
public enum mixerStatuses
{
//mixerOn = 0, mixerOff = 1
mixerOff = 0, mixerOn = 1
}
public enum xlmStatuses
{
//xlmAlarm = 0, xlmClose = 1, xlmNormal = 2, xlmOpen = 3
xlmClose = 0, xlmOpen = 1, xlmAlarm = 2
}
#endregion
#region 定义变量
Stream _sdsImageStream;
Stream _jlmImageStream;
Stream _mixerImageStream;
Stream _xlmImageStream;
sdsStatuses _sdsStatus;
jlmStatuses _jlmStatus;
mixerStatuses _mixerStatus;
xlmStatuses _xlmStatus;
string[] sdsImages, jlmImages, mixerImages, xlmImages;
//bool bNewPic = false;
bool bFirstCreatedsds = true;
bool bFirstCreatedjlm = true;
bool bFirstCreatedmixer = true;
bool bFirstCreatedxlm = true;
string _sdsStatusName;
private string _sdsUpStatusName;
private string _sdsMiddleStatusName;
private string _sdsDownStatusName;
private SdsDeviceStatuses _sdsUpStatus;
private SdsDeviceStatuses _sdsMiddleStatus;
private SdsDeviceStatuses _sdsDownStatus;
string _jlmStatusName;
string _mixerStatusName;
string _xlmStatusName;
#endregion
#region 属性
/// <summary>
/// 上顶栓高位动画属性
/// </summary>
public string SdsUpStatusName
{
get { return this._sdsUpStatusName; }
set { this._sdsUpStatusName = value; }
}
/// <summary>
/// 上顶栓中位动画属性
/// </summary>
public string SdsMiddleStatusName
{
get { return this._sdsMiddleStatusName; }
set { this._sdsMiddleStatusName = value; }
}
/// <summary>
/// 上顶栓低位动画属性
/// </summary>
public string SdsDownStatusName
{
get { return this._sdsDownStatusName; }
set { this._sdsDownStatusName = value; }
}
/// <summary>
/// 上顶栓高位状态0,1
/// </summary>
public SdsDeviceStatuses SdsUpStatus
{
get { return this._sdsUpStatus; }
set
{
bool flag = false;
if (this._sdsUpStatus != value)
flag = true;
if ((int)value > 1)
{
this._sdsUpStatus = SdsDeviceStatuses.On;
}
else if ((int)value < 0)
{
this._sdsUpStatus = SdsDeviceStatuses.Off;
}
else
{
this._sdsUpStatus = value;
}
if (flag)
this.UpdateSdsStatus();
}
}
/// <summary>
/// 上顶栓中位状态0,1
/// </summary>
public SdsDeviceStatuses SdsMiddleStatus
{
get { return this._sdsMiddleStatus; }
set
{
bool flag = false;
if (this._sdsMiddleStatus != value)
flag = true;
if ((int)value > 1)
{
this._sdsMiddleStatus = SdsDeviceStatuses.On;
}
else if ((int)value < 0)
{
this._sdsMiddleStatus = SdsDeviceStatuses.Off;
}
else
{
this._sdsMiddleStatus = value;
}
if (flag)
this.UpdateSdsStatus();
}
}
/// <summary>
/// 上顶栓低位状态0,1
/// </summary>
public SdsDeviceStatuses SdsDownStatus
{
get { return this._sdsDownStatus; }
set
{
bool flag = false;
if (this._sdsDownStatus != value)
flag = true;
if ((int)value > 1)
{
this._sdsDownStatus = SdsDeviceStatuses.On;
}
else if ((int)value < 0)
{
this._sdsDownStatus = SdsDeviceStatuses.Off;
}
else
{
this._sdsDownStatus = value;
}
if (flag)
this.UpdateSdsStatus();
}
}
/// <summary>
/// 更新上顶栓状态
/// </summary>
private void UpdateSdsStatus()
{
if (this._sdsUpStatus == SdsDeviceStatuses.On)
{
this.sdsStatus = sdsStatuses.sdsUp;
}
else if (this._sdsDownStatus == SdsDeviceStatuses.On)
{
this.sdsStatus = sdsStatuses.sdsDown;
}
else
{
this.sdsStatus = sdsStatuses.sdsMid;
}
ReloadStream(1);
this.Reload(1);
}
public string jlmStatusName
{
get
{
return _jlmStatusName;
}
set
{
_jlmStatusName = value;
}
}
public string mixerStatusName
{
get
{
return _mixerStatusName;
}
set
{
_mixerStatusName = value;
}
}
public string xlmStatusName
{
get
{
return _xlmStatusName;
}
set
{
_xlmStatusName = value;
}
}
public sdsStatuses sdsStatus
{
get
{
return _sdsStatus;
}
set
{
if ( bFirstCreatedsds == true )
{
bFirstCreatedsds = false;
}
bool flag = false;
if (_sdsStatus != value)
{
flag = true;
}
if ( (int)value < 0 )
{
_sdsStatus = (sdsStatuses)0;
}
else if ( (int)value > 3 )
{
_sdsStatus = (sdsStatuses)3;
}
else
{
_sdsStatus = value;
}
if (flag)
{
ReloadStream(1);
this.Reload(1);
if (_sdsStatus == sdsStatuses.sdsAlarm)
{
this._sdsAlarmValue_ = this._sdsAlarmValue; //设置报警信息
}
else
{
this._sdsAlarmValue_ = String.Empty; //清空报警信息
}
//有事件订阅者,则触发报警事件
if (OnAlarm != null)
{
OnAlarm(this, System.EventArgs.Empty);
}
}
}
}
public jlmStatuses jlmStatus
{
get
{
return _jlmStatus;
}
set
{
if ( bFirstCreatedjlm == true )
{
bFirstCreatedjlm = false;
}
bool flag = false;
if (_jlmStatus != value)
{
flag = true;
}
if ( (int)value < 0 )
{
_jlmStatus = (jlmStatuses)0;
}
else if ( (int)value > 2 )
{
_jlmStatus = (jlmStatuses)2;
}
else
{
_jlmStatus = value;
}
if (flag)
{
ReloadStream(2);
this.Reload(2);
if (_jlmStatus == jlmStatuses.jlmAlarm)
{
this._jlmAlarmValue_ = this._jlmAlarmValue; //设置报警信息
}
else
{
this._jlmAlarmValue_ = String.Empty; //清空报警信息
}
//有事件订阅者,则触发报警事件
if (OnAlarm != null)
{
OnAlarm(this, System.EventArgs.Empty);
}
}
}
}
public mixerStatuses mixerStatus
{
get
{
return _mixerStatus;
}
set
{
if ( bFirstCreatedmixer == true )
{
bFirstCreatedmixer = false;
}
bool flag = false;
if (_mixerStatus != value)
{
flag = true;
}
if ( (int)value < 0 )
{
_mixerStatus = (mixerStatuses)0;
}
else if ( (int)value > 1 )
{
_mixerStatus = (mixerStatuses)1;
}
else
{
_mixerStatus = value;
}
if (flag)
{
ReloadStream(3);
this.Reload(3);
}
}
}
public xlmStatuses xlmStatus
{
get
{
return _xlmStatus;
}
set
{
if ( bFirstCreatedxlm == true )
{
bFirstCreatedxlm = false;
}
bool flag = false;
if (_xlmStatus != value)
{
flag = true;
}
if ( (int)value < 0 )
{
_xlmStatus = (xlmStatuses)0;
}
else if ( (int)value > 3 )
{
_xlmStatus = (xlmStatuses)3;
}
else
{
_xlmStatus = value;
}
if (flag)
{
ReloadStream(4);
this.Reload(4);
if (_xlmStatus == xlmStatuses.xlmAlarm)
{
this._xlmAlarmValue_ = this._xlmAlarmValue; //设置报警信息
}
else
{
this._xlmAlarmValue_ = String.Empty; //清空报警信息
}
//有事件订阅者,则触发报警事件
if (OnAlarm != null)
{
OnAlarm(this, System.EventArgs.Empty);
}
}
}
}
#endregion
public Mixer2():base()
{
InitializeComponent();
Init();
ReloadStream(1);
ReloadStream(2);
ReloadStream(3);
ReloadStream(4);
this.Reload(1);
this.Reload(2);
this.Reload(3);
this.Reload(4);
}
protected override void Init()
{
base.Init();
_sdsImageStream = null;
_jlmImageStream = null;
_mixerImageStream = null;
_xlmImageStream = null;
sdsImages = new string[ 4 ];
sdsImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.mixer.sds0.png";//sdsUp
sdsImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.mixer.sds1.png";//sdsMid
sdsImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.mixer.sds2.png";//sdsDown
sdsImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.mixer.sds3.gif";//sdsAlarm
jlmImages = new string[ 5 ];
jlmImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.mixer.jlm0.png";//jlmClose
jlmImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.mixer.jlm3.png";//jlmOpen
jlmImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.mixer.jlm1.png";//jlmCloseAlarm
jlmImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.mixer.jlm2.gif";//jlmNormal
jlmImages[ 4 ] = "Mesnac.Controls.Feeding.Resources.mixer.jlm4.png";//jlmOpenAlarm
mixerImages = new string[ 2 ];
mixerImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.mixer.mixer1.png";//mixerOff
mixerImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.mixer.mixer0.gif";//mixerOn
xlmImages = new string[ 4 ];
xlmImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.mixer.xlm1.png";//xlmClose
xlmImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.mixer.xlm3.png";//xlmOpen
xlmImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.mixer.xlm0.gif";//xlmAlarm
xlmImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.mixer.xlm2.gif";//xlmNormal
_sdsStatus = sdsStatuses.sdsUp;
_jlmStatus = jlmStatuses.jlmOpen;
_mixerStatus = mixerStatuses.mixerOn;
_xlmStatus = xlmStatuses.xlmClose;
}
/// <summary>
/// 重新载入图片流
/// </summary>
/// <param name="part">1-上顶栓2-加料门3-密炼机4-卸料门</param>
private void ReloadStream(int part)
{
//closeAllStream();
int nIndex = 0;
switch (part)
{
case 1:
nIndex = (int)_sdsStatus;
_sdsImageStream = _assembly.GetManifestResourceStream(sdsImages[nIndex]);
break;
case 2:
nIndex = (int)_jlmStatus;
_jlmImageStream = _assembly.GetManifestResourceStream(jlmImages[nIndex]);
break;
case 3:
nIndex = (int)_mixerStatus;
_mixerImageStream = _assembly.GetManifestResourceStream(mixerImages[nIndex]);
break;
case 4:
nIndex = (int)_xlmStatus;
_xlmImageStream = _assembly.GetManifestResourceStream(xlmImages[nIndex]);
break;
default:
return;
}
}
/// <summary>
/// 刷新图片
/// </summary>
/// <param name="part">1-上顶栓2-加料门3-密炼机4-卸料门</param>
private void Reload(int part)
{
switch (part)
{
case 1:
if (_sdsImageStream != null)
{
Image img = Image.FromStream(_sdsImageStream);
//if ( bNewPic == true )
//{
//this.Size = img.Size;
// bNewPic = false;
//}
pictureBox1.Image = img;
pictureBox1.Refresh();
}
break;
case 2:
if (_jlmImageStream != null)
{
Image img = Image.FromStream(_jlmImageStream);
//if ( bNewPic == true )
//{
//this.Size = img.Size;
// bNewPic = false;
//}
pictureBox2.Image = img;
pictureBox2.Refresh();
}
break;
case 3:
if (_mixerImageStream != null)
{
Image img = Image.FromStream(_mixerImageStream);
//if ( bNewPic == true )
//{
//this.Size = img.Size;
// bNewPic = false;
//}
pictureBox3.Image = img;
pictureBox3.Refresh();
}
break;
case 4:
if (_xlmImageStream != null)
{
Image img = Image.FromStream(_xlmImageStream);
//if ( bNewPic == true )
//{
//this.Size = img.Size;
// bNewPic = false;
//}
pictureBox4.Image = img;
pictureBox4.Refresh();
}
break;
default:
return;
}
}
private void Mixer_Load(object sender, EventArgs e)
{
if ( this.DesignMode )
{
if ( bFirstCreatedsds )
{
//bNewPic = true;
this.ReloadStream(1);
this.ReloadStream(2);
this.ReloadStream(3);
this.ReloadStream(4);
this.Reload(1);
this.Reload(2);
this.Reload(3);
this.Reload(4);
}
bFirstCreatedsds = false;
bFirstCreatedjlm = false;
bFirstCreatedmixer = false;
bFirstCreatedxlm = false;
}
}
}
}