/// <summary> /// 得到一个对象实体 /// </summary> public DogApi.Model.UsersModel DataRowToModel(DataRow row) { DogApi.Model.UsersModel model = new DogApi.Model.UsersModel(); if (row != null) { if (row["userName"] != null) { model.userName = row["userName"].ToString(); } if (row["passWord"] != null) { model.passWord = row["passWord"].ToString(); } //model.lat=row["lat"].ToString(); //model.lng=row["lng"].ToString(); //model.alt=row["alt"].ToString(); if (row["tel"] != null) { model.tel = row["tel"].ToString(); } if (row["age"] != null && row["age"].ToString() != "") { model.age = int.Parse(row["age"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DogApi.Model.UsersModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update users set "); strSql.Append("passWord=@passWord,"); strSql.Append("lat=@lat,"); strSql.Append("lng=@lng,"); strSql.Append("alt=@alt,"); strSql.Append("tel=@tel,"); strSql.Append("age=@age"); strSql.Append(" where userName=@userName "); SQLiteParameter[] parameters = { new SQLiteParameter("@passWord", DbType.String, 50), new SQLiteParameter("@lat", DbType.Double, 8), new SQLiteParameter("@lng", DbType.Double, 8), new SQLiteParameter("@alt", DbType.Double, 8), new SQLiteParameter("@tel", DbType.String, 30), new SQLiteParameter("@age", DbType.Int32, 8), new SQLiteParameter("@userName", DbType.String, 25) }; parameters[0].Value = model.passWord; parameters[1].Value = model.lat; parameters[2].Value = model.lng; parameters[3].Value = model.alt; parameters[4].Value = model.tel; parameters[5].Value = model.age; parameters[6].Value = model.userName; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(DogApi.Model.UsersModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into users("); strSql.Append("userName,passWord,lat,lng,alt,tel,age)"); strSql.Append(" values ("); strSql.Append("@userName,@passWord,@lat,@lng,@alt,@tel,@age)"); SQLiteParameter[] parameters = { new SQLiteParameter("@userName", DbType.String, 25), new SQLiteParameter("@passWord", DbType.String, 50), new SQLiteParameter("@lat", DbType.Double, 8), new SQLiteParameter("@lng", DbType.Double, 8), new SQLiteParameter("@alt", DbType.Double, 8), new SQLiteParameter("@tel", DbType.String, 30), new SQLiteParameter("@age", DbType.Int32, 8) }; parameters[0].Value = model.userName; parameters[1].Value = model.passWord; parameters[2].Value = model.lat; parameters[3].Value = model.lng; parameters[4].Value = model.alt; parameters[5].Value = model.tel; parameters[6].Value = model.age; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DogApi.Model.UsersModel GetModel(string userName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select userName,passWord,lat,lng,alt,tel,age from users "); strSql.Append(" where userName=@userName "); SQLiteParameter[] parameters = { new SQLiteParameter("@userName", DbType.String, 25) }; parameters[0].Value = userName; DogApi.Model.UsersModel model = new DogApi.Model.UsersModel(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }