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/CBWeight.cs

267 lines
7.9 KiB
C#

using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace Mesnac.Controls.Feeding
{
/// <summary>
/// 炭黑秤
/// </summary>
[ToolboxBitmap( typeof( CBWeight ) , "ICONS.CBIMWeight.bmp" )]//新添加的代码
public partial class CBWeight : FeedingControl
{
bool bNewPic = false;
string _statusName;
private string _actOutStatusName;
private OnOffStatuses _actOutStatus;
private double _setValue = 1;
private double _weightValue;
private string _setValueName;
private string _weightValueName;
public enum Statuses
{
ssNull = 0,
ssValue1 = 1, ssValue2 = 2, ssValue3 = 3, ssValue4 = 4, ssValue5 = 5,
ssValue6 = 6, ssValue7 = 7, ssValue8 = 8, ssValue9 = 9, ssValue10 = 10,
ssValue11 = 11, ssValue12 = 12, ssValue13 = 13, ssValue14 = 14, ssValue15 = 15,
ssUnload = 16, ssWeight = 17, ssFull = 18, ssAlarm = 19,
}
Statuses _status;
string[] sImages;
public CBWeight():base()
{
InitializeComponent();
Init();
ReloadStream();
this.Reload();
}
protected override void Init()
{
base.Init();
_imageStream = null;
sImages = new string[ 20 ];
sImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.thc.thc00.png";//
sImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.thc.thc05.png";//
sImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.thc.thc06.png";//
sImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.thc.thc07.png";//
sImages[ 4 ] = "Mesnac.Controls.Feeding.Resources.thc.thc08.png";//
sImages[ 5 ] = "Mesnac.Controls.Feeding.Resources.thc.thc09.png";//
sImages[ 6 ] = "Mesnac.Controls.Feeding.Resources.thc.thc10.png";//
sImages[ 7 ] = "Mesnac.Controls.Feeding.Resources.thc.thc11.png";//
sImages[ 8 ] = "Mesnac.Controls.Feeding.Resources.thc.thc12.png";//
sImages[ 9 ] = "Mesnac.Controls.Feeding.Resources.thc.thc13.png";//
sImages[ 10 ] = "Mesnac.Controls.Feeding.Resources.thc.thc14.png";//
sImages[ 11 ] = "Mesnac.Controls.Feeding.Resources.thc.thc15.png";//
sImages[ 12 ] = "Mesnac.Controls.Feeding.Resources.thc.thc16.png";//
sImages[ 13 ] = "Mesnac.Controls.Feeding.Resources.thc.thc17.png";//
sImages[ 14 ] = "Mesnac.Controls.Feeding.Resources.thc.thc18.png";//
sImages[ 15 ] = "Mesnac.Controls.Feeding.Resources.thc.thc19.png";//
//sImages[ 16 ] = "Mesnac.Controls.Feeding.Resources.thc.thc03.png";//
sImages[ 16 ] = "Mesnac.Controls.Feeding.Resources.thc.thc_unload.gif";
sImages[ 17 ] = "Mesnac.Controls.Feeding.Resources.thc.thc01.png";//
sImages[ 18 ] = "Mesnac.Controls.Feeding.Resources.thc.thc02.png";//
sImages[ 19 ] = "Mesnac.Controls.Feeding.Resources.thc.thc04.png";//
_status = Statuses.ssValue8;
}
private void ReloadStream()
{
//CloseStream();
int nIndex = (int)_status;
_imageStream = _assembly.GetManifestResourceStream(sImages[nIndex]);
}
public Statuses Status
{
get
{
return _status;
}
set
{
if (bFirstCreated == true)
{
bFirstCreated = false;
}
bool flag = false;
//if (_status != value &&(this.Size.Width != 150 || this.Size.Height != 150) )
if (_status != value)
{
flag = true;
if (this.DesignMode == true)
{
bNewPic = true;
}
}
if ( (int)value < 0 )
{
_status = (Statuses)0;
}
else if ( (int)value > 19 )
{
_status = (Statuses)19;
}
else
{
_status = value;
}
if (flag)
{
ReloadStream();
this.Reload();
}
}
}
protected void Reload()
{
if (_imageStream != null)
{
Image img = Image.FromStream(_imageStream);
if (bNewPic == true)
{
this.Size = img.Size;
bNewPic = false;
}
this.pictureBox1.Image = img;
this.pictureBox1.Refresh();
}
}
private void CBWeight_Load(object sender, EventArgs e)
{
if (bFirstCreated == true && this.DesignMode == true)
{
bNewPic = true;
bFirstCreated = false;
}
}
#region 卸料状态
/// <summary>
/// 卸料动画属性
/// </summary>
public string ActOutStatusName
{
get { return _actOutStatusName; }
set { _actOutStatusName = value; }
}
/// <summary>
/// 卸料状态
/// </summary>
public OnOffStatuses ActOutStatus
{
get { return _actOutStatus; }
set
{
if ((int)value > 1)
{
this._actOutStatus = OnOffStatuses.On;
}
else if ((int)value < 0)
{
this._actOutStatus = OnOffStatuses.Off;
}
else
{
this._actOutStatus = value;
}
if (this._actOutStatus == OnOffStatuses.On)
{
this._status = Statuses.ssUnload;
}
else
{
this._status = Statuses.ssNull;
}
ReloadStream();
this.Reload();
}
}
#endregion
#region 称量值与设定值
/// <summary>
/// 设定值动画属性
/// </summary>
public string SetValueName
{
get { return _setValueName; }
set { _setValueName = value; }
}
/// <summary>
/// 称量值动画属性
/// </summary>
public string WeightValueName
{
get { return _weightValueName; }
set { _weightValueName = value; }
}
/// <summary>
/// 设定值
/// </summary>
public double SetValue
{
get { return _setValue; }
set
{
_setValue = value;
if (this._setValue == 0)
{
this._setValue = 1;
}
this.Status = (Statuses)Math.Floor((this._weightValue * 15) / this._setValue);
ReloadStream();
this.Reload();
}
}
/// <summary>
/// 称量值
/// </summary>
public double WeightValue
{
get { return _weightValue; }
set
{
_weightValue = value;
if (this._weightValue > this._setValue)
{
this._weightValue = this._setValue;
}
this.Status = (Statuses)(Math.Floor((this._weightValue * 15) / this._setValue) == 0 && this._weightValue > 0.0 ? 1 : Math.Floor((this._weightValue * 15) / this._setValue));
ReloadStream();
this.Reload();
}
}
#endregion
}
}