protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  stateItem.ItemName :
             *  Init - 初始化。
             *      FirstBatch - 生成第一批入库请求任务。
             *      StockInRequest - 根据请求,生成入库任务。
             *
             *  stateItem.State :参数 - 请求的卷烟编码。
            */
              //烟包托盘到达出库站台,根据返回的任务号,判断是否正常烟包:
               // 1、正常烟包,更新原有CranProcess的datatable将状态更改为3,并更改数据库状态。调用WriteToProcess(穿梭车Process).
               // 2、错误烟包,写入移库单,产生任务,调用调用WriteToProcess(穿梭车Process)。写入出库单,产生任务,并下达出库任务。
            object[] obj = ObjectUtil.GetObjects(stateItem.State);
            if (obj[0] == null || obj[0].ToString() == "0")
                return;

            try
            {
                string ToStation = "";
                string FromStation = "";
                string ReadItem2 = "";
                switch (stateItem.ItemName)
                {
                    case "02_1_304_1":
                        FromStation = "303";
                        ToStation = "304";
                        ReadItem2 = "02_1_304_2";
                        break;
                    case "02_1_308_1":
                        FromStation = "307";
                        ToStation = "308";
                        ReadItem2 = "02_1_308_2";
                        break;
                    case "02_1_312_1":
                        FromStation = "311";
                        ToStation = "313";
                        ReadItem2 = "02_1_312_2";
                        break;
                    case "02_1_316_1":
                        FromStation = "315";
                        ToStation = "316";
                        ReadItem2 = "02_1_316_2";
                        break;
                    case "02_1_320_1":
                        FromStation = "319";
                        ToStation = "320";
                        ReadItem2 = "02_1_320_2";
                        break;
                    case "02_1_322_1":
                        FromStation = "321";
                        ToStation = "322";
                        ReadItem2 = "02_1_322_2";
                        break;
                }

               string StationState ="";

                TaskDal dal = new TaskDal();
                string[] strTask = dal.GetTaskInfo(obj[0].ToString().PadLeft(4, '0'));

                if (!string.IsNullOrEmpty(strTask[0]))
                {
                    //更新
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strTask[0]), "2");

                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strTask[0]));
                    string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString();
                    CellDal Celldal = new CellDal();

                    //TaskID
                    StationState = strTask[0];

                    //校验正确烟包
                    if (obj[1].ToString() == "1")
                    {
                        WriteToProcess("CraneProcess", "StockOutToCarStation", StationState);

                        //解除货位锁定
                        Celldal.UpdateCellOutFinishUnLock(CellCode);
                        ProductStateDal psdal = new ProductStateDal();
                        psdal.UpdateOutBillNo(strTask[0]); //更新出库单
                        //获取任务记录
                        DataTable dt = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0]));
                        //调度小车;
                        WriteToProcess("CarProcess", "CarOutRequest", dt);
                    }
                    else //校验错误烟包
                    {
                        //返回读取到的RFID
                        string NewPalletCode = Common.ConvertStringChar.BytesToString((object[])ObjectUtil.GetObjects(WriteToService("StockPLC_02", ReadItem2)));

                        DataTable dtProductInfo = dal.GetProductInfoByTaskID(strTask[0]);

                        string strBillNo = "";
                        string[] strMessage = new string[3];
                        //strMessage[0] 弹出窗口类别,5是校验窗口
                        strMessage[0] = "5";
                        strMessage[1] = strTask[0];
                        strMessage[2] = NewPalletCode;

                        //弹出校验不合格窗口,人工选择处理方式
                        //strBillNo返回1 继续出库,否则返回替代的入库批次
                        while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                        {
                            string strNewBillNo = strBillNo;
                            if (string.IsNullOrEmpty(strNewBillNo))
                            {
                                if (strNewBillNo == "1")
                                {
                                    WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //更新堆垛机任务明细为完成状态。
                                    Celldal.UpdateCellOutFinishUnLock(CellCode);//解除货位锁定
                                    ProductStateDal psdal = new ProductStateDal();
                                    psdal.UpdateOutBillNo(strTask[0]); //更新出库单

                                    DataTable dtCar = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0])); //获取任务ID
                                    WriteToProcess("CarProcess", "CarOutRequest", dtCar);  //调度小车;
                                }
                                else
                                {
                                    //生成二楼退库单
                                    BillDal bdal = new BillDal();
                                    //产生WMS退库单以及WCS任务,并生成TaskDetail。
                                    string CancelTaskID = bdal.CreateCancelBillInTask(strTask[0], strTask[1]);
                                    //更新货位错误标志。
                                    Celldal.UpdateCellNewPalletCode(CellCode, NewPalletCode);
                                    //更新退库申请货位完成。
                                    dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CancelTaskID));
                                    //更新出库任务完成
                                    dal.UpdateTaskState(strTask[0], "2");

                                    string strWhere = string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=2 AND DETAIL.STATE=0 ", CancelTaskID);
                                    DataTable dt = dal.TaskCarDetail(strWhere);
                                    //写入调小车的源地址目标地址
                                    if (dt.Rows.Count > 0)
                                    {
                                        SysStationDal sysdal = new SysStationDal();
                                        DataTable dtCarStation = sysdal.GetCarSationInfo(CellCode, "22");
                                        dt.Rows[0].BeginEdit();
                                        dt.Rows[0]["IN_STATION_ADDRESS"] = dtCarStation.Rows[0]["IN_STATION_ADDRESS"];
                                        dt.Rows[0]["IN_STATION"] = dtCarStation.Rows[0]["IN_STATION"];
                                        dt.Rows[0].EndEdit();
                                    }
                                    //调度穿梭车入库。
                                    WriteToProcess("CarProcess", "CarInRequest", dt);
                                    //创建替代入库批次的WMS单据,WCS出库任务
                                    string strOutTaskID = bdal.CreateCancelBillOutTask(strTask[0], strTask[1], strNewBillNo);
                                    DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));
                                    //调度穿梭车出库
                                    WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);

                                    //延迟
                                    int i = 0;
                                    while (i < 100)
                                    {
                                        i++;
                                    }

                                    //StationState:原任务TASKID,更新堆垛机Process 状态为2.
                                    WriteToProcess("CraneProcess", "StockOutToCarStation", StationState);
                                    //插入替换批次记录
                                    DataTable dtNewProductInfo = dal.GetProductInfoByTaskID(strOutTaskID);
                                    dal.InsertChangeProduct(dtProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtProductInfo.Rows[0]["PRODUCT_CODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_CODE"].ToString());
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutToCarStationProcess:" + e.Message);
            }
        }
