コード例 #1
0
ファイル: monitor.cs プロジェクト: qingsangde/learngit
        /// <summary>
        /// 数据转换
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="OldDate">扩展报警状态位新老数据分割时间 </param>
        /// <returns></returns>
        private WebGIS.RealtimeDataServer.CarRealData[] CarDataConvent(DataTable dt, DateTime OldDate)
        {
            List <WebGIS.RealtimeDataServer.CarRealData> res = new List <WebGIS.RealtimeDataServer.CarRealData>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dtr = dt.Rows[i];
                WebGIS.RealtimeDataServer.CarRealData cdm = new WebGIS.RealtimeDataServer.CarRealData();
                cdm.TDateTime   = DateTime.Parse(dtr["T_DateTime"].ToString());
                cdm.Carid       = int.Parse(dtr["CID"].ToString());
                cdm.CarNum      = dtr["CarNo"].ToString();
                cdm.Alarm       = long.Parse(dtr["T_ALARM"].ToString());
                cdm.Alarm808    = long.Parse(dtr["T_Alarm808"].ToString());
                cdm.AlarmExt808 = long.Parse(dtr["T_AlarmExt808"].ToString());


                cdm.AltitudeMeters = int.Parse(dtr["T_AltitudeMeters"] == DBNull.Value ? "0" : dtr["T_AltitudeMeters"].ToString());

                cdm.Heading    = int.Parse(dtr["T_Heading"].ToString());
                cdm.HeadingStr = CarDataConvert.ConvertDir(cdm.Heading);
                double[] s = CarDataConvert.ConvertCoordToGCJ02(double.Parse(dtr["T_Long"].ToString()), double.Parse(dtr["T_Lati"].ToString()));
                cdm.Lati         = s[1];
                cdm.Long         = s[0];
                cdm.Speed        = float.Parse(dtr["T_Speed"].ToString());
                cdm.Status       = int.Parse(dtr["T_Status"].ToString());
                cdm.Status808    = int.Parse(dtr["T_Status808"].ToString());
                cdm.StatusExt808 = int.Parse(dtr["T_StatusExt808"].ToString());
                if (cdm.TDateTime > OldDate)
                {
                    cdm.AlarmStr  = AlarmStatusAnalysis.ConvertMain.AlarmConvertMain(cdm.Alarm, cdm.Alarm808, cdm.AlarmExt808);
                    cdm.StatusStr = AlarmStatusAnalysis.ConvertMain.StatusConvertMain(cdm.Status, cdm.Status808, cdm.StatusExt808);
                }
                else
                {
                    cdm.AlarmStr  = AlarmStatusAnalysis.ConvertMain.AlarmConvertMain(cdm.Alarm, cdm.Alarm808, cdm.AlarmExt808, false);
                    cdm.StatusStr = AlarmStatusAnalysis.ConvertMain.StatusConvertMain(cdm.Status, cdm.Status808, cdm.StatusExt808, false);
                }

                cdm.SumMiles = int.Parse(dtr["T_SumMiles"].ToString());
                if (dtr["TNO"] == DBNull.Value)
                {
                    continue;
                }
                cdm.TNO = long.Parse(dtr["TNO"].ToString());;
                //cdm.sPositionAdditionalInfo = timeResponse.Tir[i].sPositionAdditionalInfo;

                cdm.OnlineStatus = (DateTime.Now - cdm.TDateTime).TotalMinutes < 5 ? 1 : 2;

                if (cdm.OnlineStatus == 2)
                {
                    cdm.OnlineStatusStr = "停止";
                }
                else
                {
                    cdm.OnlineStatusStr = "上线";
                }

                res.Add(cdm);
            }
            return(res.ToArray());
        }
