Esempio n. 1
0
 /// <summary>
 /// ���ַ���������λ��
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static new AlarmPosition Parse(String s)
 {
     AlarmPosition pos = new AlarmPosition();
     String[] ss = s.Split(Constant.SPLIT2);
     try
     {
         pos.id = Int32.Parse(ss[0]);
         pos.CarID = Int32.Parse(ss[1]);
         pos.GpsTime = ss[2];
         pos.Pointed = Int32.Parse(ss[3]);
         pos.Lo = Double.Parse(ss[4]);
         pos.La = Double.Parse(ss[5]);
         pos.Speed = Int32.Parse(ss[6]);
         pos.Direction = Int32.Parse(ss[7]);
         pos.Status = ss[8];
         pos.Alarm = ss[9];
         pos.AlarmHandle = Int32.Parse(ss[10]);
     }
     catch { return null; }
     return pos;
 }
Esempio n. 2
0
        /// <summary>
        /// 从字符串解析定位点
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static new AlarmPosition Parse(String s)
        {
            AlarmPosition pos = new AlarmPosition();

            String[] ss = s.Split(Constant.SPLIT2);
            try
            {
                pos.id          = Int32.Parse(ss[0]);
                pos.CarID       = Int32.Parse(ss[1]);
                pos.GpsTime     = ss[2];
                pos.Pointed     = Int32.Parse(ss[3]);
                pos.Lo          = Double.Parse(ss[4]);
                pos.La          = Double.Parse(ss[5]);
                pos.Speed       = Int32.Parse(ss[6]);
                pos.Direction   = Int32.Parse(ss[7]);
                pos.Status      = ss[8];
                pos.Alarm       = ss[9];
                pos.AlarmHandle = Int32.Parse(ss[10]);
            }
            catch { return(null); }
            return(pos);
        }
Esempio n. 3
0
 //�±�����Ϣ
 private void S_Alarm(Car car, AlarmPosition apos)
 {
     try
     {
         StringBuilder stb = new StringBuilder(Constant.HEAD).Append(Constant.S_INFO).Append(Constant.S_INFO_ALARM);
         stb.Append(apos.ToString()).Append(Constant.FOOT);
         String s = stb.ToString();
         if(car.HandleAlarmClient == null)//�Ƿ��ѽӾ�
         {
             DataClient[] tempList = dataClientList.ToArray();
             foreach(DataClient dc in tempList)//����(δ�Ӿ�)
                 if(dc.LoginUser != null && dc.LoginUser.GetTeamByID(car.TeamID) != null && dc.LoginUser.PolicyAlarmList == 1)
                     dc.Send(s);
         }
         else
         {
             bool send = false;
             DataClient[] tempList = dataClientList.ToArray();
             foreach(DataClient dc in tempList)//����(�ѽӾ�)
                 if(dc == car.HandleAlarmClient)
                 {
                     send = dc.Send(s);
                     break;
                 }
             if(!send)//����ʧ�ܣ����ýӾ��û���ͬʱ���͵�������ϯ
             {
                 car.HandleAlarmClient = null;
                 foreach(DataClient dc in tempList)
                     if(dc.LoginUser != null && dc.LoginUser.GetTeamByID(car.TeamID) != null && dc.LoginUser.PolicyAlarmList == 1)
                         dc.Send(s);
             }
         }
     }
     catch(Exception e)
     {
         if(FormMain.LOG_ERR)
             logger.AddErr(e, "");
     }
 }
