using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
///
/// 自定义3阀门
///
public partial class ThreeWayValve : ChemicalWeighingControl
{
private object lockobj = new object();
public ThreeWayValve()
{
InitializeComponent();
InitControl();
}
private string[] sImages = new String[7];
private bool _zltValue;
private bool _zldValue;
private bool _almtValue;
private bool _almdValue;
///
/// 杨威
/// 20230629
/// 初始化控件
///
private void InitControl()
{
_assembly = Assembly.GetExecutingAssembly();
//默认程序
sImages[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve0.png";
//直通
sImages[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve1.png";
//斜通
sImages[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve2.png";
//直通报警通知
sImages[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveHError.png";
//斜通报警通知
sImages[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveVError.png";
//都报警
sImages[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveHVError.png";
//三个都通
sImages[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveAll.png";
}
private void ReloadStream()
{
int defaultIndex = 0;
//如果出现报警 就去判断是直还是斜
//直报警 斜报警
if (_almtValue && _almdValue)
{
defaultIndex = 5;
}
else
{
//如果直的报警
if (_almdValue && _almtValue == false)
{
defaultIndex = 3;
}
//如果斜的报警
if (_almtValue && _almdValue == false)
{
defaultIndex = 4;
}
}
//如果不是故障
if (_almtValue == false && _almdValue == false)
{
if (_zltValue && _zldValue == false)
{
defaultIndex = 2;
}
if (_zltValue == false && _zldValue)
{
defaultIndex = 1;
}
//如果都是假 就变成默认值 可能没有数据
if (_zltValue == false && _zldValue == false)
{
defaultIndex = 0;
}
//如果都是真 就是双通
if (_zltValue && _zldValue)
{
defaultIndex = 6;
}
}
_imageStream = _assembly.GetManifestResourceStream(sImages[defaultIndex]);
}
private void Reload()
{
if ( _imageStream != null )
{
Image img = Image.FromStream( _imageStream);
pictureBox1.Image = img;
pictureBox1.Refresh();
}
}
private void R()
{
lock (lockobj)
{
ReloadStream();
Reload();
}
}
///
/// 斜通到位存储Plc的Name
///
public string ZLTName { get; set; }
///
/// 斜通到位数据
///
public bool ZLTValue
{
get => _zltValue;
set
{
if(_zltValue != value) {
_zltValue = value;
R();
}
}
}
///
/// 直通到位Plc的Name
///
public string ZLDName { get; set; }
///
/// 直通到位Plc的Value
///
public bool ZLDValue
{
get => _zldValue;
set
{
if( _zldValue != value ) {
_zldValue = value;
R();
}
}
}
///
/// 协通报警
///
public string ALMTName { get; set;}
///
/// 协通报警Value
///
public bool ALMTValue
{
get => _almtValue;
set
{
if( _almtValue != value ) {
_almtValue = value;
R();
}
}
}
///
/// 直通报警
///
public string ALMDName { get; set; }
///
/// 直通报警Value
///
public bool ALMDValue
{
get => _almdValue;
set
{
if( _almdValue != value ) {
_almdValue = value;
R();
}
}
}
}
}