/// <summary> /// 根据品种有效申报标识获取有效申报取值实体 /// </summary> /// <param name="BreedClassValidID">品种有效申报标识</param> /// <returns></returns> public ManagementCenter.Model.XH_ValidDeclareValue GetModelValidDeclareValue(int BreedClassValidID) { StringBuilder strSql = new StringBuilder(); strSql.Append( "select ValidDeclareValueID,UpperLimit,LowerLimit,NewDayUpperLimit,NewDayLowerLimit,BreedClassValidID from XH_ValidDeclareValue "); strSql.Append(" where BreedClassValidID=@BreedClassValidID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "BreedClassValidID", DbType.Int32, BreedClassValidID); ManagementCenter.Model.XH_ValidDeclareValue model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 对象实体绑定数据 /// </summary> public ManagementCenter.Model.XH_ValidDeclareValue ReaderBind(IDataReader dataReader) { ManagementCenter.Model.XH_ValidDeclareValue model = new ManagementCenter.Model.XH_ValidDeclareValue(); object ojb; ojb = dataReader["ValidDeclareValueID"]; if (ojb != null && ojb != DBNull.Value) { model.ValidDeclareValueID = (int)ojb; } ojb = dataReader["UpperLimit"]; if (ojb != null && ojb != DBNull.Value) { model.UpperLimit = (decimal)ojb; } ojb = dataReader["LowerLimit"]; if (ojb != null && ojb != DBNull.Value) { model.LowerLimit = (decimal)ojb; } ojb = dataReader["NewDayUpperLimit"]; if (ojb != null && ojb != DBNull.Value) { model.NewDayUpperLimit = (decimal)ojb; } ojb = dataReader["NewDayLowerLimit"]; if (ojb != null && ojb != DBNull.Value) { model.NewDayLowerLimit = (decimal)ojb; } ojb = dataReader["BreedClassValidID"]; if (ojb != null && ojb != DBNull.Value) { model.BreedClassValidID = (int)ojb; } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ManagementCenter.Model.XH_ValidDeclareValue model, DbTransaction tran, Database db) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into XH_ValidDeclareValue("); strSql.Append("UpperLimit,LowerLimit,NewDayUpperLimit,NewDayLowerLimit,BreedClassValidID)"); strSql.Append(" values ("); strSql.Append("@UpperLimit,@LowerLimit,@NewDayUpperLimit,@NewDayLowerLimit,@BreedClassValidID)"); strSql.Append(";select @@IDENTITY"); if (db == null) { db = DatabaseFactory.CreateDatabase(); } DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); if (model.UpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "UpperLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "UpperLimit", DbType.Decimal, model.UpperLimit); } if (model.UpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "LowerLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "LowerLimit", DbType.Decimal, model.LowerLimit); } //db.AddInParameter(dbCommand, "IsMarketNewDay", DbType.Int32, model.IsMarketNewDay); if (model.NewDayUpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "NewDayUpperLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "NewDayUpperLimit", DbType.Decimal, model.NewDayUpperLimit); } if (model.NewDayLowerLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "NewDayLowerLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "NewDayLowerLimit", DbType.Decimal, model.NewDayLowerLimit); } db.AddInParameter(dbCommand, "BreedClassValidID", DbType.Int32, model.BreedClassValidID); if (tran == null) { db.ExecuteNonQuery(dbCommand); } else { db.ExecuteNonQuery(dbCommand, tran); } return(true); // return obj; }
/// <summary> /// 更新有效申报取值 /// </summary> /// <param name="model">有效申报取值实体类</param> /// <returns></returns> public bool Update(ManagementCenter.Model.XH_ValidDeclareValue model) { return(Update(model, null, null)); }
/// <summary> /// 更新有效申报取值 /// </summary> /// <param name="model">有效申报取值实体类</param> /// <param name="tran"></param> /// <param name="db"></param> /// <returns></returns> public bool Update(ManagementCenter.Model.XH_ValidDeclareValue model, DbTransaction tran, Database db) { StringBuilder strSql = new StringBuilder(); strSql.Append("update XH_ValidDeclareValue set "); strSql.Append("UpperLimit=@UpperLimit,"); strSql.Append("LowerLimit=@LowerLimit,"); strSql.Append("NewDayUpperLimit=@NewDayUpperLimit,"); strSql.Append("NewDayLowerLimit=@NewDayLowerLimit"); strSql.Append(" where BreedClassValidID=@BreedClassValidID "); if (db == null) { db = DatabaseFactory.CreateDatabase(); } DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); if (model.UpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "UpperLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "UpperLimit", DbType.Decimal, model.UpperLimit); } if (model.UpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "LowerLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "LowerLimit", DbType.Decimal, model.LowerLimit); } if (model.NewDayUpperLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "NewDayUpperLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "NewDayUpperLimit", DbType.Decimal, model.NewDayUpperLimit); } if (model.NewDayLowerLimit == AppGlobalVariable.INIT_DECIMAL) { db.AddInParameter(dbCommand, "NewDayLowerLimit", DbType.Decimal, DBNull.Value); } else { db.AddInParameter(dbCommand, "NewDayLowerLimit", DbType.Decimal, model.NewDayLowerLimit); } db.AddInParameter(dbCommand, "BreedClassValidID", DbType.Int32, model.BreedClassValidID); //db.ExecuteNonQuery(dbCommand); if (tran == null) { db.ExecuteNonQuery(dbCommand); } else { db.ExecuteNonQuery(dbCommand, tran); } return(true); }
/// <summary> /// 添加有效申报(重载,无事务) /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(ManagementCenter.Model.XH_ValidDeclareValue model) { return(Add(model, null, null)); }