Esempio n. 4
0
 //��ʼ��ϵͳ����
 private bool LoadInfoFromDB()
 {
     bool ret = false;
     dbm = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);
     if(dbm != null)
     {
         try
         {
             //regionList.Clear();
             teamList.Clear();
             userList.Clear();
             DataTable dt = null;
             /*dbm.ExecuteQuery("select_region");
             foreach(DataRow dr in dt.Rows)
             {
                 int id = Int32.Parse(dr[0].ToString());
                 String s = dr[1].ToString();
                 Region region = new Region(dr[2].ToString());
                 region.RegionID = id;
                 region.RegionName = s;
                 regionList.Add(region);
             }*/
             dt = dbm.ExecuteQuery("select_team");
             foreach(DataRow dr in dt.Rows)
             {
                 Team team = new Team();
                 team.TeamID = Int32.Parse(dr[0].ToString());
                 team.Password = dr[1].ToString();
                 team.TeamName = dr[2].ToString();
                 team.TeamLinkman = dr[3].ToString();
                 team.TeamTel = dr[4].ToString();
                 team.TeamAddress = dr[5].ToString();
                 team.JoinTime = dr[6].ToString();
                 team.PolicyModCar = Int32.Parse(dr[7].ToString());
                 team.PolicyOrder = Int32.Parse(dr[8].ToString());
                 team.PolicyRegion = Int32.Parse(dr[9].ToString());
                 team.PolicyRegionAlarm = Int32.Parse(dr[10].ToString());
                 teamList.Add(team);
             }
             dt = dbm.ExecuteQuery("select_car");
             foreach(DataRow dr in dt.Rows)
             {
                 Car car = Car.ParseWithPosition(dr);
                 if(car != null)
                 {
                     //if(car.RegionID != 0)
                         //car.Region = GetRegionByID(car.RegionID);
                     car.Team = GetTeamByID(car.TeamID);
                     car.Team.Cars.Add(car);
                 }
             }
             dt = dbm.ExecuteQuery("select_user");
             foreach(DataRow dr in dt.Rows)
             {
                 User user = new User();
                 user.UserID = Int32.Parse(dr[0].ToString());
                 user.UserName = dr[1].ToString();
                 user.Password = dr[2].ToString();
                 user.UserType = Int32.Parse(dr[3].ToString());
                 user.Tel = dr[4].ToString();
                 user.Email = dr[5].ToString();
                 user.JoinTime = dr[6].ToString();
                 if(user.UserType != User.USER_ADMIN)
                 {
                     user.Teams = new List<Team>();
                     String ts = dr[7].ToString();
                     if(ts.Length > 0)
                     {
                         if(ts[0] == Constant.SPLIT_EX_1)
                             ts = ts.Substring(1);
                         if(ts[ts.Length - 1] == Constant.SPLIT_EX_1)
                             ts = ts.Substring(0, ts.Length - 1);
                     }
                     if(ts != null && ts != "")
                     {
                         user.TeamStr = ts;
                         String[] temp = ts.Split(Constant.SPLIT_EX_1);
                         foreach(String s in temp)
                         {
                             if(s == null || s == "")
                                 continue;
                             try
                             {
                                 Team team = GetTeamByID(Int32.Parse(s));
                                 if(team != null)
                                     user.Teams.Add(team);
                             }
                             catch { }
                         }
                     }
                     else user.TeamStr = "";
                     user.PolicyModTeam = Int32.Parse(dr[8].ToString());
                     user.PolicyModCar = Int32.Parse(dr[9].ToString());
                     user.PolicyOrder = Int32.Parse(dr[10].ToString());
                     user.PolicyExportCars = Int32.Parse(dr[11].ToString());
                     user.PolicyDeclare = Int32.Parse(dr[12].ToString());
                     user.PolicyAlarmList = Int32.Parse(dr[13].ToString());
                     user.PolicyOverTime = Int32.Parse(dr[14].ToString());
                     user.PolicyNotify = Int32.Parse(dr[15].ToString());
                 }
                 else
                 {
                     user.Teams = teamList;
                 }
                 userList.Add(user);
             }
             dt = dbm.ExecuteQuery("select_alarm");
             foreach(DataRow dr in dt.Rows)
             {
                 AlarmPosition apos = new AlarmPosition();
                 apos.Id = Int32.Parse(dr[0].ToString());
                 apos.CarID = Int32.Parse(dr[1].ToString());
                 apos.GpsTime = dr[2].ToString();
                 apos.Pointed = Int32.Parse(dr[3].ToString());
                 apos.Lo = Double.Parse(dr[4].ToString());
                 apos.La = Double.Parse(dr[5].ToString());
                 apos.Speed = Int32.Parse(dr[6].ToString());
                 apos.Direction = Int32.Parse(dr[7].ToString());
                 apos.Status = dr[8].ToString();
                 apos.Alarm = dr[9].ToString();
                 //GetCarByID(apos.CarID).AlarmPos.Add(apos); ��������Ի���
             }
             dt = dbm.ExecuteQuery("select carID from tDeclare where opUser=''");
             foreach(DataRow dr in dt.Rows)
             {
                 try
                 {
                     GetCarByID(Int32.Parse(dr[0].ToString())).DeclareCount++;
                 }
                 catch{}
             }
             ret = true;
         }
         catch(Exception e)
         {
             if(FormMain.LOG_ERR)
                 logger.AddErr(e, "");
         }
     }
     inited = ret;
     return ret;
 }
