private void button6_Click(object sender, EventArgs e)
        {
            TaskME taskM = _taskBll.GetFirstUnexeAutoTask();
            BaseTaskInfo taskObj = TaskSerializer.Deserialize(taskM.taskCode, taskM.taskObj);
            if(taskObj != null)
            {
                string strXML = TaskSerializer.Serialize(taskObj);
                this.richTextBox1.AppendText(strXML + "\r\n");
                StringBuilder strBuilder = new StringBuilder();
                strBuilder.AppendLine("提取任务:");
                strBuilder.AppendLine(taskM.taskObj);
                this.richTextBox1.AppendText(strBuilder.ToString());
                InstMovL instMovl = new InstMovL();
                instMovl.targetL = 2;
                instMovl.instComment = "移动到2层";
                strXML = InstSerializer.Serialize(instMovl);
                this.richTextBox1.AppendText(strXML + "\r\n");
                IList<BaseInstInfo> instList = null;
                if(0 == TaskDisptach.ParseTask(true, true, ref taskObj, out instList))
                {
                    strBuilder.Clear();
                    strBuilder.AppendLine("任务分解成功");
                    this.richTextBox1.AppendText(strBuilder.ToString()+"\r\n");
                    strBuilder.Clear();
                    ASRSModel.GetInstance().transVehicleDic[taskObj.machineAllocated].FillInstList(instList, taskObj, taskObj.taskID);
                    foreach(BaseInstInfo inst in instList)
                    {
                        if(inst != null)
                        {
                            InstME instM = new InstME();
                            instM.instID = _instBll.GenerateNewInstID();
                            instM.instCode = (int)inst.instCode;
                            instM.instObj = InstSerializer.Serialize(inst);
                            try
                            {
                                BaseInstInfo newInst = InstSerializer.Deserialize(instM.instCode, instM.instObj);
                                richTextBox1.AppendText("指令反序列化:" + newInst.instComment + "\r\n");
                            }
                            catch (System.Exception e1)
                            {
                                richTextBox1.AppendText("反序列化失败:" + e1.Message);
                            }

                            instM.vehicleAlloc = taskObj.machineAllocated;
                            _instBll.AddInst(instM);
                            strBuilder.AppendLine("插入指令:");
                            strBuilder.AppendLine(instM.instObj);
                            this.richTextBox1.AppendText(strBuilder.ToString());
                            strBuilder.Clear();
                        }
                    }
                }

            }
        }
        /// <summary>
        /// 解析任务,行成指令列表,同时分派资源
        /// </summary>
        /// <param name="task"></param>
        /// <param name ="VehicleAllocRequire">是否需要分配小车资源</param>
        /// <param name="HouseAllocRequire">是否需要分配仓位资源</param>
        /// <returns>0:成功解析任务,任务索引向前移动一条,1:执行条件不满足,任务索引停在当前,2:执行条件不满足,任务索引向前移动一条。 /// </returns>
        public static int ParseTask(bool VehicleAllocRequire, bool HouseAllocRequire,ref BaseTaskInfo task,out IList<BaseInstInfo> instList)
        {
            instList = null;
            TransVehicle m1 = _Model.transVehicleDic[1];
            TransVehicle m2 = _Model.transVehicleDic[2];
            if(task.taskCode == TaskCode.TASK_EMPTY)
            {
                //空任务
                return 0;
            }
            else if(task.taskCode == TaskCode.TASK_PRODUCT_INHOUSE)
            {

                TaskProductInhouse realTask= (TaskProductInhouse)task;
                //分配小车
                if(VehicleAllocRequire)
                {
                    int machineNo = ProductHouseInMachineSelect(realTask.productID);
                    if (machineNo <= 0)
                    {
                        //所有小车都在忙,
                        return 1;
                    }
                    realTask.machineAllocated = machineNo;
                }
                //分配仓位
               if(HouseAllocRequire)
               {
                   int L = 0, R = 0, C = 0;
                   if(!ChooseEmptyHouse(realTask.machineAllocated,out L,out R,out C))
                   {
                       return 2;
                   }
                   realTask.targetL = L;
                   realTask.targetR = R;
                   realTask.targetC = C;
               }
                //分解任务,生成指令列表
                instList = new List<BaseInstInfo>();
                //开始
                InstBegin inst0 = new InstBegin();
                inst0.instComment = "开始";
                instList.Add(inst0);
                //1 从当前位置到取货口
                InstMovL inst1 = new InstMovL();
                inst1.targetL = 1;
                inst1.instComment = "移动到目标层";
                instList.Add(inst1);
                //2
                InstMovC inst2 = new InstMovC();
                inst2.targetC = 1;
                inst2.instComment = "移动取货口";
                instList.Add(inst2);
                //3 取货
                InstLoad inst3 = new InstLoad();
                inst3.instComment = "取货";
                instList.Add(inst3);
                //4 到目标仓位
                InstMovC inst4 = new InstMovC();
                inst4.targetC = realTask.targetC;
                inst4.instComment = "移动到目标列";
                instList.Add(inst4);
                //5
                InstMovL inst5 = new InstMovL();
                inst5.targetL = realTask.targetL;
                inst5.instComment = "移动到目标层";
                instList.Add(inst5);
                //卸货
                InstUnload inst6 = new InstUnload();
                inst6.instComment = "仓位放货";
                instList.Add(inst6);

                //结束指令
                InstEnd inst7 = new InstEnd();
                inst7.instComment = "结束";
                instList.Add(inst7);
                return 0;
            }
            else if(task.taskCode == TaskCode.TASK_PRODUCT_OUTHOUSE)
            {
                //出库任务
                TaskProductOuthouse poutTask = task as TaskProductOuthouse;
                if(poutTask == null)
                {
                    return 2;
                }
                //自动分配仓位
                int L=0,R=0,C=0;
                if (HouseAllocRequire)
                {
                    //if (!_Model.warestoreBll.GetHouseCell(poutTask.productType, out L, out R, out C))
                    int reChooseHouse = ChooseProductoutHouse(poutTask.productType, out L, out R, out C);
                    if(reChooseHouse  != 0)
                    {
                        return 2;
                    }
                    task.targetL = L;
                    task.targetR = R;
                    task.targetC = C;
                }
                //自动分配小车
                TransVehicle selectedM = null;
                if (VehicleAllocRequire)
                {
                    if (R > 0 && R < 3)
                    {
                        if (m1.MStatus != MachineWorkStatus.MACHINE_IDLE)
                            return 2;
                        task.machineAllocated = 1;
                    }
                    else if (R >= 3 && R < 5)
                    {
                        if (m2.MStatus != MachineWorkStatus.MACHINE_IDLE)
                            return 2;
                        task.machineAllocated = 2;
                    }
                    else
                        return 2;
                }
                selectedM = _Model.transVehicleDic[task.machineAllocated];
                if(selectedM.MStatus != MachineWorkStatus.MACHINE_IDLE)
                {
                    return 2;
                }
                //指令分解
                //分解任务,生成指令列表
                instList = new List<BaseInstInfo>();
                //开始
                InstBegin inst0 = new InstBegin();
                inst0.instComment = "开始";
                instList.Add(inst0);

                //1 从当前位置到目标仓位层
                InstMovL inst1 = new InstMovL();
                inst1.targetL = task.targetL;
                inst1.instComment = "移动到出库仓位所在的层";
                instList.Add(inst1);

                //2 到目标仓位所在列
                InstMovC inst2 = new InstMovC();
                inst2.targetC = task.targetC;
                inst2.instComment = "移动到出库仓位所在的列";
                instList.Add(inst2);

                //3取货
                InstLoad inst3 = new InstLoad();
                inst3.instComment = "取货";
                instList.Add(inst3);

                //4 移动到1层
                InstMovL inst4 = new InstMovL();
                inst4.targetL = 1;
                inst4.instComment = "移动到出库口所在的层";
                instList.Add(inst4);

                //5 移动到出库口所在列
                InstMovC inst5 = new InstMovC();
                inst5.targetC = _Model.wareHouseSet.columnCount;
                inst5.instComment = "移动到出库口所在列";
                instList.Add(inst5);

                //6 卸货
                InstUnload inst6 = new InstUnload();
                inst6.instComment = "卸货";
                instList.Add(inst6);

                //7 结束
                InstEnd inst7 = new InstEnd();
                inst7.instComment = "结束";
                instList.Add(inst7);

                return 0;
            }
            else if(task.taskCode == TaskCode.TASK_PALLETE_INHOUSE)
            {
                //空板入库任务
                return 0;
            }
            else if(task.taskCode == TaskCode.TASK_PALLETE_OUTHOUSE)
            {
                //空板出库任务
                return 0;
            }
            else
            {
                //不可识别的任务码
                return 0;
            }
        }