Пример #1
0
 ///<summary>
 /// 将对象转换为实体
 /// </summary>
 private Models.Rssi DataRowToModel(DataRow row)
 {
     Models.Rssi model = new Models.Rssi();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["coord_id"] != null && row["coord_id"].ToString() != "")
         {
             model.coord_id = Int32.Parse(row["coord_id"].ToString());
         }
         if (row["rssi"] != null && row["rssi"].ToString() != "")
         {
             model.rssi = Int32.Parse(row["rssi"].ToString());
         }
         if (row["mobile_id"] != null && row["mobile_id"].ToString() != "")
         {
             model.mobile_id = Int32.Parse(row["mobile_id"].ToString());
         }
         if (row["mac"] != null && row["mac"].ToString() != "")
         {
             model.mac = row["mac"].ToString();
         }
     }
     return(model);
 }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Models.Rssi model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_wifi_rssi(rssi,mobile_id,mac,coord_id,room_id)");
            strSql.Append(" values (@rssi,@mobile_id,@mac,@coord_id,@room_id)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@rssi",      SqlDbType.Int),
                new SqlParameter("@mobile_id", SqlDbType.Int),
                new SqlParameter("@mac",       SqlDbType.VarChar,20),
                new SqlParameter("@coord_id",  SqlDbType.Int),
                new SqlParameter("@room_id",   SqlDbType.Int)
            };
            parameters[0].Value = model.rssi;
            parameters[1].Value = model.mobile_id;
            parameters[2].Value = model.mac;
            parameters[3].Value = model.coord_id;
            parameters[4].Value = model.room_id;

            object obj = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            model.id = Convert.ToInt32(obj);
            if (model.id > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.Rssi GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,rssi,mobile_id,mac,coord_id");
            strSql.Append(" from tb_wifi_rssi");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Models.Rssi model = new Models.Rssi();
            DataSet     ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        // 处理json数据 执行插入操作
        private int addJsonDataToDB(JObject value)
        {
            int flag = 0;

            Models.Fingerprint model_finger = new Models.Fingerprint();
            try
            {
                model_finger.coord   = value["coord"].ToString();
                model_finger.memory  = value["memory"].ToString();
                model_finger.addtime = value["addtime"].ToString();
                model_finger.flag    = Int32.Parse(value["flag"].ToString());
            }
            catch (Exception e)
            {
                return(4);
            }

            int coord_id = db_fingerprint.Add(model_finger);

            // 插入各个AP的rssi数据
            if (coord_id > 0)
            {
                Models.Rssi model_rssi = new Models.Rssi();
                JToken      ap         = new JObject();
                model_rssi.coord_id = coord_id;
                model_rssi.room_id  = int.Parse(value["room_id"].ToString());
                try
                {
                    model_rssi.mobile_id = Int32.Parse(value["mobile_id"].ToString());
                    ap = value["ap"];
                }
                catch (Exception e)
                {
                    return(4);
                }

                if (ap.Count() > 0)
                {
                    IEnumerable <JToken> temp = ap.Values();
                    foreach (var item in temp)
                    {
                        try
                        {
                            model_rssi.rssi = Int32.Parse(item["rssi"].ToString());
                            model_rssi.mac  = item["mac"].ToString();
                        }
                        catch (Exception e)
                        {
                            return(4);
                        }
                        if (!db_rssi.Add(model_rssi))
                        {
                            flag = 1;
                            continue;
                        }
                    }
                }
                else
                {
                    flag = 2;
                }
            }
            else
            {
                flag = 3;
            }
            return(flag);
        }
Пример #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Models.Rssi model)
 {
     return(true);
 }