示例#1
0
文件: FormMain.cs 项目: yfyf510/GPS
 private void analyzer_Analyzed()
 {
     try
     {
         List <GPSInfo> list = analyzer.GetOutInfo();
         if (list == null)
         {
             return;
         }
         foreach (GPSInfo gi in list)
         {
             if (gi.PosList.Count > 0)
             {
                 Car car = null;
                 if (gi.SimNO != "")//短信方式,以Sim卡号为标准
                 {
                     car = GetCarBySNO(gi.SimNO);
                     if (car != null)
                     {
                         if (gi.PosList[0].MNO != car.MachineNO)//检测终端序列号是否登记正确
                         {
                             try
                             {
                                 String s = new StringBuilder(Constant.HEAD).Append(Constant.S_MSG).Append(Constant.S_MSG_WARN).Append("收到车辆").Append(car.CarNO).Append("终端信息,终端序列号错误,记录为").Append(car.MachineNO).Append(",收到为").Append(gi.PosList[0].MNO).Append(Constant.FOOT).ToString();
                                 foreach (DataClient dc in dataClientList)
                                 {
                                     if (dc.LoginUser != null && dc.LoginUser.GetTeamByID(car.TeamID) != null && dc.LoginUser.PolicyModCar == 1)
                                     {
                                         dc.Send(s);
                                     }
                                 }
                                 logger.AddMsg(new StringBuilder("收到车辆").Append(car.CarNO).Append("终端信息,终端序列号错误,记录为").Append(car.MachineNO).Append(",收到为").Append(gi.PosList[0].MNO).ToString());
                             }
                             catch { }
                         }
                     }
                     else
                     {
                         car = GetCarByMNO(gi.PosList[0].MNO);//未找到sim卡记录,已终端序列号为标准
                         if (car != null)
                         {
                             try
                             {
                                 String s = new StringBuilder(Constant.HEAD).Append(Constant.S_MSG).Append(Constant.S_MSG_WARN).Append("收到车辆").Append(car.CarNO).Append("终端信息,SIM号错误,记录为").Append(car.SimNO).Append(",收到为").Append(gi.SimNO).Append(Constant.FOOT).ToString();
                                 foreach (DataClient dc in dataClientList)
                                 {
                                     if (dc.LoginUser != null && dc.LoginUser.GetTeamByID(car.TeamID) != null && dc.LoginUser.PolicyModCar == 1)
                                     {
                                         dc.Send(s);
                                     }
                                 }
                                 logger.AddMsg(new StringBuilder("收到车辆").Append(car.CarNO).Append("终端信息,SIM号错误,记录为").Append(car.SimNO).Append(",收到为").Append(gi.SimNO).ToString());
                             }
                             catch { }
                         }
                         else//sim卡、终端序列号都未找到记录
                         {
                             try
                             {
                                 String s = new StringBuilder(Constant.HEAD).Append(Constant.S_MSG).Append(Constant.S_MSG_WARN).Append("收到终端信息,但是未找到SIM卡[").Append(gi.SimNO).Append("]和终端序列号[").Append(gi.PosList[0].MNO).Append("]的记录").Append(Constant.FOOT).ToString();
                                 foreach (DataClient dc in dataClientList)
                                 {
                                     if (dc.LoginUser != null)
                                     {
                                         dc.Send(s);
                                     }
                                 }
                                 logger.AddMsg(new StringBuilder("收到终端信息,但是未找到SIM卡[").Append(gi.SimNO).Append("]和终端序列号[").Append(gi.PosList[0].MNO).Append("]的记录").ToString());
                             }
                             catch { }
                             continue;
                         }
                     }
                 }
                 else if (gi.TcpConn != null)//tcp方式,以终端序列号为标准
                 {
                     if (gi.TcpConn.Car != null)
                     {
                         car          = gi.TcpConn.Car;
                         car.GprsConn = gi.TcpConn;
                     }
                     else
                     {
                         car = GetCarByMNO(gi.PosList[0].MNO);
                         try
                         {
                             //关闭重复的连接,释放资源
                             if (car.GprsConn != null)
                             {
                                 car.GprsConn.Socket.Close();
                             }
                         }
                         catch { }
                         car.GprsConn     = gi.TcpConn;
                         car.GprsConn.Car = car;
                     }
                 }
                 else//udp方式,以终端序列号为标准
                 {
                     car = GetCarByMNO(gi.PosList[0].MNO);
                     if (car != null)
                     {
                         UdpTerminal ut = (UdpTerminal)udpTable[gi.UdpRemote];
                         if (ut == null)
                         {
                             ut = new UdpTerminal(gi.UdpRemote, gi.UdpRPort);
                             udpTable.Add(gi.UdpRemote, ut);
                         }
                         ut.Port     = gi.UdpRPort;
                         car.UdpAddr = ut;
                     }
                 }
                 foreach (Position pos in gi.PosList)
                 {
                     pos.CarID = car.CarID;
                     if (pos.Mileage == 0)
                     {
                         pos.Mileage = car.Pos.Mileage; /*
                                                         * if(pos.Pointed == 0)//定位无效,位置以前次定位为准
                                                         * {
                                                         * pos.La = car.Pos.La;
                                                         * pos.Lo = car.Pos.Lo;
                                                         * }*/
                     }
                     if (pos.IsGetSetMsg)               //获取设置指令回复
                     {
                         S_GetSetting(car, pos.SettingStr);
                     }
                     else
                     {
                         car.Pos.Clone(pos);
                         if (pos.Alarm != "")//是否有报警信息
                         {
                             AlarmPosition apos = new AlarmPosition(0, pos);
                             if (car.AlarmPos.Count == 0)
                             {
                                 if (car.HandleAlarmClient != null)
                                 {
                                     car.HandleAlarmClient.HandleAlarmCar = null;
                                 }
                                 car.HandleAlarmClient = null;
                             }
                             car.AlarmPos.Add(apos);
                             S_Alarm(car, apos);
                         }
                         S_RefreshWatching(car);
                         if (pos.IsPointMsg)
                         {
                             S_Point(car);
                         }
                         //插入数据库
                         dbAssistant.AddPosition(pos.SqlInsertStr());
                     }
                 }
             }
         }
     }
     catch {}
 }
示例#2
0
 //发送信息
 public bool Send(UdpTerminal ut, String s)
 {
     return(udpConnection.Send(ut.Host, ut.Port, s));
 }
示例#3
0
 //������Ϣ
 public bool Send(UdpTerminal ut, String s)
 {
     return udpConnection.Send(ut.Host, ut.Port, s);
 }