/// <summary> /// 增加一条数据 /// </summary> public bool Add(InHouseRecordME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into InHouseRecord("); strSql.Append("count,productID,inHouseTime,houseID)"); strSql.Append(" values ("); strSql.Append("@count,@productID,@inHouseTime,@houseID)"); SqlParameter[] parameters = { new SqlParameter("@count", SqlDbType.Int,4), new SqlParameter("@productID", SqlDbType.NVarChar,50), new SqlParameter("@inHouseTime", SqlDbType.Timestamp,8), new SqlParameter("@houseID", SqlDbType.Int,4)}; parameters[0].Value = model.count; parameters[1].Value = model.productID; parameters[2].Value = model.inHouseTime; parameters[3].Value = model.houseID; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringProductDB, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(InHouseRecordME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update InHouseRecord set "); strSql.Append("productID=@productID,"); strSql.Append("houseID=@houseID"); strSql.Append(" where count=@count "); SqlParameter[] parameters = { new SqlParameter("@productID", SqlDbType.NVarChar,50), new SqlParameter("@houseID", SqlDbType.Int,4), new SqlParameter("@count", SqlDbType.Int,4)}; parameters[0].Value = model.productID; parameters[1].Value = model.houseID; parameters[2].Value = model.count; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringProductDB, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public InHouseRecordME GetModel(int count) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 count,productID,inHouseTime,houseID from InHouseRecord "); strSql.Append(" where count=@count "); SqlParameter[] parameters = { new SqlParameter("@count", SqlDbType.Int,4) }; parameters[0].Value = count; InHouseRecordME model=new InHouseRecordME(); DataSet ds = DbHelperSQL.Query(PubConstant.ConnectionStringProductDB, strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["count"]!=null && ds.Tables[0].Rows[0]["count"].ToString()!="") { model.count=int.Parse(ds.Tables[0].Rows[0]["count"].ToString()); } if(ds.Tables[0].Rows[0]["productID"]!=null && ds.Tables[0].Rows[0]["productID"].ToString()!="") { model.productID=ds.Tables[0].Rows[0]["productID"].ToString(); } if(ds.Tables[0].Rows[0]["inHouseTime"]!=null && ds.Tables[0].Rows[0]["inHouseTime"].ToString()!="") { model.inHouseTime=DateTime.Parse(ds.Tables[0].Rows[0]["inHouseTime"].ToString()); } if(ds.Tables[0].Rows[0]["houseID"]!=null && ds.Tables[0].Rows[0]["houseID"].ToString()!="") { model.houseID=int.Parse(ds.Tables[0].Rows[0]["houseID"].ToString()); } return model; } else { return null; } }