コード例 #2
0
        private DataTable ConvertTable(DataTable track, string cno, Double os, Double od)
        {
            try
            {
                //从数据库查询车辆最后轨迹信息并转化处理
                string   OldSplitDate = System.Configuration.ConfigurationManager.AppSettings[SysFlag + "_OldSplitDate"];
                DateTime olddate      = DateTime.MinValue;
                if (!string.IsNullOrEmpty(OldSplitDate) && DateTime.TryParse(OldSplitDate, out olddate))
                {
                }


                track = FormatTable(track);//格式化table
                for (int i = 0; i < track.Rows.Count; i++)
                {
                    DataRow dtr = track.Rows[i];

                    //序号
                    dtr["no"] = i + 1;
                    //车牌号
                    dtr["cno"] = cno;
                    //Gps时间
                    dtr["dt"] = dtr["T_DateTime"];

                    //速度
                    Double sp = Double.Parse(dtr["T_Speed"].ToString().Trim());
                    dtr["sp"] = sp;
                    if (sp < os)
                    {
                        dtr["os"] = false;
                    }
                    else
                    {
                        dtr["os"] = true;
                    }
                    //经纬度纠偏
                    double[] s = CarDataConvert.ConvertCoordToGCJ02(double.Parse(dtr["T_Long"].ToString()), double.Parse(dtr["T_Lati"].ToString()));
                    //经度
                    dtr["lng"] = Math.Round(s[0], 8);
                    //纬度
                    dtr["lat"] = Math.Round(s[1], 8);

                    //方向
                    dtr["dir"] = CarDataConvert.ConvertDir(int.Parse(dtr["T_Heading"].ToString()));
                    //海拔
                    dtr["tam"]            = Double.Parse(dtr["T_AltitudeMeters"] == DBNull.Value ? "0" : dtr["T_AltitudeMeters"].ToString()).ToString().Trim();
                    dtr["T_ALARM808"]     = Double.Parse(dtr["T_ALARM808"] == DBNull.Value ? "0" : dtr["T_ALARM808"].ToString()).ToString().Trim();
                    dtr["T_ALARMExt808"]  = Double.Parse(dtr["T_ALARMExt808"] == DBNull.Value ? "0" : dtr["T_ALARMExt808"].ToString()).ToString().Trim();
                    dtr["T_Status808"]    = Double.Parse(dtr["T_Status808"] == DBNull.Value ? "0" : dtr["T_Status808"].ToString()).ToString().Trim();
                    dtr["T_StatusExt808"] = Double.Parse(dtr["T_StatusExt808"] == DBNull.Value ? "0" : dtr["T_StatusExt808"].ToString()).ToString().Trim();
                    if (DateTime.Parse(dtr["T_DateTime"].ToString()) > olddate)
                    {
                        //报警状态
                        dtr["ta"] = AlarmStatusAnalysis.ConvertMain.AlarmConvertMain(long.Parse(dtr["T_ALARM"].ToString()), long.Parse(dtr["T_ALARM808"].ToString()), long.Parse(dtr["T_ALARMExt808"].ToString()));
                        //运行状态
                        dtr["ts"] = AlarmStatusAnalysis.ConvertMain.StatusConvertMain(int.Parse(dtr["T_Status"].ToString()), int.Parse(dtr["T_Status808"].ToString()), int.Parse(dtr["T_StatusExt808"].ToString()));
                    }
                    else
                    {
                        //报警状态
                        dtr["ta"] = AlarmStatusAnalysis.ConvertMain.AlarmConvertMain(long.Parse(dtr["T_ALARM"].ToString()), long.Parse(dtr["T_ALARM808"].ToString()), long.Parse(dtr["T_ALARMExt808"].ToString()), false);
                        //运行状态
                        dtr["ts"] = AlarmStatusAnalysis.ConvertMain.StatusConvertMain(int.Parse(dtr["T_Status"].ToString()), int.Parse(dtr["T_Status808"].ToString()), int.Parse(dtr["T_StatusExt808"].ToString()), false);
                    }


                    //里程解析
                    dtr["tsm"] = Double.Parse(dtr["T_SumMiles"].ToString().Trim());


                    if (i == 0)
                    {
                        dtr["od"]  = false;
                        dtr["odd"] = 0;
                    }
                    else
                    {
                        DataRow dtrLast = track.Rows[i - 1];
                        Double  lat1    = Double.Parse(dtrLast["lat"].ToString());
                        Double  lng1    = Double.Parse(dtrLast["lng"].ToString());
                        Double  lat2    = Double.Parse(dtr["lat"].ToString());
                        Double  lng2    = Double.Parse(dtr["lng"].ToString());
                        Double  sod     = Math.Round(CarDataConvert.GetDistance(lat1, lng1, lat2, lng2), 2);
                        if (sod < od)
                        {
                            dtr["od"] = false;
                        }
                        else
                        {
                            dtr["od"] = true;
                        }
                        dtr["odd"] = Math.Round(Double.Parse(dtrLast["odd"].ToString()) + sod, 2);
                    }
                    //地址解析
                    dtr["add"] = null;
                }

                //移除无用列
                track.Columns.Remove("cid");
                track.Columns.Remove("T_DateTime");
                track.Columns.Remove("T_Lati");
                track.Columns.Remove("T_Long");
                track.Columns.Remove("T_Heading");
                track.Columns.Remove("T_Speed");
                track.Columns.Remove("T_Status");
                track.Columns.Remove("T_ALARM");
                track.Columns.Remove("T_SumMiles");
                track.Columns.Remove("T_AltitudeMeters");

                return(track);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }