示例#1
0
        private void GetDeviceTracking(int DeviceID)
        {
            MG_DAL.SQLServerOperating sqlHelper = new MG_DAL.SQLServerOperating();
            string strSql = "select d.DeviceID,d.SerialNumber,DeviceName,l.OLat,l.OLng,l.LastCommunication DeviceDate,l.Speed,l.Course,l.DataContext from devices d inner join LKLocation l on l.DeviceID=d.DeviceiD where d.DeviceID =@DeviceID and d.deleted=0";// model=213 and

            dic = sqlHelper.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID) }).toDictionary();

            Geocoding geo = new Amap();
            Gps       gps = geo.Translate(dic["OLat"], dic["OLng"]);

            //Gps gps = Utils.gps84_To_Gcj02(dic["OLat"], dic["OLng"]);
            dic["OLat"]       = gps.getWgLat().ToString();
            dic["OLng"]       = gps.getWgLon().ToString();
            dic["Address"]    = gps.Address;
            dic["CourseName"] = Utils.GetCoureName(dic["Course"]);
            var dc         = dic["DataContext"];
            var doorStatus = "未知";

            if (dc.Split('-').Length > 3 && !string.IsNullOrEmpty(dc.Split('-')[3]))
            {
                dc = dc.Split('-')[3];
                if (dc.Equals("0"))
                {
                    doorStatus = "打开";
                }
                else
                {
                    doorStatus = "关闭";
                }
            }
            dic["DataContext"] = doorStatus;// = dic["DataContext"].Split('-')[3]; //0--- 主电断开, 1-----主电连接
            Response.Write(Utils.ToJson(dic));
            Response.End();
        }
示例#2
0
        public Geocoding GetCurrentMapType()
        {
            Geocoding geo;

            if (Utils.GetCache <LoginUserInfo>(cacheKey).MapType == MapType.BAIDU)
            {
                geo     = new Baidu();
                geo.key = Utils.GetBaiDuKey();
            }
            else
            {
                geo     = new Amap();
                geo.key = Utils.GetAmapKey();
            }
            return(geo);
        }
示例#3
0
        private string GetHistory(int deviceid, string startdate, string enddate)
        {
            var    list        = new List <Dictionary <string, string> >();
            string speedfilter = "2";

            if (string.IsNullOrEmpty(deviceid.ToString()) || string.IsNullOrEmpty(startdate) || string.IsNullOrEmpty(enddate))
            {
                return(Utils.ToJson(list));
            }
            if (string.IsNullOrEmpty(speedfilter))
            {
                speedfilter = Utils.SpeedFilter.toStringEmpty();
            }
            try
            {
                DateTime startTime = Convert.ToDateTime(startdate);
                DateTime endTime   = Convert.ToDateTime(enddate);
                if (startTime >= endTime)
                {
                    return(Utils.ToJson(list));
                }
                TimeSpan ts   = endTime - startTime;
                double   days = Math.Ceiling(ts.TotalDays);
                //一次最多只能看5天的数据
                if (days > 5)
                {
                    return(Utils.ToJson(list));
                }
                string        DataBaseBefore = "YWData";// ConfigurationManager.AppSettings["DataBaseName"].ToStringEmpty();
                StringBuilder strSql         = new StringBuilder();

                string startTimeUtc = startTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss");
                string endTimeUtc   = endTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss");

                strSql.Append(" select DeviceTime, OLat, OLng, Speed, Course from ( ");
                string where = " where speed > @speedfilter and deviceid=@deviceid and DeviceUTCTime>@startTimeUtc and DeviceUTCTime<@endTimeUtc";
                for (int i = 0; i < days; i++)
                {
                    string DateBase  = DataBaseBefore + startTime.ToString("yyyyMM");
                    int    TableName = Convert.ToInt32(startTime.ToString("dd"));
                    strSql.Append("select dateadd(HH,8,DeviceUTCTime)DeviceTime, OLat, OLng, Speed, Course from  [" + DateBase + "].[dbo].[Location" + TableName + @"]");
                    strSql.Append(where);
                    if (i != days - 1)
                    {
                        strSql.Append(" union all ");
                    }
                    startTime = startTime.AddDays(1);
                }
                strSql.Append(" )t order by DeviceTime");
                SQLServerOperating s     = new SQLServerOperating();
                string             model = s.Select("select di.DataText from Devices d inner join Dictionary di on di.DataValue=d.Model where DeviceID=@DeviceID", new SqlParameter[] { new SqlParameter("DeviceID", deviceid) });
                if (model.EndsWith("W") || model.EndsWith("WD") || model.EndsWith("WF"))
                {
                    speedfilter = "-1";
                }
                SqlParameter[] pars = new SqlParameter[] {
                    new SqlParameter("speedfilter", speedfilter),
                    new SqlParameter("deviceid", deviceid),
                    new SqlParameter("startTimeUtc", startTimeUtc),
                    new SqlParameter("endTimeUtc", endTimeUtc)
                };

                DataTable dt = s.Selects(strSql.ToString(), pars);
                //List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                Geocoding geo = new Amap();
                foreach (DataRow row in dt.Rows)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    foreach (DataColumn dc in dt.Columns)
                    {
                        dic[dc.ColumnName] = row[dc.ColumnName].toStringEmpty();
                    }
                    Gps gps       = geo.Translate(dic["OLat"], dic["OLng"], false);
                    var listWhere = list.Where(l => l.ContainsValue(gps.getWgLat().ToString()) && l.ContainsValue(gps.getWgLon().ToString()));
                    if (listWhere.Count() > 0)
                    {
                        continue;
                    }
                    dic["OLat"] = gps.getWgLat().toStringEmpty();
                    dic["OLng"] = gps.getWgLon().toStringEmpty();
                    list.Add(dic);
                }
                return(Utils.ToJson(list));
            }
            catch (Exception ex)
            {
                Utils.log("GetHistoryLocus Error2:" + ex.Message + ",堆栈信息:" + ex.StackTrace + "," + deviceid + "-" + startdate + "-" + enddate);
                return(Utils.ToJson(list));
            }
        }