Example #2
0
        private void ACP(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            TaskDal dal = new TaskDal();
            if (!dCraneState.ContainsKey(msg["CraneNo"]))
            {
                dCraneState.Add(msg["CraneNo"], "");
            }
            DataRow dr = null;
            if (dtCrane != null)
            {
                DataRow[] drs = dtCrane.Select(string.Format("SQUENCE_NO='{0}'", msg["SequenceNo"]));
                if (drs.Length > 0)
                {
                    dr = drs[0];
                }
            }
            //如果在datatbale中找不到,再从数据库里查找
            if (dr == null)
            {
                //根据流水号,获取资料
                DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.SQUENCE_NO='{1}' AND DETAIL.CRANE_NO='{0}'", msg["CraneNo"], msg["SequenceNo"]));
                if (dt.Rows.Count > 0)
                    dr = dt.Rows[0];

            }
            string TaskType = "";
            string TaskID = "";
            string ItemNo = "";
            if (dr != null)
            {
                TaskType = dr["TASK_TYPE"].ToString();
                TaskID = dr["TASK_ID"].ToString();
                ItemNo = dr["ITEM_NO"].ToString();
            }
            if (msg["ReturnCode"] == "000")
            {
                #region 正常处理流程

                if (dr != null)
                {
                    //判断暂存的任务是否是当前完成的任务,如果是清空暂存
                    if (dCraneWait[msg["CraneNo"]] != null)
                    {
                        if (dCraneWait[msg["CraneNo"]]["TASK_ID"].ToString() == TaskID)
                        {
                            dCraneWait[msg["CraneNo"]] = null;
                        }
                    }

                    string strWhere = string.Format("TASK_ID='{0}' and ITEM_NO='{1}'", TaskID, ItemNo);
                    //出库,一楼盘点出库
                    if (TaskType.Substring(1, 1) == "2" || (TaskType == "13" && ItemNo == "1"))
                    {
                        if (TaskType == "12") //一楼出库
                        {
                            CellDal Cdal = new CellDal();
                            //货位解锁
                            Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());
                            //更新PRODUCTSTATE 出库单号
                            ProductStateDal psdal = new ProductStateDal();
                            psdal.UpdateOutBillNo(TaskID);

                        }
                        if(TaskType=="12" || TaskType=="13")
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                        string ToStation;
                        if (TaskType == "22")
                            ToStation =  dr["MEMO"].ToString();
                        else
                            ToStation =  dr["TARGET_CODE"].ToString();

                        //更新TASK_DETAIL FROM_STATION TO_STATION STATE
                        dal.UpdateTaskDetailStation(dr["STATION_NO"].ToString(), ToStation, "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", TaskID));

                        int[] WriteValue = new int[3];
                        WriteValue[0] = int.Parse(dr["TASK_NO"].ToString());
                        if (TaskType == "22")
                            WriteValue[1] = int.Parse(dr["MEMO"].ToString());
                        else
                            WriteValue[1] = int.Parse(dr["TARGET_CODE"].ToString());

                        WriteValue[2] = int.Parse(dr["PRODUCT_TYPE"].ToString());

                        string Barcode = dr["PRODUCT_BARCODE"].ToString();
                        string PalletCode = dr["PALLET_CODE"].ToString();

                        byte[] b = new byte[190];
                        Common.ConvertStringChar.stringToByte(Barcode, 80).CopyTo(b, 0);
                        Common.ConvertStringChar.stringToByte(PalletCode, 110).CopyTo(b, 80);
                        //到达出库站台,再下任务给PLC
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_1", WriteValue);
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_2", b);
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_3", 1);
                    }
                    //入库完成,更新Task任务完成。
                    else if (TaskType.Substring(1, 1) == "1" || (TaskType == "13" && dr["ITEM_NO"].ToString() == "4"))
                    {
                        dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                        dal.UpdateTaskState(TaskID, "2");//更新任务状态。
                        if (TaskType == "11")
                        {
                            CellDal Cdal = new CellDal();
                            Cdal.UpdateCellInFinishUnLock(TaskID);//入库完成,更新货位。
                        }

                        BillDal billdal = new BillDal();
                        string isBill = "1";
                        if (dr["PRODUCT_CODE"].ToString() == "0000")
                            isBill = "0";
                        billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                    }
                    else if (TaskType == "14")
                    {
                        #region 移库
                        //如果目标地址与源地址不同巷道
                        if (dr["CRANE_NO"].ToString() != dr["NEW_CRANE_NO"].ToString())
                        {
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                            if (ItemNo == "1")
                            {
                                //更新货位信息
                                CellDal Cdal = new CellDal();
                                Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());
                                //更新TASK_DETAIL FROM_STATION TO_STATION STATE
                                dal.UpdateTaskDetailStation(dr["STATION_NO"].ToString(), dr["NEW_TARGET_CODE"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", TaskID));

                                //下达给PLC任务
                                int[] WriteValue = new int[3];
                                WriteValue[0] = int.Parse(dr["TASK_NO"].ToString());
                                WriteValue[1] = int.Parse(dr["NEW_TARGET_CODE"].ToString());
                                WriteValue[2] = int.Parse(dr["PRODUCT_TYPE"].ToString());

                                string Barcode = dr["PRODUCT_BARCODE"].ToString();
                                string PalletCode = dr["PALLET_CODE"].ToString();

                                byte[] b = new byte[190];
                                Common.ConvertStringChar.stringToByte(Barcode, 80).CopyTo(b, 0);
                                Common.ConvertStringChar.stringToByte(PalletCode, 110).CopyTo(b, 80);

                                WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_1", WriteValue);

                                WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_2", b);
                                WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_3", 1);

                                BillDal billdal = new BillDal();
                                billdal.UpdateBillMasterStart(dr["BILL_NO"].ToString(), true);//更新表单

                            }
                            else
                            {
                                dal.UpdateTaskState(TaskID, "2");//更新任务状态。

                                CellDal Cdal = new CellDal();
                                Cdal.UpdateCellInFinishUnLock(dr["NEWCELL_CODE"].ToString());

                                BillDal billdal = new BillDal();
                                string isBill = "1";
                                if (dr["PRODUCT_CODE"].ToString() == "0000")
                                    isBill = "0";
                                billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                            }

                        }
                        else   //相同巷道
                        {
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                            dal.UpdateTaskState(TaskID, "2");//更新任务状态。

                            CellDal Cdal = new CellDal();
                            Cdal.UpdateCellRemoveFinish(dr["NEWCELL_CODE"].ToString(), dr["CELL_CODE"].ToString()); //入库完成,更新货位。
                            Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());

                            BillDal billdal = new BillDal();
                            string isBill = "1";
                            if (dr["PRODUCT_CODE"].ToString() == "0000")
                                isBill = "0";
                            //更新WMS单据状态
                            billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                        }
                        #endregion
                    }
                    lock (dCraneState)
                    {
                        dCraneState[msg["CraneNo"]] = "0";
                    }
                    //移除完成的任务
                    if (dtCrane != null)
                    {
                        DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", TaskID));
                        if (drs.Length > 0)
                        {
                            dtCrane.Rows.Remove(drs[0]);
                        }
                    }

                    //查找发送下条报文。
                    GetNextTaskID(msg["CraneNo"], TaskType);
                }
                #endregion
            }
            else
            {
                string ErrMsg = "";
                DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", msg["ReturnCode"]));
                if (drMsgs.Length > 0)
                    ErrMsg = drMsgs[0]["DESCRIPTION"].ToString();

                dal.UpdateCraneErrCode(TaskID, ItemNo, msg["ReturnCode"]);//更新堆垛机错误编号
                Logger.Error(string.Format("堆垛机{0}返回错误代码{1}:{2}", msg["CraneNo"], msg["ReturnCode"], ErrMsg));

            }
            SendACK(msg);
            CraneErrWriteToPLC(msg["CraneNo"], int.Parse(msg["ReturnCode"]));
        }
Example #3
0
        /// <summary>
        /// У�鴦��
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVerficate_Click(object sender, EventArgs e)
        {
            string ServiceName = "StockPLC_02";
            string[] ItemName = new string[6];
            ItemName[0] = "02_1_304_1";
            ItemName[1] = "02_1_308_1";
            ItemName[2] = "02_1_312_1";
            ItemName[3] = "02_1_316_1";
            ItemName[4] = "02_1_320_1";
            ItemName[5] = "02_1_322_1";
            for (int i = 0; i < ItemName.Length; i++)
            {
                object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(ServiceName, ItemName[i]));
                if (obj[0] == null || obj[0].ToString() == "0")
                    continue;
                if (obj[1].ToString() == "1")
                    continue;

                string ToStation = "";
                string FromStation = "";
                string ReadItem2 = "";

                switch (ItemName[i])
                {
                    case "02_1_304_1":
                        FromStation = "303";
                        ToStation = "304";
                        ReadItem2 = "02_1_304_2";
                        break;
                    case "02_1_308_1":
                        FromStation = "307";
                        ToStation = "308";
                        ReadItem2 = "02_1_308_2";
                        break;
                    case "02_1_312_1":
                        FromStation = "311";
                        ToStation = "313";
                        ReadItem2 = "02_1_312_2";
                        break;
                    case "02_1_316_1":
                        FromStation = "315";
                        ToStation = "316";
                        ReadItem2 = "02_1_316_2";
                        break;
                    case "02_1_320_1":
                        FromStation = "319";
                        ToStation = "320";
                        ReadItem2 = "02_1_320_2";
                        break;
                    case "02_1_322_1":
                        FromStation = "321";
                        ToStation = "322";
                        ReadItem2 = "02_1_322_2";
                        break;

                }

                TaskDal dal = new TaskDal();
                string[] strTask = dal.GetTaskInfo(obj[0].ToString().PadLeft(4, '0'));
                if (!string.IsNullOrEmpty(strTask[0]))
                {
                    string NewPalletCode = THOK.XC.Process.Common.ConvertStringChar.BytesToString((object[])ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("StockPLC_02", ReadItem2)));
                    string[] StationState = new string[2];
                    CellDal Celldal = new CellDal(); //���»�λ��������RFID�������־��
                    DataTable dtProductInfo = dal.GetProductInfoByTaskID(strTask[0]);
                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strTask[0]));
                    string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString();
                    string strBillNo = "";
                    string[] strMessage = new string[3];
                    strMessage[0] = "5";
                    strMessage[1] = strTask[0];
                    strMessage[2] = NewPalletCode;
                    ProductStateDal psdal = new ProductStateDal();
                    if (psdal.ExistsPalletCode(dtTask.Rows[0]["PALLET_CODE"].ToString())) //�Ѿ������������
                        continue;
                    while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                    {

                        string strNewBillNo = strBillNo;
                        if (string.IsNullOrEmpty(strNewBillNo))
                        {
                            if (strNewBillNo == "1")
                            {
                                StationState[0] = obj[0].ToString();//�����;
                                StationState[1] = "3";

                                //this.Context.Processes["CraneProcess"].Start();
                              Context.ProcessDispatcher.WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //���¶Ѷ��Process ״̬Ϊ3.

                                Celldal.UpdateCellOutFinishUnLock(CellCode);//��������

                                psdal.UpdateOutBillNo(strTask[0]); //���³��ⵥ

                                DataTable dtCar = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0])); //��ȡ����ID
                                Context.ProcessDispatcher.WriteToProcess("CarProcess", "CarOutRequest", dtCar);  //��������
                            }
                            else
                            {
                                //���ɶ�¥�˿ⵥ
                                BillDal bdal = new BillDal();
                                string CancelTaskID = bdal.CreateCancelBillInTask(strTask[0], strTask[1]);//�����˿ⵥ����������ϸ��
                                Celldal.UpdateCellNewPalletCode(CellCode, NewPalletCode);//���»�λ�����־��

                                dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CancelTaskID)); //���������λ��ɡ�
                                dal.UpdateTaskState(strTask[0], "2");//���³����������

                                string strWhere = string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=2 AND DETAIL.STATE=0 ", CancelTaskID);
                                DataTable dt = dal.TaskCarDetail(strWhere);
                                Context.ProcessDispatcher.WriteToProcess("CarProcess", "CarInRequest", dt);//���ȴ�����⡣

                                string strOutTaskID = bdal.CreateCancelBillOutTask(strTask[0], strTask[1], strNewBillNo);
                                DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));

                                Context.ProcessDispatcher.WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);
                                int jj = 0;
                                while (jj < 100)  //�ӳ�
                                {
                                    jj++;
                                }
                                StationState[0] = strTask[0];//TaskID;
                                StationState[1] = "4";
                                Context.ProcessDispatcher.WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //���¶Ѷ��Process ״̬Ϊ4.
                                DataTable dtNewProductInfo = dal.GetProductInfoByTaskID(strOutTaskID);
                                dal.InsertChangeProduct(dtProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtProductInfo.Rows[0]["PRODUCT_CODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_CODE"].ToString());

                            }
                        }

                        break;
                    }
                }
            }
        }