/// <summary> /// 托盘入库方式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPalletIn_Click(object sender, EventArgs e) { PalletSelect frm = new PalletSelect(); if (frm.ShowDialog() == DialogResult.OK) { object obj = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService("StockPLC_01", "01_1_122_1")); if (obj == null || obj.ToString() != "0") { return; } if (frm.Flag == 1) //单托盘入库 { string writeItem = "01_2_122_"; int[] ServiceW = new int[3]; ServiceW[0] = 9999; //任务号 ServiceW[1] = 131; //目的地址 ServiceW[2] = 4; Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务 Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务 } else if (frm.Flag == 2) { PalletBillDal Billdal = new PalletBillDal(); string TaskID = Billdal.CreatePalletInBillTask(true); //空托盘组入库单,生成Task. string FromStation = "122"; string ToStation = "122"; string writeItem = "01_2_122_"; string strWhere = string.Format("TASK_ID='{0}'", TaskID); TaskDal dal = new TaskDal(); string[] CellValue = dal.AssignCell(strWhere, ToStation); //货位申请 string TaskNo = dal.InsertTaskDetail(CellValue[0]); SysStationDal sysDal = new SysStationDal(); DataTable dt = sysDal.GetSationInfo(CellValue[1], "11", "3"); dal.UpdateTaskState(CellValue[0], "1"); //更新任务开始执行 ProductStateDal StateDal = new ProductStateDal(); StateDal.UpdateProductCellCode(CellValue[0], CellValue[1]); //更新Product_State 货位 dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CellValue[0])); //更新货位申请起始地址及目标地址。 int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(TaskNo); //任务号 ServiceW[1] = int.Parse(dt.Rows[0]["STATION_NO"].ToString()); //目的地址 ServiceW[2] = 2; Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务 Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务 dal.UpdateTaskDetailStation(ToStation, dt.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", CellValue[0])); //更新货位到达入库站台, //更新单据开始 } } }
/// <summary> /// 盘点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCheckScan_Click(object sender, EventArgs e) { object obj = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService("StockPLC_01", "01_1_195")); if (obj == null || obj.ToString() == "0") { return; } string strTaskNo = obj.ToString().PadLeft(4, '0'); if (int.Parse(obj.ToString()) >= 9800 && int.Parse(obj.ToString()) < 9999) //盘点 { string[] str = new string[3]; str[0] = "6"; str[1] = ""; str[2] = ""; TaskDal dal = new TaskDal(); //更具任务号,获取TaskID及BILL_NO string[] strInfo = dal.GetTaskInfo(strTaskNo); DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0])); DataTable dtProductInfo = dal.GetProductInfoByTaskID(strInfo[0]); //线程停止 string strValue = ""; while ((strValue = FormDialog.ShowDialog(str, dtProductInfo)) != "") { dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2"); string writeItem = "01_2_195_"; DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0])); DataRow dr = dtTask.Rows[0]; SysStationDal sysdal = new SysStationDal(); DataTable dtstation = sysdal.GetSationInfo(dr["CELL_CODE"].ToString(), "11", "3"); if (strValue != "1") { CellDal celldal = new CellDal(); celldal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "条码扫描不一致"); } int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(strInfo[1]); //任务号 ServiceW[1] = int.Parse(dtstation.Rows[0]["STATION_NO"].ToString()); //目的地址 ServiceW[2] = 1; Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务 Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "3", 1); //PLC写入任务 dal.UpdateTaskDetailStation("195", dtstation.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=3", strInfo[0])); //更新货位到达入库站台, dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), dr["CELL_CODE"].ToString(), "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO=4", strInfo[0])); //更新调度堆垛机的其实位置及目标地址。 break; } } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* * 一楼入库货位申请 */ try { string FromStation = ""; string writeItem = ""; string ToStation = ""; string TaskID = ""; object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null || obj.ToString() == "0") { return; } string BarCode = ""; //读取PLC,获得产品编码 switch (stateItem.ItemName) { case "01_1_218_1": FromStation = "210"; ToStation = "218"; writeItem = "01_2_218_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_218_2"))); break; case "01_1_110_1": FromStation = "101"; ToStation = "110"; writeItem = "01_2_110_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_110_2"))); break; case "01_1_126_1": FromStation = "124"; ToStation = "126"; writeItem = "01_2_126_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_126_2"))); break; case "01_1_131": //空托盘组盘入 PalletBillDal Billdal = new PalletBillDal(); TaskID = Billdal.CreatePalletInBillTask(true); //空托盘组入库单,生成Task. FromStation = "124"; ToStation = "131"; writeItem = "01_2_131_"; break; case "PllateInRequest": break; } string strWhere = ""; if (TaskID == "") { strWhere = string.Format("PRODUCT_BARCODE='{0}'", BarCode); } else { strWhere = string.Format("TASK_ID='{0}'", TaskID); } TaskDal dal = new TaskDal(); //分配货位,返回 0:TaskID,1:货位 string[] CellValue = dal.AssignCell(strWhere, ToStation);//货位申请 //返回任务号9999 string TaskNo = dal.InsertTaskDetail(CellValue[0]); SysStationDal sysDal = new SysStationDal(); //获取task_detail行走路线item_no=3的信息,也就是堆垛机取货入库的动作 DataTable dt = sysDal.GetSationInfo(CellValue[1], "11", "3"); DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", CellValue[0])); //更新任务开始执行 dal.UpdateTaskState(CellValue[0], "1"); //更新Product_State 货位 ProductStateDal StateDal = new ProductStateDal(); StateDal.UpdateProductCellCode(CellValue[0], CellValue[1]); //更新货位申请起始地址及目标地址。 dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CellValue[0])); //0:任务号 1:目标地址 2:货物类型 int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(TaskNo); // ServiceW[1] = int.Parse(dt.Rows[0]["STATION_NO"].ToString()); if (stateItem.ItemName == "01_1_131") { ServiceW[2] = 2; } else { ServiceW[2] = 1; } //PLC写入任务 WriteToService("StockPLC_01", writeItem + "1", ServiceW); if (stateItem.ItemName == "01_1_131") { WriteToService("StockPLC_01", writeItem + "2", 1); } else { byte[] b = new byte[110]; Common.ConvertStringChar.stringToByte(dtTask.Rows[0]["PALLET_CODE"].ToString(), 110).CopyTo(b, 0); //写入RFID WriteToService("StockPLC_01", writeItem + "2", b); //标识位置1 WriteToService("StockPLC_01", writeItem + "3", 1); } BillDal Bdal = new BillDal(); Bdal.UpdateBillMasterStart(dtTask.Rows[0]["BILL_NO"].ToString(), ServiceW[2] == 1 ? true : false); dal.UpdateTaskDetailStation(ToStation, dt.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", CellValue[0]));//更新货位到达入库站台, } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_01.StockInRequestProcess:" + e.Message); } }
/// <summary> ///接收删除指令返回值 /// </summary> /// <param name="state"></param> private void DEC(object state) { Dictionary <string, string> msg = (Dictionary <string, string>)state; if (msg["ReturnCode"] == "000") //序列号出错,重新发送报文 { TaskDal dal = new TaskDal(); DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.CRANE_NO='{0}' AND ASSIGNMENT_ID='{1}'", msg["CraneNo"], msg["AssignmenID"])); DataRow dr = null; if (dt.Rows.Count > 0) { dr = dt.Rows[0]; } if (dr != null) { #region 错误处理 if (dr["ERR_CODE"].ToString() == "111") //入库,货位有货,重新分配货位 { CellDal cdal = new CellDal(); cdal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "货位有货,系统无记录"); string[] strValue = dal.AssignNewCell(string.Format("TASK_ID='{0}'", dr["TASK_ID"].ToString()), dr["CRANE_NO"].ToString()); //货位申请 ProductStateDal StateDal = new ProductStateDal(); StateDal.UpdateProductCellCode(strValue[0], strValue[1]); //更新Product_State 货位 SysStationDal sysdal = new SysStationDal(); DataTable dtstation = sysdal.GetSationInfo(strValue[1], dr["TASK_TYPE"].ToString(), dr["ITEM_NO"].ToString()); dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), strValue[1], "1", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", strValue[0], dr["ITEM_NO"].ToString()));//更新调度堆垛机的其实位置及目标地址。 dr.BeginEdit(); dr["CELLSTATION"] = "30" + strValue[1] + "01"; dr.EndEdit(); SendTelegramARQ(dr, false); //if (dtCrane != null) //{ // DataRow[] drs = dtCrane.Select(string.Format("ASSIGNMENT_ID='{0}'", msg["AssignmenID"])); // if (drs.Length > 0) // dtCrane.Rows.Remove(drs[0]); //} } else if (dr["ERR_CODE"].ToString() == "113")//出库,货位无货, { string ErrMsg = ""; DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", dr["ERR_CODE"].ToString())); if (drMsgs.Length > 0) { ErrMsg = drMsgs[0]["DESCRIPTION"].ToString(); } string strBillNo = ""; string[] strMessage = new string[3]; strMessage[0] = "8"; strMessage[1] = dr["TASK_ID"].ToString(); strMessage[2] = "错误代码:" + dr["ERR_CODE"] + ",错误内容:" + ErrMsg; DataTable dtProductInfo = dal.GetProductInfoByTaskID(dr["TASK_ID"].ToString()); while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "") { BillDal bdal = new BillDal(); string strNewBillNo = strBillNo; string strOutTaskID = bdal.CreateCancelBillOutTask(dr["TASK_ID"].ToString(), dr["BILL_NO"].ToString(), strNewBillNo); DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID)); WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask); CellDal cdal = new CellDal(); cdal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "货位无货,系统有记录"); break; } } } #endregion } }
/* 处理事项: * 抽检,补料,盘点 烟包到达,195 */ protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { try { object sta = ObjectUtil.GetObject(stateItem.State); if (sta == null || sta.ToString() == "0") { return; } string[] str = new string[3]; if (((short)sta) >= 9000 && ((short)sta) <= 9299) //补料 { str[0] = "1"; } else if (((short)sta) >= 9300 && ((short)sta) <= 9499)//抽检 { str[0] = "2"; } else if (((short)sta) >= 9800 && ((short)sta) < 9999) //盘点 { str[0] = "6"; } str[1] = ""; str[2] = ""; //根据任务号,获取TaskID及BILL_NO TaskDal dal = new TaskDal(); string[] strInfo = dal.GetTaskInfo(sta.ToString().PadLeft(4, '0')); DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0])); DataTable dtProductInfo = dal.GetProductInfoByTaskID(strInfo[0]); //线程停止 string strValue = ""; while ((strValue = FormDialog.ShowDialog(str, dtProductInfo)) != "") { dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2"); string writeItem = "01_2_195_"; if (str[0] == "1" || str[0] == "2") //抽检,补料 { dal.UpdateTaskState(strInfo[0], "2"); BillDal billdal = new BillDal(); billdal.UpdateInBillMasterFinished(strInfo[1], "1"); int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(strInfo[1]); //任务号 ServiceW[1] = 131; //目的地址 ServiceW[2] = 4; WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务 WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务 } else //盘点 { DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0])); DataRow dr = dtTask.Rows[0]; SysStationDal sysdal = new SysStationDal(); DataTable dtstation = sysdal.GetSationInfo(dr["CELL_CODE"].ToString(), "11", "3"); if (strValue != "1") { CellDal celldal = new CellDal(); celldal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "条码扫描不一致"); } int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(strInfo[1]); //任务号 ServiceW[1] = int.Parse(dtstation.Rows[0]["STATION_NO"].ToString()); //目的地址 ServiceW[2] = 1; WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务 WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务 dal.UpdateTaskDetailStation("195", dtstation.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=3", strInfo[0])); //更新货位到达入库站台, } //线程继续。 break; } } catch (Exception ex) { Logger.Error("THOK.XC.Process.Process_01.CheckOutToStationProcess:" + ex.Message); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* 处理事项: * * stateItem.ItemName : * 空托盘组,从小车站台到达入库站台。 * stateItem.State :参数 - 任务号。 */ object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null || obj.ToString() == "0") { return; } string TaskNo = obj.ToString().PadLeft(4, '0'); try { switch (stateItem.ItemName) { case "02_1_302": break; case "02_1_306": break; case "02_1_310": break; case "02_1_314": break; case "02_1_318": break; case "02_1_324": break; default: break; } TaskDal dal = new TaskDal(); string[] strValue = dal.GetTaskInfo(TaskNo); if (!string.IsNullOrEmpty(strValue[1])) { DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strValue[0])); string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString(); //更新小车站台到达入库站台任务完成。 dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO='3'", strValue[0]), "2"); SysStationDal sysdal = new SysStationDal(); DataTable dtstation = sysdal.GetSationInfo(CellCode, "21", "4"); //更新调度堆垛机的起始位置及目标地址。 dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), CellCode, "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO=4", strValue[0])); DataTable dt = dal.CraneTaskIn(string.Format("TASK.TASK_ID='{0}' and ITEM_NO='4'", strValue[0])); if (dt.Rows.Count > 0) { WriteToProcess("CraneProcess", "CraneInRequest", dt); } } } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_02.PalletToStationProcess, 原因:" + e.Message); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* * 一楼入库到达入库站台。 */ try { object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null || obj.ToString() == "0") { return; } switch (stateItem.ItemName) { case "01_1_136": break; case "01_1_148": break; case "01_1_152": break; case "01_1_170": break; case "01_1_178": break; case "01_1_186": break; } //电控系统返回任务号9999 string TaskNo = obj.ToString().PadLeft(4, '0'); TaskDal taskDal = new TaskDal(); string[] TaskInfo = taskDal.GetTaskInfo(TaskNo); DataTable dt = taskDal.TaskInfo(string.Format("TASK_ID='{0}'", TaskInfo[0])); if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; string taskType = dt.Rows[0]["TASK_TYPE"].ToString(); string ItemNo = "0"; string NextItemNo = "1"; string CellCode = ""; switch (taskType) { //入库 case "11": ItemNo = "2"; NextItemNo = "3"; CellCode = dr["CELL_CODE"].ToString(); break; //盘点 case "13": ItemNo = "3"; NextItemNo = "4"; CellCode = dr["CELL_CODE"].ToString(); break; //移库 case "14": ItemNo = "2"; NextItemNo = "3"; CellCode = dr["NEWCELL_CODE"].ToString(); break; } //更新路线完成状态 taskDal.UpdateTaskDetailState(string.Format("TASK_NO='{0}' AND ITEM_NO='{1}'", TaskNo, ItemNo), "2"); SysStationDal sysdal = new SysStationDal(); DataTable dtstation = sysdal.GetSationInfo(CellCode, "11", "3"); //更新调度堆垛机的起始位置及目标地址。 taskDal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), CellCode, "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", TaskInfo[0], NextItemNo)); string strWhere = string.Format("TASK_NO='{0}'AND DETAIL.STATE='0' and ITEM_NO='{1}'", TaskNo, NextItemNo); DataTable dtInCrane = taskDal.CraneTaskIn(strWhere); if (dtInCrane.Rows.Count > 0) { WriteToProcess("CraneProcess", "CraneInRequest", dtInCrane); } } } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_01.StockInStationProcess:" + e.Message); } }