using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ICommLayer; using CommLayerFactory; namespace ControlSystem { /// /// Creator:Richard.liu and Jack.Ma /// 设备实时状态显示 /// public partial class FrmDeviceStatus : Form { #region 变量定义 Model.MDevice _device = null; int _deviceIndex; ISendDeviceOrder sdo; CCommonFunction ccf = new CCommonFunction(); DBFactory.DBOperator dbo = CStaticClass.dbo; /// /// 设置要显示的设备索引 /// public int DeviceIndex { set { _deviceIndex = value;} } #endregion #region 构造函数/初始化 public FrmDeviceStatus() { InitializeComponent(); } private void FrmDeviceStatus_Load(object sender, EventArgs e) { btnRefresh_Click(null, EventArgs.Empty); if (_device.DeviceIndex == 22036 || _device.DeviceIndex == 22037) { this.btDown.Visible = false; this.btUP.Visible = true; } else if ("12001,12003,12005,12007,12051,12053,12055,12057".IndexOf(_device.DeviceIndex.ToString()) >= 0) { this.btDown.Visible = true; this.btUP.Visible = false; } else { this.btDown.Visible = false; this.btUP.Visible = false; } } #endregion #region 更新设备状态 private void btnRefresh_Click(object sender, EventArgs e) { //timer1.Enabled = true; _device = Model.CGetInfo.GetDeviceInfo(_deviceIndex); //20100108 if (_device == null) { MessageBox.Show("您选择的设备在数据库没有记录!", "操作提示:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //设备索引 this.lblDeviceIndex.Text = _device.DeviceIndex.ToString(); //设备名称 this.lblDeviceName.Text = _device.DeviceName; //设备指令索引 this.lblTaskIndex.Text = _device.TaskNo.ToString(); //目标位置 this.lblArrowLocation.Text = _device.ArrowLocation; //设备状态 switch (_device.RunState) { case 0: lblDeviceStatus.Text = "空闲"; break; case 1: lblDeviceStatus.Text = "运行"; break; case 2: lblDeviceStatus.Text = "故障"; break; case 3: lblDeviceStatus.Text = "离线"; break; case 4: lblDeviceStatus.Text = "停用"; break; case 5://20090920 lblDeviceStatus.Text = "动作完成"; break; } //有货/无货 this.lblHaveGoods.Text = _device.HaveGoods == true ? "有货" : "无货"; //托盘条码号 this.lblBarcode.Text = _device.Barcode; if (_device.ErrorCode >= 30) { Model.MError err = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(_device.DeviceKind.ToString() + _device.ErrorCode.ToString())); this.lblErrorName.Text = err.ErrorName; } else { this.lblErrorName.Text = ""; } if ((_device.DeviceKind == 1) || (_device.DeviceKind == 4)) { this.lblNowX.Text = _device.XCoor.ToString(); this.lblNowY.Text = _device.YCoor.ToString(); } else { this.lblNowX.Text =""; this.lblNowY.Text = ""; } //是否逻辑有物 DataView dv = dbo.ExceSQL("select F_DeviceIndex from T_Base_Device where F_HaveGoods = 1 and F_DeviceIndex =" + this._deviceIndex).Tables[0].DefaultView; if (dv.Count > 0) { lblGoods.Text = "逻辑有物"; } else { lblGoods.Text = "逻辑无物"; } if ((_device.ErrorCode == 96) && ((_device.DeviceIndex == 1341) || (_device.DeviceIndex == 1342) || (_device.DeviceIndex == 1101))) { btQuitPallet.Visible = true; } else { btQuitPallet.Visible = false; } } #endregion #region 关闭窗体 private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion private void timer1_Tick(object sender, EventArgs e) { btnRefresh_Click(sender, e); } private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("您确认要把设备:" + this._deviceIndex + "设成逻辑无物吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } dbo.ExceSQL("UPDATE T_Base_Device SET F_HaveGoods = 0 where F_DeviceIndex =" + this._deviceIndex); btnRefresh_Click(sender, e); } private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("您确认要把设备:" + this._deviceIndex + "设成逻辑有物吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } dbo.ExceSQL("UPDATE T_Base_Device SET F_HaveGoods = 1 where F_DeviceIndex =" + this._deviceIndex); btnRefresh_Click(sender, e); } private void button3_Click(object sender, EventArgs e) { if (MessageBox.Show("您确认要把设备:" + this._deviceIndex + "的接收指令区清零吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } int deviceKind = ccf.GetDeviceKindIdx(this._deviceIndex); sdo = CommModeCreate.CreateSendDeviceOrder(this._deviceIndex); if ((deviceKind == 1) || (deviceKind == 6)) { sdo.SendDeviceOrder(2, 0, 0, this._deviceIndex, 0, 0, 0, 0, 0, 0); } else { sdo.SendDeviceOrder(2, 0, 0, this._deviceIndex, 0); _device.SendMessage = null; Model.CGetInfo.SetDeviceInfo(_device); } } private void btQuitPallet_Click(object sender, EventArgs e) { if (_device.ErrorCode != 96) return; //生成出库任务 DataView dvbc = dbo.ExceSQL("SELECT FID FROM T_Manage_Task WHERE (FSTARTDEVICE=" + _device.DeviceIndex + ") and (FPALLETBARCODE = '0000000000')").Tables[0].DefaultView; if (dvbc.Count > 0) { return; } int fid = ccf.GetTempManageIdx(); string warehouse = "11"; string useAwayfork = "-"; DataView dvw = dbo.ExceSQL("SELECT F_WarehouseIndex FROM T_Warehouse").Tables[0].DefaultView; if (dvw.Count > 0) { warehouse = dvw[0]["F_WarehouseIndex"].ToString(); } string enddev = ""; if (_device.DeviceIndex == 1341) { enddev = "1442"; useAwayfork = "0"; } else if ((_device.DeviceIndex == 1342) || (_device.DeviceIndex == 1101)) { enddev = "1441"; useAwayfork = "1"; } string sql = "INSERT INTO T_Manage_Task" + "(FID, F_ManageTaskKindIndex,FPALLETBARCODE,FMANAGETASKTYPE,FCONTROLTASKTYPE, FTASKLEVEL, FISRETURN," + "FSTARTWAREHOUSE, FSTARTCELL, FSTARTDEVICE, FENDDEVICE, FENDCELL, " + "FSTATUS, FBEGTIME, FENDTIME,FIntoStepOK,FREMARK,FLANEWAY,FSTACK,FENDWAREHOUSE,FUseAwayFork)" + "VALUES (" + fid + ",2,'0000000000','0','3','1','1','" + warehouse + "','-','" + _device.DeviceIndex + "','" + enddev + "','-','0','-','-','0','',0,0,'" + warehouse + "','" + useAwayfork + "')"; dbo.ExceSQL(sql); Model.MDevice mdev; mdev = Model.CGetInfo.GetDeviceInfo(_device.DeviceIndex); mdev.ErrorCode = 0; mdev.RunState = 0; Model.CGetInfo.SetDeviceInfo(mdev); } private void btUP_Click(object sender, EventArgs e) { sdo = CommModeCreate.CreateSendDeviceOrder(this._deviceIndex); sdo.SendDeviceOrder(1, 0, 9, this._deviceIndex, 0); } private void btDown_Click(object sender, EventArgs e) { sdo = CommModeCreate.CreateSendDeviceOrder(this._deviceIndex); sdo.SendDeviceOrder(1, 0, 8, this._deviceIndex, 0); } } }