コード例 #1
0
    private void StopTime(int devID, int GateWayID, int Uid)
    {
        IBeaconData condition = new IBeaconData();

        condition.DevID     = devID;
        condition.GateWayID = GateWayID;
        condition.UserID    = Uid;
        condition.AddConditon(" and DateDiff(dd,LastTime,getdate())=0");//今天
        IBeaconData data = TableOperate <IBeaconData> .GetRowData(condition);

        if (data.ID > 0)//获取今天的数据
        {
            TimeSpan t3   = DateTime.Now - data.LastTime;
            double   time = t3.TotalSeconds;
            if (time > 58 && time <= 70)//更新间隔50秒和60s之间算持续站在范围内
            {
                condition.StopTime = data.StopTime + 1;
                condition.ID       = data.ID;
                condition.LastTime = DateTime.Now;
                TableOperate <IBeaconData> .Update(condition);

                AddStopTime(1, GateWayID);
            }
            else if (time > 120)//离开再回来120秒后计算
            {
                condition.ID       = data.ID;
                condition.LastTime = DateTime.Now;
                TableOperate <IBeaconData> .Update(condition);
            }
        }
        else
        {
            condition.StopTime = 1;
            condition.LastTime = DateTime.Now;
            TableOperate <IBeaconData> .Insert(condition);

            AddStopTime(1, GateWayID);
            IntoGetWay(GateWayID);
        }
    }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string act = "";

        if (!string.IsNullOrEmpty(this.Request["act"]))
        {
            act = Convert.ToString(Request["act"]);
        }
        string json = "";

        if (act == "getcount")
        {
            UserVistCount condition = new UserVistCount();
            condition.ID = 1;
            UserVistCount value = TableOperate <UserVistCount> .GetRowData(condition);

            int nowcount = 0;
            if (value.AddTime.Date == DateTime.Now.Date)
            {
                nowcount = value.NowDayCount;
            }
            else
            {
                nowcount = 0;
            }
            json += "{\"ID\":" + value.ID + ", \"AllCount\":\"" + value.Count + "\", \"NowDayCount\":\"" + nowcount + "\", \"StopTime\":\"" + value.StopTime + "\"}";
        }
        else if (act == "now")
        {
            #region MyRegion
            // json = "{\"list\":[";
            // List<IBeaconGateWay> list = TableOperate<IBeaconGateWay>.Select();
            // View_iBeaconNow condition = new View_iBeaconNow();
            // View_iBeaconNow value = new View_iBeaconNow();
            //// condition.AddConditon(" and DateDiff(dd,LastTime,getdate())=0");//今天
            // condition.AddConditon("and UserID!=0");//排除非绑定
            // List<View_iBeaconNow> ibeaconlist = TableOperate<View_iBeaconNow>.Select(value, condition);
            // for (int i = 0; i < list.Count; i++)
            // {
            //     json += "{\"ID\":" + list[i].ID + ", \"name\":\"" + list[i].DevName + "\", \"Count\":\"" + GetCount(ibeaconlist, list[i].ID) + "\"},";
            // }
            // json = json.Trim(',');
            // json += "]}";
            //  json = StortJson(json);
            #endregion
            json = "{\"list\":[";
            List <IBeaconGateWay> list = TableOperate <IBeaconGateWay> .Select();

            for (int i = 0; i < list.Count; i++)
            {
                json += "{\"ID\":" + list[i].ID + ", \"name\":\"" + list[i].DevName + "\", \"Count\":\"" + list[i].X + "\"},";
            }
            json  = json.Trim(',');
            json += "]}";
        }
        else if (act == "data")
        {
            json = "{\"list\":[";
            List <IBeaconGateWay> list = TableOperate <IBeaconGateWay> .Select();

            IBeaconData condition = new IBeaconData();
            IBeaconData value     = new IBeaconData();
            if (!string.IsNullOrEmpty(Request["now"]))
            {
                condition.AddConditon(" and DateDiff(dd,LastTime,getdate())=0"); //今天
            }
            if (!string.IsNullOrEmpty(Request["userid"]))                        //获取用户的
            {
                int userID = Convert.ToInt32(Request["userid"]);
                condition.UserID = userID;
            }
            condition.AddConditon("and UserID!=0");//排除非绑定
            List <IBeaconData> ibeaconlist = TableOperate <IBeaconData> .Select(value, condition);

            for (int i = 0; i < list.Count; i++)
            {
                json += "{\"ID\":" + list[i].ID + ", \"name\":\"" + list[i].DevName + "\", \"stopTime\":\"" + GetStopTime(ibeaconlist, list[i].ID) + "\", \"Count\":\"" + list[i].X + "\"},";
            }
            json  = json.Trim(',');
            json += "]}";
        }
        else if (act == "rest")
        {
            string sql = "UPDATE IBeaconDev SET UserID = 0 WHERE ID >0";
            TableOperate <IBeaconDev> .Execute(sql);
        }



        Response.Write(json);
    }