Esempio n. 5
0
        //初始化系统数据
        private bool LoadInfoFromDB()
        {
            bool ret = false;

            dbm = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);
            if (dbm != null)
            {
                try
                {
                    //regionList.Clear();
                    teamList.Clear();
                    userList.Clear();
                    DataTable dt = null;

                    /*dbm.ExecuteQuery("select_region");
                     * foreach(DataRow dr in dt.Rows)
                     * {
                     *  int id = Int32.Parse(dr[0].ToString());
                     *  String s = dr[1].ToString();
                     *  Region region = new Region(dr[2].ToString());
                     *  region.RegionID = id;
                     *  region.RegionName = s;
                     *  regionList.Add(region);
                     * }*/
                    dt = dbm.ExecuteQuery("select_team");
                    foreach (DataRow dr in dt.Rows)
                    {
                        Team team = new Team();
                        team.TeamID            = Int32.Parse(dr[0].ToString());
                        team.Password          = dr[1].ToString();
                        team.TeamName          = dr[2].ToString();
                        team.TeamLinkman       = dr[3].ToString();
                        team.TeamTel           = dr[4].ToString();
                        team.TeamAddress       = dr[5].ToString();
                        team.JoinTime          = dr[6].ToString();
                        team.PolicyModCar      = Int32.Parse(dr[7].ToString());
                        team.PolicyOrder       = Int32.Parse(dr[8].ToString());
                        team.PolicyRegion      = Int32.Parse(dr[9].ToString());
                        team.PolicyRegionAlarm = Int32.Parse(dr[10].ToString());
                        teamList.Add(team);
                    }
                    dt = dbm.ExecuteQuery("select_car");
                    foreach (DataRow dr in dt.Rows)
                    {
                        Car car = Car.ParseWithPosition(dr);
                        if (car != null)
                        {
                            //if(car.RegionID != 0)
                            //car.Region = GetRegionByID(car.RegionID);
                            car.Team = GetTeamByID(car.TeamID);
                            car.Team.Cars.Add(car);
                        }
                    }
                    dt = dbm.ExecuteQuery("select_user");
                    foreach (DataRow dr in dt.Rows)
                    {
                        User user = new User();
                        user.UserID   = Int32.Parse(dr[0].ToString());
                        user.UserName = dr[1].ToString();
                        user.Password = dr[2].ToString();
                        user.UserType = Int32.Parse(dr[3].ToString());
                        user.Tel      = dr[4].ToString();
                        user.Email    = dr[5].ToString();
                        user.JoinTime = dr[6].ToString();
                        if (user.UserType != User.USER_ADMIN)
                        {
                            user.Teams = new List <Team>();
                            String ts = dr[7].ToString();
                            if (ts.Length > 0)
                            {
                                if (ts[0] == Constant.SPLIT_EX_1)
                                {
                                    ts = ts.Substring(1);
                                }
                                if (ts[ts.Length - 1] == Constant.SPLIT_EX_1)
                                {
                                    ts = ts.Substring(0, ts.Length - 1);
                                }
                            }
                            if (ts != null && ts != "")
                            {
                                user.TeamStr = ts;
                                String[] temp = ts.Split(Constant.SPLIT_EX_1);
                                foreach (String s in temp)
                                {
                                    if (s == null || s == "")
                                    {
                                        continue;
                                    }
                                    try
                                    {
                                        Team team = GetTeamByID(Int32.Parse(s));
                                        if (team != null)
                                        {
                                            user.Teams.Add(team);
                                        }
                                    }
                                    catch { }
                                }
                            }
                            else
                            {
                                user.TeamStr = "";
                            }
                            user.PolicyModTeam    = Int32.Parse(dr[8].ToString());
                            user.PolicyModCar     = Int32.Parse(dr[9].ToString());
                            user.PolicyOrder      = Int32.Parse(dr[10].ToString());
                            user.PolicyExportCars = Int32.Parse(dr[11].ToString());
                            user.PolicyDeclare    = Int32.Parse(dr[12].ToString());
                            user.PolicyAlarmList  = Int32.Parse(dr[13].ToString());
                            user.PolicyOverTime   = Int32.Parse(dr[14].ToString());
                            user.PolicyNotify     = Int32.Parse(dr[15].ToString());
                        }
                        else
                        {
                            user.Teams = teamList;
                        }
                        userList.Add(user);
                    }
                    dt = dbm.ExecuteQuery("select_alarm");
                    foreach (DataRow dr in dt.Rows)
                    {
                        AlarmPosition apos = new AlarmPosition();
                        apos.Id        = Int32.Parse(dr[0].ToString());
                        apos.CarID     = Int32.Parse(dr[1].ToString());
                        apos.GpsTime   = dr[2].ToString();
                        apos.Pointed   = Int32.Parse(dr[3].ToString());
                        apos.Lo        = Double.Parse(dr[4].ToString());
                        apos.La        = Double.Parse(dr[5].ToString());
                        apos.Speed     = Int32.Parse(dr[6].ToString());
                        apos.Direction = Int32.Parse(dr[7].ToString());
                        apos.Status    = dr[8].ToString();
                        apos.Alarm     = dr[9].ToString();
                        //GetCarByID(apos.CarID).AlarmPos.Add(apos); 启动弹出对话框
                    }
                    dt = dbm.ExecuteQuery("select carID from tDeclare where opUser=''");
                    foreach (DataRow dr in dt.Rows)
                    {
                        try
                        {
                            GetCarByID(Int32.Parse(dr[0].ToString())).DeclareCount++;
                        }
                        catch {}
                    }
                    ret = true;
                }
                catch (Exception e)
                {
                    if (FormMain.LOG_ERR)
                    {
                        logger.AddErr(e, "");
                    }
                }
            }
            inited = ret;
            return(ret);
        }
Esempio n. 6
0
 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 {}
 }