/// <summary>
        /// 地标属性更改时触发的事件
        /// 移除上次动画,显示下一动画
        /// </summary>
        /// <param name="temp1">AGV_DisMember类</param>
        private void MarkChangeAction(AGV_DisMember temp1)
        {
            byte iagvnum = Convert.ToByte(temp1.txtAGVNum.Remove(0, 3));
            if (iagvnum > 0 && iagvnum <= AGVNUM_MAX)
            {
                Point pStart = new Point(), pEnd = new Point(), pVirtual = new Point();
                //if (Convert.ToInt32(temp1.txtDockNum) > 0)
                //{
                //    TrafficPara.Open("Select RouteNum from T_DockSetting where DockNum=" + temp1.txtDockNum + " and AGVNum=" + iagvnum.ToString());
                //    if (TrafficPara.rowcount > 0)
                //    {
                //        temp1.txtLineNum = TrafficPara.Rows[0]["RouteNum"].ToString();
                //    }
                //}


                //待测试
                //if (agvDock != null && agvCharge != null && agvCall != null)
                //{
                //    if (Convert.ToInt32(temp1.txtDockNum) == 0)
                //    {
                //        if (agvDock.dockStartStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                //        {
                //            //充电返回后,清除状态
                //            if (temp1.txtagvCharge == 4) { AGVStatus[iagvnum - 1].agvCharge = 0; }
                //            CarLine carline = agvDock.Add(iagvnum);
                //            if (carline != null)
                //            {
                //                temp1.txtDockNum = carline.dockNum.ToString();
                //                temp1.txtLineNum = carline.lineNum.ToString();
                //                AGVStatus[iagvnum - 1].dockNum = carline.dockNum;
                //                //启动车辆,发送变更为待装停靠区路线
                //                //进入待装区时,起始地标的功能为暂停,结束地标不能为停止或暂停,一定为agv运行的地标功能,也不能在交通管制点内
                //                AGVControlCommand(iagvnum, 3, 0, Convert.ToByte(carline.lineNum));
                //            }
                //            else
                //            {
                //                //这是在排队队列中,此时需要车辆停止(发送停止命令)
                //                AGVControlCommand(iagvnum, 2, 0, 0);
                //            }
                //        }
                //    }
                //    else
                //    {
                //        if (agvDock.dockEndStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                //        {
                //            //移除待装区排队
                //            CarLine carline = agvDock.Delete(iagvnum);
                //            if (carline != null)
                //            {
                //                //只有停靠区和管制区在这边需要软件更新,其他的更新可以发送控制命令,下位机更改AGV状态,上位机接收数据驱动更新
                //                AGVStatus[carline.agvNum - 1].dockNum = carline.dockNum;
                //                //如果在等待排队中有车辆,启动等待的车辆
                //                AGVControlCommand(carline.agvNum, 3, 0, Convert.ToByte(carline.lineNum));
                //            }
                //            temp1.txtDockNum = "0";
                //            AGVStatus[iagvnum - 1].dockNum = 0;
                //            //此时需要变换路线agvDock.outDockLine[iagvnum-1],发出控制命令,变更路线
                //            //1.当监测到temp1.txtagvCharge ==1时,outDockLine[iagvnum-1]为充电路线
                //            //2.当temp1.txtagvCharge ==0时,为执行任务的路线
                //            if (temp1.txtagvCharge == 1)
                //            {
                //                AGVStatus[iagvnum - 1].agvCharge = 2;
                //            }
                //            AGVControlCommand(iagvnum, 0, 0, Convert.ToByte(agvDock.outDockLine[iagvnum - 1]));
                //            agvDock.outDockLine[iagvnum - 1] = 0;
                //        }
                //    }

                //    if (temp1.txtagvCharge == 2)
                //    {
                //        if (agvCharge.dockStartStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                //        {
                //            CarLine carline = agvCharge.Add(iagvnum);
                //            if (carline != null)
                //            {
                //                temp1.txtagvCharge = 3;//充电状态
                //                AGVStatus[iagvnum - 1].agvCharge = 3;//充电状态
                //                temp1.txtLineNum = carline.lineNum.ToString();
                //                //启动车辆,发送变更路线
                //                AGVControlCommand(iagvnum, 3, 0, Convert.ToByte(carline.lineNum));
                //            }
                //            else
                //            {
                //                //这是在排队队列中,此时需要车辆停止(发送停止命令)
                //                AGVControlCommand(iagvnum, 2, 0, 0);
                //            }
                //        }
                //    }//注意:充电完成,车辆不会自行启动,需要人工拔掉充电线,然后启动车辆
                //    else if (temp1.txtagvCharge == 3)
                //    {
                //        if (agvCharge.dockEndStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                //        {
                //            //移除待装区排队
                //            CarLine carline = agvCharge.Delete(iagvnum);
                //            if (carline != null)
                //            {
                //                //只有停靠区和管制区在这边需要软件更新,其他的更新可以发送控制命令,下位机更改AGV状态,上位机接收数据驱动更新
                //                AGVStatus[carline.agvNum - 1].dockNum = carline.dockNum;
                //                //如果在等待排队(此时AGV车辆在待装区中排队,不是在充电区的起始地标排队)中有车辆,启动等待的车辆
                //                AGVControlCommand(carline.agvNum, 3, 0, 0);
                //                agvDock.outDockLine[iagvnum - 1] = agvCharge.chargeLine;//在出待装区的时候改变路线使用
                //            }
                //            temp1.txtagvCharge = 4;
                //            AGVStatus[iagvnum - 1].agvCharge = 4;
                //        }
                //    }
                //}

                #region 停靠区
                if (agvDock != null)
                {
                    // 判断是否进入停靠区
                    if (Convert.ToInt32(temp1.txtDockNum) == 0)
                    {
                        if (agvDock.dockStartStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                        {
                            //已经进入停靠区:1.更新AGV的停靠区参数 2.更新AGV的路线

                            //车辆进入停靠区
                            CarLine carline = agvDock.Add(iagvnum);
                            if (carline != null)
                            {
                                temp1.txtDockNum = carline.dockNum.ToString();
                                temp1.txtLineNum = carline.lineNum.ToString();
                                //更新停靠区参数
                                AGVStatus[iagvnum - 1].dockNum = carline.dockNum;
                                //启动车辆,发送变更为待装停靠区路线
                                //进入待装区时,起始地标的功能为暂停,结束地标不能为停止或暂停,一定为agv运行的地标功能,也不能在交通管制点内
                                AGVControlCommand(iagvnum, 3, 0, Convert.ToByte(carline.lineNum));
                            }
                            else
                            {
                                //这是在排队队列中,此时需要车辆停止(发送停止命令)
                                AGVControlCommand(iagvnum, 2, 0, 0);
                            }
                            //启用充电区
                            if (agvCharge != null)
                            {
                                //充电返回后,清除状态
                                if (temp1.txtagvCharge == 4) { AGVStatus[iagvnum - 1].agvCharge = 0; }
                            }
                            else//不启用充电区
                            {
                            }
                        }
                        else 
                        { 
                            //未进入停靠区,一直处于停靠区外面;暂不做处理
                        }
                    }
                    else//判断是否出停靠区
                    {
                        if (agvDock.dockEndStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                        {
                            //离开停靠区:1.更新AGV的停靠区参数 2.更新AGV的路线

                            //移除待装区排队
                            CarLine carline = agvDock.Delete(iagvnum);
                            //更新AGV停靠区参数
                            temp1.txtDockNum = "0";
                            AGVStatus[iagvnum - 1].dockNum = 0;
                            //更新AGV路线
                            //有车辆等待排队
                            if (carline != null)
                            {
                                //只有停靠区和管制区在这边需要软件更新,其他的更新可以发送控制命令,下位机更改AGV状态,上位机接收数据驱动更新
                                AGVStatus[carline.agvNum - 1].dockNum = carline.dockNum;
                                //如果在等待排队中有车辆,启动等待的车辆
                                AGVControlCommand(carline.agvNum, 3, 0, Convert.ToByte(carline.lineNum));
                            }
                            //启用充电区
                            if (agvCharge != null)
                            {
                                if (temp1.txtagvCharge == 1)
                                {
                                    byte linenum = agvCharge.GetChargeLine(Convert.ToByte(temp1.txtLineNum));
                                    //充电路线,当linenum=0,说明用户没有定义
                                    agvDock.outDockLine[iagvnum - 1] = linenum;//充电路线
                                    if (linenum > 0)
                                    {
                                        AGVStatus[iagvnum - 1].agvCharge = 2;
                                    }
                                }
                            }
                            else 
                            {
                                //不启动充电区
                            }

                            //车辆驶出停靠区后变更路线
                            //此时需要变换路线agvDock.outDockLine[iagvnum-1],发出控制命令,变更路线
                            //1.当监测到temp1.txtagvCharge ==1时,outDockLine[iagvnum-1]为充电路线
                            //2.当temp1.txtagvCharge ==0时,为执行任务的路线
                            if (agvDock.outDockLine[iagvnum - 1] > 0)
                            {
                                AGVControlCommand(iagvnum, 0, 0, Convert.ToByte(agvDock.outDockLine[iagvnum - 1]));
                                agvDock.outDockLine[iagvnum - 1] = 0;
                            }

                        }
                        else
                        {
                            //已经进入停靠区,但一直在停靠区内;暂不做处理
                        }
                    }
                }
                #endregion

                #region 充电区
                if (agvCharge != null)
                {
                    if (temp1.txtagvCharge == 2)
                    {
                        if (agvCharge.dockStartStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                        {
                            CarLine carline = agvCharge.Add(iagvnum,Convert.ToByte(temp1.txtLineNum));
                            if (carline != null)
                            {
                                temp1.txtagvCharge = 3;//充电状态
                                AGVStatus[iagvnum - 1].agvCharge = 3;//充电状态
                                temp1.txtLineNum = carline.lineNum.ToString();
                                //启动车辆,发送变更路线
                                AGVControlCommand(iagvnum, 3, 0, Convert.ToByte(carline.lineNum));
                            }
                            else
                            {
                                //这是在排队队列中,此时需要车辆停止(发送停止命令)
                                AGVControlCommand(iagvnum, 2, 0, 0);
                            }
                        }
                    }//注意:充电完成,车辆不会自行启动,需要人工拔掉充电线,然后启动车辆
                    else if (temp1.txtagvCharge == 3)
                    {
                        if (agvCharge.dockEndStop.Equals(new WorkMarkStr(Convert.ToInt32(temp1.txtWorkLine), Convert.ToInt32(temp1.txtMarkNum))))
                        {
                            //移除待装区排队
                            CarLine carline = agvCharge.Delete(iagvnum);
                            if (carline != null)
                            {
                                //只有停靠区和管制区在这边需要软件更新,其他的更新可以发送控制命令,下位机更改AGV状态,上位机接收数据驱动更新
                                AGVStatus[carline.agvNum - 1].dockNum = carline.dockNum;
                                //如果在等待排队(此时AGV车辆在待装区中排队,不是在充电区的起始地标排队)中有车辆,启动等待的车辆
                                temp1.txtLineNum = carline.lineNum.ToString();
                                AGVControlCommand(carline.agvNum, 3, 0, Convert.ToByte(carline.lineNum));
                            }
                            temp1.txtagvCharge = 4;
                            AGVStatus[iagvnum - 1].agvCharge = 4;
                            AGVControlCommand(iagvnum, 0, 0, agvCharge.beforeEnterLine[Convert.ToInt32(temp1.txtDockNum)]);
                        }
                    }
                }
                #endregion

                TrafficPara.Open("select T_Line.MarkOrder, T_Mark.XPos, T_Mark.YPos FROM T_Line LEFT OUTER JOIN T_Mark ON T_Mark.ID = T_Line.MarkID where WorkLine=" + temp1.txtWorkLine + " and Mark=" + temp1.txtMarkNum + " and LineNum=" + temp1.txtLineNum);
                if (TrafficPara.Rows.Count > 0)
                {
                    pStart.X = Convert.ToDouble(TrafficPara.Rows[0]["XPos"]);
                    pStart.Y = Convert.ToDouble(TrafficPara.Rows[0]["YPos"]);
                    List<Point> pointcollection1 = new List<Point>();
                    pointcollection1.Add(pStart);
                    int currentOrder = Convert.ToInt16(TrafficPara.Rows[0]["MarkOrder"]) + 1;
                    //线路起点处检测电量
                    if (currentOrder == 2)
                    {
                        //AGV到达起点位置,空闲状态;当检测到AGV状态为运行时,为执行任务
                        AGVStatus[iagvnum - 1].agvTask = 0;
                        //启用充电区
                        if (agvCharge != null)
                        {
                            if (temp1.txtagvCharge == 1)
                            {
                                byte linenum = agvCharge.GetChargeLine(Convert.ToByte(temp1.txtLineNum));
                                //当linenum=0时,说明管理员没有设置充电路线,不会启动自动充电
                                if (linenum > 0)
                                {
                                     AGVControlCommand(iagvnum, 1, 0, linenum);
                                     AGVStatus[iagvnum - 1].agvCharge = 2;
                                }
                            }
                        }
                    }
                    bool isvirtualpoint = true;
                    double dMarkdistance = 0;
                    //while (isvirtualpoint)
                    //{
                    //    TrafficPara.Open("select XPos,YPos,T_Line.Distance from T_Mark Left join T_Line on T_Mark.ID = T_Line.MarkID where T_Line.MarkOrder=" + currentOrder.ToString() +
                    //        "and LineNum=" + temp1.txtLineNum + "and T_Mark.VirtualMark=1");
                    //    if (TrafficPara.Rows.Count > 0)
                    //    {
                    //        pVirtual.X = Convert.ToDouble(TrafficPara.Rows[0]["XPos"]);
                    //        pVirtual.Y = Convert.ToDouble(TrafficPara.Rows[0]["YPos"]);
                    //        pointcollection1.Add(pVirtual);
                    //        dMarkdistance += Convert.ToDouble(TrafficPara.Rows[0]["Distance"]);
                    //        currentOrder++;
                    //    }
                    //    else { isvirtualpoint = false; break; }
                    //}
                    //TrafficPara.Open("select XPos,YPos,T_Line.Distance from T_Mark Left join T_Line on T_Mark.ID = T_Line.MarkID where T_Line.MarkOrder=" + currentOrder.ToString() +
                    //    "and LineNum=" + temp1.txtLineNum + "and T_Mark.VirtualMark=0");
                    //if (TrafficPara.Rows.Count > 0)
                    //{
                    //    pEnd.X = Convert.ToDouble(TrafficPara.Rows[0]["XPos"]);
                    //    pEnd.Y = Convert.ToDouble(TrafficPara.Rows[0]["YPos"]);
                    //    pointcollection1.Add(pEnd);
                    //    dMarkdistance += Convert.ToDouble(TrafficPara.Rows[0]["Distance"]);
                    //}
                    //else return;
                    #region 待测试方法
                    
                    do
                    {
                        TrafficPara.Open("select XPos,YPos,T_Line.Distance,VirtualMark from T_Mark Left join T_Line on T_Mark.ID = T_Line.MarkID where T_Line.MarkOrder=" + currentOrder.ToString() +
                        "and LineNum=" + temp1.txtLineNum);
                        if (TrafficPara.Rows.Count > 0)
                        {
                            pVirtual.X = Convert.ToDouble(TrafficPara.Rows[0]["XPos"]);
                            pVirtual.Y = Convert.ToDouble(TrafficPara.Rows[0]["YPos"]);
                            pointcollection1.Add(pVirtual);
                            dMarkdistance += Convert.ToDouble(TrafficPara.Rows[0]["Distance"]);
                            isvirtualpoint = Convert.ToBoolean(TrafficPara.Rows[0]["VirtualMark"]);
                            currentOrder++;
                        }
                    }
                    while (isvirtualpoint);
                    
                    
                    #endregion

                    if (pointcollection1.Count >= 2)
                    {
                        double dAgvspeed = 0;
                        TrafficPara.Open("select Speed from T_Speed where SpeedGrade='" + temp1.txtSpeedValue + "'");
                        if (TrafficPara.Rows.Count > 0)
                        {
                            dAgvspeed = Convert.ToDouble(TrafficPara.Rows[0]["Speed"]) / 60.0;
                        }
                        else return;
                        AGVStatus[iagvnum - 1].agvAnimation.DrawCarLine(pointcollection1, ColorOpt[iagvnum % ColorOpt.Length],dMarkdistance / dAgvspeed);
                    }
                }
                TrafficPara.Close();
            }
        }
 /// <summary>
 /// agv表格绑定数据初始化
 /// </summary>
 /// <param name="agvnum"></param>
 public void AGVGridInit(int agvnum)
 {
     for (int i = 0; i < agvnum; i++)
     {
         DisMember[i] = new AGV_DisMember() { txtAGVNum = "AGV" + (i + 1).ToString() };
         DisMember[i].PropertyChanged += new PropertyChangedEventHandler(Dis_PropertyChange);
         //memberData.Add(DisMember[i]);
     }
     dataGrid.DataContext = memberData;
 }
 /// <summary>
 /// 无线连接属性更改时触发的事件
 /// </summary>
 /// <param name="temp1">AGV_DisMember类</param>
 private void WLChangeAction(AGV_DisMember temp1)
 {
     byte iagvnum = Convert.ToByte(temp1.txtAGVNum.Remove(0, 3));
     AGVStatus[iagvnum - 1].agvAnimation.WLChangeAnimation(temp1.txtWLValue);
     if (temp1.txtWLValue.Equals("失败"))
     {
         memberData.Remove(DisMember[iagvnum - 1]);//20140309从表格中移除无线连接失败的agv
         if (agvCharge != null)
         {
             agvCharge.Delete(iagvnum);
         }
         if (agvDock != null)
         {
             agvDock.Delete(iagvnum);
         }
         return;
     }
     else
     {
         memberData.Insert(0, DisMember[iagvnum - 1]);//20140309添加agv到表格中第一行
         MarkChangeAction(temp1);
     }
 }
 /// <summary>
 /// 电量属性更改时触发的事件
 /// 电量低于20%时进行充电
 /// </summary>
 /// <param name="temp1">AGV_DisMember类</param>
 private void PowerChangeAction(AGV_DisMember temp1)
 {
     //20140312电量低于20%时进行充电,线路切换到充电线路
     byte iagvnum = Convert.ToByte(temp1.txtAGVNum.Remove(0, 3));
     if (iagvnum > 0 && iagvnum <= AGVNUM_MAX)
     {
         if (temp1.txtPower < 20)//电量低于20%时进行充电
         {
             //设置充电标志位
             AGVStatus[iagvnum - 1].agvCharge = 1;
         }
     }
 }
 /// <summary>
 /// 运行状态属性更改时触发的事件
 /// </summary>
 /// <param name="temp1">AGV_DisMember类</param>
 private void StatusChangeAction(AGV_DisMember temp1)
 {
     byte iagvnum = Convert.ToByte(temp1.txtAGVNum.Remove(0, 3));
     if (iagvnum > 0 && iagvnum <= AGVNUM_MAX)
     {
         AGVStatus[iagvnum - 1].agvAnimation.StatusChangeAnimation(temp1.txtStatus.Trim(),iagvnum.ToString(),temp1.txtDockNum.Trim());
         switch (temp1.txtStatus.Trim())
         {
             case "运行":
                 AGVStatus[iagvnum - 1].agvTask = 1;
                 break;
             case "暂停":
                 break;
             case "结束地标停止":
                 //if (agvCall.lineNum.Count > 0)//有叫料信息,需要车辆运送
                 //{
                 //    if (agvCall.lineNum[0] > 0)
                 //    {
                 //        agvDock.outDockLine[iagvnum - 1] = agvCall.lineNum[0];
                 //        AGVControlCommand(iagvnum, 3, 0, 0);
                 //    }
                 //}
                 break;
             default:
                 {
                     //将报警记录写入到数据库
                     string txttimer = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                     TrafficPara.Open("Insert into T_Ex (CarID,ExTimer,ExType,ExRouteNum,ExMarkNum,ExWorkLine) VALUES (" + iagvnum.ToString() + ",'" + txttimer + "','" + temp1.txtStatus + "'," + temp1.txtLineNum + "," + temp1.txtMarkNum + "," + temp1.txtWorkLine + ")");
                     TrafficPara.Close();
                     break;
                 }
         }
     }    
 }