using System;
using System.Drawing;
using System.Windows.Forms;
using Core.StlMes.Client.LgClassModel;
namespace Core.StlMes.Client.LgCommon
{
public partial class frmManualOperate : Form
{
private string _DEVICE_POSITION = ""; //设备位置:BOF01
private string _OBJECTPOS = ""; //当前工位:BOF01_DEVICE
private CommandCollection _CC; //当前岗位手动操作配置集合
private COM_STL_COMMAND _csc; //返回选中的手动操作
///
/// COM_STL_COMMAND%ROWTYPE
///
public COM_STL_COMMAND CSC
{
get { return _csc; }
}
///
/// 构造函数
///
/// 设备位置:BOF01
/// 当前工位:BOF01_DEVICE
/// 当前岗位手动操作配置集合
///
public frmManualOperate(string DEVICE_POSITION, string OBJECTPOS, CommandCollection CC)
{
InitializeComponent();
this._DEVICE_POSITION = DEVICE_POSITION.ToUpper();
this._OBJECTPOS = OBJECTPOS.ToUpper();
this._CC = CC;
}
private void frmManualOperate_Load(object sender, EventArgs e)
{
InitUnitItems();
AdjustForm();
}
///
/// 初始化操作配置
///
private void InitUnitItems()
{
try
{
if (_CC != null)
{
COM_STL_COMMAND csc;
for (int i = 0; i < _CC.Count; i++)
{
csc = _CC[i];
if (csc == null) continue;
if (_OBJECTPOS.Equals(csc.OBJECTPOS)) continue; //当前设备位置与目标位置一致
if (_OBJECTPOS.Equals(csc.OBJECTPOS.Replace("%", _DEVICE_POSITION))) continue; //当前设备位置与目标位置一致
if (csc.OPTTYPE == "2" && csc.OBJECTPOS.IndexOf(_DEVICE_POSITION) == 0) continue; //所处岗位与目标岗位一致
if (_OBJECTPOS.Contains("IDLE") && csc.VISIBLE_IDLE != "1") continue;
if (_OBJECTPOS.Contains("FRONT") && csc.VISIBLE_FRONT != "1") continue;
if (_OBJECTPOS.Contains("DEVICE") && csc.VISIBLE_DEVICE != "1") continue;
if (_OBJECTPOS.Contains("BACK") && csc.VISIBLE_BACK != "1") continue;
if (csc.OPTTYPE == "1") unit_Normal.Add(csc);
else if (csc.OPTTYPE == "2") unit_Abnormal.Add(csc);
else if (csc.OPTTYPE == "3") unit_Switch.Add(csc);
}
}
}
catch { }
}
private void AdjustForm()
{
try
{
unit_Switch.Visible = unit_Switch.Count > 0;
bool Hidden = (unit_Abnormal.Count == 0 && unit_Switch.Count == 0);
panel2.Visible = !Hidden;
if (Hidden)
{
Size iSize = panel2.Size;
Point point = btnOK.Location;
point.Offset(0, 0 - iSize.Height);
btnOK.Location = point;
point = btnCancel.Location;
point.Offset(0, 0 - iSize.Height);
btnCancel.Location = point;
point = new Point(panel1.Size);
point.Offset(0, 0 - iSize.Height);
panel1.Size = new Size(point);
point = new Point(this.Size);
point.Offset(0, 0 - iSize.Height);
this.Size = new Size(point);
}
}
catch { }
finally
{
ClsControlPack.GetChildWindowLocation(this.Size);
}
}
private COM_STL_COMMAND GetSelection()
{
if (unit_Normal.Value != null) return unit_Normal.Value;
else if (unit_Abnormal.Value != null) return unit_Abnormal.Value;
else if (unit_Switch.Value != null) return unit_Switch.Value;
else return null;
}
private void btnOK_Click(object sender, EventArgs e)
{
_csc = GetSelection();
if (_csc == null)
{
MessageBox.Show("未选择任何操作!\n如需退出,请点击【退出】按钮。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}