/// <summary> /// 更新一条数据 /// </summary> public int Update(Model.MonitorTask model) { StringBuilder strSql = new StringBuilder(); strSql.Append("UPDATE MonitorTask SET "); strSql.Append("PID=@in_PID,"); strSql.Append("Name=@in_Name,"); strSql.Append("PolygonString=geometry::STGeomFromText('LINESTRING(" + model.PolygonString + ")', 4326),"); strSql.Append("MBR=@in_MBR"); strSql.Append(" WHERE ID=@in_ID"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@in_PID", SqlDbType.Int), new SqlParameter("@in_Name", SqlDbType.NVarChar), //new SqlParameter("@in_PolygonString", SqlDbType.Binary), new SqlParameter("@in_MBR", SqlDbType.NVarChar), new SqlParameter("@in_ID", SqlDbType.Int) }; cmdParms[0].Value = model.PID; cmdParms[1].Value = model.Name; //cmdParms[2].Value = model.PolygonString; cmdParms[2].Value = model.MBR; cmdParms[3].Value = model.ID; return(DbHelperSQL.ExecuteSql(strSql.ToString(), cmdParms)); }
/// <summary> /// 由一行数据得到一个实体 /// </summary> private Model.MonitorTask GetModel(DbDataReader dr) { Model.MonitorTask model = new Model.MonitorTask(); model.ID = DbHelperSQL.GetInt(dr["ID"]); model.PID = DbHelperSQL.GetInt(dr["PID"]); model.Name = DbHelperSQL.GetString(dr["Name"]); model.PolygonString = DbHelperSQL.GetBinary(dr["PolygonString"]); model.MBR = DbHelperSQL.GetString(dr["MBR"]); return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.MonitorTask GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM MonitorTask "); strSql.Append(" WHERE ID=" + ID.ToString()); Model.MonitorTask model = null; using (SqlDataReader dr = DbHelperSQL.ExecuteReader(strSql.ToString())) { while (dr.Read()) { model = GetModel(dr); } return(model); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.MonitorTask model) { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO MonitorTask("); strSql.Append("PID,Name,PolygonString,MBR)"); strSql.Append(" VALUES ("); strSql.Append("@in_PID,@in_Name" + "geometry::STGeomFromText('LINESTRING(" + model.PolygonString + ")', 4326)" + "@in_MBR)"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@in_PID", SqlDbType.Int), new SqlParameter("@in_Name", SqlDbType.NVarChar), //new SqlParameter("@in_PolygonString", SqlDbType.Binary), new SqlParameter("@in_MBR", SqlDbType.NVarChar) }; cmdParms[0].Value = model.PID; cmdParms[1].Value = model.Name; //cmdParms[2].Value = model.PolygonString; cmdParms[2].Value = model.MBR; return(DbHelperSQL.ExecuteSql(strSql.ToString(), cmdParms)); }