using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Drawing; using System.Windows.Forms; using System.Data; namespace Mesnac.Controls.Feeding { [ToolboxBitmap(typeof(System.Windows.Forms.Label))] public partial class MixingStep : Label { private string _dataName; private DataTable _data; private DataTable _cloneData; //克隆数据源 private OnOffStatuses _finishStatus; private int _lengthMixer; private bool _isCurrent; private string _finishStatusName; private string _lengthMixerName; public MixingStep() { InitializeComponent(); } public MixingStep(IContainer container) { container.Add(this); InitializeComponent(); } /// /// 数据源动画属性 /// public string DataName { get { return _dataName; } set { _dataName = value; } } /// /// 一车结束标志动画属性 /// public string FinishStatusName { get { return _finishStatusName; } set { _finishStatusName = value; } } /// /// 当前步骤动画属性 /// public string LengthMixerName { get { return _lengthMixerName; } set { _lengthMixerName = value; } } /// /// 数据源 /// public DataTable Data { get { return _data; } set { _data = value; if (this._cloneData == null) { this.InitData(false); } } } public bool IsCurrent { get { return _isCurrent; } set { _isCurrent = value; } } /// /// 初始化数据 /// private void InitData(bool isclear) { if (isclear) { if (this._cloneData != null) { this._cloneData.Dispose(); this._cloneData = null; } } if (this._cloneData == null && this._data != null && this._data.Rows.Count > 0) { this._cloneData = new DataTable(); this._cloneData.Columns.Add("步骤", typeof(string)); this._cloneData.Columns.Add("动作", typeof(string)); int j = 1; for (int i = 0; i < this._data.Rows.Count; i++) { DataRow dr = this._cloneData.NewRow(); dr["步骤"] = this._data.Rows[i]["步骤"].ToString(); dr["动作"] = this._data.Rows[i]["动作"].ToString(); if (i + 1 == this._data.Rows.Count) { dr["步骤"] = j; this._cloneData.Rows.Add(dr); continue; } if (this._data.Rows[i + 1]["条件"].ToString().Trim() == "同时执行") { continue; } dr["步骤"] = j; this._cloneData.Rows.Add(dr); j++; } } } /// /// 当前步骤 /// public int LengthMixer { get { return _lengthMixer; } set { _lengthMixer = value; if (this._cloneData != null) { if (this._cloneData.Columns.Contains("步骤") && this._cloneData.Columns.Contains("动作")) { if (this._cloneData.Rows.Count > 0) { for (int i = 0; i < this._cloneData.Rows.Count; i++) { DataRow row = this._cloneData.Rows[i]; object val = row["步骤"]; if (val != DBNull.Value) { if (Convert.ToInt32(val) == this._lengthMixer) { if (IsCurrent) this.Text = row["动作"].ToString(); else { if ((i + 1) == this._cloneData.Rows.Count) this.Text = ""; else this.Text = this._cloneData.Rows[i + 1]["动作"].ToString(); } break; } } } if (!IsCurrent && _lengthMixer == 0) { this.Text = this._cloneData.Rows[0]["动作"].ToString(); } } } } } } /// /// 一车结束标志 /// public OnOffStatuses FinishStatus { get { return _finishStatus; } set { if ((int)value > 1) { this._finishStatus = OnOffStatuses.On; } else if ((int)value < 0) { this._finishStatus = OnOffStatuses.Off; } else { this._finishStatus = value; } //如果一车标志结束,则重新绑定数据源 if (this._finishStatus == OnOffStatuses.On) { this.InitData(true); } } } } }