/// <summary> /// 得到一个对象实体 /// </summary> /// <param name="SensorID"></param> /// <returns></returns> public Model.Sensor_1 GetModel(decimal SensorID) { StringBuilder strSql = new StringBuilder(); strSql.Append("Select * from SENSOR_1 "); strSql.Append(" Where SensorID=" + SensorID); Model.Sensor_1 model = null; //数据库连接 SqlConnection connection = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(strSql.ToString(), connection); connection.Open(); SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); using (DbDataReader dr = myReader) { while (dr.Read()) { model = GetModel(dr);//本类中的重载函数 } return(model); } }
/// <summary> /// 第一类传感器添加函数,添加删除和管理的数据库连接还存在问题 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Model.Sensor_1 model) { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO SENSOR_1("); strSql.Append("SensorID,SensorName,SensorType,BandNumber,BandCenter,LookAngle,SwathVelocity,SwathWidth,GeometryResolution,PLATFORM_ID,"); strSql.Append("Application,Inclination,PixelPerLine,SquintAngle,AzimuthDirectionResolution,DistanceResolution,MaxSlewTimesPerCircle,"); strSql.Append("MaxPowerOnTimesPerDay,MinImagingTimeNonInterupt,DuringSwitch,MaxObvDur,MinObvDur,MAXGSD)"); strSql.Append(" Values("); strSql.Append("@in_SensorID,@in_SensorName,@in_SensorType,@in_BandNumber,@in_BandCenter,@in_LookAngle,@in_SwathVelocity,@in_SwathWidth,@in_GeometryResolution,@in_PLATFORM_ID,"); strSql.Append("@in_Application,@in_Inclination,@in_PixelPerLine,@in_SquintAngle,@in_AzimuthDirectionResolution,@in_DistanceResolution,"); strSql.Append("@in_MaxSlewTimesPerCircle,@in_MaxPowerOnTimesPerDay,@in_MinImagingTimeNonInterupt,@in_DuringSwitch,@in_MaxObvDur,@in_MinObvDur,@in_MAXGSD)"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@in_SensorID", SqlDbType.Decimal), new SqlParameter("@in_SensorName", SqlDbType.NVarChar), new SqlParameter("@in_SensorType", SqlDbType.NVarChar), new SqlParameter("@in_BandNumber", SqlDbType.Decimal), new SqlParameter("@in_BandCenter", SqlDbType.Decimal), new SqlParameter("@in_LookAngle", SqlDbType.Decimal), new SqlParameter("@in_SwathVelocity", SqlDbType.Decimal), new SqlParameter("@in_SwathWidth", SqlDbType.Decimal), new SqlParameter("@in_GeometryResolution", SqlDbType.Decimal), new SqlParameter("@in_PLATFORM_ID", SqlDbType.Decimal), new SqlParameter("@in_Application", SqlDbType.NVarChar), new SqlParameter("@in_Inclination", SqlDbType.Decimal), new SqlParameter("@in_PixelPerLine", SqlDbType.Decimal), new SqlParameter("@in_SquintAngle", SqlDbType.Decimal), new SqlParameter("@in_AzimuthDirectionResolution", SqlDbType.Decimal), new SqlParameter("@in_DistanceResolution", SqlDbType.Decimal), new SqlParameter("@in_MaxSlewTimesPerCircle", SqlDbType.Decimal), new SqlParameter("@in_MaxPowerOnTimesPerDay", SqlDbType.Decimal), new SqlParameter("@in_MinImagingTimeNonInterupt", SqlDbType.Decimal), new SqlParameter("@in_DuringSwitch", SqlDbType.Decimal), new SqlParameter("@in_MaxObvDur", SqlDbType.Decimal), new SqlParameter("@in_MinObvDur", SqlDbType.Decimal), new SqlParameter("@in_MAXGSD", SqlDbType.Decimal) }; cmdParms[0].Value = model.SensorID; cmdParms[1].Value = model.SensorName; cmdParms[2].Value = model.SensorType; cmdParms[3].Value = model.BandNumber; cmdParms[4].Value = model.BandCenter; cmdParms[5].Value = model.LookAngle; cmdParms[6].Value = model.SwathVelocity; cmdParms[7].Value = model.SwathWidth; cmdParms[8].Value = model.GeometryResolution; cmdParms[9].Value = model.PLATFORM_ID; cmdParms[10].Value = model.Application; cmdParms[11].Value = model.Inclination; cmdParms[12].Value = model.PixelPerLine; cmdParms[13].Value = model.SquintAngle; cmdParms[14].Value = model.AzimuthDirectionResolution; cmdParms[15].Value = model.DistanceResolution; cmdParms[16].Value = model.MaxSlewTimesPerCircle; cmdParms[17].Value = model.MaxPowerOnTimesPerDay; cmdParms[18].Value = model.MinImagingTimeNonInterupt; cmdParms[19].Value = model.DuringSwitch; cmdParms[20].Value = model.MaxObvDur; cmdParms[21].Value = model.MinObvDur; cmdParms[22].Value = model.MAXGSD; return(DbHelperSQL.ExecuteSql(strSql.ToString(), cmdParms));//执行SQL语句,还需修改数据库连接的问题 }
/// <summary> /// 根据传感器ID修改数据库中的一条记录 /// </summary> /// <param name="model"></param>第一类传感器实体类的实例 /// <returns></returns>返回值为修改的记录数 public int Update(Model.Sensor_1 model) { StringBuilder strSql = new StringBuilder(); strSql.Append("Update SENSOR_1 set "); strSql.Append("SensorName=@in_SensorName,"); strSql.Append("SensorType=@in_SensorType,"); strSql.Append("BandNumber=@in_BandNumber,"); strSql.Append("BandCenter=@in_BandCenter,"); strSql.Append("LookAngle=@in_LookAngle,"); strSql.Append("SwathVelocity=@in_SwathVelocity,"); strSql.Append("SwathWidth=@in_SwathWidth,"); strSql.Append("GeometryResolution=@in_GeometryResolution,"); strSql.Append("PLATFORM_ID=@in_PLATFORM_ID,"); strSql.Append("Application=@in_Application,"); strSql.Append("Inclination=@in_Inclination,"); strSql.Append("PixelPerLine=@in_PixelPerLine,"); strSql.Append("SquintAngle=@in_SquintAngle,"); strSql.Append("AzimuthDirectionResolution=@in_AzimuthDirectionResolution,"); strSql.Append("DistanceResolution=@in_DistanceResolution,"); strSql.Append("MaxSlewTimesPerCircle=@in_MaxSlewTimesPerCircle,"); strSql.Append("MaxPowerOnTimesPerDay=@in_MaxPowerOnTimesPerDay,"); strSql.Append("MinImagingTimeNonInterupt=@in_MinImagingTimeNonInterupt,"); strSql.Append("DuringSwitch=@in_DuringSwitch,"); strSql.Append("MaxObvDur=@in_MaxObvDur,"); strSql.Append("MinObvDur=@in_MinObvDur,"); strSql.Append("MAXGSD=@in_MAXGSD"); strSql.Append(" where SensorID=@in_SensorID"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@in_SensorID", SqlDbType.Decimal), new SqlParameter("@in_SensorName", SqlDbType.NVarChar), new SqlParameter("@in_SensorType", SqlDbType.NVarChar), new SqlParameter("@in_BandNumber", SqlDbType.Decimal), new SqlParameter("@in_BandCenter", SqlDbType.Decimal), new SqlParameter("@in_LookAngle", SqlDbType.Decimal), new SqlParameter("@in_SwathVelocity", SqlDbType.Decimal), new SqlParameter("@in_SwathWidth", SqlDbType.Decimal), new SqlParameter("@in_GeometryResolution", SqlDbType.Decimal), new SqlParameter("@in_PLATFORM_ID", SqlDbType.Decimal), new SqlParameter("@in_Application", SqlDbType.NVarChar), new SqlParameter("@in_Inclination", SqlDbType.Decimal), new SqlParameter("@in_PixelPerLine", SqlDbType.Decimal), new SqlParameter("@in_SquintAngle", SqlDbType.Decimal), new SqlParameter("@in_AzimuthDirectionResolution", SqlDbType.Decimal), new SqlParameter("@in_DistanceResolution", SqlDbType.Decimal), new SqlParameter("@in_MaxSlewTimesPerCircle", SqlDbType.Decimal), new SqlParameter("@in_MaxPowerOnTimesPerDay", SqlDbType.Decimal), new SqlParameter("@in_MinImagingTimeNonInterupt", SqlDbType.Decimal), new SqlParameter("@in_DuringSwitch", SqlDbType.Decimal), new SqlParameter("@in_MaxObvDur", SqlDbType.Decimal), new SqlParameter("@in_MinObvDur", SqlDbType.Decimal), new SqlParameter("@in_MAXGSD", SqlDbType.Decimal) }; cmdParms[0].Value = model.SensorID; cmdParms[1].Value = model.SensorName; cmdParms[2].Value = model.SensorType; cmdParms[3].Value = model.BandNumber; cmdParms[4].Value = model.BandCenter; cmdParms[5].Value = model.LookAngle; cmdParms[6].Value = model.SwathVelocity; cmdParms[7].Value = model.SwathWidth; cmdParms[8].Value = model.GeometryResolution; cmdParms[9].Value = model.PLATFORM_ID; cmdParms[10].Value = model.Application; cmdParms[11].Value = model.Inclination; cmdParms[12].Value = model.PixelPerLine; cmdParms[13].Value = model.SquintAngle; cmdParms[14].Value = model.AzimuthDirectionResolution; cmdParms[15].Value = model.DistanceResolution; cmdParms[16].Value = model.MaxSlewTimesPerCircle; cmdParms[17].Value = model.MaxPowerOnTimesPerDay; cmdParms[18].Value = model.MinImagingTimeNonInterupt; cmdParms[19].Value = model.DuringSwitch; cmdParms[20].Value = model.MaxObvDur; cmdParms[21].Value = model.MinObvDur; cmdParms[22].Value = model.MAXGSD; return(DbHelperSQL.ExecuteSql(strSql.ToString(), cmdParms)); }